Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Initial implementation of BindingGroup added
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4442 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
  • Loading branch information
sandrejev committed Jul 14, 2009
1 parent ffccf93 commit 79e5f7d
Show file tree
Hide file tree
Showing 19 changed files with 569 additions and 350 deletions.
20 changes: 10 additions & 10 deletions src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@
<MenuItem id = "RemoveLeadingWs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.RlWs}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.RemoveLeadingWhitespace"/>
command = "AvalonEditCommands.RemoveLeadingWhitespace"/>
<MenuItem id = "RemoveTrailingWs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.RtWs}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.RemoveTrailingWhitespace"/>
command = "AvalonEditCommands.RemoveTrailingWhitespace"/>
<MenuItem id = "Seperator1" type = "Separator" insertbefore = "Separator4" />
<MenuItem id = "UpperCase"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.UpperCase}"
icon = "Icons.16x16.LowerToUpperCase"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertToUppercase"/>
command = "AvalonEditCommands.ConvertToUppercase"/>
<MenuItem id = "LowerCase"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.LowerCase}"
icon = "Icons.16x16.UpperToLowerCase"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertToLowercase"/>
command = "AvalonEditCommands.ConvertToLowercase"/>
<MenuItem id = "Capitalize"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.Capitalize}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertToTitleCase"/>
command = "AvalonEditCommands.ConvertToTitleCase"/>
<MenuItem id = "InvertCase"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.InvertCase}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.InvertCase"/>
command = "AvalonEditCommands.InvertCase"/>
<MenuItem id = "Separator2" type = "Separator" />
<MenuItem id = "SortSelection"
insertbefore = "Separator4"
Expand All @@ -60,19 +60,19 @@
<MenuItem id = "Tabs2Spaces"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.Tab2Space}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertTabsToSpaces"/>
command = "AvalonEditCommands.ConvertTabsToSpaces"/>
<MenuItem id = "Spaces2Tabs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.Space2Tab}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertSpacesToTabs"/>
command = "AvalonEditCommands.ConvertSpacesToTabs"/>
<MenuItem id = "LeadingTabs2Spaces"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.LdTab2Space}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertLeadingTabsToSpaces"/>
command = "AvalonEditCommands.ConvertLeadingTabsToSpaces"/>
<MenuItem id = "LeadingSpaces2Tabs"
insertbefore = "Separator4"
label = "${res:XML.MainMenu.EditMenu.FormatMenu.LdSpace2Tab}"
command = "ICSharpCode.AvalonEdit.AvalonEditCommands.ConvertLeadingSpacesToTabs"/>
command = "AvalonEditCommands.ConvertLeadingSpacesToTabs"/>
</Condition>
</Path>
</AddIn>
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,12 @@ public bool SaveOptions()
}
}

shortcutsMap.ForEach(p => p.Value.IsModifyed = true);
foreach (var pair in shortcutsMap)
{
pair.Value.IsModifyed = true;
}
shortcutsMap.ForEach(b => b.Value.IsModifyed = true);

UserDefinedGesturesManager.CurrentProfile = SelectedProfile;
CommandManager.InvokeInputBindingUpdateHandlers();

foreach (var profile in profiles)
{
profile.Save();
}
profiles.ForEach(p => p.Save());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static class AvalonEditCommands
/// Deletes the current line.
/// The default shortcut is Ctrl+D.
/// </summary>
public static readonly RoutedCommand DeleteLine = new RoutedCommand(
"DeleteLine", typeof(TextEditor),
public static readonly RoutedUICommand DeleteLine = new RoutedUICommand(
"${res:AcalonEditCommands.DeleteLine}", "DeleteLine", typeof(AvalonEditCommands),
new InputGestureCollection {
new KeyGesture(Key.D, ModifierKeys.Control)
});
Expand All @@ -30,60 +30,60 @@ public static class AvalonEditCommands
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Whitespace",
Justification = "WPF uses 'Whitespace'")]
public static readonly RoutedCommand RemoveLeadingWhitespace = new RoutedCommand("RemoveLeadingWhitespace", typeof(TextEditor));
public static readonly RoutedUICommand RemoveLeadingWhitespace = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.RlWs}", "RemoveLeadingWhitespace", typeof(AvalonEditCommands));

/// <summary>
/// Removes trailing whitespace from the selected lines (or the whole document if the selection is empty).
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Whitespace",
Justification = "WPF uses 'Whitespace'")]
public static readonly RoutedCommand RemoveTrailingWhitespace = new RoutedCommand("RemoveTrailingWhitespace", typeof(TextEditor));
public static readonly RoutedUICommand RemoveTrailingWhitespace = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.RtWs}", "RemoveTrailingWhitespace", typeof(AvalonEditCommands));

/// <summary>
/// Converts the selected text to upper case.
/// </summary>
public static readonly RoutedCommand ConvertToUppercase = new RoutedCommand("ConvertToUppercase", typeof(TextEditor));
public static readonly RoutedUICommand ConvertToUppercase = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.UpperCase}", "ConvertToUppercase", typeof(AvalonEditCommands));

/// <summary>
/// Converts the selected text to lower case.
/// </summary>
public static readonly RoutedCommand ConvertToLowercase = new RoutedCommand("ConvertToLowercase", typeof(TextEditor));
public static readonly RoutedUICommand ConvertToLowercase = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.LowerCase}", "ConvertToLowercase", typeof(AvalonEditCommands));

/// <summary>
/// Converts the selected text to title case.
/// </summary>
public static readonly RoutedCommand ConvertToTitleCase = new RoutedCommand("ConvertToTitleCase", typeof(TextEditor));
public static readonly RoutedUICommand ConvertToTitleCase = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.Capitalize}", "ConvertToTitleCase", typeof(AvalonEditCommands));

/// <summary>
/// Inverts the case of the selected text.
/// </summary>
public static readonly RoutedCommand InvertCase = new RoutedCommand("InvertCase", typeof(TextEditor));
public static readonly RoutedUICommand InvertCase = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.InvertCase}", "InvertCase", typeof(AvalonEditCommands));

/// <summary>
/// Converts tabs to spaces in the selected text.
/// </summary>
public static readonly RoutedCommand ConvertTabsToSpaces = new RoutedCommand("ConvertTabsToSpaces", typeof(TextEditor));
public static readonly RoutedUICommand ConvertTabsToSpaces = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.Tab2Space}", "ConvertTabsToSpaces", typeof(AvalonEditCommands));

/// <summary>
/// Converts spaces to tabs in the selected text.
/// </summary>
public static readonly RoutedCommand ConvertSpacesToTabs = new RoutedCommand("ConvertSpacesToTabs", typeof(TextEditor));
public static readonly RoutedUICommand ConvertSpacesToTabs = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.Space2Tab}", "ConvertSpacesToTabs", typeof(AvalonEditCommands));

/// <summary>
/// Converts leading tabs to spaces in the selected lines (or the whole document if the selection is empty).
/// </summary>
public static readonly RoutedCommand ConvertLeadingTabsToSpaces = new RoutedCommand("ConvertLeadingTabsToSpaces", typeof(TextEditor));
public static readonly RoutedUICommand ConvertLeadingTabsToSpaces = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.LdTab2Space}", "ConvertLeadingTabsToSpaces", typeof(AvalonEditCommands));

/// <summary>
/// Converts leading spaces to tabs in the selected lines (or the whole document if the selection is empty).
/// </summary>
public static readonly RoutedCommand ConvertLeadingSpacesToTabs = new RoutedCommand("ConvertLeadingSpacesToTabs", typeof(TextEditor));
public static readonly RoutedUICommand ConvertLeadingSpacesToTabs = new RoutedUICommand("${res:XML.MainMenu.EditMenu.FormatMenu.LdSpace2Tab}", "ConvertLeadingSpacesToTabs", typeof(AvalonEditCommands));

/// <summary>
/// Runs the IIndentationStrategy on the selected lines (or the whole document if the selection is empty).
/// </summary>
public static readonly RoutedCommand IndentSelection = new RoutedCommand(
"IndentSelection", typeof(TextEditor),
public static readonly RoutedUICommand IndentSelection = new RoutedUICommand("${res:AcalonEditCommands.IndentSelection}",
"IndentSelection", typeof(AvalonEditCommands),
new InputGestureCollection {
new KeyGesture(Key.I, ModifierKeys.Control)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Utils;

using ICSharpCode.Core.Presentation;
using SDCommandManager=ICSharpCode.Core.Presentation.CommandManager;

namespace ICSharpCode.AvalonEdit.Editing
{
/// <summary>
Expand Down Expand Up @@ -61,6 +64,14 @@ static EditingCommandHandler()
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);

CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopy, CanCutOrCopy));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCut, CanCutOrCopy));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPaste, CanPaste));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void AddBinding(ICommand command, ModifierKeys modifiers, Key key, Execut
this.InputBindings.Add(new KeyBinding(command, key, modifiers));
}
#endregion

#region NestedInputHandlers
/// <summary>
/// Gets the collection of nested input handlers. NestedInputHandlers are activated and deactivated
Expand All @@ -133,7 +133,7 @@ public void AddBinding(ICommand command, ModifierKeys modifiers, Key key, Execut
public ICollection<ITextAreaInputHandler> NestedInputHandlers {
get { return nestedInputHandlers; }
}

void NestedInputHandler_Added(ITextAreaInputHandler handler)
{
if (handler == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,10 @@
<Page Include="TextEditor.xaml" />
<Page Include="themes\generic.xaml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public ICollection BuildItems(Codon codon, object owner)
CommandManager.RegisterInputBinding(inputBindingInfo);
}

var updatedGestures = CommandManager.FindInputGestures(CommandManager.DefaultContextName, null, routedCommandName);
var updatedGestures = CommandManager.FindInputGestures(CommandManager.DefaultContextName, null, routedCommandName, null);
var updatedGesturesText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
items[i].InputGestureText = updatedGesturesText;
items[i].Command = CommandManager.GetRoutedUICommand(routedCommandName);
Expand Down Expand Up @@ -554,7 +554,7 @@ public ICollection BuildItems(Codon codon, object owner)

item.Command = CommandManager.GetRoutedUICommand(routedCommandName);

var updatedGestures = CommandManager.FindInputGestures(CommandManager.DefaultContextName, null, routedCommandName);
var updatedGestures = CommandManager.FindInputGestures(CommandManager.DefaultContextName, null, routedCommandName, null);
var updatedGesturesText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
item.InputGestureText = updatedGesturesText;

Expand Down
9 changes: 5 additions & 4 deletions src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ public void Initialize()

// Use shortened assembly qualified name to not lose user defined gestures
// when sharp develop is updated
CommandManager.DefaultContextName =
string.Format("{0}, {1}", GetType().FullName, GetType().Assembly.GetName().Name);

CommandsService.RegisterBuiltInRoutedUICommands();
CommandManager.DefaultContextName = GetType().GetShortAssemblyQualifiedName();
CommandManager.RegisterNamedUIType(CommandManager.DefaultContextName, GetType());

CommandsService.RegisterBuiltInRoutedUICommands();
CommandsService.RegisterRoutedCommands(typeof(ICSharpCode.AvalonEdit.AvalonEditCommands));

// Load all commands and and key bindings from addin tree
CommandsService.RegisterInputBindingCategories(this, "/SharpDevelop/CommandManager/InputBindingCategories");
Expand Down
1 change: 1 addition & 0 deletions src/Main/Core/Project/ICSharpCode.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Src\Util\AbstractCommand.cs" />
<Compile Include="Src\Util\CallbackOnDispose.cs" />
<Compile Include="Src\Util\DebugTextWriter.cs" />
<Compile Include="Src\Util\ExtensionMethods.cs" />
<Compile Include="Src\Util\ICommand.cs" />
<Compile Include="Src\AddInTree\AddIn\IBuildItemsModifier.cs" />
<Compile Include="Src\AddInTree\AddIn\DefaultDoozers\IncludeDoozer.cs" />
Expand Down
31 changes: 31 additions & 0 deletions src/Main/Core/Project/Src/Util/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Created by SharpDevelop.
* User: Sergej Andrejev
* Date: 7/14/2009
* Time: 2:30 PM
*/
using System;
using System.Collections.Generic;

namespace ICSharpCode.Core
{
public static class ExtensionMethods
{
/// <summary>
/// Determines whether collection contains any elements from other collection
/// </summary>
/// <param name="thisCollection">This collection</param>
/// <param name="otherCollection">Collection of objects to locate in other collection</param>
/// <returns><code>true</code> if item is found; otherwise false</returns>
public static bool ContainsAnyFromCollection<T>(this ICollection<T> thisCollection, ICollection<T> otherCollection)
{
foreach(var thisCollectionItem in thisCollection) {
if(otherCollection.Contains(thisCollectionItem)) {
return true;
}
}

return false;
}
}
}
Loading

0 comments on commit 79e5f7d

Please sign in to comment.