To create a proper interface for the settings on the Options dialog, we use the same application component framework that we used to create the text editor. We start by creating the TextEditorConfigComponent, except this time we use a special derived class of ApplicationComponent called ConfigurationApplicationComponent that provides much of the basic configuration-related support.
using System;
using ClearCanvas.Desktop.Configuration;
namespace MyPlugin.TextEditor
{
public class TextEditorConfigComponent : ConfigurationApplicationComponent
{
public override void Save()
{
throw new Exception("The method or operation is not implemented.");
}
}
}
Any user interface for the settings will need to be able to read, write, and be notified of changes to the settings, so we add a public property to access the setting.
using System;
using ClearCanvas.Desktop.Configuration;
namespace MyPlugin.TextEditor
{
public class TextEditorConfigComponent : ConfigurationApplicationComponent
{
private bool _wordWrap;
public bool WordWrap
{
get { return _wordWrap; }
set
{
if (_wordWrap != value)
{
_wordWrap = value;
base.NotifyPropertyChanged("WordWrap");
base.Modified = true;
}
}
}
public override void Start()
{
base.Start();
}
public override void Save()
{
throw new Exception("The method or operation is not implemented.");
}
}
}
Of course, the settings class is the one that is actually storing and persisting the value of the setting, so we need to make sure we read from the settings store when the component is started, and write to it when the Save() method is called.
public override void Start()
{
_wordWrap = TextEditorSettings.Default.WordWrap;
base.Start();
}
public override void Save()
{
TextEditorSettings.Default.WordWrap = _wordWrap;
TextEditorSettings.Default.Save();
}
As with the TextEditorComponent, we will need to create a view extension point and associate it with our configuration component.
using ClearCanvas.Common;
using ClearCanvas.Desktop;
using ClearCanvas.Desktop.Configuration;
namespace MyPlugin.TextEditor
{
[ExtensionPoint]
public class TextEditorConfigComponentViewExtensionPoint : ExtensionPoint<IApplicationComponentView> {}
[AssociateView(typeof (TextEditorConfigComponentViewExtensionPoint))]
public class TextEditorConfigComponent : ConfigurationApplicationComponent
{
}
}
The actual view control just needs a CheckBox control that is bound to the WordWrap property. If we follow the same steps that we used to create TextEditorComponentView and TextEditorControl, we should end up with something similar to the following:
using System.Windows.Forms;
namespace MyPlugin.TextEditor
{
public partial class TextEditorConfigControl : UserControl
{
private TextEditorConfigComponent _component;
public TextEditorConfigControl(TextEditorConfigComponent component)
{
InitializeComponent();
_component = component;
_chkWordWrap.DataBindings.Add("Checked", _component,
"WordWrap", false,
DataSourceUpdateMode.OnPropertyChanged);
}
}
}
using ClearCanvas.Common;
using ClearCanvas.Desktop;
using ClearCanvas.Desktop.View.WinForms;
namespace MyPlugin.TextEditor
{
[ExtensionOf(typeof (TextEditorConfigComponentViewExtensionPoint))]
public class TextEditorConfigComponentView : WinFormsView, IApplicationComponentView
{
private TextEditorConfigComponent _component;
private TextEditorConfigControl _control;
public void SetComponent(IApplicationComponent component)
{
_component = (TextEditorConfigComponent) component;
}
public override object GuiElement
{
get
{
if (_control == null)
{
_control = new TextEditorConfigControl(_component);
}
return _control;
}
}
}
}