Options system
In ReSharper, options are centralized in a single modal dialog, displaying option pages. Option pages are organized in a tree using same technique as in action system - specifying parent and anchoring point. In order to create option page one has to create UserControl, attach OptionsPage attribute and implement IOptionsPage interface. Constructor of the options page should receive single parameter of IOptionsUI type:
Example of simple option page
Below is simple options page without .Designer.cs parts. Attribute specifies attributes and position in options tree. IOptionsUI parameter is not used here, see Cyclomatic Complexity power toy for example of its use.
[OptionsPage( "MyPluginOptions", // Page ID "My Plugin Options", // Title "MyPlugin.Icon.png", // Icon resource id InsertionPosition = PageInsertionPosition.AFTER, // Position relative to anchor ParentId = "HighlightingPage", // Parent ID AnchorId = "ValueAnalysisPage") // Anchor ID ] public partial class MyPluginOptionsPage : UserControl, IOptionsPage { public MyPluginOptionsPage( IOptionsUI optionsUI ) { InitializeComponent(); } public void InitializeUI() { myEditor.Value = MyPlugin.Threshold; } public void OnActivated(bool activated) // Called when page becomes active or inactive { } public bool ValidatePage() // Verifies if page has consistent state { return true; } public bool OnOk() // Options dialog is closed with OK button, apply changes { MyPlugin.Threshold = (int) myEditor.Value; return true; } public Control Control { get { return this; } } }
References
JetBrains.ReSharper.IDECore.dll – provides constants and types specific to ReSharper environment
JetBrains.ReSharper.Util.dll – contains utility classes used throughout the project