Browse Source

Don't use lazy loading for built-in WPF commands.

pull/520/merge
Daniel Grunwald 11 years ago
parent
commit
e5dde6f4ac
  1. 11
      src/Main/Core/Project/Src/Util/CommandWrapper.cs
  2. 7
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs
  3. 3
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs
  4. 7
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs
  5. 4
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs
  6. 12
      src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs
  7. 2
      src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs

11
src/Main/Core/Project/Src/Util/CommandWrapper.cs

@ -44,6 +44,17 @@ namespace ICSharpCode.Core @@ -44,6 +44,17 @@ namespace ICSharpCode.Core
/// </summary>
public static ICommand CreateLazyCommand(Codon codon, IReadOnlyCollection<ICondition> conditions)
{
if (codon.Properties["loadclasslazy"] == "false") {
// if lazy loading was explicitly disabled, create the actual command now
return CreateCommand(codon, conditions);
}
if (codon.Properties.Contains("command") && !codon.Properties.Contains("loadclasslazy")) {
// If we're using the 'command=' syntax, this is most likely a built-in command
// where lazy loading isn't useful (and hurts if CanExecute is used).
// Don't use lazy loading unless loadclasslazy is set explicitly.
return CreateCommand(codon, conditions);
}
// Create the wrapper that lazily loads the actual command.
return new CommandWrapper(codon, conditions);
}

7
src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs

@ -32,13 +32,10 @@ namespace ICSharpCode.Core.Presentation @@ -32,13 +32,10 @@ namespace ICSharpCode.Core.Presentation
{
readonly string ActivationMethod;
public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, string activationMethod, IReadOnlyCollection<ICondition> conditions) : base(codon, caller, conditions)
public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, string activationMethod, IReadOnlyCollection<ICondition> conditions) : base(codon, caller, conditions)
{
this.ActivationMethod = activationMethod;
if (createCommand)
this.Command = CommandWrapper.CreateCommand(codon, conditions);
else
this.Command = CommandWrapper.CreateLazyCommand(codon, conditions);
this.Command = CommandWrapper.CreateLazyCommand(codon, conditions);
this.CommandParameter = caller;
if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) {

3
src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs

@ -211,7 +211,6 @@ namespace ICSharpCode.Core.Presentation @@ -211,7 +211,6 @@ namespace ICSharpCode.Core.Presentation
{
Codon codon = descriptor.Codon;
string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
bool createCommand = codon.Properties["loadclasslazy"] == "false";
switch (type) {
case "Separator":
@ -220,7 +219,7 @@ namespace ICSharpCode.Core.Presentation @@ -220,7 +219,7 @@ namespace ICSharpCode.Core.Presentation
return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Parameter, descriptor.Conditions);
case "Item":
case "Command":
return new MenuCommand(context.InputBindingOwner, codon, descriptor.Parameter, createCommand, context.ActivationMethod, descriptor.Conditions);
return new MenuCommand(context.InputBindingOwner, codon, descriptor.Parameter, context.ActivationMethod, descriptor.Conditions);
case "Menu":
var item = new CoreMenuItem(codon, descriptor.Parameter, descriptor.Conditions) {
ItemsSource = new object[1],

7
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs

@ -36,16 +36,13 @@ namespace ICSharpCode.Core.Presentation @@ -36,16 +36,13 @@ namespace ICSharpCode.Core.Presentation
readonly string inputGestureText;
readonly IEnumerable<ICondition> conditions;
public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, IReadOnlyCollection<ICondition> conditions)
public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, IReadOnlyCollection<ICondition> conditions)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
if (createCommand)
this.Command = CommandWrapper.CreateCommand(codon, conditions);
else
this.Command = CommandWrapper.CreateLazyCommand(codon, conditions);
this.Command = CommandWrapper.CreateLazyCommand(codon, conditions);
this.CommandParameter = caller;
this.Content = ToolBarService.CreateToolBarItemContent(codon);
this.conditions = conditions;

4
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs

@ -65,15 +65,13 @@ namespace ICSharpCode.Core.Presentation @@ -65,15 +65,13 @@ namespace ICSharpCode.Core.Presentation
object caller = descriptor.Parameter;
string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Item";
bool createCommand = codon.Properties["loadclasslazy"] == "false";
switch (type) {
case "Separator":
return new ConditionalSeparator(codon, caller, true, descriptor.Conditions);
case "CheckBox":
return new ToolBarCheckBox(codon, caller, descriptor.Conditions);
case "Item":
return new ToolBarButton(inputBindingOwner, codon, caller, createCommand, descriptor.Conditions);
return new ToolBarButton(inputBindingOwner, codon, caller, descriptor.Conditions);
case "DropDownButton":
return new ToolBarDropDownButton(
codon, caller, MenuService.CreateUnexpandedMenuItems(

12
src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs

@ -43,23 +43,13 @@ namespace ICSharpCode.Core.WinForms @@ -43,23 +43,13 @@ namespace ICSharpCode.Core.WinForms
}
public MenuCommand(Codon codon, object caller, IReadOnlyCollection<ICondition> conditions)
: this(codon, caller, false, conditions)
{
}
public MenuCommand(Codon codon, object caller, bool createCommand, IReadOnlyCollection<ICondition> conditions)
{
this.RightToLeft = RightToLeft.Inherit;
this.caller = caller;
this.codon = codon;
this.conditions = conditions;
if (createCommand) {
this.command = CommandWrapper.CreateCommand(codon, conditions);
} else {
this.command = CommandWrapper.CreateLazyCommand(codon, conditions);
}
this.command = CommandWrapper.CreateLazyCommand(codon, conditions);
UpdateText();
}

2
src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.Core.WinForms @@ -62,7 +62,7 @@ namespace ICSharpCode.Core.WinForms
return new MenuCheckBox(codon, descriptor.Parameter, descriptor.Conditions);
case "Item":
case "Command":
return new MenuCommand(codon, descriptor.Parameter, createCommand, descriptor.Conditions);
return new MenuCommand(codon, descriptor.Parameter, descriptor.Conditions);
case "Menu":
return new Menu(codon, descriptor.Parameter, ConvertSubItems(descriptor.SubItems), descriptor.Conditions);
case "Builder":

Loading…
Cancel
Save