Browse Source

More binding groups. (Not working well. Commit to save changes I don't want to lose before trying to switch to dependency

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4454 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts^2
Sergej Andrejev 16 years ago
parent
commit
95074eff88
  1. 30
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin
  2. 4
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs
  3. 95
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/CaretNavigationCommandHandler.cs
  4. 106
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs
  5. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs
  6. 46
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextAreaInputHandler.cs
  7. 2
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs
  8. 2
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  9. 63
      src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingGroup.cs
  10. 6
      src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingGroupCollection.cs
  11. 77
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandBindingInfo.cs
  12. 146
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs
  13. 26
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandsService.cs
  14. 82
      src/Main/ICSharpCode.Core.Presentation/CommandsService/InputBindingInfo.cs

30
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin

@ -27,44 +27,53 @@ @@ -27,44 +27,53 @@
<MenuItem id = "RemoveLeadingWs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.RlWs}"
command = "AvalonEditCommands.RemoveLeadingWhitespace"/>
command = "AvalonEditCommands.RemoveLeadingWhitespace"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "RemoveTrailingWs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.RtWs}"
command = "AvalonEditCommands.RemoveTrailingWhitespace"/>
command = "AvalonEditCommands.RemoveTrailingWhitespace"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "Seperator1" type = "Separator" insertbefore = "Separator4" />
<MenuItem id = "UpperCase"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.UpperCase}"
icon = "Icons.16x16.LowerToUpperCase"
command = "AvalonEditCommands.ConvertToUppercase"/>
command = "AvalonEditCommands.ConvertToUppercase"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "LowerCase"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.LowerCase}"
icon = "Icons.16x16.UpperToLowerCase"
command = "AvalonEditCommands.ConvertToLowercase"/>
command = "AvalonEditCommands.ConvertToLowercase"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "Capitalize"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.Capitalize}"
command = "AvalonEditCommands.ConvertToTitleCase"/>
command = "AvalonEditCommands.ConvertToTitleCase"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "InvertCase"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.InvertCase}"
command = "AvalonEditCommands.InvertCase"/>
command = "AvalonEditCommands.InvertCase"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "Separator2" type = "Separator" />
<MenuItem id = "SortSelection"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.SortLines}"
class ="ICSharpCode.SharpDevelop.Editor.Commands.SortSelection"/>
class ="ICSharpCode.SharpDevelop.Editor.Commands.SortSelection"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "Separator3" type = "Separator" insertbefore = "Separator4" />
<MenuItem id = "Tabs2Spaces"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.Tab2Space}"
command = "AvalonEditCommands.ConvertTabsToSpaces"/>
command = "AvalonEditCommands.ConvertTabsToSpaces"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "Spaces2Tabs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.Space2Tab}"
command = "AvalonEditCommands.ConvertSpacesToTabs"/>
command = "AvalonEditCommands.ConvertSpacesToTabs"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
<MenuItem id = "LeadingTabs2Spaces"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.LdTab2Space}"
@ -72,7 +81,8 @@ @@ -72,7 +81,8 @@
<MenuItem id = "LeadingSpaces2Tabs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.LdSpace2Tab}"
command = "AvalonEditCommands.ConvertLeadingSpacesToTabs"/>
command = "AvalonEditCommands.ConvertLeadingSpacesToTabs"
ownertype="ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit" />
</Condition>
</Path>
</AddIn>

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

@ -193,10 +193,10 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -193,10 +193,10 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
}
}
var inputBindingInfos = CommandManager.FindInputBindingInfos(null, null, null);
var inputBindingInfos = CommandManager.FindInputBindingInfos(null, null, null, null);
foreach (var inputBindingInfo in inputBindingInfos)
{
// Get shortcut entry text. Normaly shortcut entry text is equalt to routed command text
// Get shortcut entry text. Normaly shortcut entry text is equal to routed command text
// but this value can be overriden through InputBindingInfo.RoutedCommandText value
var shortcutText = inputBindingInfo.RoutedCommand.Text;
if (!string.IsNullOrEmpty(inputBindingInfo.RoutedCommandText))

95
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/CaretNavigationCommandHandler.cs

@ -16,67 +16,96 @@ using ICSharpCode.AvalonEdit.Document; @@ -16,67 +16,96 @@ using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Core.Presentation;
using SDCommandManager=ICSharpCode.Core.Presentation.CommandManager;
namespace ICSharpCode.AvalonEdit.Editing
{
static class CaretNavigationCommandHandler
{
static BindingGroup bindingGroup;
/// <summary>
/// Creates a new <see cref="TextAreaInputHandler"/> for the text area.
/// </summary>
public static TextAreaInputHandler Create(TextArea textArea)
{
TextAreaInputHandler handler = new TextAreaInputHandler(textArea);
handler.CommandBindings.AddRange(CommandBindings);
handler.InputBindings.AddRange(InputBindings);
handler.BindingGroup = bindingGroup;
// TODO: DELETE
// handler.CommandBindings.AddRange(CommandBindings);
// handler.InputBindings.AddRange(InputBindings);
return handler;
}
static readonly List<CommandBinding> CommandBindings = new List<CommandBinding>();
static readonly List<InputBinding> InputBindings = new List<InputBinding>();
static void AddBinding(ICommand command, ModifierKeys modifiers, Key key, ExecutedRoutedEventHandler handler)
static void AddBinding(string routedCommandName, string gesturesString, CanExecuteRoutedEventHandler canExecuteHandler, ExecutedRoutedEventHandler executedHandler)
{
AddCommandBinding(routedCommandName, canExecuteHandler, executedHandler);
AddInputBinding(routedCommandName, gesturesString);
}
static void AddInputBinding(string routedCommandName, string gesturesString)
{
var inputBinding = new InputBindingInfo();
inputBinding.OwnerTypeName = typeof(TextArea).GetShortAssemblyQualifiedName();
inputBinding.DefaultGestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFrom(gesturesString);
inputBinding.Groups.Add(bindingGroup);
inputBinding.RoutedCommandName = routedCommandName;
SDCommandManager.RegisterInputBinding(inputBinding);
}
static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHandler canExecuteHandler, ExecutedRoutedEventHandler executedHandler)
{
CommandBindings.Add(new CommandBinding(command, handler));
InputBindings.Add(new KeyBinding(command, key, modifiers));
var commandBinding = new CommandBindingInfo();
commandBinding.OwnerTypeName = typeof(TextArea).GetShortAssemblyQualifiedName();
commandBinding.ExecutedEventHandler = executedHandler;
commandBinding.CanExecuteEventHandler = canExecuteHandler;
commandBinding.IsLazy = false;
commandBinding.Groups.Add(bindingGroup);
commandBinding.RoutedCommandName = routedCommandName;
SDCommandManager.RegisterCommandBinding(commandBinding);
}
static CaretNavigationCommandHandler()
{
const ModifierKeys None = ModifierKeys.None;
const ModifierKeys Ctrl = ModifierKeys.Control;
const ModifierKeys Shift = ModifierKeys.Shift;
bindingGroup = new BindingGroup();
AddBinding(EditingCommands.MoveLeftByCharacter, None, Key.Left, OnMoveCaret(CaretMovementType.CharLeft));
AddBinding(EditingCommands.SelectLeftByCharacter, Shift, Key.Left, OnMoveCaretExtendSelection(CaretMovementType.CharLeft));
AddBinding(EditingCommands.MoveRightByCharacter, None, Key.Right, OnMoveCaret(CaretMovementType.CharRight));
AddBinding(EditingCommands.SelectRightByCharacter, Shift, Key.Right, OnMoveCaretExtendSelection(CaretMovementType.CharRight));
AddBinding("EditingCommands.MoveLeftByCharacter", "Left", null, OnMoveCaret(CaretMovementType.CharLeft));
AddBinding("EditingCommands.SelectLeftByCharacter", "Shift+Left", null, OnMoveCaretExtendSelection(CaretMovementType.CharLeft));
AddBinding("EditingCommands.MoveRightByCharacter", "Right", null, OnMoveCaret(CaretMovementType.CharRight));
AddBinding("EditingCommands.SelectRightByCharacter", "Shift+Right", null, OnMoveCaretExtendSelection(CaretMovementType.CharRight));
AddBinding(EditingCommands.MoveLeftByWord, Ctrl, Key.Left, OnMoveCaret(CaretMovementType.WordLeft));
AddBinding(EditingCommands.SelectLeftByWord, Ctrl | Shift, Key.Left, OnMoveCaretExtendSelection(CaretMovementType.WordLeft));
AddBinding(EditingCommands.MoveRightByWord, Ctrl, Key.Right, OnMoveCaret(CaretMovementType.WordRight));
AddBinding(EditingCommands.SelectRightByWord, Ctrl | Shift, Key.Right, OnMoveCaretExtendSelection(CaretMovementType.WordRight));
AddBinding("EditingCommands.MoveLeftByWord", "Ctrl+Left", null, OnMoveCaret(CaretMovementType.WordLeft));
AddBinding("EditingCommands.SelectLeftByWord", "Ctrl+Shift+Left", null, OnMoveCaretExtendSelection(CaretMovementType.WordLeft));
AddBinding("EditingCommands.MoveRightByWord", "Ctrl+Right", null, OnMoveCaret(CaretMovementType.WordRight));
AddBinding("EditingCommands.SelectRightByWord", "Ctrl+Shift+Right", null, OnMoveCaretExtendSelection(CaretMovementType.WordRight));
AddBinding(EditingCommands.MoveUpByLine, None, Key.Up, OnMoveCaret(CaretMovementType.LineUp));
AddBinding(EditingCommands.SelectUpByLine, Shift, Key.Up, OnMoveCaretExtendSelection(CaretMovementType.LineUp));
AddBinding(EditingCommands.MoveDownByLine, None, Key.Down, OnMoveCaret(CaretMovementType.LineDown));
AddBinding(EditingCommands.SelectDownByLine, Shift, Key.Down, OnMoveCaretExtendSelection(CaretMovementType.LineDown));
AddBinding("EditingCommands.MoveUpByLine", "Up", null, OnMoveCaret(CaretMovementType.LineUp));
AddBinding("EditingCommands.SelectUpByLine", "Shift+Up", null, OnMoveCaretExtendSelection(CaretMovementType.LineUp));
AddBinding("EditingCommands.MoveDownByLine", "Down", null, OnMoveCaret(CaretMovementType.LineDown));
AddBinding("EditingCommands.SelectDownByLine", "Shift+Down", null, OnMoveCaretExtendSelection(CaretMovementType.LineDown));
AddBinding(EditingCommands.MoveDownByPage, None, Key.PageDown, OnMoveCaret(CaretMovementType.PageDown));
AddBinding(EditingCommands.SelectDownByPage, Shift, Key.PageDown, OnMoveCaretExtendSelection(CaretMovementType.PageDown));
AddBinding(EditingCommands.MoveUpByPage, None, Key.PageUp, OnMoveCaret(CaretMovementType.PageUp));
AddBinding(EditingCommands.SelectUpByPage, Shift, Key.PageUp, OnMoveCaretExtendSelection(CaretMovementType.PageUp));
AddBinding("EditingCommands.MoveDownByPage", "PageDown", null, OnMoveCaret(CaretMovementType.PageDown));
AddBinding("EditingCommands.SelectDownByPage", "Shift+PageDown", null, OnMoveCaretExtendSelection(CaretMovementType.PageDown));
AddBinding("EditingCommands.MoveUpByPage", "PageUp", null, OnMoveCaret(CaretMovementType.PageUp));
AddBinding("EditingCommands.SelectUpByPage", "Shift+PageUp", null, OnMoveCaretExtendSelection(CaretMovementType.PageUp));
AddBinding(EditingCommands.MoveToLineStart, None, Key.Home, OnMoveCaret(CaretMovementType.LineStart));
AddBinding(EditingCommands.SelectToLineStart, Shift, Key.Home, OnMoveCaretExtendSelection(CaretMovementType.LineStart));
AddBinding(EditingCommands.MoveToLineEnd, None, Key.End, OnMoveCaret(CaretMovementType.LineEnd));
AddBinding(EditingCommands.SelectToLineEnd, Shift, Key.End, OnMoveCaretExtendSelection(CaretMovementType.LineEnd));
AddBinding("EditingCommands.MoveToLineStart", "Home", null, OnMoveCaret(CaretMovementType.LineStart));
AddBinding("EditingCommands.SelectToLineStart", "Shift+Home", null, OnMoveCaretExtendSelection(CaretMovementType.LineStart));
AddBinding("EditingCommands.MoveToLineEnd", "End", null, OnMoveCaret(CaretMovementType.LineEnd));
AddBinding("EditingCommands.SelectToLineEnd", "Shift+End", null, OnMoveCaretExtendSelection(CaretMovementType.LineEnd));
AddBinding(EditingCommands.MoveToDocumentStart, Ctrl, Key.Home, OnMoveCaret(CaretMovementType.DocumentStart));
AddBinding(EditingCommands.SelectToDocumentStart, Ctrl | Shift, Key.Home, OnMoveCaretExtendSelection(CaretMovementType.DocumentStart));
AddBinding(EditingCommands.MoveToDocumentEnd, Ctrl, Key.End, OnMoveCaret(CaretMovementType.DocumentEnd));
AddBinding(EditingCommands.SelectToDocumentEnd, Ctrl | Shift, Key.End, OnMoveCaretExtendSelection(CaretMovementType.DocumentEnd));
AddBinding("EditingCommands.MoveToDocumentStart", "Ctrl+Home", null, OnMoveCaret(CaretMovementType.DocumentStart));
AddBinding("EditingCommands.SelectToDocumentStart", "Ctrl+Shift+Home", null, OnMoveCaretExtendSelection(CaretMovementType.DocumentStart));
AddBinding("EditingCommands.MoveToDocumentEnd", "Ctrl+End", null, OnMoveCaret(CaretMovementType.DocumentEnd));
AddBinding("EditingCommands.SelectToDocumentEnd", "Ctrl+Shift+End", null, OnMoveCaretExtendSelection(CaretMovementType.DocumentEnd));
CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, OnSelectAll));
AddCommandBinding("ApplicationCommands.SelectAll", null, OnSelectAll);
}
static void OnSelectAll(object target, ExecutedRoutedEventArgs args)

106
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

@ -31,64 +31,94 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -31,64 +31,94 @@ namespace ICSharpCode.AvalonEdit.Editing
/// </summary>
static class EditingCommandHandler
{
static BindingGroup bindingGroup;
/// <summary>
/// Creates a new <see cref="TextAreaInputHandler"/> for the text area.
/// </summary>
public static TextAreaInputHandler Create(TextArea textArea)
{
TextAreaInputHandler handler = new TextAreaInputHandler(textArea);
handler.CommandBindings.AddRange(CommandBindings);
handler.InputBindings.AddRange(InputBindings);
handler.BindingGroup = bindingGroup;
// TODO: REMOVE
// var groups = new BindingGroupCollection { bindingGroup };
// var commandBindings = SDCommandManager.FindCommandBindings(null, null, null, groups);
// handler.CommandBindings.AddRange(commandBindings.Cast<CommandBinding>()); // Todo: fix later
// var inputBindings = SDCommandManager.FindInputBindings(null, null, null, groups);
// handler.InputBindings.AddRange(inputBindings.Cast<InputBinding>()); // Todo: fix later
return handler;
}
static readonly List<CommandBinding> CommandBindings = new List<CommandBinding>();
static readonly List<InputBinding> InputBindings = new List<InputBinding>();
static void AddBinding(ICommand command, ModifierKeys modifiers, Key key, ExecutedRoutedEventHandler handler)
static void AddBinding(string routedCommandName, string gesturesString, CanExecuteRoutedEventHandler canExecuteHandler, ExecutedRoutedEventHandler executedHandler)
{
CommandBindings.Add(new CommandBinding(command, handler));
InputBindings.Add(new KeyBinding(command, key, modifiers));
AddCommandBinding(routedCommandName, canExecuteHandler, executedHandler);
AddInputBinding(routedCommandName, gesturesString);
}
static void AddInputBinding(string routedCommandName, string gesturesString)
{
var inputBinding = new InputBindingInfo();
inputBinding.OwnerTypeName = typeof(TextArea).GetShortAssemblyQualifiedName();
inputBinding.DefaultGestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFrom(gesturesString);
inputBinding.Groups.Add(bindingGroup);
inputBinding.Categories.AddRange(SDCommandManager.GetInputBindingCategoryCollection("/MainMenu/Edit", true));
inputBinding.RoutedCommandName = routedCommandName;
SDCommandManager.RegisterInputBinding(inputBinding);
}
static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHandler canExecuteHandler, ExecutedRoutedEventHandler executedHandler)
{
var commandBinding = new CommandBindingInfo();
commandBinding.OwnerTypeName = typeof(TextArea).GetShortAssemblyQualifiedName();
commandBinding.ExecutedEventHandler = executedHandler;
commandBinding.CanExecuteEventHandler = canExecuteHandler;
commandBinding.IsLazy = false;
commandBinding.Groups.Add(bindingGroup);
commandBinding.RoutedCommandName = routedCommandName;
SDCommandManager.RegisterCommandBinding(commandBinding);
}
static EditingCommandHandler()
{
CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, OnDelete(ApplicationCommands.NotACommand), CanDelete));
AddBinding(EditingCommands.Delete, ModifierKeys.None, Key.Delete, OnDelete(EditingCommands.SelectRightByCharacter));
AddBinding(EditingCommands.DeleteNextWord, ModifierKeys.Control, Key.Delete, OnDelete(EditingCommands.SelectRightByWord));
AddBinding(EditingCommands.Backspace, ModifierKeys.None, Key.Back, OnDelete(EditingCommands.SelectLeftByCharacter));
InputBindings.Add(new KeyBinding(EditingCommands.Backspace, Key.Back, ModifierKeys.Shift)); // make Shift-Backspace do the same as plain backspace
AddBinding(EditingCommands.DeletePreviousWord, ModifierKeys.Control, Key.Back, OnDelete(EditingCommands.SelectLeftByWord));
AddBinding(EditingCommands.EnterParagraphBreak, ModifierKeys.None, Key.Enter, OnEnter);
AddBinding(EditingCommands.EnterLineBreak, ModifierKeys.Shift, Key.Enter, OnEnter);
AddBinding(EditingCommands.TabForward, ModifierKeys.None, Key.Tab, OnTab);
AddBinding(EditingCommands.TabBackward, ModifierKeys.Shift, Key.Tab, OnShiftTab);
//var copyCommand = new CommandBindingInfo();
//copyCommand.OwnerInstance = typeof();
//copyCommand.CanExecuteEventHandler = CanCutOrCopy;
//copyCommand.ExecutedEventHandler = OnCopy;
//copyCommand.IsLazy = false;
//copyCommand.RoutedCommandName = "ApplicationCommands.Copy";
//SDCommandManager.RegisterCommandBinding(copyCommand);
bindingGroup = new BindingGroup();
CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopy, CanCutOrCopy));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCut, CanCutOrCopy));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPaste, CanPaste));
AddCommandBinding("ApplicationCommands.Delete", CanDelete, OnDelete(ApplicationCommands.NotACommand));
AddBinding("EditingCommands.Delete", "Delete", null, OnDelete(EditingCommands.SelectRightByCharacter));
AddBinding("EditingCommands.DeleteNextWord", "Ctrl+Delete", null, OnDelete(EditingCommands.SelectRightByWord));
AddBinding("EditingCommands.Backspace", "Back", null, OnDelete(EditingCommands.SelectLeftByCharacter));
AddInputBinding("EditingCommands.Backspace", "Shift+Back"); // make Shift-Backspace do the same as plain backspace
AddBinding("EditingCommands.DeletePreviousWord", "Ctrl+Back", null, OnDelete(EditingCommands.SelectLeftByWord));
AddBinding("EditingCommands.EnterParagraphBreak", "Return", null, OnEnter);
AddBinding("EditingCommands.EnterLineBreak", "Shift+Return", null, OnEnter);
AddBinding("EditingCommands.TabForward", "Tab", null, OnTab);
AddBinding("EditingCommands.TabBackward", "Shift+Tab", null, OnShiftTab);
AddBinding("ApplicationCommands.Copy", "Ctrl+C", CanCutOrCopy, OnCopy);
AddBinding("ApplicationCommands.Cut", "Ctrl+X", CanCutOrCopy, OnCut);
AddBinding("ApplicationCommands.Paste", "Ctrl+V", CanPaste, OnPaste);
CommandBindings.Add(new CommandBinding(AvalonEditCommands.DeleteLine, OnDeleteLine));
AddBinding("AvalonEditCommands.DeleteLine", "Ctrl+D", null, OnDeleteLine);
CommandBindings.Add(new CommandBinding(AvalonEditCommands.RemoveLeadingWhitespace, OnRemoveLeadingWhitespace));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.RemoveTrailingWhitespace, OnRemoveTrailingWhitespace));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertToUppercase, OnConvertToUpperCase));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertToLowercase, OnConvertToLowerCase));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertToTitleCase, OnConvertToTitleCase));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.InvertCase, OnInvertCase));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertTabsToSpaces, OnConvertTabsToSpaces));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertSpacesToTabs, OnConvertSpacesToTabs));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertLeadingTabsToSpaces, OnConvertLeadingTabsToSpaces));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ConvertLeadingSpacesToTabs, OnConvertLeadingSpacesToTabs));
CommandBindings.Add(new CommandBinding(AvalonEditCommands.IndentSelection, OnIndentSelection));
AddBinding("AvalonEditCommands.RemoveLeadingWhitespace", "", null, OnRemoveLeadingWhitespace);
AddBinding("AvalonEditCommands.RemoveTrailingWhitespace", "", null, OnRemoveTrailingWhitespace);
AddBinding("AvalonEditCommands.ConvertToUppercase", "", null, OnConvertToUpperCase);
AddBinding("AvalonEditCommands.ConvertToLowercase", "", null, OnConvertToLowerCase);
AddBinding("AvalonEditCommands.ConvertToTitleCase", "", null, OnConvertToTitleCase);
AddBinding("AvalonEditCommands.InvertCase", "", null, OnInvertCase);
AddBinding("AvalonEditCommands.ConvertTabsToSpaces", "", null, OnConvertTabsToSpaces);
AddBinding("AvalonEditCommands.ConvertSpacesToTabs", "", null, OnConvertSpacesToTabs);
AddBinding("AvalonEditCommands.ConvertLeadingTabsToSpaces", "", null, OnConvertLeadingTabsToSpaces);
AddBinding("AvalonEditCommands.ConvertLeadingSpacesToTabs", "", null, OnConvertLeadingSpacesToTabs);
AddBinding("AvalonEditCommands.IndentSelection", "", null, OnIndentSelection);
}
static TextArea GetTextArea(object target)

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -24,6 +24,10 @@ using ICSharpCode.AvalonEdit.Indentation; @@ -24,6 +24,10 @@ using ICSharpCode.AvalonEdit.Indentation;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Core.Presentation;
using SDCommandManager = ICSharpCode.Core.Presentation.CommandManager;
using CommandManager = System.Windows.Input.CommandManager;
namespace ICSharpCode.AvalonEdit.Editing
{
/// <summary>
@ -34,6 +38,8 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -34,6 +38,8 @@ namespace ICSharpCode.AvalonEdit.Editing
#region Constructor
static TextArea()
{
SDCommandManager.RegisterNamedUIType(typeof(TextArea).GetShortAssemblyQualifiedName(), typeof(TextArea));
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextArea),
new FrameworkPropertyMetadata(typeof(TextArea)));
KeyboardNavigation.IsTabStopProperty.OverrideMetadata(

46
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextAreaInputHandler.cs

@ -6,11 +6,15 @@ @@ -6,11 +6,15 @@
// </file>
using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Core.Presentation;
using SDCommandManager = ICSharpCode.Core.Presentation.CommandManager;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace ICSharpCode.AvalonEdit.Editing
{
/// <summary>
@ -47,6 +51,17 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -47,6 +51,17 @@ namespace ICSharpCode.AvalonEdit.Editing
readonly TextArea textArea;
bool isAttached;
private BindingGroup m_bindingGroup;
public BindingGroup BindingGroup
{
get {
return m_bindingGroup;
}
set {
m_bindingGroup = value;
}
}
/// <summary>
/// Creates a new TextAreaInputHandler.
/// </summary>
@ -55,6 +70,7 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -55,6 +70,7 @@ namespace ICSharpCode.AvalonEdit.Editing
if (textArea == null)
throw new ArgumentNullException("textArea");
this.textArea = textArea;
commandBindings = new ObserveAddRemoveCollection<CommandBinding>(CommandBinding_Added, CommandBinding_Removed);
inputBindings = new ObserveAddRemoveCollection<InputBinding>(InputBinding_Added, InputBinding_Removed);
nestedInputHandlers = new ObserveAddRemoveCollection<ITextAreaInputHandler>(NestedInputHandler_Added, NestedInputHandler_Removed);
@ -159,10 +175,16 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -159,10 +175,16 @@ namespace ICSharpCode.AvalonEdit.Editing
throw new InvalidOperationException("Input handler is already attached");
isAttached = true;
textArea.CommandBindings.AddRange(commandBindings);
textArea.InputBindings.AddRange(inputBindings);
foreach (ITextAreaInputHandler handler in nestedInputHandlers)
handler.Attach();
if(BindingGroup != null) {
BindingGroup.AttachTo(textArea);
}
// TODO: REMOVE
// textArea.CommandBindings.AddRange(commandBindings);
// textArea.InputBindings.AddRange(inputBindings);
//foreach (ITextAreaInputHandler handler in nestedInputHandlers)
// handler.Attach();
}
/// <inheritdoc/>
@ -172,12 +194,16 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -172,12 +194,16 @@ namespace ICSharpCode.AvalonEdit.Editing
throw new InvalidOperationException("Input handler is not attached");
isAttached = false;
foreach (CommandBinding b in commandBindings)
textArea.CommandBindings.Remove(b);
foreach (InputBinding b in inputBindings)
textArea.InputBindings.Remove(b);
foreach (ITextAreaInputHandler handler in nestedInputHandlers)
handler.Detach();
BindingGroup.DetachFrom(textArea);
// TODO: REMOVE
// foreach (CommandBinding b in commandBindings)
// textArea.CommandBindings.Remove(b);
// foreach (InputBinding b in inputBindings)
// textArea.InputBindings.Remove(b);
// foreach (ITextAreaInputHandler handler in nestedInputHandlers)
// handler.Detach();
}
#endregion
}

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

@ -89,7 +89,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -89,7 +89,7 @@ namespace ICSharpCode.SharpDevelop.Gui
placeholder = null;
var contextName = padInstance.GetType().FullName;
CommandManager.RegisterNamedUIElementInstance(contextName, (UIElement)Content);
CommandManager.RegisterNamedUIElement(contextName, (UIElement)Content);
}
}
}

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

@ -109,7 +109,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -109,7 +109,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (newActiveViewContent != null) {
string ownerName = newActiveViewContent.GetType().FullName;
CommandManager.RegisterNamedUIElementInstance(ownerName, (UIElement)Content);
CommandManager.RegisterNamedUIElement(ownerName, (UIElement)Content);
}
}

63
src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingGroup.cs

@ -25,7 +25,8 @@ namespace ICSharpCode.Core.Presentation @@ -25,7 +25,8 @@ namespace ICSharpCode.Core.Presentation
private ObservableCollection<InputBindingInfo> _inputBindings;
private ObservableCollection<CommandBindingInfo> _commandBindings;
private List<string> _attachedInstances = new List<string>();
private List<string> _attachedNamedInstances = new List<string>();
private List<UIElement> _attachedInstances = new List<UIElement>();
private List<BindingGroup> _nestedGroups = new List<BindingGroup>();
@ -43,15 +44,45 @@ namespace ICSharpCode.Core.Presentation @@ -43,15 +44,45 @@ namespace ICSharpCode.Core.Presentation
get; set;
}
public bool IsAttachedTo(UIElement instance)
{
return _attachedInstances.Contains(instance);
}
public bool IsAttachedTo(string instanceName)
{
return _attachedInstances.Contains(instanceName);
return _attachedNamedInstances.Contains(instanceName);
}
public void AttachTo(UIElement instance)
{
if(!_attachedInstances.Contains(instance)) {
AttachToWithoutInvoke(instance);
}
}
public void AttachTo(string instanceName)
{
if(!_attachedNamedInstances.Contains(instanceName)) {
AttachToWithoutInvoke(instanceName);
}
}
private void AttachToWithoutInvoke(UIElement instance)
{
if(!_attachedInstances.Contains(instance)) {
_attachedInstances.Add(instance);
foreach(var nestedGroup in _nestedGroups) {
nestedGroup.AttachToWithoutInvoke(instance);
}
}
}
private void AttachToWithoutInvoke(string instanceName)
{
if(!_attachedInstances.Contains(instanceName)) {
_attachedInstances.Add(instanceName);
if(!_attachedNamedInstances.Contains(instanceName)) {
_attachedNamedInstances.Add(instanceName);
foreach(var nestedGroup in _nestedGroups) {
nestedGroup.AttachToWithoutInvoke(instanceName);
@ -59,20 +90,21 @@ namespace ICSharpCode.Core.Presentation @@ -59,20 +90,21 @@ namespace ICSharpCode.Core.Presentation
}
}
public void AttachTo(string instanceName)
public void DetachFromWithoutInvoke(UIElement instance)
{
if(!_attachedInstances.Contains(instanceName)) {
AttachToWithoutInvoke(instanceName);
if(_attachedInstances.Contains(instance)) {
_attachedInstances.Remove(instance);
CommandManager.InvokeCommandBindingUpdateHandlers(null, instanceName);
CommandManager.InvokeInputBindingUpdateHandlers(null, instanceName);
foreach(var nestedGroup in _nestedGroups) {
nestedGroup.DetachFrom(instance);
}
}
}
public void DetachFromWithoutInvoke(string instanceName)
{
if(_attachedInstances.Contains(instanceName)) {
_attachedInstances.Remove(instanceName);
if(_attachedNamedInstances.Contains(instanceName)) {
_attachedNamedInstances.Remove(instanceName);
foreach(var nestedGroup in _nestedGroups) {
nestedGroup.DetachFrom(instanceName);
@ -80,9 +112,16 @@ namespace ICSharpCode.Core.Presentation @@ -80,9 +112,16 @@ namespace ICSharpCode.Core.Presentation
}
}
public void DetachFrom(UIElement instance)
{
if(_attachedInstances.Contains(instance)) {
DetachFromWithoutInvoke(instance);
}
}
public void DetachFrom(string instanceName)
{
if(_attachedInstances.Contains(instanceName)) {
if(_attachedNamedInstances.Contains(instanceName)) {
DetachFromWithoutInvoke(instanceName);
CommandManager.InvokeCommandBindingUpdateHandlers(null, instanceName);

6
src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingGroupCollection.cs

@ -67,6 +67,10 @@ namespace ICSharpCode.Core.Presentation @@ -67,6 +67,10 @@ namespace ICSharpCode.Core.Presentation
public void Add(BindingGroup bindingGroup)
{
if(bindingGroup == null) {
throw new ArgumentNullException("bindingGroup");
}
if(!_bindingGroups.Contains(bindingGroup)) {
_bindingGroups.Add(bindingGroup);
}
@ -99,7 +103,7 @@ namespace ICSharpCode.Core.Presentation @@ -99,7 +103,7 @@ namespace ICSharpCode.Core.Presentation
public void AddRange(IEnumerable<BindingGroup> bindingGroups)
{
foreach(var bindingGroup in _bindingGroups) {
foreach(var bindingGroup in bindingGroups) {
Add(bindingGroup);
}
}

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using CommandManager=ICSharpCode.Core.Presentation.CommandManager;
@ -19,18 +20,24 @@ namespace ICSharpCode.Core.Presentation @@ -19,18 +20,24 @@ namespace ICSharpCode.Core.Presentation
{
IsModifyed = true;
OldCommandBindings = new CommandBindingCollection();
NewCommandBindings = new CommandBindingCollection();
ActiveCommandBindings = new CommandBindingCollection();
Groups = new BindingGroupCollection();
Groups.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) {
Groups.CollectionChanged += Groups_CollectionChanged;
}
private void Groups_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
if(e.OldItems != null) {
foreach(BindingGroup oldGroup in e.OldItems) {
oldGroup.CommandBindings.Remove(this);
}
foreach(BindingGroup oldGroup in e.NewItems) {
oldGroup.CommandBindings.Add(this);
}
if(e.NewItems != null) {
foreach(BindingGroup newGroup in e.NewItems) {
newGroup.CommandBindings.Add(this);
}
};
}
}
public BindingGroupCollection Groups
@ -200,8 +207,6 @@ namespace ICSharpCode.Core.Presentation @@ -200,8 +207,6 @@ namespace ICSharpCode.Core.Presentation
}
}
private UIElement _ownerInstance;
/// <summary>
/// Stores owner instance to which this binding belongs. When this binding is registered a
/// <see cref="CommandBinding" /> is assigned to owner instance
@ -209,13 +214,13 @@ namespace ICSharpCode.Core.Presentation @@ -209,13 +214,13 @@ namespace ICSharpCode.Core.Presentation
/// If this attribute is used <see cref="OwnerInstanceName" />, <see cref="OwnerType" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// </summary>
public UIElement OwnerInstance{
public ICollection<UIElement> OwnerInstances {
get {
if(_ownerInstance == null && _ownerInstanceName != null) {
_ownerInstance = CommandManager.GetNamedUIElementInstance(_ownerInstanceName);
if(_ownerInstanceName != null) {
return CommandManager.GetNamedUIElement(_ownerInstanceName);
}
return _ownerInstance;
return null;
}
}
@ -241,8 +246,6 @@ namespace ICSharpCode.Core.Presentation @@ -241,8 +246,6 @@ namespace ICSharpCode.Core.Presentation
}
}
private Type _ownerType;
/// <summary>
/// Stores owner type. When this binding is registered <see cref="CommandBinding" />
/// is assigned to all instances of provided class
@ -250,13 +253,13 @@ namespace ICSharpCode.Core.Presentation @@ -250,13 +253,13 @@ namespace ICSharpCode.Core.Presentation
/// If this attribute is used <see cref="OwnerInstance" />, <see cref="OwnerInstanceName" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// </summary>
public Type OwnerType {
public ICollection<Type> OwnerTypes {
get {
if(_ownerType == null && _ownerTypeName != null) {
_ownerType = CommandManager.GetNamedUIType(_ownerTypeName);
if(_ownerTypeName != null) {
return CommandManager.GetNamedUIType(_ownerTypeName);
}
return _ownerType;
return null;
}
}
@ -270,15 +273,17 @@ namespace ICSharpCode.Core.Presentation @@ -270,15 +273,17 @@ namespace ICSharpCode.Core.Presentation
get {
if(defaultCommandBindingHandler == null && OwnerTypeName != null) {
defaultCommandBindingHandler = delegate {
if(OwnerType != null && IsModifyed) {
if(OwnerTypes != null && IsModifyed) {
GenerateCommandBindings();
foreach(CommandBinding binding in OldCommandBindings) {
CommandManager.RemoveClassCommandBinding(OwnerType, binding);
}
foreach(CommandBinding binding in NewCommandBindings) {
System.Windows.Input.CommandManager.RegisterClassCommandBinding(OwnerType, binding);
foreach(var ownerType in OwnerTypes) {
foreach(CommandBinding binding in OldCommandBindings) {
CommandManager.RemoveClassCommandBinding(ownerType, binding);
}
foreach(CommandBinding binding in ActiveCommandBindings) {
System.Windows.Input.CommandManager.RegisterClassCommandBinding(ownerType, binding);
}
}
IsModifyed = false;
@ -286,14 +291,16 @@ namespace ICSharpCode.Core.Presentation @@ -286,14 +291,16 @@ namespace ICSharpCode.Core.Presentation
};
} else if(defaultCommandBindingHandler == null && OwnerInstanceName != null) {
defaultCommandBindingHandler = delegate {
if(OwnerInstance != null && IsModifyed) {
if(OwnerInstances != null && IsModifyed) {
GenerateCommandBindings();
foreach(CommandBinding binding in OldCommandBindings) {
OwnerInstance.CommandBindings.Remove(binding);
}
foreach(var ownerInstance in OwnerInstances) {
foreach(CommandBinding binding in OldCommandBindings) {
ownerInstance.CommandBindings.Remove(binding);
}
OwnerInstance.CommandBindings.AddRange(NewCommandBindings);
ownerInstance.CommandBindings.AddRange(ActiveCommandBindings);
}
IsModifyed = false;
}
@ -329,15 +336,15 @@ namespace ICSharpCode.Core.Presentation @@ -329,15 +336,15 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
internal void GenerateCommandBindings()
{
OldCommandBindings = NewCommandBindings;
OldCommandBindings = ActiveCommandBindings;
NewCommandBindings = new CommandBindingCollection();
ActiveCommandBindings = new CommandBindingCollection();
if(IsActive) {
var commandBinding = new CommandBinding(RoutedCommand);
commandBinding.CanExecute += GenerateCanExecuteEventHandler;
commandBinding.Executed += GenerateExecutedEventHandler;
NewCommandBindings.Add(commandBinding);
ActiveCommandBindings.Add(commandBinding);
}
}
@ -355,7 +362,7 @@ namespace ICSharpCode.Core.Presentation @@ -355,7 +362,7 @@ namespace ICSharpCode.Core.Presentation
/// <summary>
/// New input bindings are assigned to owner when <see cref="CommandBindingInfo" /> is modified
/// </summary>
internal CommandBindingCollection NewCommandBindings
public CommandBindingCollection ActiveCommandBindings
{
get; set;
}

146
src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs

@ -46,8 +46,8 @@ namespace ICSharpCode.Core.Presentation @@ -46,8 +46,8 @@ namespace ICSharpCode.Core.Presentation
private static Dictionary<string, List<BindingsUpdatedHandler>> instanceInputBindingUpdateHandlers = new Dictionary<string, List<BindingsUpdatedHandler>>();
// Named instances and types
private static Dictionary<string, UIElement> namedUIInstances = new Dictionary<string, UIElement>();
private static Dictionary<string, Type> namedUITypes = new Dictionary<string, Type>();
private static Dictionary<string, List<UIElement>> namedUIInstances = new Dictionary<string, List<UIElement>>();
private static Dictionary<string, List<Type>> namedUITypes = new Dictionary<string, List<Type>>();
// Categories
public static List<InputBindingCategory> InputBindingCategories = new List<InputBindingCategory>();
@ -57,10 +57,16 @@ namespace ICSharpCode.Core.Presentation @@ -57,10 +57,16 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="instanceName">Instance name</param>
/// <param name="element">Instance</param>
public static void RegisterNamedUIElementInstance(string instanceName, UIElement element)
public static void RegisterNamedUIElement(string instanceName, UIElement element)
{
if(!namedUIInstances.ContainsKey(instanceName)){
namedUIInstances.Add(instanceName, element);
namedUIInstances.Add(instanceName, new List<UIElement>());
}
var namedUIInstanceCollection = namedUIInstances[instanceName];
if(!namedUIInstanceCollection.Contains(element)) {
namedUIInstanceCollection.Add(element);
// If there are some bindings and update handlers already registered,
// but owner is not loaded then invoke those bindings
@ -79,25 +85,14 @@ namespace ICSharpCode.Core.Presentation @@ -79,25 +85,14 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="instanceName">Instance name</param>
/// <returns></returns>
public static UIElement GetNamedUIElementInstance(string instanceName)
public static ICollection<UIElement> GetNamedUIElement(string instanceName)
{
UIElement instance;
List<UIElement> instance;
namedUIInstances.TryGetValue(instanceName, out instance);
return instance;
}
public static string GetNamedUIElementName(UIElement instance)
{
foreach(var currentInstance in namedUIInstances) {
if(currentInstance.Value == instance) {
return currentInstance.Key;
}
}
return null;
}
/// <summary>
/// Register UI type which can be accessible by name
/// </summary>
@ -106,7 +101,12 @@ namespace ICSharpCode.Core.Presentation @@ -106,7 +101,12 @@ namespace ICSharpCode.Core.Presentation
public static void RegisterNamedUIType(string typeName, Type type)
{
if(!namedUITypes.ContainsKey(typeName)){
namedUITypes.Add(typeName, type);
namedUITypes.Add(typeName, new List<Type>());
}
var namedUITypeCollection = namedUITypes[typeName];
if(!namedUITypeCollection.Contains(type)) {
namedUITypeCollection.Add(type);
// If any update handlers where assigned to the type and type was not
// loaded yet then invoke update handlers
@ -125,9 +125,9 @@ namespace ICSharpCode.Core.Presentation @@ -125,9 +125,9 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="typeName">Type name</param>
/// <returns>Type</returns>
public static Type GetNamedUIType(string typeName)
public static List<Type> GetNamedUIType(string typeName)
{
Type instance;
List<Type> instance;
namedUITypes.TryGetValue(typeName, out instance);
return instance;
@ -210,7 +210,7 @@ namespace ICSharpCode.Core.Presentation @@ -210,7 +210,7 @@ namespace ICSharpCode.Core.Presentation
/// <param name="inputBindingInfo">Input binding parameters</param>
public static void RegisterInputBinding(InputBindingInfo inputBindingInfo)
{
var similarInputBinding = FindInputBindingInfos(inputBindingInfo.OwnerTypeName, inputBindingInfo.OwnerInstanceName, inputBindingInfo.RoutedCommandName).FirstOrDefault();
var similarInputBinding = FindInputBindingInfos(inputBindingInfo.OwnerTypeName, inputBindingInfo.OwnerInstanceName, inputBindingInfo.RoutedCommandName, null).FirstOrDefault();
if(similarInputBinding != null) {
foreach(InputGesture gesture in inputBindingInfo.DefaultGestures) {
@ -221,7 +221,7 @@ namespace ICSharpCode.Core.Presentation @@ -221,7 +221,7 @@ namespace ICSharpCode.Core.Presentation
similarInputBinding.Categories.AddRange(inputBindingInfo.Categories);
similarInputBinding.Groups.AddRange(inputBindingInfo.Groups);
similarInputBinding.IsModifyed = true;
similarInputBinding.DefaultInputBindingHandler.Invoke();
} else {
@ -241,27 +241,31 @@ namespace ICSharpCode.Core.Presentation @@ -241,27 +241,31 @@ namespace ICSharpCode.Core.Presentation
/// <param name="inputBindingInfo">Input binding parameters</param>
public static void UnregisterInputBinding(InputBindingInfo inputBindingInfo)
{
var similarInputBindingInfos = FindInputBindingInfos(inputBindingInfo.OwnerTypeName, inputBindingInfo.OwnerInstanceName, inputBindingInfo.RoutedCommandName);
var similarInputBindingInfos = FindInputBindingInfos(inputBindingInfo.OwnerTypeName, inputBindingInfo.OwnerInstanceName, inputBindingInfo.RoutedCommandName, null);
foreach(var similarInputBindingInfo in similarInputBindingInfos) {
inputBidnings.Remove(similarInputBindingInfo);
// Remove command bindings
if(similarInputBindingInfo.OwnerType != null) {
foreach(InputBinding binding in similarInputBindingInfo.OldInputBindings) {
RemoveClassInputBinding(similarInputBindingInfo.OwnerType, binding);
if(similarInputBindingInfo.OwnerTypes != null) {
foreach(var ownerType in similarInputBindingInfo.OwnerTypes) {
foreach(InputBinding binding in similarInputBindingInfo.OldInputBindings) {
RemoveClassInputBinding(ownerType, binding);
}
foreach(InputBinding binding in similarInputBindingInfo.ActiveInputBindings) {
RemoveClassInputBinding(ownerType, binding);
}
}
} else if (similarInputBindingInfo.OwnerInstances != null) {
foreach(var ownerInstance in similarInputBindingInfo.OwnerInstances) {
foreach(InputBinding binding in similarInputBindingInfo.OldInputBindings) {
ownerInstance.InputBindings.Remove(binding);
}
foreach(InputBinding binding in similarInputBindingInfo.NewInputBindings) {
RemoveClassInputBinding(similarInputBindingInfo.OwnerType, binding);
}
} else if (similarInputBindingInfo.OwnerInstance != null) {
foreach(InputBinding binding in similarInputBindingInfo.OldInputBindings) {
similarInputBindingInfo.OwnerInstance.InputBindings.Remove(binding);
}
foreach(InputBinding binding in similarInputBindingInfo.NewInputBindings) {
similarInputBindingInfo.OwnerInstance.InputBindings.Remove(binding);
foreach(InputBinding binding in similarInputBindingInfo.ActiveInputBindings) {
ownerInstance.InputBindings.Remove(binding);
}
}
}
}
@ -275,13 +279,20 @@ namespace ICSharpCode.Core.Presentation @@ -275,13 +279,20 @@ namespace ICSharpCode.Core.Presentation
/// <param name="contextName">Context class full name</param>
/// <param name="contextInstance">Unregister binding assigned to specific context instance</param>
/// <param name="routedCommandName">Routed UI command name</param>
public static ICollection<InputBindingInfo> FindInputBindingInfos(string ownerTypeName, string ownerInstanceName, string routedCommandName) {
public static ICollection<InputBindingInfo> FindInputBindingInfos(string ownerTypeName, string ownerInstanceName, string routedCommandName, BindingGroupCollection bindingGroups)
{
var foundBindings = new List<InputBindingInfo>();
foreach(var binding in inputBidnings) {
if(binding.RoutedCommandName == "AvalonEditCommands.ConvertToUppercase")
{
}
if( (ownerInstanceName == null || binding.OwnerInstanceName == ownerInstanceName)
&& (ownerTypeName == null || binding.OwnerTypeName == ownerTypeName)
&& (routedCommandName == null || binding.RoutedCommandName == routedCommandName)
&& (bindingGroups == null || bindingGroups.ContainsAnyFromCollection(binding.Groups))
) {
foundBindings.Add(binding);
}
@ -290,6 +301,18 @@ namespace ICSharpCode.Core.Presentation @@ -290,6 +301,18 @@ namespace ICSharpCode.Core.Presentation
return foundBindings;
}
public static InputBindingCollection FindInputBindings(string ownerTypeName, string ownerInstanceName, string routedCommandName, BindingGroupCollection bindingGroups)
{
var inputBindingInfoCollection = FindInputBindingInfos(ownerTypeName, ownerInstanceName, routedCommandName, bindingGroups);
var inputBindingCollection = new InputBindingCollection();
foreach(var bindingInfo in inputBindingInfoCollection) {
inputBindingCollection.AddRange(bindingInfo.ActiveInputBindings);
}
return inputBindingCollection;
}
/// <summary>
/// Remove input binding associated with type
/// </summary>
@ -362,27 +385,31 @@ namespace ICSharpCode.Core.Presentation @@ -362,27 +385,31 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="commandBindingInfo">Command binding parameters</param>
public static void UnregisterCommandBinding(CommandBindingInfo commandBindingInfo) {
var similarCommandBindingInfos = FindCommandBindingInfos(commandBindingInfo.OwnerTypeName, commandBindingInfo.OwnerInstanceName, commandBindingInfo.RoutedCommandName);
var similarCommandBindingInfos = FindCommandBindingInfos(commandBindingInfo.OwnerTypeName, commandBindingInfo.OwnerInstanceName, commandBindingInfo.RoutedCommandName, null);
foreach(var similarCommandBindingInfo in similarCommandBindingInfos) {
commandBindings.Remove(similarCommandBindingInfo);
// Remove command bindings
if(similarCommandBindingInfo.OwnerType != null) {
foreach(CommandBinding binding in similarCommandBindingInfo.OldCommandBindings) {
RemoveClassCommandBinding(similarCommandBindingInfo.OwnerType, binding);
if(similarCommandBindingInfo.OwnerTypes != null) {
foreach(var ownerType in similarCommandBindingInfo.OwnerTypes) {
foreach(CommandBinding binding in similarCommandBindingInfo.OldCommandBindings) {
RemoveClassCommandBinding(ownerType, binding);
}
foreach(CommandBinding binding in similarCommandBindingInfo.ActiveCommandBindings) {
RemoveClassCommandBinding(ownerType, binding);
}
}
} else if (similarCommandBindingInfo.OwnerInstances != null) {
foreach(var ownerInstance in similarCommandBindingInfo.OwnerInstances) {
foreach(CommandBinding binding in similarCommandBindingInfo.OldCommandBindings) {
ownerInstance.CommandBindings.Remove(binding);
}
foreach(CommandBinding binding in similarCommandBindingInfo.NewCommandBindings) {
RemoveClassCommandBinding(similarCommandBindingInfo.OwnerType, binding);
}
} else if (similarCommandBindingInfo.OwnerInstance != null) {
foreach(CommandBinding binding in similarCommandBindingInfo.OldCommandBindings) {
similarCommandBindingInfo.OwnerInstance.CommandBindings.Remove(binding);
}
foreach(CommandBinding binding in similarCommandBindingInfo.NewCommandBindings) {
similarCommandBindingInfo.OwnerInstance.CommandBindings.Remove(binding);
foreach(CommandBinding binding in similarCommandBindingInfo.ActiveCommandBindings) {
ownerInstance.CommandBindings.Remove(binding);
}
}
}
}
@ -561,13 +588,15 @@ namespace ICSharpCode.Core.Presentation @@ -561,13 +588,15 @@ 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 ICollection<CommandBindingInfo> FindCommandBindingInfos(string ownerTypeName, string ownerInstanceName, string routedCommandName) {
public static ICollection<CommandBindingInfo> FindCommandBindingInfos(string ownerTypeName, string ownerInstanceName, string routedCommandName, BindingGroupCollection bindingGroups)
{
var foundBindings = new List<CommandBindingInfo>();
foreach(var binding in commandBindings) {
if( (ownerInstanceName == null || binding.OwnerInstanceName == ownerInstanceName)
&& (ownerTypeName == null || binding.OwnerTypeName == ownerTypeName)
&& (routedCommandName == null || binding.RoutedCommandName == routedCommandName)
&& (bindingGroups == null || bindingGroups.ContainsAnyFromCollection(binding.Groups))
) {
foundBindings.Add(binding);
}
@ -576,7 +605,16 @@ namespace ICSharpCode.Core.Presentation @@ -576,7 +605,16 @@ namespace ICSharpCode.Core.Presentation
return foundBindings;
}
public static CommandBindingCollection FindCommandBindings(string ownerTypeName, string ownerInstanceName, string routedCommandName, BindingGroupCollection bindingGroups)
{
var commandBindingInfoCollection = FindCommandBindingInfos(ownerTypeName, ownerInstanceName, routedCommandName, bindingGroups);
var commandBindingCollection = new CommandBindingCollection();
foreach(var bindingInfo in commandBindingInfoCollection) {
commandBindingCollection.AddRange(bindingInfo.ActiveCommandBindings);
}
return commandBindingCollection;
}
/// <summary>
/// Get list of input gestures from all input bindings which satisfy provided parameters
@ -588,7 +626,7 @@ namespace ICSharpCode.Core.Presentation @@ -588,7 +626,7 @@ namespace ICSharpCode.Core.Presentation
/// <param name="routedCommandName">Routed UI command name</param>
/// <param name="gesture">Gesture</param>
public static InputGestureCollection FindInputGestures(string ownerTypeName, string ownerInstanceName, string routedCommandName, BindingGroupCollection bindingGroups) {
var bindings = FindInputBindingInfos(ownerTypeName, ownerInstanceName, routedCommandName);
var bindings = FindInputBindingInfos(ownerTypeName, ownerInstanceName, routedCommandName, bindingGroups);
var gestures = new InputGestureCollection();
foreach(InputBindingInfo bindingInfo in bindings) {

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

@ -38,12 +38,7 @@ namespace ICSharpCode.Core.Presentation @@ -38,12 +38,7 @@ namespace ICSharpCode.Core.Presentation
string routedCommandName = null;
string routedCommandText = null;
if(codon.Properties.Contains("command")) {
if(codon.Properties["command"] == "AvalonEditCommands.RemoveLeadingWhitespace")
{
}
if(codon.Properties.Contains("command")) {
routedCommandName = codon.Properties["command"];
routedCommandText = codon.Properties["command"];
} else if(codon.Properties.Contains("link") || codon.Properties.Contains("class")) {
@ -59,7 +54,11 @@ namespace ICSharpCode.Core.Presentation @@ -59,7 +54,11 @@ namespace ICSharpCode.Core.Presentation
if(!codon.Properties.Contains("command") && (codon.Properties.Contains("link") || codon.Properties.Contains("class"))) {
var commandBindingInfo = new CommandBindingInfo();
commandBindingInfo.AddIn = codon.AddIn;
commandBindingInfo.OwnerTypeName = CommandManager.DefaultContextName;
if(codon.Properties.Contains("ownerinstance")) {
commandBindingInfo.OwnerInstanceName = codon.Properties["ownerinstance"];
} else {
commandBindingInfo.OwnerTypeName = codon.Properties.Contains("ownertype") ? codon.Properties["ownertype"] : CommandManager.DefaultContextName;
}
commandBindingInfo.CommandInstance = CommandWrapper.GetCommand(codon, null, codon.Properties["loadclasslazy"] == "true");
commandBindingInfo.RoutedCommandName = routedCommandName;
commandBindingInfo.IsLazy = true;
@ -69,7 +68,11 @@ namespace ICSharpCode.Core.Presentation @@ -69,7 +68,11 @@ namespace ICSharpCode.Core.Presentation
// Register input bindings
var inputBindingInfo = new InputBindingInfo();
inputBindingInfo.AddIn = codon.AddIn;
inputBindingInfo.OwnerTypeName = CommandManager.DefaultContextName;
if(codon.Properties.Contains("ownerinstance")) {
inputBindingInfo.OwnerInstanceName = codon.Properties["ownerinstance"];
} else {
inputBindingInfo.OwnerTypeName = codon.Properties.Contains("ownertype") ? codon.Properties["ownertype"] : CommandManager.DefaultContextName;
}
inputBindingInfo.RoutedCommandName = routedCommandName;
var defaultGesture = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromInvariantString(codon.Properties["shortcut"]);
@ -112,13 +115,6 @@ namespace ICSharpCode.Core.Presentation @@ -112,13 +115,6 @@ namespace ICSharpCode.Core.Presentation
if(command != null) {
CommandManager.RegisterRoutedUICommand(command);
if(command.Name == "RemoveLeadingWhitespace")
{
var cmd = CommandManager.GetRoutedUICommand("AvalonEditCommands.RemoveLeadingWhitespace");
Console.WriteLine(cmd);
}
}
}
}

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

@ -18,19 +18,25 @@ namespace ICSharpCode.Core.Presentation @@ -18,19 +18,25 @@ namespace ICSharpCode.Core.Presentation
{
IsModifyed = true;
OldInputBindings = new InputBindingCollection();
NewInputBindings = new InputBindingCollection();
ActiveInputBindings = new InputBindingCollection();
DefaultGestures = new InputGestureCollection();
Categories = new InputBindingCategoryCollection();
Groups = new BindingGroupCollection();
Groups.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) {
Groups.CollectionChanged += Groups_CollectionChanged;
}
private void Groups_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
if(e.OldItems != null) {
foreach(BindingGroup oldGroup in e.OldItems) {
oldGroup.InputBindings.Remove(this);
}
foreach(BindingGroup newGroup in e.NewItems) {
newGroup.InputBindings.Add(this);
}
if(e.NewItems != null) {
foreach(BindingGroup oldGroup in e.NewItems) {
oldGroup.InputBindings.Add(this);
}
};
}
}
public BindingGroupCollection Groups
@ -71,8 +77,6 @@ namespace ICSharpCode.Core.Presentation @@ -71,8 +77,6 @@ namespace ICSharpCode.Core.Presentation
}
}
private UIElement _ownerInstance;
/// <summary>
/// Stores owner instance to which this binding belongs. When this binding is registered a
/// <see cref="InputBinding" /> is assigned to owner instance
@ -80,13 +84,13 @@ namespace ICSharpCode.Core.Presentation @@ -80,13 +84,13 @@ namespace ICSharpCode.Core.Presentation
/// If this attribute is used <see cref="OwnerInstanceName" />, <see cref="OwnerType" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// </summary>
public UIElement OwnerInstance{
public ICollection<UIElement> OwnerInstances {
get {
if(_ownerInstanceName != null && _ownerInstance == null) {
_ownerInstance = CommandManager.GetNamedUIElementInstance(_ownerInstanceName);
if(_ownerInstanceName != null) {
return CommandManager.GetNamedUIElement(_ownerInstanceName);
}
return _ownerInstance;
return null;
}
}
@ -112,8 +116,6 @@ namespace ICSharpCode.Core.Presentation @@ -112,8 +116,6 @@ namespace ICSharpCode.Core.Presentation
}
}
private Type _ownerType;
/// <summary>
/// Stores owner type. When this binding is registered <see cref="InputBinding" />
/// is assigned to all instances of provided class
@ -121,13 +123,13 @@ namespace ICSharpCode.Core.Presentation @@ -121,13 +123,13 @@ namespace ICSharpCode.Core.Presentation
/// If this attribute is used <see cref="OwnerInstance" />, <see cref="OwnerInstanceName" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// </summary>
public Type OwnerType {
public ICollection<Type> OwnerTypes {
get {
if(_ownerType == null && _ownerTypeName != null) {
_ownerType = CommandManager.GetNamedUIType(_ownerTypeName);
if(_ownerTypeName != null) {
return CommandManager.GetNamedUIType(_ownerTypeName);
}
return _ownerType;
return null;
}
}
@ -212,13 +214,13 @@ namespace ICSharpCode.Core.Presentation @@ -212,13 +214,13 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
public void GenerateInputBindings()
{
OldInputBindings = NewInputBindings;
OldInputBindings = ActiveInputBindings;
NewInputBindings = new InputBindingCollection();
ActiveInputBindings = new InputBindingCollection();
if(ActiveGestures != null && IsActive) {
foreach(InputGesture gesture in ActiveGestures) {
var inputBinding = new InputBinding(RoutedCommand, gesture);
NewInputBindings.Add(inputBinding);
ActiveInputBindings.Add(inputBinding);
}
}
}
@ -234,35 +236,39 @@ namespace ICSharpCode.Core.Presentation @@ -234,35 +236,39 @@ namespace ICSharpCode.Core.Presentation
get {
if(defaultInputBindingHandler == null && OwnerTypeName != null) {
defaultInputBindingHandler = delegate {
if(OwnerType != null && IsModifyed) {
if(OwnerTypes != null && IsModifyed) {
GenerateInputBindings();
foreach(InputBinding binding in OldInputBindings) {
CommandManager.RemoveClassInputBinding(OwnerType, binding);
}
foreach(InputBinding binding in NewInputBindings) {
System.Windows.Input.CommandManager.RegisterClassInputBinding(OwnerType, binding);
foreach(var ownerType in OwnerTypes) {
foreach(InputBinding binding in OldInputBindings) {
CommandManager.RemoveClassInputBinding(ownerType, binding);
}
foreach(InputBinding binding in ActiveInputBindings) {
System.Windows.Input.CommandManager.RegisterClassInputBinding(ownerType, binding);
}
CommandManager.OrderClassInputBindingsByChords(ownerType);
}
CommandManager.OrderClassInputBindingsByChords(OwnerType);
IsModifyed = false;
}
};
} else if(defaultInputBindingHandler == null && OwnerInstanceName != null){
defaultInputBindingHandler = delegate {
if(OwnerInstance != null && IsModifyed) {
if(OwnerInstances != null && IsModifyed) {
GenerateInputBindings();
foreach(InputBinding binding in NewInputBindings) {
OwnerInstance.InputBindings.Remove(binding);
foreach(var ownerInstance in OwnerInstances) {
foreach(InputBinding binding in OldInputBindings) {
ownerInstance.InputBindings.Remove(binding);
}
ownerInstance.InputBindings.AddRange(ActiveInputBindings);
CommandManager.OrderInstanceInputBindingsByChords(ownerInstance);
}
OwnerInstance.InputBindings.AddRange(NewInputBindings);
CommandManager.OrderInstanceInputBindingsByChords(OwnerInstance);
IsModifyed = false;
}
};
@ -286,7 +292,7 @@ namespace ICSharpCode.Core.Presentation @@ -286,7 +292,7 @@ namespace ICSharpCode.Core.Presentation
/// <summary>
/// New input bindings are assigned to owner when <see cref="CommandBindingInfo" /> is modified
/// </summary>
internal InputBindingCollection NewInputBindings
public InputBindingCollection ActiveInputBindings
{
get; set;
}

Loading…
Cancel
Save