Browse Source

mark Codon.GetFailedAction obsolete, because it does not check inherited conditions

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
f1c64399e9
  1. 1
      src/Main/Core/Project/Src/AddInTree/AddIn/Codon.cs
  2. 8
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/MenuItem/MenuItemDoozer.cs
  3. 7
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/ToolBarItemDoozer.cs
  4. 7
      src/Main/ICSharpCode.Core.Presentation/ConditionalSeparator.cs
  5. 7
      src/Main/ICSharpCode.Core.Presentation/Menu/CoreMenuItem.cs
  6. 7
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCheckBox.cs
  7. 25
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs
  8. 8
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs
  9. 9
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs
  10. 9
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarCheckBox.cs
  11. 7
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarComboBox.cs
  12. 7
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarDropDownButton.cs
  13. 12
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs
  14. 9
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarSplitButton.cs

1
src/Main/Core/Project/Src/AddInTree/AddIn/Codon.cs

@ -74,6 +74,7 @@ namespace ICSharpCode.Core @@ -74,6 +74,7 @@ namespace ICSharpCode.Core
this.conditions = conditions;
}
[Obsolete("Use BuildItemArgs.Conditions instead")]
public ConditionFailedAction GetFailedAction(object caller)
{
return Condition.GetFailedAction(conditions, caller);

8
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/MenuItem/MenuItemDoozer.cs

@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.Core
{
@ -63,7 +65,7 @@ namespace ICSharpCode.Core @@ -63,7 +65,7 @@ namespace ICSharpCode.Core
public object BuildItem(BuildItemArgs args)
{
return new MenuItemDescriptor(args.Caller, args.Codon, args.BuildSubItems<object>());
return new MenuItemDescriptor(args.Caller, args.Codon, args.BuildSubItems<object>(), args.Conditions);
}
}
@ -76,14 +78,16 @@ namespace ICSharpCode.Core @@ -76,14 +78,16 @@ namespace ICSharpCode.Core
public readonly object Caller;
public readonly Codon Codon;
public readonly IList SubItems;
public readonly IEnumerable<ICondition> Conditions;
public MenuItemDescriptor(object caller, Codon codon, IList subItems)
public MenuItemDescriptor(object caller, Codon codon, IList subItems, IEnumerable<ICondition> conditions)
{
if (codon == null)
throw new ArgumentNullException("codon");
this.Caller = caller;
this.Codon = codon;
this.SubItems = subItems;
this.Conditions = conditions;
}
}
}

7
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/ToolBarItemDoozer.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.Core
{
@ -53,7 +54,7 @@ namespace ICSharpCode.Core @@ -53,7 +54,7 @@ namespace ICSharpCode.Core
public object BuildItem(BuildItemArgs args)
{
return new ToolbarItemDescriptor(args.Caller, args.Codon, args.BuildSubItems<object>());
return new ToolbarItemDescriptor(args.Caller, args.Codon, args.BuildSubItems<object>(), args.Conditions);
}
}
@ -66,12 +67,14 @@ namespace ICSharpCode.Core @@ -66,12 +67,14 @@ namespace ICSharpCode.Core
public readonly object Caller;
public readonly Codon Codon;
public readonly IList SubItems;
public readonly IEnumerable<ICondition> Conditions;
public ToolbarItemDescriptor(object caller, Codon codon, IList subItems)
public ToolbarItemDescriptor(object caller, Codon codon, IList subItems, IEnumerable<ICondition> conditions)
{
this.Caller = caller;
this.Codon = codon;
this.SubItems = subItems;
this.Conditions = conditions;
}
}
}

7
src/Main/ICSharpCode.Core.Presentation/ConditionalSeparator.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
@ -14,11 +15,13 @@ namespace ICSharpCode.Core.Presentation @@ -14,11 +15,13 @@ namespace ICSharpCode.Core.Presentation
{
readonly Codon codon;
readonly object caller;
readonly IEnumerable<ICondition> conditions;
public ConditionalSeparator(Codon codon, object caller, bool inToolbar)
public ConditionalSeparator(Codon codon, object caller, bool inToolbar, IEnumerable<ICondition> conditions)
{
this.codon = codon;
this.caller = caller;
this.conditions = conditions;
if (inToolbar) {
SetResourceReference(FrameworkElement.StyleProperty, ToolBar.SeparatorStyleKey);
@ -31,7 +34,7 @@ namespace ICSharpCode.Core.Presentation @@ -31,7 +34,7 @@ namespace ICSharpCode.Core.Presentation
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
if (Condition.GetFailedAction(conditions, caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;

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

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -16,6 +17,7 @@ namespace ICSharpCode.Core.Presentation @@ -16,6 +17,7 @@ namespace ICSharpCode.Core.Presentation
{
protected readonly Codon codon;
protected readonly object caller;
protected readonly IEnumerable<ICondition> conditions;
/// <summary>
/// If true, UpdateStatus() sets the enabled flag.
@ -23,10 +25,11 @@ namespace ICSharpCode.Core.Presentation @@ -23,10 +25,11 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
internal bool SetEnabled;
public CoreMenuItem(Codon codon, object caller)
public CoreMenuItem(Codon codon, object caller, IEnumerable<ICondition> conditions)
{
this.codon = codon;
this.caller = caller;
this.conditions = conditions;
if (codon.Properties.Contains("icon")) {
try {
@ -47,7 +50,7 @@ namespace ICSharpCode.Core.Presentation @@ -47,7 +50,7 @@ namespace ICSharpCode.Core.Presentation
public virtual void UpdateStatus()
{
ConditionFailedAction result = codon.GetFailedAction(caller);
ConditionFailedAction result = Condition.GetFailedAction(conditions, caller);
if (result == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else

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

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows;
using System.Windows.Data;
@ -14,10 +15,10 @@ namespace ICSharpCode.Core.Presentation @@ -14,10 +15,10 @@ namespace ICSharpCode.Core.Presentation
{
BindingExpressionBase isCheckedBinding;
public MenuCheckBox(UIElement inputBindingOwner, Codon codon, object caller)
: base(codon, caller)
public MenuCheckBox(UIElement inputBindingOwner, Codon codon, object caller, IEnumerable<ICondition> conditions)
: base(codon, caller, conditions)
{
this.Command = CommandWrapper.GetCommand(codon, caller, true);
this.Command = CommandWrapper.GetCommand(codon, caller, true, conditions);
CommandWrapper wrapper = this.Command as CommandWrapper;
if (wrapper != null) {
ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand;

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

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
@ -15,7 +15,7 @@ namespace ICSharpCode.Core.Presentation @@ -15,7 +15,7 @@ namespace ICSharpCode.Core.Presentation
{
class CommandWrapper : System.Windows.Input.ICommand
{
public static System.Windows.Input.ICommand GetCommand(Codon codon, object caller, bool createCommand)
public static System.Windows.Input.ICommand GetCommand(Codon codon, object caller, bool createCommand, IEnumerable<ICondition> conditions)
{
string commandName = codon.Properties["command"];
if (!string.IsNullOrEmpty(commandName)) {
@ -25,32 +25,39 @@ namespace ICSharpCode.Core.Presentation @@ -25,32 +25,39 @@ namespace ICSharpCode.Core.Presentation
} else {
MessageService.ShowError("Could not find WPF command '" + commandName + "'.");
// return dummy command
return new CommandWrapper(codon, caller, null);
return new CommandWrapper(codon, caller, null, conditions);
}
}
return new CommandWrapper(codon, caller, createCommand);
return new CommandWrapper(codon, caller, createCommand, conditions);
}
bool commandCreated;
ICommand addInCommand;
IEnumerable<ICondition> conditions;
readonly Codon codon;
readonly object caller;
public CommandWrapper(Codon codon, object caller, bool createCommand)
public CommandWrapper(Codon codon, object caller, bool createCommand, IEnumerable<ICondition> conditions)
{
if (conditions == null)
throw new ArgumentNullException("conditions");
this.codon = codon;
this.caller = caller;
this.conditions = conditions;
if (createCommand) {
commandCreated = true;
CreateCommand();
}
}
public CommandWrapper(Codon codon, object caller, ICommand command)
public CommandWrapper(Codon codon, object caller, ICommand command, IEnumerable<ICondition> conditions)
{
if (conditions == null)
throw new ArgumentNullException("conditions");
this.codon = codon;
this.caller = caller;
this.addInCommand = command;
this.conditions = conditions;
commandCreated = true;
}
@ -103,7 +110,7 @@ namespace ICSharpCode.Core.Presentation @@ -103,7 +110,7 @@ namespace ICSharpCode.Core.Presentation
public bool CanExecute(object parameter)
{
//LoggingService.Debug("CanExecute " + codon.Id);
if (codon.GetFailedAction(caller) != ConditionFailedAction.Nothing)
if (Condition.GetFailedAction(conditions, caller) != ConditionFailedAction.Nothing)
return false;
if (!commandCreated)
return true;
@ -122,10 +129,10 @@ namespace ICSharpCode.Core.Presentation @@ -122,10 +129,10 @@ namespace ICSharpCode.Core.Presentation
{
readonly string ActivationMethod;
public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, string activationMethod) : base(codon, caller)
public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, string activationMethod, IEnumerable<ICondition> conditions) : base(codon, caller, conditions)
{
this.ActivationMethod = activationMethod;
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand, conditions);
if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) {
KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);

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

@ -212,14 +212,14 @@ namespace ICSharpCode.Core.Presentation @@ -212,14 +212,14 @@ namespace ICSharpCode.Core.Presentation
switch (type) {
case "Separator":
return new ConditionalSeparator(codon, descriptor.Caller, false);
return new ConditionalSeparator(codon, descriptor.Caller, false, descriptor.Conditions);
case "CheckBox":
return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Caller);
return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Caller, descriptor.Conditions);
case "Item":
case "Command":
return new MenuCommand(context.InputBindingOwner, codon, descriptor.Caller, createCommand, context.ActivationMethod);
return new MenuCommand(context.InputBindingOwner, codon, descriptor.Caller, createCommand, context.ActivationMethod, descriptor.Conditions);
case "Menu":
var item = new CoreMenuItem(codon, descriptor.Caller) {
var item = new CoreMenuItem(codon, descriptor.Caller, descriptor.Conditions) {
ItemsSource = new object[1],
SetEnabled = true
};

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

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
@ -18,15 +19,17 @@ namespace ICSharpCode.Core.Presentation @@ -18,15 +19,17 @@ namespace ICSharpCode.Core.Presentation
readonly Codon codon;
readonly object caller;
readonly string inputGestureText;
readonly IEnumerable<ICondition> conditions;
public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand)
public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, IEnumerable<ICondition> conditions)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand, conditions);
this.Content = ToolBarService.CreateToolBarItemContent(codon);
this.conditions = conditions;
if (codon.Properties.Contains("name")) {
this.Name = codon.Properties["name"];
@ -73,7 +76,7 @@ namespace ICSharpCode.Core.Presentation @@ -73,7 +76,7 @@ namespace ICSharpCode.Core.Presentation
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
if (Condition.GetFailedAction(conditions, caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;

9
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarCheckBox.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@ -15,14 +16,16 @@ namespace ICSharpCode.Core.Presentation @@ -15,14 +16,16 @@ namespace ICSharpCode.Core.Presentation
readonly Codon codon;
readonly object caller;
BindingExpressionBase isCheckedBinding;
readonly IEnumerable<ICondition> conditions;
public ToolBarCheckBox(Codon codon, object caller)
public ToolBarCheckBox(Codon codon, object caller, IEnumerable<ICondition> conditions)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
this.Command = CommandWrapper.GetCommand(codon, caller, true);
this.conditions = conditions;
this.Command = CommandWrapper.GetCommand(codon, caller, true, conditions);
CommandWrapper wrapper = this.Command as CommandWrapper;
if (wrapper != null) {
ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand;
@ -49,7 +52,7 @@ namespace ICSharpCode.Core.Presentation @@ -49,7 +52,7 @@ namespace ICSharpCode.Core.Presentation
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
if (Condition.GetFailedAction(conditions, caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;

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

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
@ -12,13 +13,15 @@ namespace ICSharpCode.Core.Presentation @@ -12,13 +13,15 @@ namespace ICSharpCode.Core.Presentation
IComboBoxCommand menuCommand;
readonly Codon codon;
readonly object caller;
readonly IEnumerable<ICondition> conditions;
public ToolBarComboBox(Codon codon, object caller)
public ToolBarComboBox(Codon codon, object caller, IEnumerable<ICondition> conditions)
{
if (codon == null)
throw new ArgumentNullException("codon");
this.codon = codon;
this.caller = caller;
this.conditions = conditions;
ToolTipService.SetShowOnDisabled(this, true);
this.IsEditable = false;
menuCommand = (IComboBoxCommand)codon.AddIn.CreateObject(codon.Properties["class"]);
@ -38,7 +41,7 @@ namespace ICSharpCode.Core.Presentation @@ -38,7 +41,7 @@ namespace ICSharpCode.Core.Presentation
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
if (Condition.GetFailedAction(conditions, caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;

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

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
@ -15,13 +16,15 @@ namespace ICSharpCode.Core.Presentation @@ -15,13 +16,15 @@ namespace ICSharpCode.Core.Presentation
{
readonly Codon codon;
readonly object caller;
readonly IEnumerable<ICondition> conditions;
public ToolBarDropDownButton(Codon codon, object caller, IList subMenu)
public ToolBarDropDownButton(Codon codon, object caller, IList subMenu, IEnumerable<ICondition> conditions)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
this.conditions = conditions;
this.Content = ToolBarService.CreateToolBarItemContent(codon);
if (codon.Properties.Contains("name")) {
@ -40,7 +43,7 @@ namespace ICSharpCode.Core.Presentation @@ -40,7 +43,7 @@ namespace ICSharpCode.Core.Presentation
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
if (Condition.GetFailedAction(conditions, caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;

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

@ -54,13 +54,13 @@ namespace ICSharpCode.Core.Presentation @@ -54,13 +54,13 @@ namespace ICSharpCode.Core.Presentation
switch (type) {
case "Separator":
return new ConditionalSeparator(codon, caller, true);
return new ConditionalSeparator(codon, caller, true, descriptor.Conditions);
case "CheckBox":
return new ToolBarCheckBox(codon, caller);
return new ToolBarCheckBox(codon, caller, descriptor.Conditions);
case "Item":
return new ToolBarButton(inputBindingOwner, codon, caller, createCommand);
return new ToolBarButton(inputBindingOwner, codon, caller, createCommand, descriptor.Conditions);
case "ComboBox":
return new ToolBarComboBox(codon, caller);
return new ToolBarComboBox(codon, caller, descriptor.Conditions);
case "TextBox":
return "TextBox";
//return new ToolBarTextBox(codon, caller);
@ -71,12 +71,12 @@ namespace ICSharpCode.Core.Presentation @@ -71,12 +71,12 @@ namespace ICSharpCode.Core.Presentation
return new ToolBarDropDownButton(
codon, caller, MenuService.CreateUnexpandedMenuItems(
new MenuService.MenuCreateContext { ActivationMethod = "ToolbarDropDownMenu" },
descriptor.SubItems));
descriptor.SubItems), descriptor.Conditions);
case "SplitButton":
return new ToolBarSplitButton(
codon, caller, MenuService.CreateUnexpandedMenuItems(
new MenuService.MenuCreateContext { ActivationMethod = "ToolbarDropDownMenu" },
descriptor.SubItems));
descriptor.SubItems), descriptor.Conditions);
case "Builder":
object result = codon.AddIn.CreateObject(codon.Properties["class"]);
if (result is IToolBarItemBuilder)

9
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarSplitButton.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
@ -16,13 +17,15 @@ namespace ICSharpCode.Core.Presentation @@ -16,13 +17,15 @@ namespace ICSharpCode.Core.Presentation
ICommand menuCommand;
object caller;
Codon codon;
IEnumerable<ICondition> conditions;
public ToolBarSplitButton(Codon codon, object caller, IList submenu)
public ToolBarSplitButton(Codon codon, object caller, IList submenu, IEnumerable<ICondition> conditions)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
this.conditions = conditions;
this.Content = ToolBarService.CreateToolBarItemContent(codon);
if (codon.Properties.Contains("name")) {
@ -32,7 +35,7 @@ namespace ICSharpCode.Core.Presentation @@ -32,7 +35,7 @@ namespace ICSharpCode.Core.Presentation
menuCommand = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
menuCommand.Owner = this;
this.Command = new CommandWrapper(codon, caller, menuCommand);
this.Command = new CommandWrapper(codon, caller, menuCommand, conditions);
this.DropDownMenu = MenuService.CreateContextMenu(submenu);
UpdateText();
@ -47,7 +50,7 @@ namespace ICSharpCode.Core.Presentation @@ -47,7 +50,7 @@ namespace ICSharpCode.Core.Presentation
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
if (Condition.GetFailedAction(conditions, caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;

Loading…
Cancel
Save