| Enhancing the File Parser to Process the Settings |
Now that you have implemented the user interface for configuring the file type plug-in settings as well as the functionality to load and save these settings, you need to extend your file parser class to make it 'aware' of the settings, so that they can be taken into consideration when processing a given file.
First, you need to make sure that your parser class also uses the following, additional namespaces:
Then your parser class needs to implement the ISettingsAware interface, which makes it 'aware' of the plug-in settings and provides the method that allows it to initialize the settings.
In the next step, add the following boolean property to your parser class:
public bool LockPrdCodes { get; set; }
Then, use the InitializeSettings method of the interface to initialize the plug-in setting. Within this method, we call on the UserSettings class and apply the PopulateFromSettingsBundle method to retrieve the current plug-in configuration and then set the LockPrdCodes of the main verifier component accordingly.
public void InitializeSettings(Sdl.Core.Settings.ISettingsBundle settingsBundle, string configurationId) { UserSettings _userSettings = new UserSettings(); _userSettings.PopulateFromSettingsBundle(settingsBundle, configurationId); LockPrdCodes = _userSettings.LockPrdCodes; }
Modify the ProcessLine() helper function so that it triggers WriteLockedContent() only if the current line starts with the Prd-Code string and if LockPrdCodes equals True.
// determines whether a given line is // translatable or not // if not, a structure tag is output // otherwise, the translatable text is exposed private void ProcessLine(string sLine) { if (sLine.StartsWith("[") && sLine.EndsWith("]")) { WriteStructureTag(sLine); WriteContext(sLine); } else if (sLine.StartsWith("Prd-Code") && LockPrdCodes==true) { WriteLockedContent(sLine); } else { WriteText(ProcessFormatting(sLine)); } }