Browse Source

Display MenuItem shortcuts in shortcuts management dialog. Allow modifying link commands

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4276 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts^2
Sergej Andrejev 16 years ago
parent
commit
dd36269a67
  1. 15
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 15
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  3. BIN
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement.suo
  4. 2
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.addin
  5. 2
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/GesturesCollectionConverter.cs
  6. 9
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/AddIn.cs
  7. 1
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs
  8. 11
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutCategory.cs
  9. 9
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutsFinder.cs
  10. 33
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs
  11. 2
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsTreeView.xaml.cs
  12. 17
      src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs
  13. 15
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs
  14. 13
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  15. 20
      src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
  16. 33
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandBindingInfo.cs
  17. 179
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandsRegistry.cs
  18. 4
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandsService.cs
  19. 22
      src/Main/ICSharpCode.Core.Presentation/CommandsService/InputBindingInfo.cs
  20. 67
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs
  21. 6
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs
  22. 34
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs

15
AddIns/ICSharpCode.SharpDevelop.addin

@ -72,7 +72,6 @@ @@ -72,7 +72,6 @@
<RoutedUICommand name="SDProjectCommands.ShowSelectedProjectBrowserNodeProperties" text="${res:MainWindow.Windows.PropertiesScoutLabel}" />
<RoutedUICommand name="SDProjectCommands.ShowHiddenFilesInProjectBrowser" text="${res:Gui.ProjectBrowser.ShowAllFiles}" />
<RoutedUICommand name="SDProjectCommands.RefreshProjectBrowser" text="${res:AddIns.HtmlHelp2.Refresh}" />
<RoutedUICommand name="SDDebugCommands.Execute" text="${res:XML.MainMenu.RunMenu.Run}" />
<RoutedUICommand name="SDDebugCommands.ExecuteWithoutDebugger" text="${res:XML.MainMenu.DebugMenu.RunWithoutDebug}" />
@ -106,6 +105,11 @@ @@ -106,6 +105,11 @@
category="Test" />
<CommandBinding
command = "SDProjectCommands.ShowSelectedProjectBrowserNodeProperties"
class = "ICSharpCode.SharpDevelop.Project.Commands.ShowPropertiesForNode"
category="Project viewer" />
<CommandBinding
command="SDBuildCommands.BuildSolution"
class="ICSharpCode.SharpDevelop.Project.Commands.Build"
@ -115,7 +119,8 @@ @@ -115,7 +119,8 @@
command="SDBuildCommands.RebuildSolution"
class="ICSharpCode.SharpDevelop.Project.Commands.Rebuild"
gestures="Alt+F8"
category="Building" />
category="Building"
/>
<CommandBinding
command="SDBuildCommands.CleanSolution"
class="ICSharpCode.SharpDevelop.Project.Commands.Clean"
@ -192,7 +197,7 @@ @@ -192,7 +197,7 @@
<CommandBinding
command="SDDebugCommands.ContinueDebugging"
class="ICSharpCode.SharpDevelop.Project.Commands.ContinueDebuggingCommand"
gestures="Ctrl+Alt+B | Ctrl+Alt+D"
gestures="Ctrl+Alt+B | Ctrl+Alt+D"
category="Debugger" />
<CommandBinding
command="SDDebugCommands.StepOver"
@ -1400,7 +1405,7 @@ @@ -1400,7 +1405,7 @@
<Condition name = "WindowActive" activewindow="*" action="Disable">
<MenuItem id = "Reloadfile"
label = "${res:XML.MainMenu.FileMenu.Reload}"
shortcut = "Shift|Control|U"
shortcut = "Ctrl+Shift+U"
class = "ICSharpCode.SharpDevelop.Commands.ReloadFile" />
</Condition>
@ -1909,7 +1914,7 @@ @@ -1909,7 +1914,7 @@
class = "ICSharpCode.SharpDevelop.Commands.ShowSensitiveHelp"/>
<MenuItem id = "Help"
label = "${res:XML.MainMenu.HelpMenu.Topics}"
shortcut = "Alt|F1"
shortcut = "Alt+F1"
link = "http://wiki.sharpdevelop.net/"/>
<MenuItem id = "Separator1" type = "Separator" />
<MenuItem id = "ViewReadme"

15
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -118,8 +118,19 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -118,8 +118,19 @@ namespace ICSharpCode.AvalonEdit.AddIn
public CodeEditor()
{
var contextName = this.GetType().FullName;
CommandsRegistry.RegisterCommandBindingsUpdateHandler(contextName, this, CommandsRegistry.CreateCommandBindingUpdateHandler(CommandBindings, contextName, this));
CommandsRegistry.RegisterInputBindingUpdateHandler(contextName, this, CommandsRegistry.CreateInputBindingUpdateHandler(InputBindings, contextName, this));
CommandsRegistry.RegisterCommandBindingsUpdateHandler(contextName, this, delegate {
var newBindings = CommandsRegistry.FindCommandBindings(contextName, this, null, null);
CommandsRegistry.RemoveManagedCommandBindings(CommandBindings);
CommandBindings.AddRange(newBindings);
});
CommandsRegistry.RegisterInputBindingUpdateHandler(contextName, this, delegate {
var newBindings = CommandsRegistry.FindInputBindings(contextName, this, null);
CommandsRegistry.RemoveManagedInputBindings(InputBindings);
InputBindings.AddRange(newBindings);
});
var commandBindingInfo = new CommandBindingInfo();
commandBindingInfo.ContextName = contextName;

BIN
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement.suo

Binary file not shown.

2
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.addin

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<AddIn name = "ShortcutsPrototype"
<AddIn name = "ShortcutsManagement"
author = "Sergej Andrejev"
url = ""
description = "Addin allows managing application shortcuts">

2
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/GesturesCollectionConverter.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.ShortcutsManagement.Converters @@ -31,7 +31,7 @@ namespace ICSharpCode.ShortcutsManagement.Converters
foreach (var gesture in (ObservableCollection<InputGesture>)value) {
inputGestureCollection.Add(gesture);
}
return new InputGestureCollectionConverter().ConvertToInvariantString(inputGestureCollection).Replace("+", " + ").Replace("|", " | ");
return new InputGestureCollectionConverter().ConvertToInvariantString(inputGestureCollection).Replace("|", " | ");
}
return value.ToString();

9
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/AddIn.cs

@ -115,6 +115,15 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -115,6 +115,15 @@ namespace ICSharpCode.ShortcutsManagement.Data
return clonedAddIn;
}
public void SortEntries()
{
Categories.Sort((a, b) => a.Name.CompareTo(b.Name));
foreach (var category in Categories)
{
category.SortEntries();
}
}
/// <summary>
/// Notify observers about property changes
/// </summary>

1
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs

@ -3,6 +3,7 @@ using System.Collections.ObjectModel; @@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
namespace ICSharpCode.ShortcutsManagement.Data
{
/// <summary>

11
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutCategory.cs

@ -103,6 +103,17 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -103,6 +103,17 @@ namespace ICSharpCode.ShortcutsManagement.Data
return clonedCategory;
}
public void SortEntries()
{
SubCategories.Sort((a, b) => a.Name.CompareTo(b.Name));
Shortcuts.Sort((a, b) => a.Text.CompareTo(b.Text));
foreach (var category in SubCategories)
{
category.SortEntries();
}
}
/// <summary>
/// Find shortcut shortcut by ID in this category and subcategories
/// </summary>

9
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutsFinder.cs

@ -162,7 +162,7 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -162,7 +162,7 @@ namespace ICSharpCode.ShortcutsManagement.Data
{
foreach (var addIn in AddIns) {
// If add-in name matches filter string show all sub-elements
var addInNameContainsFilterString = addIn.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0;
var addInNameContainsFilterString = !string.IsNullOrEmpty(filterString) && addIn.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0;
// Apply filter to categories
var subCategoryIsVisible = false;
@ -189,7 +189,8 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -189,7 +189,8 @@ namespace ICSharpCode.ShortcutsManagement.Data
private static bool Filter(ShortcutCategory category, string filterString, bool? forseMatch)
{
// If category name matches filter show all sub-categories and shortcuts
if(category.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) {
if (!string.IsNullOrEmpty(filterString) && category.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0)
{
forseMatch = true;
}
@ -203,9 +204,7 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -203,9 +204,7 @@ namespace ICSharpCode.ShortcutsManagement.Data
// Filter shortcuts which text match the filter
foreach (var shortcut in category.Shortcuts) {
if (
(forseMatch.HasValue && forseMatch.Value)
|| shortcut.Text.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) {
if ((forseMatch.HasValue && forseMatch.Value) || shortcut.Text.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) {
shortcut.IsVisible = true;
isSubElementVisible = true;
}

33
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs

@ -17,6 +17,8 @@ namespace ICSharpCode.ShortcutsManagement @@ -17,6 +17,8 @@ namespace ICSharpCode.ShortcutsManagement
/// </summary>
public partial class ShortcutsManagementOptionsPanel : UserControl, IOptionPanel
{
private readonly Dictionary<Shortcut, InputBindingInfo> shortcutsMap = new Dictionary<Shortcut, InputBindingInfo>();
private static InputGestureCollection GetGestures(string gesturesString)
{
var converter = new InputGestureCollectionConverter();
@ -68,13 +70,14 @@ namespace ICSharpCode.ShortcutsManagement @@ -68,13 +70,14 @@ namespace ICSharpCode.ShortcutsManagement
var unspecifiedAddInSection = new ShortcutManagement.AddIn("Unspecified");
unspecifiedAddInSection.Categories.Add(new ShortcutCategory("Uncategorized"));
var addIns = new ObservableCollection<ShortcutManagement.AddIn>();
var addIns = new List<ShortcutManagement.AddIn>();
addIns.Add(unspecifiedAddInSection);
var addInsMap = new Dictionary<AddIn, ShortcutManagement.AddIn>();
var categoriesMap = new Dictionary<ShortcutManagement.AddIn, Dictionary<string, ShortcutCategory>>();
foreach(var inputBindingInfo in CommandsRegistry.InputBidnings) {
var inputBindingInfos = CommandsRegistry.FindInputBindingInfos(null, null, null);
foreach(var inputBindingInfo in inputBindingInfos) {
ShortcutManagement.AddIn addinSection;
if(inputBindingInfo.AddIn == null) {
addinSection = unspecifiedAddInSection;
@ -89,8 +92,12 @@ namespace ICSharpCode.ShortcutsManagement @@ -89,8 +92,12 @@ namespace ICSharpCode.ShortcutsManagement
}
ShortcutCategory categorySection;
if(string.IsNullOrEmpty(inputBindingInfo.CategoryName) || !categoriesMap[addinSection].ContainsKey(inputBindingInfo.CategoryName)) {
if(string.IsNullOrEmpty(inputBindingInfo.CategoryName)) {
categorySection = addinSection.Categories[0];
} else if(!categoriesMap[addinSection].ContainsKey(inputBindingInfo.CategoryName)) {
categorySection = new ShortcutCategory(inputBindingInfo.CategoryName);
addinSection.Categories.Add(categorySection);
categoriesMap[addinSection].Add(inputBindingInfo.CategoryName, categorySection);
} else {
categorySection = categoriesMap[addinSection][inputBindingInfo.CategoryName];
}
@ -106,12 +113,32 @@ namespace ICSharpCode.ShortcutsManagement @@ -106,12 +113,32 @@ namespace ICSharpCode.ShortcutsManagement
var shortcut = new Shortcut(shortcutText, inputBindingInfo.Gestures);
categorySection.Shortcuts.Add(shortcut);
shortcutsMap.Add(shortcut, inputBindingInfo);
}
addIns.Sort((a, b) => a.Name.CompareTo(b.Name));
foreach (var addIn in addIns)
{
addIn.SortEntries();
}
new ShortcutsFinder(addIns).Filter("");
shortcutsManagementOptionsPanel.DataContext = addIns;
}
public bool SaveOptions() {
foreach (var pair in shortcutsMap)
{
var shortcut = pair.Key;
var inputBindingInfo = pair.Value;
inputBindingInfo.Gestures = new InputGestureCollection(shortcut.Gestures);
}
CommandsRegistry.InvokeInputBindingUpdateHandlers(null, null);
return true;
}

2
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsTreeView.xaml.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.ShortcutsManagement @@ -82,7 +82,7 @@ namespace ICSharpCode.ShortcutsManagement
/// </summary>
public ShortcutsTreeView()
{
InitializeComponent();
InitializeComponent();
}
private void shortcutEntry_MouseDown(object sender, MouseButtonEventArgs e)

17
src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs

@ -471,7 +471,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -471,7 +471,7 @@ namespace ICSharpCode.SharpDevelop.Commands
}
var routedCommandName = "SDViewCommands.ShowView_" + padContent.Class;
var routedCommandText = "Show view " + MenuService.ConvertLabel(StringParser.Parse(padContent.Title));
var routedCommandText = "Show view \"" + MenuService.ConvertLabel(StringParser.Parse(padContent.Title)) + "\"";
// TODO: fix this hack
if(!bindingsAssigned.Contains(routedCommandName)) {
@ -483,7 +483,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -483,7 +483,7 @@ namespace ICSharpCode.SharpDevelop.Commands
var commandBindingInfo = new CommandBindingInfo();
commandBindingInfo.ClassName = routedCommandName;
commandBindingInfo.ContextName = CommandsRegistry.DefaultContext;
commandBindingInfo.ContextName = CommandsRegistry.DefaultContextName;
commandBindingInfo.RoutedCommandName = routedCommandName;
commandBindingInfo.AddIn = addIn;
@ -494,7 +494,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -494,7 +494,7 @@ namespace ICSharpCode.SharpDevelop.Commands
var gestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromString(padContent.Shortcut);
var inputBindingInfo = new InputBindingInfo();
inputBindingInfo.ContextName = CommandsRegistry.DefaultContext;
inputBindingInfo.ContextName = CommandsRegistry.DefaultContextName;
inputBindingInfo.RoutedCommandName = routedCommandName;
inputBindingInfo.Gestures = gestures;
inputBindingInfo.CategoryName = "Views";
@ -506,10 +506,15 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -506,10 +506,15 @@ namespace ICSharpCode.SharpDevelop.Commands
bindingsAssigned.Add(routedCommandName);
}
CommandsRegistry.InvokeCommandBindingUpdateHandlers(CommandsRegistry.DefaultContext, null);
CommandsRegistry.InvokeInputBindingUpdateHandlers(CommandsRegistry.DefaultContext, null);
CommandsRegistry.RegisterInputBindingUpdateHandler(CommandsRegistry.DefaultContextName, null, delegate {
var updatedGestures = CommandsRegistry.FindInputGestures(CommandsRegistry.DefaultContextName, null, routedCommandName);
item.InputGestureText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
});
item.InputGestureText = padContent.Shortcut;
CommandsRegistry.InvokeCommandBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
CommandsRegistry.InvokeInputBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
item.Command = CommandsRegistry.GetRoutedUICommand(routedCommandName);
// item.Command = new BringPadToFrontCommand(padContent);

15
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs

@ -91,8 +91,19 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -91,8 +91,19 @@ namespace ICSharpCode.SharpDevelop.Gui
CommandsRegistry.LoadContext(contextName, (UIElement)Content);
CommandsRegistry.RegisterCommandBindingsUpdateHandler(contextName, null, CommandsRegistry.CreateCommandBindingUpdateHandler(CommandBindings, contextName, null));
CommandsRegistry.RegisterInputBindingUpdateHandler(contextName, null, CommandsRegistry.CreateInputBindingUpdateHandler(InputBindings, contextName, null));
CommandsRegistry.RegisterCommandBindingsUpdateHandler(contextName, null, delegate {
var newBindings = CommandsRegistry.FindCommandBindings(contextName, null, null, null);
CommandsRegistry.RemoveManagedCommandBindings(CommandBindings);
CommandBindings.AddRange(newBindings);
});
CommandsRegistry.RegisterInputBindingUpdateHandler(contextName, null, delegate {
var newBindings = CommandsRegistry.FindInputBindings(contextName, null, null);
CommandsRegistry.RemoveManagedInputBindings(InputBindings);
InputBindings.AddRange(newBindings);
});
CommandsRegistry.InvokeCommandBindingUpdateHandlers(contextName, null);
CommandsRegistry.InvokeInputBindingUpdateHandlers(contextName, null);
}

13
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -97,9 +97,18 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -97,9 +97,18 @@ namespace ICSharpCode.SharpDevelop.Gui
CommandsRegistry.LoadContext(contextName, (UIElement)Content);
CommandsRegistry.RegisterCommandBindingsUpdateHandler(contextName, null, delegate {
var newBindings = CommandsRegistry.FindCommandBindings(contextName, null, null, null);
CommandsRegistry.RemoveManagedCommandBindings(CommandBindings);
CommandBindings.AddRange(newBindings);
});
CommandsRegistry.RegisterInputBindingUpdateHandler(contextName, null, delegate {
var newBindings = CommandsRegistry.FindInputBindings(contextName, null, null);
CommandsRegistry.RemoveManagedInputBindings(InputBindings);
InputBindings.AddRange(newBindings);
});
CommandsRegistry.RegisterCommandBindingsUpdateHandler(contextName, null, CommandsRegistry.CreateCommandBindingUpdateHandler(CommandBindings, contextName, null));
CommandsRegistry.RegisterInputBindingUpdateHandler(contextName, null, CommandsRegistry.CreateInputBindingUpdateHandler(InputBindings, contextName, null));
CommandsRegistry.InvokeCommandBindingUpdateHandlers(contextName, null);
CommandsRegistry.InvokeInputBindingUpdateHandlers(contextName, null);
}

20
src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs

@ -80,7 +80,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -80,7 +80,7 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
CommandsRegistry.DefaultContext = this.GetType().Name;
CommandsRegistry.DefaultContextName = this.GetType().Name;
CommandsService.RegisterBuiltInRoutedUICommands();
@ -92,10 +92,20 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -92,10 +92,20 @@ namespace ICSharpCode.SharpDevelop.Gui
// Register context and load all commands from addin
CommandsRegistry.LoadAddinCommands(AddInTree.AddIns.FirstOrDefault(a => a.Name == "SharpDevelop"));
CommandsRegistry.RegisterCommandBindingsUpdateHandler(CommandsRegistry.DefaultContext, null, CommandsRegistry.CreateCommandBindingUpdateHandler(CommandBindings, CommandsRegistry.DefaultContext, null));
CommandsRegistry.RegisterInputBindingUpdateHandler(CommandsRegistry.DefaultContext, null, CommandsRegistry.CreateInputBindingUpdateHandler(InputBindings, CommandsRegistry.DefaultContext, null));
CommandsRegistry.InvokeCommandBindingUpdateHandlers(CommandsRegistry.DefaultContext, null);
CommandsRegistry.InvokeInputBindingUpdateHandlers(CommandsRegistry.DefaultContext, null);
CommandsRegistry.RegisterCommandBindingsUpdateHandler(CommandsRegistry.DefaultContextName, null, delegate {
var newBindings = CommandsRegistry.FindCommandBindings(CommandsRegistry.DefaultContextName, null, null, null);
CommandsRegistry.RemoveManagedCommandBindings(CommandBindings);
CommandBindings.AddRange(newBindings);
});
CommandsRegistry.RegisterInputBindingUpdateHandler(CommandsRegistry.DefaultContextName, null, delegate {
var newBindings = CommandsRegistry.FindInputBindings(null, null, null);
CommandsRegistry.RemoveManagedInputBindings(InputBindings);
InputBindings.AddRange(newBindings);
});
CommandsRegistry.InvokeCommandBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
CommandsRegistry.InvokeInputBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
mainMenu.ItemsSource = MenuService.CreateMenuItems(this, this, mainMenuPath);

33
src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandBindingInfo.cs

@ -13,6 +13,7 @@ namespace ICSharpCode.Core.Presentation @@ -13,6 +13,7 @@ namespace ICSharpCode.Core.Presentation
public CommandBindingInfo()
{
ContextName = CommandsRegistry.DefaultContextName;
}
/// <summary>
@ -45,11 +46,11 @@ namespace ICSharpCode.Core.Presentation @@ -45,11 +46,11 @@ namespace ICSharpCode.Core.Presentation
}
/// <summary>
/// Binded command full name
/// Binded command class full name
///
/// This command is invoke when this binding is triggered
/// Instance of this class is created as soon as user executes the command. See
/// <see cref="IsLazy" /> for details
/// </summary>
/// <seealso cref="Class"></seealso>
public string ClassName {
get; set;
}
@ -59,11 +60,10 @@ namespace ICSharpCode.Core.Presentation @@ -59,11 +60,10 @@ namespace ICSharpCode.Core.Presentation
/// <summary>
/// Binded command instance
///
/// This command is invoke when this binding is triggered. If this value is equal
/// to null then add-in is not loaded yet, see <see cref="IsLazy">IsLazy</see> attribute
/// Reference to the command which is invoke when the binding is triggered. If this value is equal
/// to null then add-in is not loaded yet, see <see cref="IsLazy" /> attribute
/// for details
/// </summary>
/// <seealso cref="ClassName"></seealso>
public System.Windows.Input.ICommand Class {
set {
classInstance = value;
@ -73,6 +73,10 @@ namespace ICSharpCode.Core.Presentation @@ -73,6 +73,10 @@ namespace ICSharpCode.Core.Presentation
return classInstance;
}
if(ExecutedEventHandler != null || CanExecutedEventHandler != null) {
return null;
}
if(AddIn != null && (AddIn.DependenciesLoaded || IsLazy)) {
CommandsRegistry.LoadAddinCommands(AddIn);
}
@ -86,18 +90,14 @@ namespace ICSharpCode.Core.Presentation @@ -86,18 +90,14 @@ namespace ICSharpCode.Core.Presentation
}
/// <summary>
/// Context class full name
///
/// Described binding will be valid in this context
/// Name of the class which owns this binding
/// </summary>
public string ContextName{
get; set;
}
/// <summary>
/// Context class instance
///
/// Described binding will be valid in this context
/// Instance of class which owns this binding
/// </summary>
public UIElement Context {
set {
@ -120,9 +120,10 @@ namespace ICSharpCode.Core.Presentation @@ -120,9 +120,10 @@ namespace ICSharpCode.Core.Presentation
///
/// If lazy load is enabled then all add-in references are loaded when this
/// command is invoked. Otherwice if add-in is not loaded and IsLazy is set
/// to false then this binding can't be triggered until add-in is loaded.
/// to false then this binding can't be triggered until it is loaded manualy is loaded
/// using <see cref="CommandsRegistry.LoadCommand" /> or <see cref="CommandsRegistry.LoadAddInCommands" />.
/// </summary>
public bool IsLazy{
public bool IsLazy {
get; set;
}
@ -154,7 +155,9 @@ namespace ICSharpCode.Core.Presentation @@ -154,7 +155,9 @@ namespace ICSharpCode.Core.Presentation
}
internal void GeneratedCanExecuteEventHandler(object sender, CanExecuteRoutedEventArgs e) {
if(CanExecutedEventHandler != null) {
if(CanExecutedEventHandler == null && ExecutedEventHandler != null) {
e.CanExecute = true;
} else if(CanExecutedEventHandler != null) {
CanExecutedEventHandler.Invoke(sender, e);
} else {
if(IsLazy && Class == null) {

179
src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandsRegistry.cs

@ -4,6 +4,7 @@ using System.Windows.Input; @@ -4,6 +4,7 @@ using System.Windows.Input;
using System.Windows;
using ICSharpCode.Core;
using System.Threading;
using System.Text;
namespace ICSharpCode.Core.Presentation
{
@ -24,23 +25,9 @@ namespace ICSharpCode.Core.Presentation @@ -24,23 +25,9 @@ namespace ICSharpCode.Core.Presentation
///
/// This should be set to the root UI element
/// </summary>
public static string DefaultContext {
public static string DefaultContextName {
get; set;
}
public static ICollection<CommandBindingInfo> CommandBindings
{
get {
return commandBindings;
}
}
public static List<InputBindingInfo> InputBidnings
{
get {
return inputBidnings;
}
}
private static List<CommandBindingInfo> commandBindings = new List<CommandBindingInfo>();
private static List<InputBindingInfo> inputBidnings = new List<InputBindingInfo>();
@ -82,7 +69,7 @@ namespace ICSharpCode.Core.Presentation @@ -82,7 +69,7 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="routedCommandName">Routed command name</param>
/// <param name="text">Short text describing command functionality</param>
public static void RegisterRoutedUICommand(string routedCommandName, string text) {
public static RoutedUICommand RegisterRoutedUICommand(string routedCommandName, string text) {
var routedCommand = new RoutedUICommand(text, routedCommandName, typeof(CommandsRegistry));
if(!routedCommands.ContainsKey(routedCommandName)) {
@ -91,6 +78,8 @@ namespace ICSharpCode.Core.Presentation @@ -91,6 +78,8 @@ namespace ICSharpCode.Core.Presentation
var test = routedCommands[routedCommandName];
throw new IndexOutOfRangeException("Routed UI command with name " + routedCommandName + " is already registered");
}
return routedCommand;
}
/// <summary>
@ -124,6 +113,7 @@ namespace ICSharpCode.Core.Presentation @@ -124,6 +113,7 @@ namespace ICSharpCode.Core.Presentation
public static void RegisterInputBinding(InputBindingInfo inputBindingInfo)
{
inputBidnings.Add(inputBindingInfo);
CommandsRegistry.InvokeCommandBindingUpdateHandlers(inputBindingInfo.ContextName, null);
}
public static void UnregisterInputBinding(InputBindingInfo inputBindingInfo)
@ -140,13 +130,12 @@ namespace ICSharpCode.Core.Presentation @@ -140,13 +130,12 @@ namespace ICSharpCode.Core.Presentation
/// <param name="contextInstance">Unregister binding assigned to specific context instance</param>
/// <param name="routedCommandName">Routed UI command name</param>
/// <param name="gesture">Gesture</param>
public static ICollection<InputBindingInfo> FindInputBindingInfos(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) {
public static ICollection<InputBindingInfo> FindInputBindingInfos(string contextName, UIElement contextInstance, string routedCommandName) {
var foundBindings = new List<InputBindingInfo>();
for(int i = inputBidnings.Count - 1; i >= 0; i--) {
if((contextName == null || inputBidnings[i].ContextName == contextName)
&& (contextInstance == null || inputBidnings[i].Context == null || inputBidnings[i].Context == contextInstance)
&& (routedCommandName == null || inputBidnings[i].RoutedCommandName == routedCommandName)
&& (gesture == null || inputBidnings[i].Gestures.ContainsCopy(gesture))) {
&& (routedCommandName == null || inputBidnings[i].RoutedCommandName == routedCommandName)) {
foundBindings.Add(inputBidnings[i]);
}
}
@ -254,27 +243,10 @@ namespace ICSharpCode.Core.Presentation @@ -254,27 +243,10 @@ namespace ICSharpCode.Core.Presentation
commandBindings.Add(commandBindingInfo);
}
/// <summary>
/// Remove all command bindings which satisfy provided parameters
///
/// Null arguments are ignored
/// </summary>
/// <param name="contextName">Context class full name</param>
/// <param name="contextInstance">Unregister update handler which was triggered only if command bindings registered for specific instance where updated</param>
/// <param name="routedCommandName">Routed UI command name</param>
/// <param name="className">Command full name to which invokation event is routed</param>
public static void UnregisterCommandBindings(string contextName, UIElement contextInstance, string routedCommandName, string className) {
for(int i = commandBindings.Count - 1; i >= 0; i--) {
if((contextName == null || commandBindings[i].ContextName == contextName)
&& (contextInstance == null || commandBindings[i].Context == null || commandBindings[i].Context == contextInstance)
&& (routedCommandName == null || commandBindings[i].RoutedCommandName == routedCommandName)
&& (className == null || commandBindings[i].ClassName == className)) {
inputBidnings.RemoveAt(i);
}
}
public static void UnregisterCommandBinding(CommandBindingInfo commandBindingInfo) {
commandBindings.Remove(commandBindingInfo);
}
/// <summary>
/// Register delegate which will be invoked on any chage in command bindings of specified context
/// </summary>
@ -378,12 +350,7 @@ namespace ICSharpCode.Core.Presentation @@ -378,12 +350,7 @@ namespace ICSharpCode.Core.Presentation
foreach(var binding in commandBindings) {
if(binding.AddIn != addIn) continue;
if(binding.ClassName == null)
{
}
if(!commands.ContainsKey(binding.ClassName)){
if(binding.ClassName != null && !commands.ContainsKey(binding.ClassName)){
var command = addIn.CreateObject(binding.ClassName);
var wpfCommand = command as System.Windows.Input.ICommand;
if(wpfCommand == null) {
@ -419,8 +386,7 @@ namespace ICSharpCode.Core.Presentation @@ -419,8 +386,7 @@ namespace ICSharpCode.Core.Presentation
public static void LoadContext(string contextName, UIElement context) {
contexts[contextName] = context;
}
/// <summary>
/// Get list of all command bindings which satisfy provided parameters
///
@ -431,8 +397,8 @@ namespace ICSharpCode.Core.Presentation @@ -431,8 +397,8 @@ namespace ICSharpCode.Core.Presentation
/// <param name="routedCommandName">Context class full name</param>
/// <param name="className">Context class full name</param>
/// <returns>Collection of managed command bindings</returns>
public static CommandBindingCollection GetCommandBindings(string contextName, UIElement contextInstance, string routedCommandName, string className) {
var bindings = new CommandBindingCollection();
public static ICollection<CommandBindingInfo> FindCommandBindingInfos(string contextName, UIElement contextInstance, string routedCommandName, string className) {
var foundBindings = new List<CommandBindingInfo>();
foreach(var binding in commandBindings) {
if((contextName == null || binding.ContextName == contextName)
@ -440,14 +406,36 @@ namespace ICSharpCode.Core.Presentation @@ -440,14 +406,36 @@ namespace ICSharpCode.Core.Presentation
&& (routedCommandName == null || binding.RoutedCommandName == routedCommandName)
&& (className == null || binding.ClassName == className)) {
var managedCommandBinding = new ManagedCommandBinding(binding.RoutedCommand);
managedCommandBinding.CanExecute += binding.GeneratedCanExecuteEventHandler;
managedCommandBinding.Executed += binding.GeneratedExecutedEventHandler;
bindings.Add(managedCommandBinding);
foundBindings.Add(binding);
}
}
return foundBindings;
}
/// <summary>
/// Get list of all command bindings which satisfy provided parameters
///
/// Null arguments are ignored
/// </summary>
/// <param name="contextName">Context class full name</param>
/// <param name="contextInstance">Get command bindings assigned only to specific context</param>
/// <param name="routedCommandName">Context class full name</param>
/// <param name="className">Context class full name</param>
/// <returns>Collection of managed command bindings</returns>
public static CommandBindingCollection FindCommandBindings(string contextName, UIElement contextInstance, string routedCommandName, string className) {
var commandBindingInfos = FindCommandBindingInfos(contextName, contextInstance, routedCommandName, className);
var bindings = new CommandBindingCollection();
foreach(var binding in commandBindingInfos) {
var managedCommandBinding = new ManagedCommandBinding(binding.RoutedCommand);
managedCommandBinding.CanExecute += binding.GeneratedCanExecuteEventHandler;
managedCommandBinding.Executed += binding.GeneratedExecutedEventHandler;
bindings.Add(managedCommandBinding);
}
return bindings;
}
@ -459,19 +447,13 @@ namespace ICSharpCode.Core.Presentation @@ -459,19 +447,13 @@ namespace ICSharpCode.Core.Presentation
/// <param name="contextName">Context class full name</param>
/// <param name="contextInstance">Get input bindings assigned only to specific context</param>
/// <param name="routedCommandName">Routed UI command name</param>
/// <param name="gesture">Gesture</param>
public static InputBindingCollection GetInputBindings(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) {
var bindings = new InputBindingCollection();
public static InputBindingCollection FindInputBindings(string contextName, UIElement contextInstance, string routedCommandName) {
var inputBindingInfos = FindInputBindingInfos(contextName, contextInstance, routedCommandName);
foreach(var binding in inputBidnings) {
if((contextName == null || binding.ContextName == contextName)
&& (contextInstance == null || binding.Context == null || binding.Context == contextInstance)
&& (routedCommandName == null || binding.RoutedCommandName == routedCommandName)
&& (gesture == null || binding.Gestures.ContainsCopy(gesture))) {
foreach(InputGesture bindingGesture in binding.Gestures) {
bindings.Add(new ManagedInputBinding(binding.RoutedCommand, bindingGesture));
}
var bindings = new InputBindingCollection();
foreach(var binding in inputBindingInfos) {
foreach(InputGesture bindingGesture in binding.Gestures) {
bindings.Add(new ManagedInputBinding(binding.RoutedCommand, bindingGesture));
}
}
@ -487,8 +469,8 @@ namespace ICSharpCode.Core.Presentation @@ -487,8 +469,8 @@ namespace ICSharpCode.Core.Presentation
/// <param name="contextInstance">Get gestures assigned only to specific context</param>
/// <param name="routedCommandName">Routed UI command name</param>
/// <param name="gesture">Gesture</param>
public static InputGestureCollection GetInputGestures(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) {
var bindings = GetInputBindings(contextName, contextInstance, routedCommandName, gesture);
public static InputGestureCollection FindInputGestures(string contextName, UIElement contextInstance, string routedCommandName) {
var bindings = FindInputBindings(contextName, contextInstance, routedCommandName);
var gestures = new InputGestureCollection();
foreach(InputBinding binding in bindings) {
@ -497,66 +479,5 @@ namespace ICSharpCode.Core.Presentation @@ -497,66 +479,5 @@ namespace ICSharpCode.Core.Presentation
return gestures;
}
/// <summary>
/// Create default BindingUpdateHandler which will update command bindings in specified context
/// </summary>
/// <param name="bindingsCollection">Collection which should be updated with latest bindings</param>
/// <param name="contextName">Context name which was used to register command bindings</param>
/// <param name="contextInstance">Reference to instance which is used to find command bindings registered in specific context instance</param>
/// <returns>Bindings updated handler</returns>
public static BindingsUpdatedHandler CreateCommandBindingUpdateHandler(CommandBindingCollection bindingsCollection, string contextName, UIElement contextInstance) {
return new CommonCommandBindingUpdateDelegate(bindingsCollection, contextName, contextInstance).UpdateCommandBinding;
}
/// <summary>
/// Create default BindingUpdateHandler which will update input bindings in specified context
/// </summary>
/// <param name="bindingsCollection">Collection which should be updated with latest bindings</param>
/// <param name="contextName">Context name which was used to register input bindings</param>
/// <param name="contextInstance">Reference to instance which is used to find command bindings registered in specific context instance</param>
/// <returns>Bindings updated handler</returns>
public static BindingsUpdatedHandler CreateInputBindingUpdateHandler(InputBindingCollection bindingsCollection, string contextName, UIElement contextInstance) {
return new CommonInputBindingUpdateDelegate(bindingsCollection, contextName, contextInstance).UpdateInputBinding;
}
class CommonCommandBindingUpdateDelegate
{
CommandBindingCollection bindingsCollection;
string contextName;
UIElement contextInstance;
public CommonCommandBindingUpdateDelegate(CommandBindingCollection bindingsCollection, string contextName, UIElement contextInstance) {
this.bindingsCollection = bindingsCollection;
this.contextName = contextName;
this.contextInstance = contextInstance;
}
public void UpdateCommandBinding() {
var newBindings = CommandsRegistry.GetCommandBindings(contextName, contextInstance, null, null);
CommandsRegistry.RemoveManagedCommandBindings(bindingsCollection);
bindingsCollection.AddRange(newBindings);
}
}
class CommonInputBindingUpdateDelegate
{
InputBindingCollection bindingsCollection;
string contextName;
UIElement contextInstance;
public CommonInputBindingUpdateDelegate(InputBindingCollection bindingsCollection, string contextName, UIElement contextInstance) {
this.bindingsCollection = bindingsCollection;
this.contextName = contextName;
this.contextInstance = contextInstance;
}
public void UpdateInputBinding() {
var newBindings = CommandsRegistry.GetInputBindings(contextName, contextInstance, null, null);
CommandsRegistry.RemoveManagedInputBindings(bindingsCollection);
bindingsCollection.AddRange(newBindings);
}
}
}
}

4
src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandsService.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.Core.Presentation @@ -39,7 +39,7 @@ namespace ICSharpCode.Core.Presentation
{
var descriptors = AddInTree.BuildItems<CommandBindingDescriptor>(path, caller, false);
foreach(var desc in descriptors) {
var contextName = !string.IsNullOrEmpty(desc.Context) ? desc.Context : CommandsRegistry.DefaultContext;
var contextName = !string.IsNullOrEmpty(desc.Context) ? desc.Context : CommandsRegistry.DefaultContextName;
// If routed with such name is not registered register routed command with text same as name
if(CommandsRegistry.GetRoutedUICommand(desc.Command) == null) {
@ -83,7 +83,7 @@ namespace ICSharpCode.Core.Presentation @@ -83,7 +83,7 @@ namespace ICSharpCode.Core.Presentation
var descriptors = AddInTree.BuildItems<InputBindingDescriptor>(path, caller, false);
foreach(var desc in descriptors) {
var gestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromString(desc.Gestures);
var contextName = !string.IsNullOrEmpty(desc.Context) ? desc.Context : CommandsRegistry.DefaultContext;
var contextName = !string.IsNullOrEmpty(desc.Context) ? desc.Context : CommandsRegistry.DefaultContextName;
var inputBindingInfo = new InputBindingInfo();
inputBindingInfo.ContextName = contextName;

22
src/Main/ICSharpCode.Core.Presentation/CommandsService/InputBindingInfo.cs

@ -12,29 +12,9 @@ namespace ICSharpCode.Core.Presentation @@ -12,29 +12,9 @@ namespace ICSharpCode.Core.Presentation
private UIElement contextInstance;
public InputBindingInfo() {
ContextName = CommandsRegistry.DefaultContextName;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="contextName">Context full name</param>
/// <param name="routedCommandName">Name of routed UI command which is triggered by this binding</param>
/// <param name="gesture">Gesture which triggers this binding</param>
public InputBindingInfo(string contextName, string routedCommandName, InputGestureCollection gestures) {
ContextName = contextName;
RoutedCommandName = routedCommandName;
Gestures = gestures;
}
public InputBindingInfo(string contextName, UIElement contextInstance, string routedCommandName, InputGestureCollection gestures) {
ContextName = contextName;
RoutedCommandName = routedCommandName;
Gestures = gestures;
this.contextInstance = contextInstance;
}
/// <summary>
/// Context class full name
///

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

@ -13,6 +13,7 @@ using System.Threading; @@ -13,6 +13,7 @@ using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Text;
namespace ICSharpCode.Core.Presentation
{
@ -118,29 +119,51 @@ namespace ICSharpCode.Core.Presentation @@ -118,29 +119,51 @@ namespace ICSharpCode.Core.Presentation
{
public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand) : base(codon, caller)
{
if(!string.IsNullOrEmpty(codon.Properties["command"])) {
var routedCommandName = codon.Properties["command"];
var routedCommand = CommandsRegistry.GetRoutedUICommand(routedCommandName);
string routedCommandName = null;
string routedCommandText = null;
if(codon.Properties.Contains("command")) {
routedCommandName = codon.Properties["command"];
routedCommandText = codon.Properties["command"];
} else if(codon.Properties.Contains("link") || codon.Properties.Contains("class")) {
routedCommandName = string.IsNullOrEmpty(codon.Properties["link"]) ? codon.Properties["class"] : codon.Properties["link"];
routedCommandText = "Menu item \"" + codon.Properties["label"] + "\"";
}
var routedCommand = CommandsRegistry.GetRoutedUICommand(routedCommandName);
if(routedCommand == null) {
routedCommand = CommandsRegistry.RegisterRoutedUICommand(routedCommandName, routedCommandText);
}
this.Command = routedCommand;
if(!codon.Properties.Contains("command") && (codon.Properties.Contains("link") || codon.Properties.Contains("class"))) {
var commandBindingInfo = new CommandBindingInfo();
commandBindingInfo.AddIn = codon.AddIn;
commandBindingInfo.ContextName = CommandsRegistry.DefaultContextName;
commandBindingInfo.Class = CommandWrapper.GetCommand(codon, caller, createCommand);
commandBindingInfo.RoutedCommandName = routedCommandName;
commandBindingInfo.IsLazy = true;
if(routedCommand == null) {
MessageService.ShowError("Routed command with name '" + routedCommandName + "' not registered");
} else {
this.Command = routedCommand;
var gestures = CommandsRegistry.GetInputGestures(CommandsRegistry.DefaultContext, null, routedCommand.Name, null);
var gesturesString = (string)new InputGestureCollectionConverter().ConvertToInvariantString(gestures);
this.InputGestureText = gesturesString;
}
} else {
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) {
KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
if (inputBindingOwner != null) {
inputBindingOwner.InputBindings.Add(new InputBinding(this.Command, kg));
}
this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
}
CommandsRegistry.RegisterCommandBinding(commandBindingInfo);
CommandsRegistry.InvokeCommandBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
}
if(codon.Properties.Contains("shortcut")) {
var shortcut = codon.Properties["shortcut"];
var inputBindingInfo = new InputBindingInfo();
inputBindingInfo.AddIn = codon.AddIn;
inputBindingInfo.CategoryName = "Menu items";
inputBindingInfo.ContextName = CommandsRegistry.DefaultContextName;
inputBindingInfo.RoutedCommandName = routedCommandName;
inputBindingInfo.Gestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromInvariantString(codon.Properties["gestures"]);
CommandsRegistry.RegisterInputBinding(inputBindingInfo);
CommandsRegistry.RegisterInputBindingUpdateHandler(CommandsRegistry.DefaultContextName, null, delegate {
var updatedGestures = CommandsRegistry.FindInputGestures(null, null, routedCommandName);
this.InputGestureText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
});
CommandsRegistry.InvokeInputBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
}
}
}

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

@ -177,7 +177,11 @@ namespace ICSharpCode.Core.Presentation @@ -177,7 +177,11 @@ namespace ICSharpCode.Core.Presentation
IMenuItemBuilder builder = codon.AddIn.CreateObject(codon.Properties["class"]) as IMenuItemBuilder;
if (builder == null)
throw new NotSupportedException("Menu item builder " + codon.Properties["class"] + " does not implement IMenuItemBuilder");
return new MenuItemBuilderPlaceholder(builder, descriptor.Codon, descriptor.Caller);
var placeHolder = new MenuItemBuilderPlaceholder(builder, descriptor.Codon, descriptor.Caller);
placeHolder.BuildItems(); // Build items to register key gestures
return placeHolder;
default:
throw new System.NotSupportedException("unsupported menu item type : " + type);
}

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

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;
namespace ICSharpCode.Core.Presentation
{
@ -26,11 +27,36 @@ namespace ICSharpCode.Core.Presentation @@ -26,11 +27,36 @@ namespace ICSharpCode.Core.Presentation
this.codon = codon;
this.caller = caller;
if(!string.IsNullOrEmpty(codon.Properties["command"])) {
this.Command = CommandsRegistry.GetRoutedUICommand(codon.Properties["command"]);
} else {
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
string routedCommandName = null;
string routedCommandText = null;
if(codon.Properties.Contains("command")) {
routedCommandName = codon.Properties["command"];
routedCommandText = codon.Properties["command"];
} else if(codon.Properties.Contains("link") || codon.Properties.Contains("class")) {
routedCommandName = string.IsNullOrEmpty(codon.Properties["link"]) ? codon.Properties["class"] : codon.Properties["link"];
routedCommandText = "Menu item \"" + codon.Properties["label"] + "\"";
}
var routedCommand = CommandsRegistry.GetRoutedUICommand(routedCommandName);
if(routedCommand == null) {
routedCommand = CommandsRegistry.RegisterRoutedUICommand(routedCommandName, routedCommandText);
}
this.Command = routedCommand;
if(!codon.Properties.Contains("command") && (codon.Properties.Contains("link") || codon.Properties.Contains("class"))) {
var commandBindingInfo = new CommandBindingInfo();
commandBindingInfo.AddIn = codon.AddIn;
commandBindingInfo.ContextName = CommandsRegistry.DefaultContextName;
commandBindingInfo.Class = CommandWrapper.GetCommand(codon, caller, createCommand);
commandBindingInfo.RoutedCommandName = routedCommandName;
commandBindingInfo.IsLazy = true;
CommandsRegistry.RegisterCommandBinding(commandBindingInfo);
CommandsRegistry.InvokeCommandBindingUpdateHandlers(CommandsRegistry.DefaultContextName, null);
}
if (codon.Properties.Contains("icon")) {

Loading…
Cancel
Save