Adding a Settings UI to our Batch Task
Add a settings page to your batch task so that users can select the status that defines whether the content of a particular segment pair shall be exported to a text file.
The User Control
In your Visual Studio project, go to the empty MyCustomBatchTaskSettingsControl.cs control and add the following UI elements:
Add the following list items to the dropdown list element (which we name combo_Status):
- Unspecified
- Draft
- Translated
- Approved
- Rejected
- Signed-off
- Sign-off rejected
The Class that Controls the Plug-in Settings
Open the MyCustomBatchTaskSettings.cs class, which has been automatically added to your Visual Studio project. This is the class that we use to programmatically access the settings configured by the elements on the user control UI.
This class needs to inherit the following class:
// The settings class needs to implement the SettingsGroup interface
public class MyCustomBatchTaskSettings : SettingsGroup
Here we declare the default setting value, which is the integer value '2' and corresponds to the confirmation level 'Translated':
// We set the default confirmation leve to 2, which corresponds to the 'Translated' status
private readonly int _confirmationLevel = 2;
The following member gets or to sets the value used for the plug-in settings. In this implementation there is only one integer value that defines the confirmation level:
// Retrieves and sets the segment status value
public int ConfirmationLevelSetting
{
get { return GetSetting<int>(nameof(ConfirmationLevelSetting)); }
set { GetSetting<int>(nameof(ConfirmationLevelSetting)).Value = value; }
}
Then we add the following member, which sets the confirmation property to the default value when the user clicks the corresponding button on the UI.
// When the user clicks the Restore defaults button
// The default segment status, i.e. 'Translated' (2) should be set
public void ResetToDefaults()
{
ConfirmationLevelSetting = _confirmationLevel;
}
Finally, the following member is added to retrieve the default value for the confirmation level property of our implementation:
// Gets the the default segment status value
protected override object GetDefaultValue(string settingId)
{
switch (settingId)
{
case nameof(ConfirmationLevelSetting):
return _confirmationLevel;
}
return base.GetDefaultValue(settingId);
}
Adding Functionality to the User Control
Open the code view of the user control MyCustomBatchTaskSettingsControl.cs. This control implements the following interfaces:
// The visible UI control needs to implement the following interfaces:
public partial class MyCustomBatchTaskSettingsControl : UserControl, ISettingsAware<MyCustomBatchTaskSettings>
The following mandatory member needs to be implemented to set and get the settings properties from the MyCustomBatchTaskSettings class:
// Member that refers to the batch task settings
public MyCustomBatchTaskSettings Settings { get; set; }
The following member initializes the user control:
// Initializes the UI component
public MyCustomBatchTaskSettingsControl()
{
InitializeComponent();
}
The following member sets the settings on the UI control:
public void SetSettings(MyCustomBatchTaskSettings taskSettings)
{
// sets the UI element, i.e. the status dropdown list to the corresponding segment status value
Settings = taskSettings;
SettingsBinder.DataBindSetting<int>(combo_Status, "SelectedIndex", Settings, nameof(Settings.ConfirmationLevelSetting));
UpdateUI(taskSettings);
}
The following member updates the settings on the UI control:
public void UpdateSettings(MyCustomBatchTaskSettings mySettings)
{
Settings = mySettings;
}
The above member is called by the following function:
// Updates the UI elements to the corresponding settings
public void UpdateUI(MyCustomBatchTaskSettings mySettings)
{
Settings = mySettings;
this.UpdateSettings(Settings);
}
When the UI control is loaded, its control elements are populated with the corresponding values:
// The control elements on the UI are configured with the corresponding values
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.SetSettings(Settings);
}
When the user clicks the Restore Defaults button, the UI controls are set to their default values:
// Set dropbown control to the default value 'Translate' (2) when the user
// clicks the Restore Defaults button
private void btn_Reset_Click(object sender, EventArgs e)
{
Settings.ResetToDefaults();
this.UpdateUI(Settings);
}
The Settings UI Container
Note the MyCustomBatchTaskSettingsPage.cs class, which has been added to the project by default. This is the class that references the settings UI and the class that controls the UI. Without the settings page class the plug-in would not be aware of the settings UI. It enables the settings UI to be shown when you reach the Settings page of the plug-in:
Note
Leave this class as it is, you do not have to change anything here.