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

Commit

Permalink
Unit test & minor fixes to update handlers
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4505 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
  • Loading branch information
sandrejev committed Jul 22, 2009
1 parent a467f46 commit e72ab0a
Show file tree
Hide file tree
Showing 18 changed files with 843 additions and 400 deletions.
394 changes: 197 additions & 197 deletions SharpDevelop.Tests.sln

Large diffs are not rendered by default.

Expand Up @@ -168,7 +168,8 @@ Keys[] GetKeyboardShortcut(string path, string id)

Keys[] GetKeyBoardShortcut(string routedCommandName)
{
var gestureCollection = SDCommandManager.FindInputGestures(new BindingInfoTemplate { RoutedCommandName = routedCommandName});
var template = new BindingInfoTemplate { RoutedCommandName = routedCommandName};
var gestureCollection = SDCommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, template);
var keyCollection = new Keys[gestureCollection.Count];

var i = 0;
Expand Down
Expand Up @@ -193,7 +193,7 @@ private void BindShortcuts()
}
}

var inputBindingInfos = CommandManager.FindInputBindingInfos(new BindingInfoTemplate());
var inputBindingInfos = CommandManager.FindInputBindingInfos(BindingInfoMatchType.SuperSet, new BindingInfoTemplate());
foreach (var inputBindingInfo in inputBindingInfos)
{
// Get shortcut entry text. Normaly shortcut entry text is equal to routed command text
Expand Down
Expand Up @@ -82,9 +82,13 @@
<ItemGroup>
<Folder Include="Document" />
<Folder Include="Utils" />
<ProjectReference Include="..\..\..\Main\ICSharpCode.Core.Presentation\Test\ICSharpCode.Core.Presentation.Tests.csproj">
<Project>{FFA7988E-7348-4669-9E9D-27E629C873A2}</Project>
<Name>ICSharpCode.Core.Presentation.Tests</Name>
<ProjectReference Include="..\..\..\Main\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
<ProjectReference Include="..\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">
<Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project>
Expand Down
Expand Up @@ -9,13 +9,23 @@
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using NUnit.Framework;

namespace ICSharpCode.AvalonEdit.Tests
{
[TestFixture]
public class WeakReferenceTests
{
[TestFixtureSetUp]
public void FixtureSetup()
{
PropertyService.InitializeServiceForUnitTests();
var category = new InputBindingCategory("/MainMenu/Edit", "Edit");
CommandManager.RegisterInputBindingCategory(category);
}

[Test]
public void GCCallbackTest()
{
Expand Down
Expand Up @@ -28,6 +28,8 @@ public static BindingGroup ClassWideBindingGroup
get; private set;
}

private static InputBindingCategory classWideInputBindingCategory;

/// <summary>
/// Creates a new <see cref="TextAreaInputHandler"/> for the text area.
/// </summary>
Expand All @@ -36,10 +38,6 @@ public static TextAreaInputHandler Create(TextArea textArea)
TextAreaInputHandler handler = new TextAreaInputHandler(textArea);
handler.BindingGroup = ClassWideBindingGroup;

// TODO: DELETE
// handler.CommandBindings.AddRange(CommandBindings);
// handler.InputBindings.AddRange(InputBindings);

return handler;
}

Expand All @@ -58,6 +56,7 @@ static void AddInputBinding(string routedCommandName, string gesturesString)
inputBinding.OwnerTypeName = typeof(TextArea).GetShortAssemblyQualifiedName();
inputBinding.DefaultGestures.AddRange((InputGestureCollection)new InputGestureCollectionConverter().ConvertFrom(gesturesString));
inputBinding.Groups.Add(ClassWideBindingGroup);
inputBinding.Categories.Add(classWideInputBindingCategory);
inputBinding.RoutedCommandName = routedCommandName;
SDCommandManager.RegisterInputBinding(inputBinding);
}
Expand All @@ -77,6 +76,7 @@ static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHan
static CaretNavigationCommandHandler()
{
ClassWideBindingGroup = new BindingGroup();
classWideInputBindingCategory = new InputBindingCategory("/CaretNavigation", "Caret navigation commands");

AddBinding("EditingCommands.MoveLeftByCharacter", "Left", null, OnMoveCaret(CaretMovementType.CharLeft));
AddBinding("EditingCommands.SelectLeftByCharacter", "Shift+Left", null, OnMoveCaretExtendSelection(CaretMovementType.CharLeft));
Expand Down
Expand Up @@ -36,6 +36,8 @@ public static BindingGroup ClassWideBindingGroup
get; private set;
}

private static InputBindingCategory classWideInputBindingCategory;

/// <summary>
/// Creates a new <see cref="TextAreaInputHandler"/> for the text area.
/// </summary>
Expand All @@ -62,6 +64,7 @@ static void AddInputBinding(string routedCommandName, string gesturesString)
inputBinding.OwnerTypeName = typeof(TextArea).GetShortAssemblyQualifiedName();
inputBinding.DefaultGestures.AddRange((InputGestureCollection)new InputGestureCollectionConverter().ConvertFrom(gesturesString));
inputBinding.Groups.Add(ClassWideBindingGroup);
inputBinding.Categories.Add(classWideInputBindingCategory);
inputBinding.Categories.AddRange(SDCommandManager.GetInputBindingCategoryCollection("/MainMenu/Edit", true));
inputBinding.RoutedCommandName = routedCommandName;
SDCommandManager.RegisterInputBinding(inputBinding);
Expand All @@ -82,6 +85,7 @@ static void AddCommandBinding(string routedCommandName, CanExecuteRoutedEventHan
static EditingCommandHandler()
{
ClassWideBindingGroup = new BindingGroup();
classWideInputBindingCategory = new InputBindingCategory("/EditingCommands", "Editing commands");

AddCommandBinding("ApplicationCommands.Delete", CanDelete, OnDelete(ApplicationCommands.NotACommand));
AddBinding("EditingCommands.Delete", "Delete", null, OnDelete(EditingCommands.SelectRightByCharacter));
Expand Down
Expand Up @@ -41,27 +41,11 @@ public static BindingGroup ClassWideBindingGroup
static TextAreaDefaultInputHandler()
{
ClassWideBindingGroup = new BindingGroup();

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

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.AddRange((InputGestureCollection)new InputGestureCollectionConverter().ConvertFrom(gesturesString));
inputBinding.Groups.Add(ClassWideBindingGroup);
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();
Expand Down
4 changes: 2 additions & 2 deletions src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs
Expand Up @@ -246,7 +246,7 @@ public ICollection BuildItems(Codon codon, object owner)
var gesturesTemplate = new BindingInfoTemplate();
gesturesTemplate.OwnerTypeName = CommandManager.DefaultContextName;
gesturesTemplate.RoutedCommandName = routedCommandName;
var updatedGestures = CommandManager.FindInputGestures(gesturesTemplate);
var updatedGestures = CommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, gesturesTemplate);
var updatedGesturesText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);

items[i].InputGestureText = updatedGesturesText;
Expand Down Expand Up @@ -561,7 +561,7 @@ public ICollection BuildItems(Codon codon, object owner)
var gesturesTemplate = new BindingInfoTemplate();
gesturesTemplate.OwnerTypeName = CommandManager.DefaultContextName;
gesturesTemplate.RoutedCommandName = routedCommandName;
var updatedGestures = CommandManager.FindInputGestures(gesturesTemplate);
var updatedGestures = CommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, gesturesTemplate);
var updatedGesturesText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
item.InputGestureText = updatedGesturesText;

Expand Down
Expand Up @@ -99,8 +99,8 @@ private void InvokeBindingUpdateHandlers(UIElement instance)
bindingInfoTemplates[i++] = new BindingInfoTemplate { OwnerTypeName = typeName };
}

CommandManager.InvokeCommandBindingUpdateHandlers(bindingInfoTemplates);
CommandManager.InvokeInputBindingUpdateHandlers(bindingInfoTemplates);
CommandManager.InvokeCommandBindingUpdateHandlers(BindingInfoMatchType.SubSet | BindingInfoMatchType.SuperSet, bindingInfoTemplates);
CommandManager.InvokeInputBindingUpdateHandlers(BindingInfoMatchType.SubSet | BindingInfoMatchType.SuperSet, bindingInfoTemplates);
}

public List<BindingGroup> NestedGroups
Expand Down
Expand Up @@ -4,7 +4,8 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using CommandManager=ICSharpCode.Core.Presentation.CommandManager;
using SDCommandManager=ICSharpCode.Core.Presentation.CommandManager;
using CommandManager=System.Windows.Input.CommandManager;

namespace ICSharpCode.Core.Presentation
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public BindingGroupCollection Groups
/// </summary>
public RoutedUICommand RoutedCommand {
get {
return CommandManager.GetRoutedUICommand(RoutedCommandName);
return SDCommandManager.GetRoutedUICommand(RoutedCommandName);
}
}

Expand Down Expand Up @@ -117,11 +118,11 @@ public BindingGroupCollection Groups
}

if(AddIn != null && (AddIn.DependenciesLoaded || IsLazy)) {
CommandManager.LoadAddinCommands(AddIn);
SDCommandManager.LoadAddinCommands(AddIn);
}

System.Windows.Input.ICommand command;
CommandManager.commands.TryGetValue(CommandTypeName, out command);
SDCommandManager.commands.TryGetValue(CommandTypeName, out command);
commandInstance = command;

return command;
Expand Down Expand Up @@ -212,7 +213,7 @@ public CanExecuteRoutedEventHandler CanExecuteEventHandler
public ICollection<UIElement> OwnerInstances {
get {
if(_ownerInstanceName != null) {
return CommandManager.GetNamedUIElementCollection(_ownerInstanceName);
return SDCommandManager.GetNamedUIElementCollection(_ownerInstanceName);
}

return null;
Expand Down Expand Up @@ -251,7 +252,7 @@ public CanExecuteRoutedEventHandler CanExecuteEventHandler
public ICollection<Type> OwnerTypes {
get {
if(_ownerTypeName != null) {
return CommandManager.GetNamedUITypeCollection(_ownerTypeName);
return SDCommandManager.GetNamedUITypeCollection(_ownerTypeName);
}

return null;
Expand All @@ -262,6 +263,27 @@ public bool IsRegistered
{
get; set;
}

public void RemoveActiveCommandBindings()
{
if(_ownerTypeName != null) {
if(OwnerTypes != null) {
foreach(var ownerType in OwnerTypes) {
foreach(CommandBinding binding in ActiveCommandBindings) {
SDCommandManager.RemoveClassCommandBinding(ownerType, binding);
}
}
}
} else if(_ownerInstanceName != null) {
if(OwnerInstances != null) {
foreach(var ownerInstance in OwnerInstances) {
foreach(CommandBinding binding in ActiveCommandBindings) {
ownerInstance.CommandBindings.Remove(binding);
}
}
}
}
}

private BindingsUpdatedHandler defaultCommandBindingHandler;

Expand All @@ -273,12 +295,16 @@ internal BindingsUpdatedHandler DefaultCommandBindingHandler
get {
if(defaultCommandBindingHandler == null && OwnerTypeName != null) {
defaultCommandBindingHandler = delegate {
if(RoutedCommand != null && OwnerTypes != null && IsRegistered) {
var routedCommand = RoutedCommand;
var ownerTypes = OwnerTypes;
var isRegistered = IsRegistered;

if(routedCommand != null && ownerTypes != null && isRegistered) {
GenerateCommandBindings();

foreach(var ownerType in OwnerTypes) {
foreach(var ownerType in ownerTypes) {
foreach(CommandBinding binding in OldCommandBindings) {
CommandManager.RemoveClassCommandBinding(ownerType, binding);
SDCommandManager.RemoveClassCommandBinding(ownerType, binding);
}

foreach(CommandBinding binding in ActiveCommandBindings) {
Expand Down Expand Up @@ -368,7 +394,7 @@ public CommandBindingCollection ActiveCommandBindings
AddIn.LoadRuntimeAssemblies();

var command = (ICommand)AddIn.CreateObject(CommandTypeName);
CommandManager.LoadCommand(CommandTypeName, command);
SDCommandManager.LoadCommand(CommandTypeName, command);
}

if(CommandInstance != null) {
Expand Down

0 comments on commit e72ab0a

Please sign in to comment.