I've made some changes to Options menu processing to implement the following features. Nice how some small changes amplifies developer abilities. I guess that's due to a well programmed framework and MEF.
- Allow developer to specify custom OptionsDialog class.
- Clean up of custom OptionsDialogView feature.
- Correct issue occurring with second invocation of OptionsDialogView.ShowDialog.
Changes to ToolMenu.cs
// patch - begin
[Import(CompositionPoints.Options.OptionsDialog, typeof(IOptionsDialog))]
private IOptionsDialog optionsDialog { get; set; }
[Import(ExtensionPoints.Options.OptionsDialog.View, typeof(Lazy<IWindowFactory>), AllowDefault=true, AllowRecomposition = true)]
private Lazy<IWindowFactory> optionsDialogViewWF { get; set; }
protected override void Run()
{
if (optionsDialog == null)
optionsDialog = new OptionsDialog();
optionsDialog.ShowDialog(optionsDialogViewWF == null ? new OptionsDialogView() : optionsDialogViewWF.Value.CreateWindow());
}
}
// patch - should be moved to a more appropriate location
public interface IOptionsDialog
{
void ShowDialog(Window optionsDialogView);
}
// patch - should be moved to a more appropriate location
public interface IWindowFactory
{
Window CreateWindow();
}
// patch - end
Changes to OptionsDialog.cs
// patch - removed [Export(CompositionPoints.Options.OptionsDialog,
typeof(IOptionsDialog))]
class OptionsDialog : AbstractOptionsItem,
IOptionsDialog, IPartImportsSatisfiedNotification // patch - insert IOptionsDialog
asked
11 Sep '10, 10:16
BSalita
276●11●14●17
accept rate:
22%
I bow to your superior MEF-ness. :) Using the optional import is much cleaner. I am ashamed to admit I didn't even know about the AllowDefault=true parameter. Heh.
My instincts told me the feature should be there -- and there it was.
Do we really need IWindowFactory, or will Lazy< Window > still work? And the first import requires AllowDefault=true as well, right?
Yes, IWindowFactory is needed. AFAIK, Window.ShowDialog closes the Window rendering the singleton MEF unusable for future use. A second Option Menu call on the same Window MEF object will fail because it was closed by the first ShowDialog. Instead, a factory must be called to make an instance of Window each time. Therefore, IWindowFactory is required.
Yes, I agree I should have put AllowDefault=true in the first Import because I removed the Export of SoapBox's OptionDialog. Therefore, SoapBox will no longer Export OptionDialog. The only possible Export will be the developer's custom OptionDialog, if present. AllowDefault=true is needed because the exporting is optional.
Got it. I'll be releasing a new version today (Version 2010.09.11). It will include all outstanding feature requests, including this. I'll post my code below for a review.