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

Commit

Permalink
More documentation and code refactoring
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4646 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
  • Loading branch information
sandrejev committed Aug 11, 2009
1 parent 6893862 commit 41266b4
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 764 deletions.
Expand Up @@ -73,8 +73,13 @@ static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHan
SDCommandManager.RegisterCommandBindingInfo(commandBinding);
}

static CaretNavigationCommandHandler()
private static bool bindingsRegistered;

public static void RegisterBindings()
{
if(bindingsRegistered) return;
bindingsRegistered = true;

ClassWideBindingGroup = new BindingGroup("CaretNavigationCommandHandler");
classWideInputBindingCategory = new InputBindingCategory("/CaretNavigation", "Caret navigation commands");
SDCommandManager.RegisterInputBindingCategory(classWideInputBindingCategory);
Expand Down
Expand Up @@ -82,8 +82,13 @@ static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHan
SDCommandManager.RegisterCommandBindingInfo(commandBinding);
}

static EditingCommandHandler()
private static bool bindingsRegistered;

public static void RegisterBindings()
{
if(bindingsRegistered) return;
bindingsRegistered = true;

ClassWideBindingGroup = new BindingGroup("EditingCommandHandler");
classWideInputBindingCategory = new InputBindingCategory("/EditingCommands", "Editing commands");
SDCommandManager.RegisterInputBindingCategory(classWideInputBindingCategory);
Expand Down
Expand Up @@ -38,12 +38,20 @@ public static BindingGroup ClassWideBindingGroup
get; private set;
}

static TextAreaDefaultInputHandler()
private static bool bindingsRegistered;

public static void RegisterBindings()
{
if(bindingsRegistered) return;
bindingsRegistered = true;

ClassWideBindingGroup = new BindingGroup("TextAreaDefaultInputHandler");

AddCommandBinding("ApplicationCommands.Undo", CanExecuteUndo, ExecuteUndo);
AddCommandBinding("ApplicationCommands.Redo", CanExecuteRedo, ExecuteRedo);

CaretNavigationCommandHandler.RegisterBindings();
EditingCommandHandler.RegisterBindings();
}

static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHandler canExecuteHandler, ExecutedRoutedEventHandler executedHandler)
Expand Down
4 changes: 3 additions & 1 deletion src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
Expand Up @@ -76,7 +76,6 @@ protected override void OnSourceInitialized(EventArgs e)

public void Initialize()
{

// Use shortened assembly qualified name to not lose user defined gestures
// when sharp develop is updated
SDCommandManager.DefaultOwnerTypeName = SDCommandManager.GetShortAssemblyQualifiedName(GetType());
Expand All @@ -101,6 +100,9 @@ public void Initialize()
}
}

// Hack: Later on bindings should be created from *.addin file
ICSharpCode.AvalonEdit.Editing.TextAreaDefaultInputHandler.RegisterBindings();

mainMenu.ItemsSource = MenuService.CreateMenuItems(this, this, mainMenuPath);

toolBars = ToolBarService.CreateToolBars(this, "/SharpDevelop/Workbench/ToolBar");
Expand Down
Expand Up @@ -90,6 +90,7 @@
<Compile Include="ConditionalSeparator.cs" />
<Compile Include="DropDownButton.cs" />
<Compile Include="GetBitmapExtension.cs" />
<Compile Include="Input\GestureCompareMode.cs" />
<Compile Include="Input\InputGestureCollectionConverter.cs" />
<Compile Include="Input\ObservableInputGestureCollection.cs" />
<Compile Include="IOptionBindingContainer.cs" />
Expand Down
38 changes: 38 additions & 0 deletions src/Main/ICSharpCode.Core.Presentation/Input/GestureCompareMode.cs
@@ -0,0 +1,38 @@
using System;
using System.Windows.Input;

namespace ICSharpCode.Core.Presentation
{
public enum GestureCompareMode
{
/// <summary>
/// Match is successfull when all chrods from both instance of <see cref="InputGesture" /> match
/// or all gestures in both instance of <see cref="InputGestureCollections" /> match
/// </summary>
ExactlyMatches,

/// <summary>
/// Match is successfull when two instance of <see cref="InputGesture" /> ar conflicting.
///
/// Either one or another instance starts with the same chors as other one
/// </summary>
Conflicting,

/// <summary>
/// Match is successfull when template <see cref="InputGesture" /> partly matches compared <see cref="InputGesture" />.
/// Template is found in any place within matched gesture
/// </summary>
PartlyMatches,


/// <summary>
/// Match is successfull when examined <see cref="InputGesture" /> starts with the same keys as template
/// </summary>
StartsWith,

/// <summary>
/// Match is successfull when examined <see cref="InputGesture" /> starts with the same complite chords as template
/// </summary>
StartsWithFullChords,
}
}
Expand Up @@ -6,10 +6,18 @@
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Description of InputGestureCollectionExtensions.
/// Contains utility methods for work with <see cref="InputGestureCollection" />
/// </summary>
public static class InputGestureCollectionExtensions
{
/// <summary>
/// Determines whether any item from first <see cref="InputGestureCollection" /> is qualified as template for
/// any item from second <see cref="InputGestureCollection" /> when examining using specific <see cref="GestureCompareMode" />
/// </summary>
/// <param name="inputGestureTemplateCollection">Collection of examined templates</param>
/// <param name="testedInputGestureCollection">Collection of examined gestures</param>
/// <param name="mode">Additional comparing rules. See <see cref="GestureCompareMode" /> for details</param>
/// <returns><code>true</code> if first collection contains item which can be qualified as template for any item from second collection; otherwise <code>false</code></returns>
public static bool ContainsTemplateForAny(this InputGestureCollection inputGestureTemplateCollection, InputGestureCollection testedInputGestureCollection, GestureCompareMode mode) {
if((inputGestureTemplateCollection == null || inputGestureTemplateCollection.Count == 0) && (testedInputGestureCollection == null || testedInputGestureCollection.Count == 0)) {
return true;
Expand All @@ -23,7 +31,14 @@ public static class InputGestureCollectionExtensions
return false;
}


/// <summary>
/// Determines whether any item from first <see cref="InputGestureCollection" /> is qualified as template for
/// provided <see cref="InputGesture" /> when examining using specific <see cref="GestureCompareMode" />
/// </summary>
/// <param name="inputGestureTemplateCollection">Collection of examined templates</param>
/// <param name="testedInputGestureCollection">Examined Gesture</param>
/// <param name="mode">Additional comparing rules. See <see cref="GestureCompareMode" /> for details</param>
/// <returns><code>true</code> if collection contains template which match provided <see cref="InputGesture" />; otherwise <code>false</code></returns>
public static bool ContainsTemplateFor(this InputGestureCollection inputGestureTemplateCollection, InputGesture testedGesture, GestureCompareMode mode) {
foreach (InputGesture template in inputGestureTemplateCollection) {
if (template.IsTemplateFor(testedGesture, mode)) {
Expand All @@ -35,9 +50,12 @@ public static class InputGestureCollectionExtensions
}

/// <summary>
/// Sort key gestures within input gesture collection by length and type
/// Shorter gestures should be first so they could be matched first.
/// Sort bindings in <see cref="InputBindingCollection" /> according to number of chords each <see cref="InputBinding" />
/// contains.
///
/// Bindings associated with gestures having more chords should be on top.
/// </summary>
/// <param name="inputGestureCollection"></param>
public static void SortByChords(this InputBindingCollection inputGestureCollection)
{
ArrayList.Adapter(inputGestureCollection).Sort(new ChordsCountComparer());
Expand Down

0 comments on commit 41266b4

Please sign in to comment.