Browse Source

Remove redundant code (InputBindingInfo, BindingInfoTemplate, IBindingInfoTemplate) => BindingInfoTemplate. Unit tests

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4598 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts^2
Sergej Andrejev 16 years ago
parent
commit
81c76aa0c8
  1. 2
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplaceDialog.cs
  2. 10
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs
  3. 4
      src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs
  4. 4
      src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingInfoBase.cs
  5. 175
      src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingInfoTemplate.cs
  6. 119
      src/Main/ICSharpCode.Core.Presentation/CommandsService/Collections/BindingInfoTemplateDictionary.cs
  7. 64
      src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs
  8. 8
      src/Main/ICSharpCode.Core.Presentation/CommandsService/Events/NotifyBindingsChangedEvent.cs
  9. 6
      src/Main/ICSharpCode.Core.Presentation/CommandsService/Events/NotifyGesturesChangedEvent.cs
  10. 41
      src/Main/ICSharpCode.Core.Presentation/CommandsService/IBindingInfo.cs
  11. 49
      src/Main/ICSharpCode.Core.Presentation/CommandsService/IBindingInfoTemplate.cs
  12. 19
      src/Main/ICSharpCode.Core.Presentation/CommandsService/InputBindingIndentifier.cs
  13. 26
      src/Main/ICSharpCode.Core.Presentation/CommandsService/InputBindingInfo.cs
  14. 21
      src/Main/ICSharpCode.Core.Presentation/CommandsService/Profile/UserGestureProfile.cs
  15. 30
      src/Main/ICSharpCode.Core.Presentation/CommandsService/Utils/IBindingInfoEqualityComparer.cs
  16. 2
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  17. 10
      src/Main/ICSharpCode.Core.Presentation/Input/ObservableInputGestureCollection.cs
  18. 14
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs
  19. 114
      src/Main/ICSharpCode.Core.Presentation/Test/BindingInfoTemplateDictionaryTests.cs
  20. 129
      src/Main/ICSharpCode.Core.Presentation/Test/BindingInfoTemplateTests.cs
  21. 20
      src/Main/ICSharpCode.Core.Presentation/Test/CommandManagerTests.cs
  22. 1
      src/Main/ICSharpCode.Core.Presentation/Test/ICSharpCode.Core.Presentation.Tests.csproj
  23. 4
      src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs
  24. 4
      src/Main/ICSharpCode.Core.Presentation/Test/UserDefinedGestureProfileTests.cs

2
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplaceDialog.cs

@ -169,7 +169,7 @@ namespace SearchAndReplace @@ -169,7 +169,7 @@ namespace SearchAndReplace
Keys[] GetKeyBoardShortcut(string routedCommandName)
{
var template = new BindingInfoTemplate { RoutedCommandName = routedCommandName };
var gestureCollection = SDCommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, template);
var gestureCollection = SDCommandManager.FindInputGestures(template);
var keyCollection = new Keys[gestureCollection.Count];
var i = 0;

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

@ -178,7 +178,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -178,7 +178,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
}
}
var inputBindingInfos = SDCommandManager.FindInputBindingInfos(BindingInfoMatchType.SuperSet, new BindingInfoTemplate());
var inputBindingInfos = SDCommandManager.FindInputBindingInfos(new BindingInfoTemplate());
foreach (var inputBindingInfo in inputBindingInfos) {
// Get shortcut entry text. Normaly shortcut entry text is equal to routed command text
// but this value can be overriden through InputBindingInfo.RoutedCommandText value
@ -193,9 +193,9 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -193,9 +193,9 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
// Strip this sign from shortcut entry text
shortcutText = Regex.Replace(shortcutText, @"&([^\s])", @"$1");
var shortcutGestures = inputBindingInfo.DefaultGestures.GetInputGestureCollection();
if(SelectedProfile != null && SelectedProfile[inputBindingInfo.Identifier] != null) {
shortcutGestures = new InputGestureCollection(SelectedProfile[inputBindingInfo.Identifier]);
var shortcutGestures = inputBindingInfo.DefaultGestures.InputGesturesCollection;
if(SelectedProfile != null && SelectedProfile[BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo)] != null) {
shortcutGestures = new InputGestureCollection(SelectedProfile[BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo)]);
}
var shortcut = new Shortcut(shortcutText, shortcutGestures);
@ -384,7 +384,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -384,7 +384,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
originalRelatedShortcut.Gestures.Clear();
originalRelatedShortcut.Gestures.AddRange(relatedShortcutCopy.Gestures);
var id = shortcutsMap.MapForward(originalRelatedShortcut).Identifier;
var id = BindingInfoTemplate.CreateFromIBindingInfo(shortcutsMap.MapForward(originalRelatedShortcut));
SelectedProfile[id] = new InputGestureCollection(relatedShortcutCopy.Gestures);
}
}

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

@ -246,7 +246,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -246,7 +246,7 @@ namespace ICSharpCode.SharpDevelop.Commands
var gesturesTemplate = new BindingInfoTemplate();
gesturesTemplate.OwnerTypeName = CommandManager.DefaultContextName;
gesturesTemplate.RoutedCommandName = routedCommandName;
var updatedGestures = CommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, gesturesTemplate);
var updatedGestures = CommandManager.FindInputGestures(gesturesTemplate);
var updatedGesturesText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
items[i].InputGestureText = updatedGesturesText;
@ -561,7 +561,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -561,7 +561,7 @@ namespace ICSharpCode.SharpDevelop.Commands
var gesturesTemplate = new BindingInfoTemplate();
gesturesTemplate.OwnerTypeName = CommandManager.DefaultContextName;
gesturesTemplate.RoutedCommandName = routedCommandName;
var updatedGestures = CommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, gesturesTemplate);
var updatedGestures = CommandManager.FindInputGestures(gesturesTemplate);
var updatedGesturesText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
item.InputGestureText = updatedGesturesText;

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

@ -13,7 +13,7 @@ namespace ICSharpCode.Core.Presentation @@ -13,7 +13,7 @@ namespace ICSharpCode.Core.Presentation
/// <summary>
/// Description of BindingInfoBase.
/// </summary>
abstract public class BindingInfoBase : IBindingInfo, IBindingInfoTemplate
abstract public class BindingInfoBase : IBindingInfo
{
private BindingGroupCollection _groups;
@ -211,7 +211,7 @@ namespace ICSharpCode.Core.Presentation @@ -211,7 +211,7 @@ namespace ICSharpCode.Core.Presentation
return;
}
if( (args.Action == NotifyBindingsChangedAction.BindingInfoModified && args.ModifiedBindingInfoTemplates.Contains(new BindingInfoTemplate(this, false)))
if( (args.Action == NotifyBindingsChangedAction.BindingInfoModified && args.ModifiedBindingInfoTemplates.Contains(BindingInfoTemplate.CreateFromIBindingInfo(this)))
|| (args.Action == NotifyBindingsChangedAction.NamedInstanceModified && OwnerInstanceName == args.UIElementName)
|| (args.Action == NotifyBindingsChangedAction.RoutedUICommandModified && routedCommandName == args.RoutedCommandName)
|| (args.Action == NotifyBindingsChangedAction.NamedTypeModified && OwnerTypeName == args.TypeName)

175
src/Main/ICSharpCode.Core.Presentation/CommandsService/BindingInfoTemplate.cs

@ -7,7 +7,7 @@ using System.Reflection; @@ -7,7 +7,7 @@ using System.Reflection;
namespace ICSharpCode.Core.Presentation
{
public class BindingInfoTemplate : IBindingInfoTemplate
public struct BindingInfoTemplate
{
public string OwnerInstanceName
{
@ -24,175 +24,14 @@ namespace ICSharpCode.Core.Presentation @@ -24,175 +24,14 @@ namespace ICSharpCode.Core.Presentation
get; set;
}
public BindingGroupCollection Groups
{
get; set;
}
public BindingInfoTemplate()
public static BindingInfoTemplate CreateFromIBindingInfo(IBindingInfo bindingInfo)
{
var tpl = new BindingInfoTemplate();
tpl.OwnerInstanceName = bindingInfo.OwnerInstanceName;
tpl.OwnerTypeName = bindingInfo.OwnerTypeName;
tpl.RoutedCommandName = bindingInfo.RoutedCommandName;
return tpl;
}
public BindingInfoTemplate(InputBindingIdentifier identifier)
{
OwnerInstanceName = identifier.OwnerInstanceName;
OwnerTypeName = identifier.OwnerTypeName;
RoutedCommandName = identifier.RoutedCommandName;
}
public BindingInfoTemplate(IBindingInfoTemplate template, bool includeGroup)
{
OwnerInstanceName = template.OwnerInstanceName;
OwnerTypeName = template.OwnerTypeName;
RoutedCommandName = template.RoutedCommandName;
if(includeGroup) {
Groups = template.Groups;
}
}
}
public interface IBindingInfoTemplate
{
string OwnerInstanceName
{
get; set;
}
string OwnerTypeName
{
get; set;
}
string RoutedCommandName
{
get; set;
}
BindingGroupCollection Groups
{
get; set;
}
// public List<BindingInfoTemplate> GetWildCardTemplates()
// {
// var notNullProperties = GetNotNullProperties();
// var notNullPropertiesCopy = new List<PropertyInfo>(notNullProperties);
// var generatedTemplates = new List<BindingInfoTemplate>((int)Math.Pow(2, notNullProperties.Count));
// generatedTemplates.Add(this);
//
// GetWildCardTemplatesRecursive(notNullPropertiesCopy, this, generatedTemplates);
//
// return generatedTemplates;
// }
//
// static List<PropertyInfo> properties;
//
// static PropertyInfo OwnerInstanceNameProperty;
// static PropertyInfo OwnerTypeNameProperty;
// static PropertyInfo RoutedCommandNameProperty;
// static PropertyInfo GroupProperty;
//
// static BindingInfoTemplate()
// {
// var t = typeof(BindingInfoTemplate);
// properties = new List<PropertyInfo>(4);
// properties.Add(OwnerInstanceNameProperty = t.GetProperty("OwnerInstanceName"));
// properties.Add(OwnerTypeNameProperty = t.GetProperty("OwnerTypeName"));
// properties.Add(RoutedCommandNameProperty = t.GetProperty("RoutedCommandName"));
// properties.Add(GroupProperty = t.GetProperty("Group"));
// }
//
// private void GetWildCardTemplatesRecursive(List<PropertyInfo> notNullPropertiesCollection, BindingInfoTemplate rootTemplate, List<BindingInfoTemplate> generatedTemplates)
// {
// foreach(var property in notNullPropertiesCollection) {
// var nestedNotNullPropertiesCollection = new List<PropertyInfo>(notNullPropertiesCollection);
// nestedNotNullPropertiesCollection.Remove(property);
//
// var template = new BindingInfoTemplate();
//
// template.OwnerInstanceName = rootTemplate.OwnerInstanceName;
// template.OwnerTypeName = rootTemplate.OwnerTypeName;
// template.RoutedCommandName = rootTemplate.RoutedCommandName;
// template.Group = rootTemplate.Group;
//
// if(property == OwnerInstanceNameProperty) {
// template.OwnerInstanceName = null;
// } else if(property == OwnerTypeNameProperty) {
// template.OwnerTypeName = null;
// } else if(property == RoutedCommandNameProperty) {
// template.RoutedCommandName = null;
// } else if(property == GroupProperty) {
// template.Group = null;
// }
//
// generatedTemplates.Add(template);
//
// GetWildCardTemplatesRecursive(nestedNotNullPropertiesCollection, template, generatedTemplates);
// GetWildCardTemplatesRecursive(nestedNotNullPropertiesCollection, rootTemplate, generatedTemplates);
// }
// }
//
// public List<PropertyInfo> GetNotNullProperties()
// {
// var notNullProperties = new List<PropertyInfo>();
// foreach(var property in properties) {
// if(property.GetValue(this, null) != null) {
// notNullProperties.Add(property);
// }
// }
//
// return notNullProperties;
// }
}
public static class IBindingInfoTemplateExtensions
{
public static bool IsTemplateFor(this IBindingInfoTemplate thisTemplate, IBindingInfoTemplate binding, BindingInfoMatchType matchType)
{
var bindingOwnerInstanceName = binding.OwnerInstanceName;
var bindingOwnerTypeName = binding.OwnerTypeName;
var bindingRoutedCommandName = binding.RoutedCommandName;
var bindingGroups = binding.Groups;
var templateOwnerInstanceName = thisTemplate.OwnerInstanceName;
var templateOwnerTypeName = thisTemplate.OwnerTypeName;
var templateRoutedCommandName = thisTemplate.RoutedCommandName;
var templateGroups = thisTemplate.Groups;
if(bindingOwnerTypeName == "ICSharpCode.AvalonEdit.Editing.TextArea, ICSharpCode.AvalonEdit")
{
}
var groupsOverlap = templateGroups != null && bindingGroups != null && bindingGroups.ContainsAnyFromCollection(templateGroups);
var exactMatch = false;
if((matchType & BindingInfoMatchType.Exact) == BindingInfoMatchType.Exact) {
exactMatch = templateOwnerInstanceName == bindingOwnerInstanceName
&& templateOwnerTypeName == bindingOwnerTypeName
&& templateRoutedCommandName == bindingRoutedCommandName
&& ((templateGroups == null && bindingGroups == null) || groupsOverlap);
}
var superSetMatch = false;
if((matchType & BindingInfoMatchType.SuperSet) == BindingInfoMatchType.SuperSet) {
superSetMatch = (templateOwnerInstanceName == null || templateOwnerInstanceName == bindingOwnerInstanceName)
&& (templateOwnerTypeName == null || templateOwnerTypeName == bindingOwnerTypeName)
&& (templateRoutedCommandName == null || templateRoutedCommandName == bindingRoutedCommandName)
&& (templateGroups == null || templateGroups.Count == 0 || groupsOverlap);
}
var subSetMatch = false;
if((matchType & BindingInfoMatchType.SubSet) == BindingInfoMatchType.SubSet) {
subSetMatch = (bindingOwnerInstanceName == null || templateOwnerInstanceName == bindingOwnerInstanceName)
&& (bindingOwnerTypeName == null || templateOwnerTypeName == bindingOwnerTypeName)
&& (bindingRoutedCommandName == null || templateRoutedCommandName == bindingRoutedCommandName)
&& (bindingGroups == null || bindingGroups.Count == 0 || groupsOverlap);
}
return subSetMatch || superSetMatch;
}
}
}

119
src/Main/ICSharpCode.Core.Presentation/CommandsService/Collections/BindingInfoTemplateDictionary.cs

@ -4,6 +4,7 @@ using System.Windows; @@ -4,6 +4,7 @@ using System.Windows;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Reflection;
namespace ICSharpCode.Core.Presentation
{
@ -12,37 +13,54 @@ namespace ICSharpCode.Core.Presentation @@ -12,37 +13,54 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
public class BindingInfoTemplateDictionary<T>
{
private Dictionary<IBindingInfoTemplate, HashSet<T>> dictionary = new Dictionary<IBindingInfoTemplate, HashSet<T>>(new IBindingInfoTemplateEqualityComparer());
static List<PropertyInfo> properties;
static PropertyInfo OwnerInstanceNameProperty;
static PropertyInfo OwnerTypeNameProperty;
static PropertyInfo RoutedCommandNameProperty;
static BindingInfoTemplateDictionary()
{
var t = typeof(BindingInfoTemplate);
properties = new List<PropertyInfo>(4);
properties.Add(OwnerInstanceNameProperty = t.GetProperty("OwnerInstanceName"));
properties.Add(OwnerTypeNameProperty = t.GetProperty("OwnerTypeName"));
properties.Add(RoutedCommandNameProperty = t.GetProperty("RoutedCommandName"));
}
private Dictionary<BindingInfoTemplate, HashSet<T>> dictionary = new Dictionary<BindingInfoTemplate, HashSet<T>>();
public void Add(IBindingInfoTemplate template, T item)
public void Add(BindingInfoTemplate template, T item)
{
if(!dictionary.ContainsKey(template)) {
dictionary.Add(template, new HashSet<T>());
foreach(var wildCardTemplate in GetWildCardTemplates(template)) {
if(!dictionary.ContainsKey(wildCardTemplate)) {
dictionary.Add(wildCardTemplate, new HashSet<T>());
}
dictionary[wildCardTemplate].Add(item);
}
dictionary[template].Add(item);
}
public HashSet<T> FindItems(IBindingInfoTemplate template, BindingInfoMatchType matchType)
public ICollection<T> FindItems(BindingInfoTemplate template)
{
var allItems = new HashSet<T>();
foreach(var bucket in FindBuckets(template, matchType)) {
foreach(var item in bucket) {
allItems.Add(item);
}
var bucket = FindBucket(template);
if(bucket != null) {
var items = new T[bucket.Count];
bucket.CopyTo(items, 0);
return items;
}
return allItems;
return null;
}
public IEnumerable<HashSet<T>> FindBuckets(IBindingInfoTemplate template, BindingInfoMatchType matchType)
{
foreach(var pair in dictionary) {
if(template.IsTemplateFor(pair.Key, matchType)) {
yield return pair.Value;
}
public HashSet<T> FindBucket(BindingInfoTemplate template)
{
HashSet<T> bucket;
dictionary.TryGetValue(template, out bucket);
if(bucket == null) {
bucket = new HashSet<T>();
}
return bucket;
}
public void Remove(T item)
@ -52,9 +70,10 @@ namespace ICSharpCode.Core.Presentation @@ -52,9 +70,10 @@ namespace ICSharpCode.Core.Presentation
}
}
public void Remove(IBindingInfoTemplate template, BindingInfoMatchType matchType, T item)
public void Remove(BindingInfoTemplate template, T item)
{
foreach(var bucket in FindBuckets(template, matchType)) {
var bucket = FindBucket(template);
if(bucket != null) {
bucket.Remove(item);
}
}
@ -64,5 +83,61 @@ namespace ICSharpCode.Core.Presentation @@ -64,5 +83,61 @@ namespace ICSharpCode.Core.Presentation
dictionary.Clear();
}
private List<BindingInfoTemplate> GetWildCardTemplates(BindingInfoTemplate template)
{
var notNullProperties = GetNotNullProperties(template);
var notNullPropertiesCopy = new List<PropertyInfo>(notNullProperties);
var generatedTemplates = new List<BindingInfoTemplate>((int)Math.Pow(2, notNullProperties.Count));
generatedTemplates.Add(template);
GetWildCardTemplatesRecursive(notNullPropertiesCopy, template, generatedTemplates);
return generatedTemplates;
}
private void GetWildCardTemplatesRecursive(List<PropertyInfo> notNullPropertiesCollection, BindingInfoTemplate rootTemplate, List<BindingInfoTemplate> generatedTemplates)
{
foreach(var property in notNullPropertiesCollection) {
var nestedNotNullPropertiesCollection = new List<PropertyInfo>(notNullPropertiesCollection);
nestedNotNullPropertiesCollection.Remove(property);
var template = new BindingInfoTemplate();
if(property == OwnerInstanceNameProperty) {
template.OwnerInstanceName = null;
} else {
template.OwnerInstanceName = rootTemplate.OwnerInstanceName;
}
if(property == OwnerTypeNameProperty) {
template.OwnerTypeName = null;
} else {
template.OwnerTypeName = rootTemplate.OwnerTypeName;
}
if(property == RoutedCommandNameProperty) {
template.RoutedCommandName = null;
} else {
template.RoutedCommandName = rootTemplate.RoutedCommandName;
}
generatedTemplates.Add(template);
GetWildCardTemplatesRecursive(nestedNotNullPropertiesCollection, template, generatedTemplates);
GetWildCardTemplatesRecursive(nestedNotNullPropertiesCollection, rootTemplate, generatedTemplates);
}
}
private List<PropertyInfo> GetNotNullProperties(BindingInfoTemplate template)
{
var notNullProperties = new List<PropertyInfo>();
foreach(var property in properties) {
if(property.GetValue(template, null) != null) {
notNullProperties.Add(property);
}
}
return notNullProperties;
}
}
}

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

@ -65,7 +65,7 @@ namespace ICSharpCode.Core.Presentation @@ -65,7 +65,7 @@ namespace ICSharpCode.Core.Presentation
static void UserDefinedGesturesManager_CurrentProfileChanged(object sender, NotifyUserGestureProfileChangedEventArgs args)
{
var changedGestures = new Dictionary<InputBindingIdentifier, Tuple<InputGestureCollection, InputGestureCollection>>();
var changedGestures = new Dictionary<BindingInfoTemplate, Tuple<InputGestureCollection, InputGestureCollection>>();
if(args.OldProfile != null) {
args.OldProfile.GesturesChanged -= Profile_GesturesChanged;
@ -88,13 +88,13 @@ namespace ICSharpCode.Core.Presentation @@ -88,13 +88,13 @@ namespace ICSharpCode.Core.Presentation
}
}
var modifiedBindingTemplates = new HashSet<IBindingInfoTemplate>(new IBindingInfoTemplateEqualityComparer());
var modifiedBindingTemplates = new HashSet<BindingInfoTemplate>();
var descriptions = new List<GesturesModificationDescription>(changedGestures.Count);
foreach(var changedGesture in changedGestures) {
var bindingInfoTemplate = new BindingInfoTemplate(changedGesture.Key);
var bindingInfoTemplate = changedGesture.Key;
InputGestureCollection defaultUserGesture = null;
if(changedGesture.Value.Item1 == null || changedGesture.Value.Item2 == null) {
defaultUserGesture = FindInputGestures(BindingInfoMatchType.Exact, bindingInfoTemplate);
defaultUserGesture = FindInputGestures(bindingInfoTemplate);
}
var oldGestures = changedGesture.Value.Item1 ?? defaultUserGesture;
@ -110,9 +110,9 @@ namespace ICSharpCode.Core.Presentation @@ -110,9 +110,9 @@ namespace ICSharpCode.Core.Presentation
static void Profile_GesturesChanged(object sender, NotifyGesturesChangedEventArgs args)
{
var modifiedBindingTemplates = new HashSet<IBindingInfoTemplate>(new IBindingInfoTemplateEqualityComparer());
var modifiedBindingTemplates = new HashSet<BindingInfoTemplate>();
foreach(var description in args.ModificationDescriptions) {
modifiedBindingTemplates.Add(new BindingInfoTemplate(description.InputBindingIdentifier));
modifiedBindingTemplates.Add(description.InputBindingIdentifier);
}
InvokeBindingsChanged(typeof(CommandManager), new NotifyBindingsChangedEventArgs(NotifyBindingsChangedAction.BindingInfoModified, modifiedBindingTemplates));
@ -346,8 +346,8 @@ namespace ICSharpCode.Core.Presentation @@ -346,8 +346,8 @@ namespace ICSharpCode.Core.Presentation
throw new ArgumentException("Routed command name must be specified");
}
var similarTemplate = new BindingInfoTemplate(inputBindingInfo, false);
var similarInputBinding = FindInputBindingInfos(BindingInfoMatchType.SuperSet, similarTemplate).FirstOrDefault();
var similarTemplate = BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo);
var similarInputBinding = FindInputBindingInfos(similarTemplate).FirstOrDefault();
if(similarInputBinding != null) {
foreach(InputGesture gesture in inputBindingInfo.DefaultGestures) {
@ -360,7 +360,7 @@ namespace ICSharpCode.Core.Presentation @@ -360,7 +360,7 @@ namespace ICSharpCode.Core.Presentation
similarInputBinding.Categories.AddRange(inputBindingInfo.Categories);
similarInputBinding.Groups.AddRange(inputBindingInfo.Groups);
} else {
inputBidnings.Add(inputBindingInfo, inputBindingInfo);
inputBidnings.Add(BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo), inputBindingInfo);
inputBindingInfo.IsRegistered = true;
CommandManager.BindingsChanged += inputBindingInfo.BindingsChangedHandler;
@ -414,11 +414,11 @@ namespace ICSharpCode.Core.Presentation @@ -414,11 +414,11 @@ namespace ICSharpCode.Core.Presentation
throw new ArgumentException("Routed command name must be specified");
}
commandBindings.Add(commandBindingInfo, commandBindingInfo);
commandBindings.Add(BindingInfoTemplate.CreateFromIBindingInfo(commandBindingInfo), commandBindingInfo);
commandBindingInfo.IsRegistered = true;
CommandManager.BindingsChanged += commandBindingInfo.BindingsChangedHandler;
InvokeBindingsChanged(null, new NotifyBindingsChangedEventArgs(NotifyBindingsChangedAction.BindingInfoModified, new []{ new BindingInfoTemplate(commandBindingInfo, false) }));
InvokeBindingsChanged(null, new NotifyBindingsChangedEventArgs(NotifyBindingsChangedAction.BindingInfoModified, new []{ BindingInfoTemplate.CreateFromIBindingInfo(commandBindingInfo) }));
}
public static event NotifyBindingsChangedEventHandler BindingsChanged;
@ -444,7 +444,7 @@ namespace ICSharpCode.Core.Presentation @@ -444,7 +444,7 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="addIn">Add-in</param>
public static void LoadAddinCommands(AddIn addIn) {
foreach(CommandBindingInfo binding in FindCommandBindingInfos(BindingInfoMatchType.SuperSet, new BindingInfoTemplate())) {
foreach(CommandBindingInfo binding in FindCommandBindingInfos(new BindingInfoTemplate())) {
if(binding.AddIn != addIn) continue;
if(binding.CommandTypeName != null && !commands.ContainsKey(binding.CommandTypeName)){
@ -482,23 +482,23 @@ namespace ICSharpCode.Core.Presentation @@ -482,23 +482,23 @@ namespace ICSharpCode.Core.Presentation
/// Unregister input binding
/// </summary>
/// <param name="inputBindingInfo">Input binding parameters</param>
public static void UnregisterInputBinding(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
public static void UnregisterInputBinding(params BindingInfoTemplate[] templates)
{
UnregisterBindingInfo(inputBidnings, matchType, templates);
UnregisterBindingInfo(inputBidnings, templates);
}
/// <summary>
/// Unregister command binding
/// </summary>
/// <param name="commandBindingInfo">Command binding parameters</param>
public static void UnregisterCommandBinding(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
public static void UnregisterCommandBinding(params BindingInfoTemplate[] templates)
{
UnregisterBindingInfo(commandBindings, matchType, templates);
UnregisterBindingInfo(commandBindings, templates);
}
private static void UnregisterBindingInfo(BindingInfoTemplateDictionary<BindingInfoBase> bindingInfoDictionary, BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
private static void UnregisterBindingInfo(BindingInfoTemplateDictionary<BindingInfoBase> bindingInfoDictionary, params BindingInfoTemplate[] templates)
{
var foundBindings = FindBindingInfos(bindingInfoDictionary, matchType, templates).ToList();
var foundBindings = FindBindingInfos(bindingInfoDictionary, templates).ToList();
foreach(var similarBindingInfo in foundBindings) {
BindingsUpdatedHandler defaultUpdatesHandler;
@ -508,8 +508,8 @@ namespace ICSharpCode.Core.Presentation @@ -508,8 +508,8 @@ namespace ICSharpCode.Core.Presentation
((CommandBindingInfo)similarBindingInfo).IsRegistered = false;
}
var removedTemplate = new BindingInfoTemplate(similarBindingInfo, false);
bindingInfoDictionary.Remove(removedTemplate, BindingInfoMatchType.Exact, similarBindingInfo);
var removedTemplate = BindingInfoTemplate.CreateFromIBindingInfo(similarBindingInfo);
bindingInfoDictionary.Remove(removedTemplate, similarBindingInfo);
CommandManager.BindingsChanged -= similarBindingInfo.BindingsChangedHandler;
similarBindingInfo.RemoveActiveBindings();
@ -532,24 +532,24 @@ namespace ICSharpCode.Core.Presentation @@ -532,24 +532,24 @@ 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 IEnumerable<CommandBindingInfo> FindCommandBindingInfos(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
public static IEnumerable<CommandBindingInfo> FindCommandBindingInfos(params BindingInfoTemplate[] templates)
{
var bindings = FindBindingInfos(commandBindings, matchType, templates).ToList();
var bindings = FindBindingInfos(commandBindings, templates).ToList();
return bindings.Cast<CommandBindingInfo>();
}
public static IEnumerable<InputBindingInfo> FindInputBindingInfos(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
public static IEnumerable<InputBindingInfo> FindInputBindingInfos(params BindingInfoTemplate[] templates)
{
var bindings = FindBindingInfos(inputBidnings, matchType, templates).ToList();
var bindings = FindBindingInfos(inputBidnings, templates).ToList();
return bindings.Cast<InputBindingInfo>();
}
private static IEnumerable<BindingInfoBase> FindBindingInfos(BindingInfoTemplateDictionary<BindingInfoBase> bindingInfos, BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
private static IEnumerable<BindingInfoBase> FindBindingInfos(BindingInfoTemplateDictionary<BindingInfoBase> bindingInfos, params BindingInfoTemplate[] templates)
{
foreach(var template in templates) {
foreach(var item in bindingInfos.FindItems(template, matchType)) {
foreach(var item in bindingInfos.FindItems(template)) {
if(item != null) {
yield return item;
}
@ -557,9 +557,9 @@ namespace ICSharpCode.Core.Presentation @@ -557,9 +557,9 @@ namespace ICSharpCode.Core.Presentation
}
}
public static CommandBindingCollection FindCommandBindings(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
public static CommandBindingCollection FindCommandBindings(params BindingInfoTemplate[] templates)
{
var commandBindingInfoCollection = FindCommandBindingInfos(matchType, templates);
var commandBindingInfoCollection = FindCommandBindingInfos(templates);
var commandBindingCollection = new CommandBindingCollection();
foreach(var bindingInfo in commandBindingInfoCollection) {
commandBindingCollection.AddRange(bindingInfo.ActiveCommandBindings);
@ -568,9 +568,9 @@ namespace ICSharpCode.Core.Presentation @@ -568,9 +568,9 @@ namespace ICSharpCode.Core.Presentation
return commandBindingCollection;
}
public static InputBindingCollection FindInputBindings(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates)
public static InputBindingCollection FindInputBindings(params BindingInfoTemplate[] templates)
{
var inputBindingInfoCollection = FindInputBindingInfos(matchType, templates);
var inputBindingInfoCollection = FindInputBindingInfos(templates);
var inputBindingCollection = new InputBindingCollection();
foreach(var bindingInfo in inputBindingInfoCollection) {
@ -589,8 +589,8 @@ namespace ICSharpCode.Core.Presentation @@ -589,8 +589,8 @@ namespace ICSharpCode.Core.Presentation
/// <param name="contextInstance">Get gestures assigned only to specific context</param>
/// <param name="routedCommandName">Routed UI command name</param>
/// <param name="gesture">Gesture</param>
public static InputGestureCollection FindInputGestures(BindingInfoMatchType matchType, params IBindingInfoTemplate[] templates) {
var bindings = FindInputBindingInfos(matchType, templates);
public static InputGestureCollection FindInputGestures(params BindingInfoTemplate[] templates) {
var bindings = FindInputBindingInfos(templates);
var gestures = new InputGestureCollection();
foreach(InputBindingInfo bindingInfo in bindings) {

8
src/Main/ICSharpCode.Core.Presentation/CommandsService/Events/NotifyBindingsChangedEvent.cs

@ -11,8 +11,8 @@ namespace ICSharpCode.Core.Presentation @@ -11,8 +11,8 @@ namespace ICSharpCode.Core.Presentation
public class NotifyBindingsChangedEventArgs : EventArgs
{
private ICollection<IBindingInfoTemplate> _modifiedBindingInfoTemplates;
public ICollection<IBindingInfoTemplate> ModifiedBindingInfoTemplates
private ICollection<BindingInfoTemplate> _modifiedBindingInfoTemplates;
public ICollection<BindingInfoTemplate> ModifiedBindingInfoTemplates
{
get {
return _modifiedBindingInfoTemplates;
@ -185,7 +185,7 @@ namespace ICSharpCode.Core.Presentation @@ -185,7 +185,7 @@ namespace ICSharpCode.Core.Presentation
_routedCommandName = routedCommandName;
}
public NotifyBindingsChangedEventArgs(NotifyBindingsChangedAction action, IEnumerable<IBindingInfoTemplate> templates)
public NotifyBindingsChangedEventArgs(NotifyBindingsChangedAction action, IEnumerable<BindingInfoTemplate> templates)
{
if(action != NotifyBindingsChangedAction.BindingInfoModified) {
throw new ArgumentException("This constructor only supports 'BindingInfoModified' action (got '" + Enum.GetName(typeof(NotifyBindingsChangedAction), action) + "')");
@ -196,7 +196,7 @@ namespace ICSharpCode.Core.Presentation @@ -196,7 +196,7 @@ namespace ICSharpCode.Core.Presentation
}
_action = action;
_modifiedBindingInfoTemplates = new HashSet<IBindingInfoTemplate>(templates, new IBindingInfoTemplateEqualityComparer());
_modifiedBindingInfoTemplates = new HashSet<BindingInfoTemplate>(templates);
}
public NotifyBindingsChangedEventArgs(NotifyBindingsChangedAction action, BindingGroupCollection groups, ICollection<UIElement> attachedInstances)

6
src/Main/ICSharpCode.Core.Presentation/CommandsService/Events/NotifyGesturesChangedEvent.cs

@ -43,14 +43,14 @@ namespace ICSharpCode.Core.Presentation @@ -43,14 +43,14 @@ namespace ICSharpCode.Core.Presentation
public class GesturesModificationDescription
{
public GesturesModificationDescription(InputBindingIdentifier identifier, InputGestureCollection oldGestures, InputGestureCollection newGestures)
public GesturesModificationDescription(BindingInfoTemplate inputBindingInfoTemplate, InputGestureCollection oldGestures, InputGestureCollection newGestures)
{
InputBindingIdentifier = identifier;
InputBindingIdentifier = inputBindingInfoTemplate;
OldGestures = oldGestures;
NewGestures = newGestures;
}
public InputBindingIdentifier InputBindingIdentifier
public BindingInfoTemplate InputBindingIdentifier
{
get; private set;
}

41
src/Main/ICSharpCode.Core.Presentation/CommandsService/IBindingInfo.cs

@ -1,9 +1,3 @@ @@ -1,9 +1,3 @@
/*
* Created by SharpDevelop.
* User: Sergej Andrejev
* Date: 7/17/2009
* Time: 10:55 AM
*/
using System;
using System.Collections.Generic;
using System.Windows;
@ -53,39 +47,4 @@ namespace ICSharpCode.Core.Presentation @@ -53,39 +47,4 @@ namespace ICSharpCode.Core.Presentation
void RemoveActiveBindings();
}
internal static class IBindingInfoExtensions
{
// public static IBindingInfoTemplate[] GenerateTemplates(this IBindingInfo thisObject, bool includeGroup)
// {
// var invokeTemplates = new BindingInfoTemplate[thisObject.Groups.Count == 0 || !includeGroup ? 1 : thisObject.Groups.Count];
// var groupEnumerator = thisObject.Groups.Count == 0 ? null : thisObject.Groups.GetEnumerator();
// var groupCounter = 0;
// while(groupEnumerator == null || groupEnumerator.MoveNext()) {
// var invokeTemplate = new BindingInfoTemplate();
// invokeTemplate.RoutedCommandName = thisObject.RoutedCommandName;
// invokeTemplate.OwnerInstanceName = thisObject.OwnerInstanceName;
// invokeTemplate.OwnerTypeName = thisObject.OwnerTypeName;
// if(includeGroup && groupEnumerator != null) {
// invokeTemplate.Group = groupEnumerator.Current;
// }
//
// invokeTemplates[groupCounter++] = invokeTemplate;
//
// if(groupEnumerator == null || !includeGroup) {
// break;
// }
// }
//
// return invokeTemplates;
// }
}
[FlagsAttribute]
public enum BindingInfoMatchType
{
SubSet = 1,
SuperSet = 2,
Exact = 4
}
}

49
src/Main/ICSharpCode.Core.Presentation/CommandsService/IBindingInfoTemplate.cs

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
/*
* Created by SharpDevelop.
* User: Sergej Andrejev
* Date: 7/23/2009
* Time: 2:38 PM
*/
using System;
namespace ICSharpCode.Core.Presentation.CommandsService
{
/// <summary>
/// Description of IBindingInfoTemplate.
/// </summary>
public interface IBindingInfoTemplate
{
public struct BindingInfoTemplate : IBindingInfo
{
public string OwnerInstanceName
{
get; set;
}
public ICollection<UIElement> OwnerInstances
{
get; set;
}
public string OwnerTypeName
{
get; set;
}
public ICollection<Type> OwnerTypes
{
get; set;
}
public string RoutedCommandName
{
get; set;
}
public BindingGroupCollection Groups
{
get;
}
}
}

19
src/Main/ICSharpCode.Core.Presentation/CommandsService/InputBindingIndentifier.cs

@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
using System;
namespace ICSharpCode.Core.Presentation
{
public struct InputBindingIdentifier
{
public string OwnerInstanceName {
get; set;
}
public string OwnerTypeName {
get; set;
}
public string RoutedCommandName {
get; set;
}
}
}

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

@ -49,9 +49,9 @@ namespace ICSharpCode.Core.Presentation @@ -49,9 +49,9 @@ namespace ICSharpCode.Core.Presentation
var oldGestures = _defaultGestures;
_defaultGestures = value;
if(IsRegistered && (UserGestureManager.CurrentProfile == null || UserGestureManager.CurrentProfile[Identifier] == null)) {
if(IsRegistered && (UserGestureManager.CurrentProfile == null || UserGestureManager.CurrentProfile[BindingInfoTemplate.CreateFromIBindingInfo(this)] == null)) {
var description = new GesturesModificationDescription(
Identifier,
BindingInfoTemplate.CreateFromIBindingInfo(this),
oldGestures != null ? oldGestures.InputGesturesCollection : new InputGestureCollection(),
value != null ? value.InputGesturesCollection : new InputGestureCollection());
@ -62,7 +62,7 @@ namespace ICSharpCode.Core.Presentation @@ -62,7 +62,7 @@ namespace ICSharpCode.Core.Presentation
private void DefaultGestures_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if(IsRegistered && (UserGestureManager.CurrentProfile == null || UserGestureManager.CurrentProfile[Identifier] == null)) {
if(IsRegistered && (UserGestureManager.CurrentProfile == null || UserGestureManager.CurrentProfile[BindingInfoTemplate.CreateFromIBindingInfo(this)] == null)) {
var newGestures = DefaultGestures.InputGesturesCollection;
var oldGestures = new InputGestureCollection();
oldGestures.AddRange(newGestures);
@ -81,7 +81,7 @@ namespace ICSharpCode.Core.Presentation @@ -81,7 +81,7 @@ namespace ICSharpCode.Core.Presentation
}
}
var description = new GesturesModificationDescription(Identifier, oldGestures, newGestures);
var description = new GesturesModificationDescription(BindingInfoTemplate.CreateFromIBindingInfo(this), oldGestures, newGestures);
SDCommandManager.InvokeGesturesChanged(this, new NotifyGesturesChangedEventArgs(description));
}
}
@ -92,11 +92,11 @@ namespace ICSharpCode.Core.Presentation @@ -92,11 +92,11 @@ namespace ICSharpCode.Core.Presentation
public InputGestureCollection ActiveGestures {
get {
if(UserGestureManager.CurrentProfile == null
|| UserGestureManager.CurrentProfile[Identifier] == null) {
return DefaultGestures.GetInputGestureCollection();
|| UserGestureManager.CurrentProfile[BindingInfoTemplate.CreateFromIBindingInfo(this)] == null) {
return DefaultGestures.InputGesturesCollection;
}
return UserGestureManager.CurrentProfile[Identifier];
return UserGestureManager.CurrentProfile[BindingInfoTemplate.CreateFromIBindingInfo(this)];
}
}
@ -225,18 +225,6 @@ namespace ICSharpCode.Core.Presentation @@ -225,18 +225,6 @@ namespace ICSharpCode.Core.Presentation
ActiveInputBindings.Add(inputBinding);
}
}
public InputBindingIdentifier Identifier {
get {
var identifier = new InputBindingIdentifier();
identifier.OwnerInstanceName = OwnerInstanceName;
identifier.OwnerTypeName = OwnerTypeName;
identifier.RoutedCommandName = RoutedCommandName;
return identifier;
}
}
}
}

21
src/Main/ICSharpCode.Core.Presentation/CommandsService/Profile/UserGestureProfile.cs

@ -10,9 +10,9 @@ namespace ICSharpCode.Core.Presentation @@ -10,9 +10,9 @@ namespace ICSharpCode.Core.Presentation
/// <summary>
/// Description of UserGesturesProfile.
/// </summary>
public class UserGestureProfile : IEnumerable<KeyValuePair<InputBindingIdentifier, InputGestureCollection>>, ICloneable
public class UserGestureProfile : IEnumerable<KeyValuePair<BindingInfoTemplate, InputGestureCollection>>, ICloneable
{
private Dictionary<InputBindingIdentifier, InputGestureCollection> userDefinedGestures = new Dictionary<InputBindingIdentifier, InputGestureCollection>();
private Dictionary<BindingInfoTemplate, InputGestureCollection> userDefinedGestures = new Dictionary<BindingInfoTemplate, InputGestureCollection>();
public string Path
{
@ -63,7 +63,7 @@ namespace ICSharpCode.Core.Presentation @@ -63,7 +63,7 @@ namespace ICSharpCode.Core.Presentation
ReadOnly = Convert.ToBoolean(rootNode.Attributes["read-only"].Value);
foreach(XmlElement bindingInfoNode in xmlDocument.SelectNodes("//InputBinding")) {
var identifier = new InputBindingIdentifier();
var identifier = new BindingInfoTemplate();
identifier.RoutedCommandName = bindingInfoNode.Attributes["routed-command"].Value;
var ownerInstanceAttribute = bindingInfoNode.Attributes["owner-instance"];
@ -140,8 +140,8 @@ namespace ICSharpCode.Core.Presentation @@ -140,8 +140,8 @@ namespace ICSharpCode.Core.Presentation
var args = new NotifyGesturesChangedEventArgs();
foreach(var pair in this) {
var template = new BindingInfoTemplate(pair.Key);
var newGestures = SDCommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, template);
var template = pair.Key;
var newGestures = SDCommandManager.FindInputGestures(template);
descriptions.Add(
new GesturesModificationDescription(
@ -155,7 +155,7 @@ namespace ICSharpCode.Core.Presentation @@ -155,7 +155,7 @@ namespace ICSharpCode.Core.Presentation
SDCommandManager.InvokeGesturesChanged(this, args);
}
public InputGestureCollection this[InputBindingIdentifier identifier]
public InputGestureCollection this[BindingInfoTemplate identifier]
{
get { return GetInputBindingGesture(identifier); }
set { SetInputBindingGestures(identifier, value); }
@ -166,7 +166,7 @@ namespace ICSharpCode.Core.Presentation @@ -166,7 +166,7 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="inputBindingInfoName">Input binding</param>
/// <returns>Gestures assigned to this input binding</returns>
private InputGestureCollection GetInputBindingGesture(InputBindingIdentifier identifier)
private InputGestureCollection GetInputBindingGesture(BindingInfoTemplate identifier)
{
InputGestureCollection gestures;
userDefinedGestures.TryGetValue(identifier, out gestures);
@ -179,14 +179,13 @@ namespace ICSharpCode.Core.Presentation @@ -179,14 +179,13 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
/// <param name="inputBindingInfoName">Input binding name</param>
/// <param name="inputGestureCollection">Gesture assigned to this input binding</param>
private void SetInputBindingGestures(InputBindingIdentifier identifier, InputGestureCollection inputGestureCollection)
private void SetInputBindingGestures(BindingInfoTemplate identifier, InputGestureCollection inputGestureCollection)
{
var oldGestures = GetInputBindingGesture(identifier);
var newGestures = inputGestureCollection;
if(oldGestures == null || newGestures == null) {
var template = new BindingInfoTemplate(identifier);
var defaultGestures = SDCommandManager.FindInputGestures(BindingInfoMatchType.Exact, template);
var defaultGestures = SDCommandManager.FindInputGestures(identifier);
oldGestures = oldGestures ?? defaultGestures;
newGestures = newGestures ?? defaultGestures;
@ -200,7 +199,7 @@ namespace ICSharpCode.Core.Presentation @@ -200,7 +199,7 @@ namespace ICSharpCode.Core.Presentation
InvokeGesturesChanged(this, args);
}
public IEnumerator<KeyValuePair<InputBindingIdentifier, InputGestureCollection>> GetEnumerator()
public IEnumerator<KeyValuePair<BindingInfoTemplate, InputGestureCollection>> GetEnumerator()
{
return userDefinedGestures.GetEnumerator();
}

30
src/Main/ICSharpCode.Core.Presentation/CommandsService/Utils/IBindingInfoEqualityComparer.cs

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
namespace ICSharpCode.Core.Presentation
{
public class IBindingInfoTemplateEqualityComparer : IEqualityComparer<IBindingInfoTemplate>
{
bool IEqualityComparer<IBindingInfoTemplate>.Equals(IBindingInfoTemplate key, IBindingInfoTemplate comparedValue)
{
return key.OwnerInstanceName == comparedValue.OwnerInstanceName
&& key.OwnerTypeName == comparedValue.OwnerTypeName
&& key.RoutedCommandName == comparedValue.RoutedCommandName;
}
int IEqualityComparer<IBindingInfoTemplate>.GetHashCode(IBindingInfoTemplate value)
{
var instanceNameHashCode = value.OwnerInstanceName != null ? value.OwnerInstanceName.GetHashCode() : 0;
var typeNameHashCode = value.OwnerTypeName != null ? value.OwnerTypeName.GetHashCode() : 0;
var routedCommandNameHashCode = value.RoutedCommandName != null ? value.RoutedCommandName.GetHashCode() : 0;
var groupsHashCode = 0;
if(value.Groups != null) {
foreach(var group in value.Groups) {
groupsHashCode ^= group != null ? group.GetHashCode() : 0;
}
}
return instanceNameHashCode ^ typeNameHashCode ^ routedCommandNameHashCode ^ groupsHashCode;
}
}
}

2
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -83,11 +83,9 @@ @@ -83,11 +83,9 @@
<Compile Include="CommandsService\Events\NotifyUserGestureProfileChangedEvent.cs" />
<Compile Include="CommandsService\IBindingInfo.cs" />
<Compile Include="CommandsService\InputBindingCategory.cs" />
<Compile Include="CommandsService\InputBindingIndentifier.cs" />
<Compile Include="CommandsService\InputBindingInfo.cs" />
<Compile Include="CommandsService\Profile\UserGestureManager.cs" />
<Compile Include="CommandsService\Profile\UserGestureProfile.cs" />
<Compile Include="CommandsService\Utils\IBindingInfoEqualityComparer.cs" />
<Compile Include="CommandsService\Utils\IObservableCollection.cs" />
<Compile Include="CommandsService\Utils\WeakReferenceEqualirtyComparer.cs" />
<Compile Include="CommandsService\WpfCommandWrapper.cs" />

10
src/Main/ICSharpCode.Core.Presentation/Input/ObservableInputGestureCollection.cs

@ -80,11 +80,6 @@ namespace ICSharpCode.Core.Presentation @@ -80,11 +80,6 @@ namespace ICSharpCode.Core.Presentation
return observedInputGestures.Contains(item);
}
public InputGestureCollection GetInputGestureCollection()
{
return new InputGestureCollection(observedInputGestures);
}
public void AddRange(InputGestureCollection items)
{
foreach(InputGesture item in items) {
@ -131,10 +126,7 @@ namespace ICSharpCode.Core.Presentation @@ -131,10 +126,7 @@ namespace ICSharpCode.Core.Presentation
public InputGestureCollection InputGesturesCollection
{
get {
var gestures = new InputGestureCollection();
gestures.AddRange(observedInputGestures);
return gestures;
return new InputGestureCollection(observedInputGestures);
}
}
}

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

@ -142,7 +142,7 @@ namespace ICSharpCode.Core.Presentation @@ -142,7 +142,7 @@ namespace ICSharpCode.Core.Presentation
this.Command = routedCommand;
}
var gestures = CommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, bindingTemplate);
var gestures = CommandManager.FindInputGestures(bindingTemplate);
this.InputGestureText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(gestures);
CommandManager.GesturesChanged += MenuCommand_GesturesChanged;
@ -150,9 +150,15 @@ namespace ICSharpCode.Core.Presentation @@ -150,9 +150,15 @@ namespace ICSharpCode.Core.Presentation
private void MenuCommand_GesturesChanged(object sender, NotifyGesturesChangedEventArgs e)
{
if(e.ModificationDescriptions.Any(d => bindingTemplate.IsTemplateFor(new BindingInfoTemplate(d.InputBindingIdentifier), BindingInfoMatchType.SuperSet))) {
var updatedGestures = CommandManager.FindInputGestures(BindingInfoMatchType.SuperSet, bindingTemplate);
this.InputGestureText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
foreach(var desc in e.ModificationDescriptions) {
var temp = desc.InputBindingIdentifier;
if((bindingTemplate.OwnerInstanceName == null || bindingTemplate.OwnerInstanceName == temp.OwnerInstanceName)
&& (bindingTemplate.OwnerTypeName == null || bindingTemplate.OwnerTypeName == temp.OwnerTypeName)
&& (bindingTemplate.RoutedCommandName == null || bindingTemplate.RoutedCommandName == temp.RoutedCommandName)) {
var updatedGestures = CommandManager.FindInputGestures(bindingTemplate);
this.InputGestureText = (string)new InputGestureCollectionConverter().ConvertToInvariantString(updatedGestures);
}
}
}
}

114
src/Main/ICSharpCode.Core.Presentation/Test/BindingInfoTemplateDictionaryTests.cs

@ -30,12 +30,8 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -30,12 +30,8 @@ namespace ICSharpCode.Core.Presentation.Tests
new BindingInfoTemplate { OwnerTypeName = "Global2", RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest", OwnerInstanceName = "3" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething2", Groups = new BindingGroupCollection { new BindingGroup() } },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest", OwnerInstanceName = "4" });
var allBindingInfos = dictionary.FindItems(new BindingInfoTemplate(), BindingInfoMatchType.SuperSet);
Assert.AreEqual(4, allBindingInfos.Count());
var allBindingInfos = dictionary.FindItems(new BindingInfoTemplate());
Assert.AreEqual(3, allBindingInfos.Count());
Assert.IsTrue(allBindingInfos.All(i => i.RoutedCommandName == "SuccessfullTest"));
}
@ -56,16 +52,12 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -56,16 +52,12 @@ namespace ICSharpCode.Core.Presentation.Tests
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething", Groups = new BindingGroupCollection { new BindingGroup() } },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomethingOther" },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
var doSomethingBindingInfos = dictionary.FindItems(new BindingInfoTemplate { RoutedCommandName = "TestCommands.DoSomething" }, BindingInfoMatchType.SuperSet);
Assert.AreEqual(3, doSomethingBindingInfos.Count());
var doSomethingBindingInfos = dictionary.FindItems(new BindingInfoTemplate { RoutedCommandName = "TestCommands.DoSomething" });
Assert.AreEqual(2, doSomethingBindingInfos.Count());
Assert.IsTrue(doSomethingBindingInfos.All(i => i.RoutedCommandName == "SuccessfullTest"));
}
@ -86,112 +78,16 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -86,112 +78,16 @@ namespace ICSharpCode.Core.Presentation.Tests
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething", Groups = new BindingGroupCollection { new BindingGroup() } },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomethingOther" },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
var doSomethingBindingInfos = dictionary.FindItems(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething" },
BindingInfoMatchType.SuperSet);
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething" });
Assert.AreEqual(2, doSomethingBindingInfos.Count());
Assert.IsTrue(doSomethingBindingInfos.All(i => i.RoutedCommandName == "SuccessfullTest"));
}
[Test]
public void FindAllSubSetsTest()
{
var dictionary = new BindingInfoTemplateDictionary<CommandBindingInfo>();
dictionary.Add(
new BindingInfoTemplate { },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global2", RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething2", Groups = new BindingGroupCollection { new BindingGroup() } },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
var doSomethingBindingInfos = dictionary.FindItems(new BindingInfoTemplate(), BindingInfoMatchType.SubSet);
Assert.AreEqual(1, doSomethingBindingInfos.Count());
Assert.IsTrue(doSomethingBindingInfos.All(i => i.RoutedCommandName == "SuccessfullTest"));
}
[Test]
public void FindSubSetWithGroupTest()
{
var dictionary = new BindingInfoTemplateDictionary<CommandBindingInfo>();
var group = new BindingGroup();
dictionary.Add(
new BindingInfoTemplate { },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { Groups = new BindingGroupCollection { group } },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", Groups = new BindingGroupCollection { group } },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething", Groups = new BindingGroupCollection { group } },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", Groups = new BindingGroupCollection { new BindingGroup() } },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
var doSomethingBindingInfos = dictionary.FindItems(new BindingInfoTemplate { Groups = new BindingGroupCollection { group } }, BindingInfoMatchType.SubSet);
Assert.AreEqual(2, doSomethingBindingInfos.Count());
Assert.IsTrue(doSomethingBindingInfos.All(i => i.RoutedCommandName == "SuccessfullTest"));
}
[Test]
public void FindSubSetWithTwoAttributesTest()
{
var dictionary = new BindingInfoTemplateDictionary<CommandBindingInfo>();
dictionary.Add(
new BindingInfoTemplate { },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething" },
new CommandBindingInfo { RoutedCommandName = "SuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething", Groups = new BindingGroupCollection { new BindingGroup() } },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
dictionary.Add(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomethingOther" },
new CommandBindingInfo { RoutedCommandName = "UnsuccessfullTest" });
var doSomethingBindingInfos = dictionary.FindItems(
new BindingInfoTemplate { OwnerTypeName = "Global", RoutedCommandName = "TestCommands.DoSomething" },
BindingInfoMatchType.SubSet);
Assert.AreEqual(3, doSomethingBindingInfos.Count());
Assert.IsTrue(doSomethingBindingInfos.All(i => i.RoutedCommandName == "SuccessfullTest"));
}
}
}

129
src/Main/ICSharpCode.Core.Presentation/Test/BindingInfoTemplateTests.cs

@ -1,129 +0,0 @@ @@ -1,129 +0,0 @@
using System;
using NUnit.Framework;
using ICSharpCode.Core.Presentation;
using SDCommandManager=ICSharpCode.Core.Presentation.CommandManager;
namespace ICSharpCode.Core.Presentation.Tests
{
[TestFixture]
public class BindingInfoTemplateTests
{
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
PropertyService.InitializeServiceForUnitTests();
}
[SetUp]
public void SetuUp()
{
}
[TearDown]
public void TearDown()
{
SDCommandManager.Reset();
}
[TestAttribute]
public void IsTemplateForSupersetsTests()
{
var source = new InputBindingInfo();
source.RoutedCommandName = "TestCommand";
source.OwnerTypeName = "TestOwnerType";
var emptyTemplate = new BindingInfoTemplate();
Assert.IsTrue(emptyTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet));
var matchingTemplate = new BindingInfoTemplate();
matchingTemplate.RoutedCommandName = "TestCommand";
Assert.IsTrue(matchingTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet));
var unmatchingTemplate = new BindingInfoTemplate();
unmatchingTemplate.RoutedCommandName = "OtherTestCommand";
Assert.IsFalse(unmatchingTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet));
var overlappingTemplate = new BindingInfoTemplate();
overlappingTemplate.RoutedCommandName = "TestCommand";
overlappingTemplate.OwnerInstanceName = "TestOwnerInstance";
Assert.IsFalse(overlappingTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet));
var biggerTemplate = new BindingInfoTemplate();
biggerTemplate.RoutedCommandName = "TestCommand";
biggerTemplate.OwnerTypeName = "TestOwnerType";
biggerTemplate.OwnerInstanceName = "TestOwnerInstance";
Assert.IsFalse(biggerTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet));
var exactTemplate = new BindingInfoTemplate();
exactTemplate.RoutedCommandName = "TestCommand";
exactTemplate.OwnerTypeName = "TestOwnerType";
Assert.IsTrue(exactTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet));
}
[TestAttribute]
public void IsTemplateForSubsetsTests()
{
var source = new InputBindingInfo();
source.RoutedCommandName = "TestCommand";
source.OwnerTypeName = "TestOwnerType";
var emptyTemplate = new BindingInfoTemplate();
Assert.IsFalse(emptyTemplate.IsTemplateFor(source, BindingInfoMatchType.SubSet));
var smallerTemplate = new BindingInfoTemplate();
smallerTemplate.RoutedCommandName = "TestCommand";
Assert.IsFalse(smallerTemplate.IsTemplateFor(source, BindingInfoMatchType.SubSet));
var overlappingTemplate = new BindingInfoTemplate();
overlappingTemplate.RoutedCommandName = "TestCommand";
overlappingTemplate.OwnerInstanceName = "TestOwnerInstance";
Assert.IsFalse(overlappingTemplate.IsTemplateFor(source, BindingInfoMatchType.SubSet));
var biggerTemplate = new BindingInfoTemplate();
biggerTemplate.RoutedCommandName = "TestCommand";
biggerTemplate.OwnerTypeName = "TestOwnerType";
biggerTemplate.OwnerInstanceName = "TestOwnerInstance";
Assert.IsTrue(biggerTemplate.IsTemplateFor(source, BindingInfoMatchType.SubSet));
var exactTemplate = new BindingInfoTemplate();
exactTemplate.RoutedCommandName = "TestCommand";
exactTemplate.OwnerTypeName = "TestOwnerType";
Assert.IsTrue(exactTemplate.IsTemplateFor(source, BindingInfoMatchType.SubSet));
}
[TestAttribute]
public void IsTemplateForPartlyMatchingTests()
{
var source = new InputBindingInfo();
source.RoutedCommandName = "TestCommand";
source.OwnerTypeName = "TestOwnerType";
var emptyTemplate = new BindingInfoTemplate();
Assert.IsTrue(emptyTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet | BindingInfoMatchType.SubSet));
var matchingTemplate = new BindingInfoTemplate();
matchingTemplate.RoutedCommandName = "TestCommand";
Assert.IsTrue(matchingTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet | BindingInfoMatchType.SubSet));
var unmatchingTemplate = new BindingInfoTemplate();
unmatchingTemplate.RoutedCommandName = "OtherTestCommand";
Assert.IsFalse(unmatchingTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet | BindingInfoMatchType.SubSet));
var overlappingTemplate = new BindingInfoTemplate();
overlappingTemplate.RoutedCommandName = "TestCommand";
overlappingTemplate.OwnerInstanceName = "TestOwnerInstance";
Assert.IsFalse(overlappingTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet | BindingInfoMatchType.SubSet));
var biggerTemplate = new BindingInfoTemplate();
biggerTemplate.RoutedCommandName = "TestCommand";
biggerTemplate.OwnerTypeName = "TestOwnerType";
biggerTemplate.OwnerInstanceName = "TestOwnerInstance";
Assert.IsTrue(biggerTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet | BindingInfoMatchType.SubSet));
var exactTemplate = new BindingInfoTemplate();
exactTemplate.RoutedCommandName = "TestCommand";
exactTemplate.OwnerTypeName = "TestOwnerType";
Assert.IsTrue(exactTemplate.IsTemplateFor(source, BindingInfoMatchType.SuperSet | BindingInfoMatchType.SubSet));
}
}
}

20
src/Main/ICSharpCode.Core.Presentation/Test/CommandManagerTests.cs

@ -147,7 +147,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -147,7 +147,7 @@ namespace ICSharpCode.Core.Presentation.Tests
SDCommandManager.RegisterNamedUIElement("TestOwnerInstance", uiElement);
SDCommandManager.BindingsChanged += delegate(object sender, NotifyBindingsChangedEventArgs args) {
var template = new BindingInfoTemplate(bindingInfo, false);
var template = BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo);
var contains = args.ModifiedBindingInfoTemplates.Contains(template);
if(args.Action == NotifyBindingsChangedAction.BindingInfoModified && contains) {
testResult = true;
@ -175,7 +175,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -175,7 +175,7 @@ namespace ICSharpCode.Core.Presentation.Tests
SDCommandManager.RegisterNamedUIElement("TestOwnerInstance", uiElement);
SDCommandManager.BindingsChanged += delegate(object sender, NotifyBindingsChangedEventArgs args) {
if(args.Action == NotifyBindingsChangedAction.BindingInfoModified && args.ModifiedBindingInfoTemplates.Contains(bindingInfo)) {
if(args.Action == NotifyBindingsChangedAction.BindingInfoModified && args.ModifiedBindingInfoTemplates.Contains(BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo))) {
testResult = true;
}
};
@ -273,7 +273,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -273,7 +273,7 @@ namespace ICSharpCode.Core.Presentation.Tests
var oldGestures = new InputGestureCollection();
var newGestures = new InputGestureCollection();
var identifier = new InputBindingIdentifier { OwnerInstanceName = "SomeOwner", RoutedCommandName = "SomeCommand" };
var identifier = new BindingInfoTemplate { OwnerInstanceName = "SomeOwner", RoutedCommandName = "SomeCommand" };
SDCommandManager.GesturesChanged += delegate(object sender, NotifyGesturesChangedEventArgs args) {
if(args.ModificationDescriptions.Count == 1
@ -306,7 +306,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -306,7 +306,7 @@ namespace ICSharpCode.Core.Presentation.Tests
newGestures.Add(new KeyGesture(Key.C, ModifierKeys.Alt));
newGestures.Add(new KeyGesture(Key.D, ModifierKeys.Alt));
var identifier = new InputBindingIdentifier { OwnerInstanceName = "SomeOwner", RoutedCommandName = "SomeCommand" };
var identifier = new BindingInfoTemplate { OwnerInstanceName = "SomeOwner", RoutedCommandName = "SomeCommand" };
SDCommandManager.GesturesChanged += delegate(object sender, NotifyGesturesChangedEventArgs args) {
if(args.ModificationDescriptions.Count == 1
@ -361,7 +361,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -361,7 +361,7 @@ namespace ICSharpCode.Core.Presentation.Tests
SDCommandManager.GesturesChanged += delegate(object sender, NotifyGesturesChangedEventArgs args) {
if(args.ModificationDescriptions.Count == 1
&& args.ModificationDescriptions.Any(
d => d.InputBindingIdentifier.Equals(bindingInfo.Identifier)
d => d.InputBindingIdentifier.Equals(BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo))
&& d.OldGestures.Count == 2
&& d.NewGestures.Count == 3)) {
results.Add("GestureAdded");
@ -369,7 +369,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -369,7 +369,7 @@ namespace ICSharpCode.Core.Presentation.Tests
if(args.ModificationDescriptions.Count == 1
&& args.ModificationDescriptions.Any(
d => d.InputBindingIdentifier.Equals(bindingInfo.Identifier)
d => d.InputBindingIdentifier.Equals(BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo))
&& d.OldGestures.Count == 3
&& d.NewGestures.Count == 2)) {
results.Add("GestureRemoved");
@ -378,7 +378,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -378,7 +378,7 @@ namespace ICSharpCode.Core.Presentation.Tests
if(args.ModificationDescriptions.Count == 1
&& args.ModificationDescriptions.Any(
d => d.InputBindingIdentifier.Equals(bindingInfo.Identifier)
d => d.InputBindingIdentifier.Equals(BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo))
&& d.OldGestures.Count == 0
&& d.NewGestures.Count == 2)) {
results.Add("GesturesSet");
@ -386,7 +386,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -386,7 +386,7 @@ namespace ICSharpCode.Core.Presentation.Tests
if(args.ModificationDescriptions.Count == 1
&& args.ModificationDescriptions.Any(
d => d.InputBindingIdentifier.Equals(bindingInfo.Identifier)
d => d.InputBindingIdentifier.Equals(BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo))
&& d.OldGestures.Count == 2
&& d.NewGestures.Count == 0)) {
results.Add("GesturesReset");
@ -407,7 +407,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -407,7 +407,7 @@ namespace ICSharpCode.Core.Presentation.Tests
Assert.IsFalse(results.Contains("GestureAdded"));
var profile = new UserGestureProfile();
profile[bindingInfo.Identifier] = new InputGestureCollection();
profile[BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo)] = new InputGestureCollection();
UserGestureManager.CurrentProfile = profile;
// User defined gestures are used
@ -417,7 +417,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -417,7 +417,7 @@ namespace ICSharpCode.Core.Presentation.Tests
Assert.IsFalse(results.Contains("GestureRemoved"));
Assert.IsFalse(results.Contains("GestureAdded"));
profile[bindingInfo.Identifier] = null;
profile[BindingInfoTemplate.CreateFromIBindingInfo(bindingInfo)] = null;
results.Clear();
var backupDefaultGestures = bindingInfo.DefaultGestures;
bindingInfo.DefaultGestures = null;

1
src/Main/ICSharpCode.Core.Presentation/Test/ICSharpCode.Core.Presentation.Tests.csproj

@ -59,7 +59,6 @@ @@ -59,7 +59,6 @@
<ItemGroup>
<Compile Include="BindingGroupTests.cs" />
<Compile Include="BindingInfoTemplateDictionaryTests.cs" />
<Compile Include="BindingInfoTemplateTests.cs" />
<Compile Include="CommandManagerTests.cs" />
<Compile Include="InputBindingCategoryTests.cs" />
<Compile Include="InputGestureTests.cs" />

4
src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs

@ -385,8 +385,8 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -385,8 +385,8 @@ namespace ICSharpCode.Core.Presentation.Tests
var sameBinding2 = new InputBindingInfo { OwnerTypeName="Binding", RoutedCommandName="Binding" };
var sameBinding3 = new InputBindingInfo { OwnerTypeName="Binding3", RoutedCommandName="Binding" };
Assert.AreEqual(sameBinding1.Identifier, sameBinding2.Identifier);
Assert.AreNotEqual(sameBinding1.Identifier, sameBinding3.Identifier);
Assert.AreEqual(BindingInfoTemplate.CreateFromIBindingInfo(sameBinding1), BindingInfoTemplate.CreateFromIBindingInfo(sameBinding2));
Assert.AreNotEqual(BindingInfoTemplate.CreateFromIBindingInfo(sameBinding1), BindingInfoTemplate.CreateFromIBindingInfo(sameBinding3));
}
}
}

4
src/Main/ICSharpCode.Core.Presentation/Test/UserDefinedGestureProfileTests.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -46,7 +46,7 @@ namespace ICSharpCode.Core.Presentation.Tests
binding.DefaultGestures.Add(gesture);
var userDefinedGestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromInvariantString("Ctrl+B;Ctrl+C");
profile[binding.Identifier] = userDefinedGestures;
profile[BindingInfoTemplate.CreateFromIBindingInfo(binding)] = userDefinedGestures;
UserGestureManager.CurrentProfile = profile;
// Default gestures stay the same
@ -66,7 +66,7 @@ namespace ICSharpCode.Core.Presentation.Tests @@ -66,7 +66,7 @@ namespace ICSharpCode.Core.Presentation.Tests
binding2.DefaultGestures.Add(gesture);
var userDefinedGestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromInvariantString("Ctrl+B;Ctrl+C");
profile[binding.Identifier] = userDefinedGestures;
profile[BindingInfoTemplate.CreateFromIBindingInfo(binding)] = userDefinedGestures;
UserGestureManager.CurrentProfile = profile;
// Default gestures are used because current profile doesn't contain modifications to this gesture

Loading…
Cancel
Save