diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/App.xaml b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/App.xaml deleted file mode 100644 index e9e4c1ddeef..00000000000 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/App.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/App.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/App.xaml.cs deleted file mode 100644 index 70a7bada785..00000000000 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/App.xaml.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Windows; -using ICSharpCode.Core; - -namespace ICSharpCode.ShortcutsManagement -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - public App() { - Startup += App_Startup; - } - - void App_Startup(object sender, StartupEventArgs e) - { - PropertyService.InitializeService(".", ".", "."); - PropertyService.Load(); - - ResourceService.InitializeService(FileUtility.Combine(PropertyService.DataDirectory, "resources")); - } - } -} diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj index ab74bd7475e..75d13a08ef3 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj @@ -25,6 +25,8 @@ False True DEBUG;TRACE + Program + ..\..\..\..\..\bin\SharpDevelop.exe bin\Release\ @@ -41,6 +43,10 @@ AnyCPU 4096 + + Program + C:\VSC\SharpDevelop40\SharpDevelop\bin\SharpDevelop.exe + 3.0 @@ -56,9 +62,6 @@ - - App.xaml - @@ -71,6 +74,7 @@ + @@ -94,9 +98,6 @@ - - Window1.xaml - @@ -129,7 +130,6 @@ - @@ -137,7 +137,6 @@ - diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj.user b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj.user index 0c6a24d00a6..6a34e7dcdf5 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj.user +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj.user @@ -1,8 +1,4 @@  - - Program - C:\VSC\SharpDevelop40\SharpDevelop\bin\SharpDevelop.exe - ShowAllFiles diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/AdditionConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/AdditionConverter.cs index d32ff918205..10fc55f2a79 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/AdditionConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/AdditionConverter.cs @@ -4,40 +4,38 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Converts double value to another double value by adding another value provided in converter parameter - /// - class AddidionConverter : IValueConverter - { - /// - /// Convert double value to another double value by adding another value provided in converter parameter - /// - /// Original double value - /// Convertion target type - /// Another double value to be added to original value - /// Not used - /// New double value - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - double additionParameter = 0; - var additionParameterString = parameter as string; - if (additionParameterString != null) - { - Double.TryParse(additionParameterString, out additionParameter); - } - - if(value is double) - { - var doubleValue = (double)value; - return doubleValue + additionParameter; - } - - return value; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Converts double value to another double value by adding another value provided in converter parameter + /// + class AddidionConverter : IValueConverter + { + /// + /// Convert double value to another double value by adding another value provided in converter parameter + /// + /// Original double value + /// Convertion target type + /// Another double value to be added to original value + /// Not used + /// New double value + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + double additionParameter = 0; + var additionParameterString = parameter as string; + if (additionParameterString != null) { + Double.TryParse(additionParameterString, out additionParameter); + } + + if(value is double) { + var doubleValue = (double)value; + return doubleValue + additionParameter; + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/BoolToVisibilityConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/BoolToVisibilityConverter.cs index b7bdf4df198..3f392f1e313 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/BoolToVisibilityConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/BoolToVisibilityConverter.cs @@ -5,33 +5,32 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Converts boolean value to enum - /// - public class BoolToVisibilityConverter : IValueConverter - { - /// - /// Convert forward - /// - /// Boolean value - /// Target type (Only string is supported) - /// Hide type (Hidden - reserve space but don't show, Collapse - do not reserve space) - /// Culture info (Invariant culture is used always) - /// Visibility value - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if(value is bool) - { - var hidden = parameter ?? "Hidden"; - return (bool)value ? "Visible" : hidden; - } - - throw new NotSupportedException(); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Converts boolean value to enum + /// + public class BoolToVisibilityConverter : IValueConverter + { + /// + /// Convert forward + /// + /// Boolean value + /// Target type (Only string is supported) + /// Hide type (Hidden - reserve space but don't show, Collapse - do not reserve space) + /// Culture info (Invariant culture is used always) + /// Visibility value + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is bool) { + var hidden = parameter ?? "Hidden"; + return (bool)value ? "Visible" : hidden; + } + + throw new NotSupportedException(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/GesturesCollectionConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/GesturesCollectionConverter.cs index 6baa8753877..e69234fc62a 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/GesturesCollectionConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/GesturesCollectionConverter.cs @@ -7,40 +7,40 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Converts input gestures collection into string - /// - public class GesturesListConverter : IValueConverter - { - /// - /// Convert collection of gestures to a string - /// - /// Collection of gestures - /// Convertion target type (only string is supported) - /// Not used - /// Not used - /// String representing collection of gestures - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - string converterValue = ""; - if (value is InputGestureCollection && (targetType == typeof(string) || targetType.IsSubclassOf(typeof(string)))) { - converterValue = new InputGestureCollectionConverter().ConvertToInvariantString(value); - } - - if (value is ObservableCollection && (targetType == typeof(string) || targetType.IsSubclassOf(typeof(string)))) { - var inputGestureCollection = new InputGestureCollection(); - foreach (var gesture in (ObservableCollection)value) { - inputGestureCollection.Add(gesture); - } - converterValue = new InputGestureCollectionConverter().ConvertToInvariantString(inputGestureCollection); - } - - return converterValue.Replace("+", " + ").Replace(",", ", ").Replace(";", "; "); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Converts input gestures collection into string + /// + public class GesturesListConverter : IValueConverter + { + /// + /// Convert collection of gestures to a string + /// + /// Collection of gestures + /// Convertion target type (only string is supported) + /// Not used + /// Not used + /// String representing collection of gestures + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string converterValue = ""; + if (value is InputGestureCollection && (targetType == typeof(string) || targetType.IsSubclassOf(typeof(string)))) { + converterValue = new InputGestureCollectionConverter().ConvertToInvariantString(value); + } + + if (value is ObservableCollection && (targetType == typeof(string) || targetType.IsSubclassOf(typeof(string)))) { + var inputGestureCollection = new InputGestureCollection(); + foreach (var gesture in (ObservableCollection)value) { + inputGestureCollection.Add(gesture); + } + converterValue = new InputGestureCollectionConverter().ConvertToInvariantString(inputGestureCollection); + } + + return converterValue.Replace("+", " + ").Replace(",", ", ").Replace(";", "; "); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/InputGestureConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/InputGestureConverter.cs index d71a7aa4bf0..4a0a69f7285 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/InputGestureConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/InputGestureConverter.cs @@ -6,38 +6,36 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Converts input gesture to string representation - /// - public class InputGestureConverter : IValueConverter - { - /// - /// Convert input gesture to string - /// - /// Input gesture - /// Convertion target type (Only string is supported) - /// Not used - /// Not used - /// - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is KeyGesture && targetType == typeof(string)) - { - var gestures = new InputGestureCollection(new[] {value}); - return new InputGestureCollectionConverter().ConvertToInvariantString(gestures).Replace("+", " + ").Replace(",", ", "); - } - - if(value is MouseGesture && targetType == typeof(string)) - { - return new MouseGestureConverter().ConvertToInvariantString(value); - } - - return ""; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Converts input gesture to string representation + /// + public class InputGestureConverter : IValueConverter + { + /// + /// Convert input gesture to string + /// + /// Input gesture + /// Convertion target type (Only string is supported) + /// Not used + /// Not used + /// String representing + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is KeyGesture && targetType == typeof(string)) { + var gestures = new InputGestureCollection(new[] {value}); + return new InputGestureCollectionConverter().ConvertToInvariantString(gestures).Replace("+", " + ").Replace(",", ", "); + } + + if(value is MouseGesture && targetType == typeof(string)) { + return new MouseGestureConverter().ConvertToInvariantString(value); + } + + return ""; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/NotNullOrEmptyConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/NotNullOrEmptyConverter.cs index a71070aa252..f862707bd39 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/NotNullOrEmptyConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/NotNullOrEmptyConverter.cs @@ -4,32 +4,31 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Converts null and empty string to true and all other values to false - /// - class NotNullOrEmptyConverter : IValueConverter - { - /// - /// Converts null and empty string to true and all other values to false - /// - /// String or any other object - /// Convertion target type - /// Not used - /// Not used - /// Bool value - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if ((value is string && !string.IsNullOrEmpty((string)value)) || (!(value is string) && value != null)) - { - return true; - } - - return false; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Converts null and empty string to true and all other values to false + /// + class NotNullOrEmptyConverter : IValueConverter + { + /// + /// Converts null and empty string to true and all other values to false + /// + /// String or any other object + /// Convertion target type + /// Not used + /// Not used + /// Bool value + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if ((value is string && !string.IsNullOrEmpty((string)value)) || (!(value is string) && value != null)) { + return true; + } + + return false; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfileToStringConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfileToStringConverter.cs index 9b32dc5e122..9eeef334e5e 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfileToStringConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfileToStringConverter.cs @@ -6,39 +6,37 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Converts profile to representing string - /// - public class ProfileToStringConverter : IValueConverter - { - /// - /// Converts profile to representing string - /// - /// UserGestureProfile instance - /// Convertion target type (only string is supported) - /// Not supported - /// Not supported - /// String representing instance of UserGestureProfile - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - var profile = value as UserGestureProfile; - if(profile != null) - { - var readOnlyString = ""; - if(profile.ReadOnly) - { - readOnlyString = string.Format(" ({0})", StringParser.Parse("${res:ShortcutsManagement.ReadOnly}")); - } - - return profile.Text + readOnlyString; - } - - return value; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Converts profile to representing string + /// + public class ProfileToStringConverter : IValueConverter + { + /// + /// Converts profile to representing string + /// + /// UserGestureProfile instance + /// Convertion target type (only string is supported) + /// Not supported + /// Not supported + /// String representing instance of UserGestureProfile + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var profile = value as UserGestureProfile; + if(profile != null) { + var readOnlyString = ""; + if(profile.ReadOnly) { + readOnlyString = string.Format(" ({0})", StringParser.Parse("${res:ShortcutsManagement.ReadOnly}")); + } + + return profile.Text + readOnlyString; + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfilesComboBoxItemStyleSelector.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfilesComboBoxItemStyleSelector.cs index 5ad03e7d013..c383b038d67 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfilesComboBoxItemStyleSelector.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ProfilesComboBoxItemStyleSelector.cs @@ -4,30 +4,28 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Selects profilesComboBox item style - /// - public class ProfilesComboBoxItemStyleSelector : StyleSelector - { - /// - /// Selects profilesComboBox item style - /// - /// Item contained in ComboBoxItem - /// ComboBoxItem container - /// ComboBoxItem style - public override Style SelectStyle(object item, DependencyObject container) - { - if(item is SeparatorData) - { - return (Style)((FrameworkElement)container).FindResource("SeparatorStyle"); - } - - if(item is UserGestureProfileAction) - { - return (Style)((FrameworkElement)container).FindResource("ProfileActionStyle"); - } - - return null; - } - } + /// + /// Selects profilesComboBox item style + /// + public class ProfilesComboBoxItemStyleSelector : StyleSelector + { + /// + /// Selects profilesComboBox item style + /// + /// Item contained in ComboBoxItem + /// ComboBoxItem container + /// ComboBoxItem style + public override Style SelectStyle(object item, DependencyObject container) + { + if(item is SeparatorData) { + return (Style)((FrameworkElement)container).FindResource("SeparatorStyle"); + } + + if(item is UserGestureProfileAction) { + return (Style)((FrameworkElement)container).FindResource("ProfileActionStyle"); + } + + return null; + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ShortcutCategorySubElementsMergedConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ShortcutCategorySubElementsMergedConverter.cs index 7d17ef5a885..faf02d26a60 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ShortcutCategorySubElementsMergedConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/ShortcutCategorySubElementsMergedConverter.cs @@ -7,31 +7,31 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Merges category's sub-categories and shortcuts into one list - /// - public class ShortcutCategorySubElementsMergedConverter : IMultiValueConverter - { - /// - /// Merge category's sub-categories and shortcuts into one list - /// - /// List of sub-categories and list of shortcuts - /// Not used - /// Not used - /// Not used - /// List of objects where objects are either a shortcut category or a shortcut - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - var items = new List(); - items.AddRange(((IEnumerable)values[0]).Cast()); - items.AddRange(((IEnumerable)values[1]).Cast()); - - return items; - } - - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Merges category's sub-categories and shortcuts into one list + /// + public class ShortcutCategorySubElementsMergedConverter : IMultiValueConverter + { + /// + /// Merge category's sub-categories and shortcuts into one list + /// + /// List of sub-categories and list of shortcuts + /// Not used + /// Not used + /// Not used + /// List of objects where objects are either a shortcut category or a shortcut + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + var items = new List(); + items.AddRange(((IEnumerable)values[0]).Cast()); + items.AddRange(((IEnumerable)values[1]).Cast()); + + return items; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/TypeNameConverter.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/TypeNameConverter.cs index 50ae284f08c..1a3f85e65b7 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/TypeNameConverter.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Converters/TypeNameConverter.cs @@ -4,27 +4,27 @@ namespace ICSharpCode.ShortcutsManagement.Converters { - /// - /// Convert object to its type name - /// - class TypeNameConverter : IValueConverter - { - /// - /// Convert object to type name - /// - /// Any object - /// Convertion target type (Only string is supported) - /// Not used - /// Not used - /// Passed object type name - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return value.GetType().Name; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } + /// + /// Convert object to its type name + /// + class TypeNameConverter : IValueConverter + { + /// + /// Convert object to type name + /// + /// Any object + /// Convertion target type (Only string is supported) + /// Not used + /// Not used + /// Passed object type name + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value.GetType().Name; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/AddIn.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/AddIn.cs index 103fc1662a2..a460e10a205 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/AddIn.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/AddIn.cs @@ -6,143 +6,120 @@ namespace ICSharpCode.ShortcutsManagement.Data /// /// Add-in where shortcuts were registered /// - public class AddIn : INotifyPropertyChanged, IShortcutTreeEntry - { - private string name; - - /// - /// Add-in name - /// - /// Dependency property - /// - public string Name - { - get - { - return name; - } - set - { - if (name != value) { - name = value; - InvokePropertyChanged("Name"); - } - } - } - - private bool isVisible; - - /// - /// Is category visible in shortcuts tree - /// - /// Dependency property - /// - public bool IsVisible - { - get - { - return isVisible; - } - set - { - if (isVisible != value) { - isVisible = value; - InvokePropertyChanged("IsVisible"); - } - } - } - - /// - /// List of add-in categories - /// - public List Categories - { - get; - private set; - } - - /// - /// Create new instance of add-in - /// - /// Add-in name - public AddIn(string addInName) - { - IsVisible = true; - Name = addInName; - Categories = new List(); - } - - /// - /// Find shortcut by shortcutId in add-in categories - /// - /// - /// - public Shortcut FindShortcut(string shortcutId) - { - foreach (var c in Categories) { - Shortcut foundShortcut; - if ((foundShortcut = c.FindShortcut(shortcutId)) != null) { - return foundShortcut; - } - } - - return null; - } - - /// - /// Clone add-in - /// - /// Deep copy of add-in - public object Clone() - { - var clonedAddIn = new AddIn(Name); - foreach (var category in Categories) { - clonedAddIn.Categories.Add((ShortcutCategory)category.Clone()); - } - - return clonedAddIn; - } - - /// - /// Sort add-in sub categories - /// - public void SortSubEntries() - { - Categories.Sort((a, b) => a.Name.CompareTo(b.Name)); - foreach (var category in Categories) - { - category.SortSubEntries(); - } - } - - /// - /// Notify observers about property changes - /// - public event PropertyChangedEventHandler PropertyChanged; - - /// - /// Compare add-in to other instances of - /// - /// Compared object - /// Comparison result - public int CompareTo(object obj) { - if (obj is ShortcutCategory) return -1; - if (obj is Shortcut) return -1; - - var addInObj = (AddIn)obj; - return Name.CompareTo(addInObj.Name); - } - - /// - /// Invoke dependency property changed event - /// - /// Name of dependency property from this classs - private void InvokePropertyChanged(string propertyName) - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - } + public class AddIn : INotifyPropertyChanged, IShortcutTreeEntry + { + private string name; + + /// + /// Gets or sets add-in name + /// + public string Name + { + get { + return name; + } + set { + if (name != value) { + name = value; + InvokePropertyChanged("Name"); + } + } + } + + private bool isVisible; + + /// + /// Gets or sets value specifying whether category is visible in shortcuts tree or not + /// + public bool IsVisible + { + get { + return isVisible; + } + set { + if (isVisible != value) { + isVisible = value; + InvokePropertyChanged("IsVisible"); + } + } + } + + /// + /// Gets list of add-in categories + /// + public List Categories + { + get; + private set; + } + + /// + /// Creates new instance of + /// + /// Add-in name + public AddIn(string addInName) + { + IsVisible = true; + Name = addInName; + Categories = new List(); + } + + /// + /// Finds shortcut by shortcut Id in add-in categories + /// + /// Shortcut Id + /// Shortcut with matching Id value + public Shortcut FindShortcut(string shortcutId) + { + foreach (var c in Categories) { + Shortcut foundShortcut; + if ((foundShortcut = c.FindShortcut(shortcutId)) != null) { + return foundShortcut; + } + } + + return null; + } + + /// + /// Sorts add-in sub-categories + /// + public void SortSubEntries() + { + Categories.Sort((a, b) => a.Name.CompareTo(b.Name)); + foreach (var category in Categories) { + category.SortSubEntries(); + } + } + + /// + /// Occurs when or or property value changes + /// + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Compares add-in to other instances of type + /// + /// Compared object + /// Comparison result + public int CompareTo(object obj) + { + if (obj is ShortcutCategory) return -1; + if (obj is Shortcut) return -1; + + var addInObj = (AddIn)obj; + return Name.CompareTo(addInObj.Name); + } + + /// + /// Invoke dependency property changed event + /// + /// Name of dependency property from this classs + private void InvokePropertyChanged(string propertyName) + { + if (PropertyChanged != null) { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntry.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntry.cs index da6532d5006..b2d7c1b9634 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntry.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntry.cs @@ -2,34 +2,34 @@ namespace ICSharpCode.ShortcutsManagement.Data { - public interface IShortcutTreeEntry : IComparable, ICloneable + public interface IShortcutTreeEntry : IComparable { - /// - /// Shortcut entry name displayed in shortcuts tree - /// - string Name - { - get; set; - } - - /// - /// Specifies whether shortcut tree entry is visible - /// - bool IsVisible - { - get; set; - } - - /// - /// Sort shortcut entry sub elements - /// - void SortSubEntries(); - - /// - /// Search for shortcut in this shortcut entry and sub-elements - /// - /// - /// - Shortcut FindShortcut(string shortcutId); - } + /// + /// Gets or sets shortcut entry name displayed in shortcuts tree + /// + string Name + { + get; set; + } + + /// + /// Specifies whether shortcut tree entry is visible + /// + bool IsVisible + { + get; set; + } + + /// + /// Sort shortcut entry sub elements + /// + void SortSubEntries(); + + /// + /// Search for shortcut in this shortcut entry and sub-elements + /// + /// + /// + Shortcut FindShortcut(string shortcutId); + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntryCloner.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntryCloner.cs new file mode 100644 index 00000000000..5df0c465521 --- /dev/null +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntryCloner.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; + +namespace ICSharpCode.ShortcutsManagement.Data +{ + /// + /// Creates deep copy of , or + /// + public class IShortcutTreeEntryCloner + { + /// + /// Creates new instance of + /// + public IShortcutTreeEntryCloner() + { + } + + /// + /// Deep clone collection of + /// + /// Re-uses instances for similar shortcuts in different categories + /// + /// Collection of + /// Cloned entries + public ICollection CloneShortcutTree(ICollection entries) + { + Shortcut shortcutCopy = null; + var clonedShortcuts = new Dictionary(); + var clonedEntries = new List(); + + // Make a deep copy of all add-ins, categories and shortcuts + foreach (var entry in entries) { + var shortcut = entry as Shortcut; + var category = entry as ShortcutCategory; + var addin = entry as AddIn; + + IShortcutTreeEntry clonedEntry = null; + if(shortcut != null) { + clonedEntry = CloneShortcut(shortcut, clonedShortcuts); + } else if(category != null) { + clonedEntry = CloneShortutCategory(category, clonedShortcuts); + } else if(addin != null) { + clonedEntry = CloneAddin(addin, clonedShortcuts); + } + + clonedEntries.Add(clonedEntry); + } + + return clonedEntries; + } + + + /// + /// Creates a deep copy of instance + /// + /// Re-uses instances for similar shortcuts in different categories + /// + /// Cloned shortcut category + /// Dictionary of shortcuts which should be re-used. If cloned shortcut property value is already preset in this dictionary instance from dictionary is used instead + /// Deep copy of + public ShortcutCategory CloneShortutCategory(ShortcutCategory category, Dictionary clonedShortcuts) + { + var clonedCategory = new ShortcutCategory(category.Name); + + foreach (var subCategory in category.SubCategories) { + clonedCategory.SubCategories.Add(CloneShortutCategory(subCategory, clonedShortcuts)); + } + + foreach (var shortcut in category.Shortcuts) { + clonedCategory.Shortcuts.Add(CloneShortcut(shortcut, clonedShortcuts)); + } + + return clonedCategory; + } + + /// + /// Create a deep copy of instance + /// + /// Re-uses instances for similar shortcuts in different categories + /// + /// Cloned shortcut + /// Dictionary of shortcuts which should be re-used. If cloned shortcut property value is already preset in this dictionary instance from dictionary is used instead + /// Deep copy of + public Shortcut CloneShortcut(Shortcut shortcut, Dictionary clonedShortcuts) + { + if(clonedShortcuts.ContainsKey(shortcut.Id)) { + return clonedShortcuts[shortcut.Id]; + } else { + var clonedShortcut = new Shortcut(shortcut.Name, null); + clonedShortcut.Id = shortcut.Id; + + foreach (var gesture in shortcut.Gestures) { + clonedShortcut.Gestures.Add(gesture); + } + + clonedShortcuts.Add(clonedShortcut.Id, clonedShortcut); + + return clonedShortcut; + } + } + + /// + /// Creates a deep copy of instance + /// + /// Re-uses instances for similar shortcuts in different categories + /// + /// Cloned add-in + /// Dictionary of shortcuts which should be re-used. If cloned shortcut property value is already preset in this dictionary instance from dictionary is used instead + /// Deep copy of instance + public AddIn CloneAddin(AddIn addin, Dictionary clonedShortcuts) + { + var clonedAddIn = new AddIn(addin.Name); + foreach (var category in addin.Categories) { + clonedAddIn.Categories.Add(CloneShortutCategory(category, clonedShortcuts)); + } + + return clonedAddIn; + } + } +} diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/MapTable.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/MapTable.cs index 90d1ed8b8b2..78dbc41f495 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/MapTable.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/MapTable.cs @@ -3,49 +3,82 @@ namespace ICSharpCode.ShortcutsManagement.Data { + /// + /// Stores one-to-one relationships beween two objects of type T1 and T2 + /// public class MapTable : IEnumerable> { private readonly Dictionary forwardMaping = new Dictionary(); - private readonly Dictionary backwardMaping = new Dictionary(); + /// + /// Add new relationship between mapped and mapping object + /// + /// Mapping object + /// Mapping object public void Add(T1 mappingObject, T2 mappedObject) { forwardMaping.Add(mappingObject, mappedObject); backwardMaping.Add(mappedObject, mappingObject); } + /// + /// Tries to find object related to mapping object + /// + /// Mapping object + /// Mapped object public void TryMapForward(T1 mappingObject, out T2 mappedObject) { forwardMaping.TryGetValue(mappingObject, out mappedObject); } - public void TryMapBackward(T2 mappingObject, out T1 mappedObject) + /// + /// Tries to find object related to mapped object + /// + /// Mapped object + /// Mapping object + public void TryMapBackward(T2 mappedObject, out T1 mappingObject) { - backwardMaping.TryGetValue(mappingObject, out mappedObject); + backwardMaping.TryGetValue(mappedObject, out mappingObject); } + + /// + /// Finds object related to mapping object + /// + /// Mapping object + /// Mapped object public T2 MapForward(T1 mappingObject) { return forwardMaping[mappingObject]; } + /// + /// Finds object related to mapped object + /// + /// Mapped object + /// Mapping object public T1 MapBackward(T2 mappingObject) { return backwardMaping[mappingObject]; } + /// + /// Removes all relationships from map + /// public void Clear() { forwardMaping.Clear(); backwardMaping.Clear(); } + /// public IEnumerator> GetEnumerator() { return forwardMaping.GetEnumerator(); } + /// IEnumerator IEnumerable.GetEnumerator() { return forwardMaping.GetEnumerator(); diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/SeparatorData.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/SeparatorData.cs index 7217ac70965..f5a669bac26 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/SeparatorData.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/SeparatorData.cs @@ -1,9 +1,9 @@ namespace ICSharpCode.ShortcutsManagement.Data { - /// - /// Represents a seporator in data binded control - /// - class SeparatorData - { - } + /// + /// Represents a seporator in data binded control + /// + class SeparatorData + { + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs index e83e535e569..53b27af5339 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs @@ -6,185 +6,160 @@ namespace ICSharpCode.ShortcutsManagement.Data { - /// - /// Shortcut - /// + /// + /// Shortcut + /// public class Shortcut : INotifyPropertyChanged, IShortcutTreeEntry - { + { /// - /// List of input gestures which invoking this action + /// Gets collection of input gestures assigned to this instance /// - public ObservableCollection Gestures - { - get; - private set; - } - - - private string _name; - - /// - /// Shortcut action name (displayed to user) - /// - public string Name - { - get - { - return _name; - } - set - { - if(_name != value) - { - _name = value; - InvokePropertyChanged("Name"); - } - } - } - - /// - /// Sort shortcut sub-elements. - /// - /// Does nothing. - /// - public void SortSubEntries() - { - - } - - /// - /// Shortcut Id. - /// - /// This value is used to identify shortcut clones - /// - public string Id - { - get; set; - } - - private bool isVisible; - - /// - /// Is category visible in shortcuts tree - /// - /// Dependency property - /// - public bool IsVisible - { - get - { - return isVisible; - } - set - { - if(isVisible != value) { - isVisible = value; - InvokePropertyChanged("IsVisible"); - } - } - } - - /// - /// Notify observers about property changes - /// - public event PropertyChangedEventHandler PropertyChanged; - - /// - /// Create new instance of shortcut - /// - /// Shortcut action name (displayed to user) - /// Gestures - public Shortcut(string shortcutText, InputGestureCollection gestures) - { - IsVisible = true; - Id = Guid.NewGuid().ToString(); - Name = shortcutText; - - Gestures = new ObservableCollection(); - if(gestures != null) { - foreach (InputGesture gesture in gestures) { - Gestures.Add(gesture); - } - } - - // On changes in gestures collection notify that whole property has changed - Gestures.CollectionChanged += delegate { InvokePropertyChanged("Gestures"); }; - } - - /// - /// Determines whether provided gesture is already assigned to this action - /// - /// Input gesture - /// True if provided gesture is assigned to this action. Otherwise false - public bool ContainsGesture(InputGesture gesture) - { - foreach (var existingGesture in Gestures) { - if(existingGesture == gesture) { - return true; - } - - if(existingGesture is KeyGesture && gesture is KeyGesture) { - var existingKeyGesture = (KeyGesture) existingGesture; - var keyGesture = (KeyGesture) gesture; - - if(existingKeyGesture.Key == keyGesture.Key && existingKeyGesture.Modifiers == keyGesture.Modifiers) { - return true; - } - } - } - - return false; - } - - /// - /// Make a deep copy of this object - /// - /// Deep copy of action - public object Clone() - { - var clone = new Shortcut(Name, null); - clone.Id = Id; - - foreach (var gesture in Gestures) { - clone.Gestures.Add(gesture); - } - - return clone; - } - - /// - /// Compare shortcut to other instances of - /// - /// Compared object - /// Comparison result - public int CompareTo(object obj) - { - if (obj is AddIn) return 1; - if (obj is ShortcutCategory) return 1; - - var shortcutObj = (Shortcut)obj; - return Name.CompareTo(shortcutObj.Name); - } - - /// - /// Returns this instance if searched id matches - /// - /// Searched shortcut id - /// Found shortcut instance or null - public Shortcut FindShortcut(string shortcutId) { - return Id == shortcutId ? this : null; - } - - /// - /// Invoke dependency property changed event - /// - /// Name of dependency property from this classs - private void InvokePropertyChanged(string propertyName) - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - } + public ObservableCollection Gestures + { + get; + private set; + } + + private string _name; + + /// + /// Gets or sets shortcut name (displayed to user) + /// + public string Name + { + get { + return _name; + } + set { + if(_name != value) { + _name = value; + InvokePropertyChanged("Name"); + } + } + } + + /// + /// Sorts shortcut sub-elements + /// + public void SortSubEntries() + { + + } + + /// + /// Gets or sets shortcut id. + /// + /// This value is used to identify shortcut clones + /// + public string Id + { + get; set; + } + + private bool isVisible; + + /// + /// Gets or sets whether category is visible in shortcuts tree + /// + /// Dependency property + /// + public bool IsVisible + { + get { + return isVisible; + } + set { + if(isVisible != value) { + isVisible = value; + InvokePropertyChanged("IsVisible"); + } + } + } + + /// + /// Notify observers about property changes + /// + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Create new instance of shortcut + /// + /// Shortcut action name (displayed to user) + /// Gestures + public Shortcut(string shortcutText, InputGestureCollection gestures) + { + IsVisible = true; + Id = Guid.NewGuid().ToString(); + Name = shortcutText; + + Gestures = new ObservableCollection(); + if(gestures != null) { + foreach (InputGesture gesture in gestures) { + Gestures.Add(gesture); + } + } + + // On changes in gestures collection notify that whole property has changed + Gestures.CollectionChanged += delegate { InvokePropertyChanged("Gestures"); }; + } + + /// + /// Determines whether provided gesture is already assigned to this action + /// + /// Input gesture + /// True if provided gesture is assigned to this action. Otherwise false + public bool ContainsGesture(InputGesture gesture) + { + foreach (var existingGesture in Gestures) { + if(existingGesture == gesture) { + return true; + } + + if(existingGesture is KeyGesture && gesture is KeyGesture) { + var existingKeyGesture = (KeyGesture) existingGesture; + var keyGesture = (KeyGesture) gesture; + + if(existingKeyGesture.Key == keyGesture.Key && existingKeyGesture.Modifiers == keyGesture.Modifiers) { + return true; + } + } + } + + return false; + } + + /// + /// Compare shortcut to other instances of + /// + /// Compared object + /// Comparison result + public int CompareTo(object obj) + { + if (obj is AddIn) return 1; + if (obj is ShortcutCategory) return 1; + + var shortcutObj = (Shortcut)obj; + return Name.CompareTo(shortcutObj.Name); + } + + /// + /// Returns this instance if searched id matches + /// + /// Searched shortcut id + /// Found shortcut instance or null + public Shortcut FindShortcut(string shortcutId) { + return Id == shortcutId ? this : null; + } + + /// + /// Invoke dependency property changed event + /// + /// Name of dependency property from this classs + private void InvokePropertyChanged(string propertyName) + { + if (PropertyChanged != null) { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutCategory.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutCategory.cs index 3334394618a..62e11f91f0a 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutCategory.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutCategory.cs @@ -4,172 +4,142 @@ namespace ICSharpCode.ShortcutsManagement.Data { /// - /// Shortcut category + /// Stores shortcut category data /// - public class ShortcutCategory : INotifyPropertyChanged, IShortcutTreeEntry - { - private string name; - - /// - /// Category name - /// - /// Dependency property - /// - public string Name - { - get - { - return name; - } - set - { - if (name != value) - { - name = value; - InvokePropertyChanged("Name"); - } - } - } - - private bool isVisible; - - /// - /// Is category visible in shortcuts tree - /// - /// Dependency property - /// - public bool IsVisible - { - get - { - return isVisible; - } - set - { - if (isVisible != value) { - isVisible = value; - InvokePropertyChanged("IsVisible"); - } - } - } - - /// - /// Sub cateories - /// - public List SubCategories - { - get; - private set; - } - - /// - /// Shortcuts assigned to this category - /// - public List Shortcuts - { - get; - private set; - } - - /// - /// Notify observers about property changes - /// - public event PropertyChangedEventHandler PropertyChanged; - - /// - /// Create new instance of category - /// - /// Category name - public ShortcutCategory(string categoryName) - { - IsVisible = true; - Shortcuts = new List(); - SubCategories = new List(); - Name = categoryName; - } - - /// - /// Make a deep copy of category object - /// - /// Deep copy of this category - public object Clone() - { - var clonedCategory = new ShortcutCategory(Name); - - foreach (var subCategory in SubCategories) { - clonedCategory.SubCategories.Add((ShortcutCategory)subCategory.Clone()); - } - - foreach (var shortcut in Shortcuts) { - clonedCategory.Shortcuts.Add((Shortcut)shortcut.Clone()); - } - - return clonedCategory; - } - - /// - /// Sort category shortcuts - /// - public void SortSubEntries() - { - SubCategories.Sort((a, b) => a.Name.CompareTo(b.Name)); - Shortcuts.Sort((a, b) => a.Name.CompareTo(b.Name)); - - foreach (var category in SubCategories) - { - category.SortSubEntries(); - } - } - - /// - /// Find shortcut shortcut by ID in this category and subcategories - /// - /// Shortcut ID - /// Shortcut with ID equal to provided one - public Shortcut FindShortcut(string shortcutId) - { - // Search for shortcut in shortcuts assigned to this category - foreach (var s in Shortcuts) { - if(s.Id == shortcutId) { - return s; - } - } - - // Search for shortcut in sub categories - foreach (var category in SubCategories) { - Shortcut foundShortcut; - if ((foundShortcut = category.FindShortcut(shortcutId)) != null) { - return foundShortcut; - } - } - - return null; - } - - /// - /// Compare shortcut category to other instances of - /// - /// Compared object - /// Comparison result - public int CompareTo(object obj) - { - if (obj is AddIn) return 1; - if (obj is Shortcut) return -1; - - var categoryObj = (ShortcutCategory)obj; - return Name.CompareTo(categoryObj.Name); - } - - /// - /// Invoke dependency property changed event - /// - /// Name of dependency property from this classs - private void InvokePropertyChanged(string propertyName) - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - } + public class ShortcutCategory : INotifyPropertyChanged, IShortcutTreeEntry + { + private string name; + + /// + /// Gets or sets category name + /// + public string Name + { + get { + return name; + } + set { + if (name != value) { + name = value; + InvokePropertyChanged("Name"); + } + } + } + + private bool isVisible; + + /// + /// Gets or sets whether category is visible in shortcuts tree + /// + public bool IsVisible + { + get { + return isVisible; + } + set { + if (isVisible != value) { + isVisible = value; + InvokePropertyChanged("IsVisible"); + } + } + } + + /// + /// Gets list of sub-cateories + /// + public List SubCategories + { + get; + private set; + } + + /// + /// Gets shortcuts assigned to this category + /// + public List Shortcuts + { + get; + private set; + } + + /// + /// Occurs when or property changes + /// + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Creates new instance of + /// + /// Category name + public ShortcutCategory(string categoryName) + { + IsVisible = true; + Shortcuts = new List(); + SubCategories = new List(); + Name = categoryName; + } + + /// + /// Sorts category shortcuts + /// + public void SortSubEntries() + { + SubCategories.Sort((a, b) => a.Name.CompareTo(b.Name)); + Shortcuts.Sort((a, b) => a.Name.CompareTo(b.Name)); + + foreach (var category in SubCategories) { + category.SortSubEntries(); + } + } + + /// + /// In this category and sub-categories finds shortcut by shortcut ID + /// + /// Shortcut ID + /// Shortcut with ID equal to provided + public Shortcut FindShortcut(string shortcutId) + { + // Search for shortcut in shortcuts assigned to this category + foreach (var s in Shortcuts) { + if(s.Id == shortcutId) { + return s; + } + } + + // Search for shortcut in sub categories + foreach (var category in SubCategories) { + Shortcut foundShortcut; + if ((foundShortcut = category.FindShortcut(shortcutId)) != null) { + return foundShortcut; + } + } + + return null; + } + + /// + /// Compares instance to another instance of type + /// + /// Compared object + /// Comparison result + public int CompareTo(object obj) + { + if (obj is AddIn) return 1; + if (obj is Shortcut) return -1; + + var categoryObj = (ShortcutCategory)obj; + return Name.CompareTo(categoryObj.Name); + } + + /// + /// Invoke dependency property changed event + /// + /// Name of dependency property from this classs + private void InvokePropertyChanged(string propertyName) + { + if (PropertyChanged != null) { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutsFinder.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutsFinder.cs index a2fcc9b01fe..7b67f5add1a 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutsFinder.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/ShortcutsFinder.cs @@ -7,265 +7,259 @@ namespace ICSharpCode.ShortcutsManagement.Data { - /// - /// Filters and hides shortcuts from add-in collection - /// - public class ShortcutsFinder - { - /// - /// Collection of add-ins containing shortcuts and shortcut categories - /// - public ICollection RootEntries - { - get; set; - } - - /// - /// Create new instance of - /// - /// - public ShortcutsFinder(ICollection rootEntries) { - RootEntries = rootEntries; - } - - /// - /// Hide shortcut by setting to false - /// - /// Also this function hides parent categories and Add-in if it has no sub - /// elements left - /// - /// Shortcut to be hidden - public void HideShortcut(Shortcut shortcut) - { - foreach (var entry in RootEntries) { - var subCategoryIsVisible = false; - - var rootAddIn = entry as AddIn; - if (rootAddIn != null) { - foreach (var category in rootAddIn.Categories) { - if (HideShortcut(category, shortcut)) { - subCategoryIsVisible = true; - } - } - - // Hide add-in if it doesn't have any visible sub-elements - rootAddIn.IsVisible = subCategoryIsVisible; - } - - var rootCategory = entry as ShortcutCategory; - if(rootCategory != null) { - HideShortcut(rootCategory, shortcut); - } - - var rootShortcut = entry as Shortcut; - if (rootShortcut != null) { - shortcut.IsVisible = false; - } - } - } - - private static bool HideShortcut(ShortcutCategory category, Shortcut filteredShortcut) - { - // Check if this shortcut is in subcategories - var isSubElementVisible = false; - foreach (var subCategory in category.SubCategories) { - if (HideShortcut(subCategory, filteredShortcut)) { - isSubElementVisible = true; - } - } - - // Determine whether provided shortcut is in provided category and - // hide it if so - foreach (var shortcut in category.Shortcuts) { - if (shortcut.Id == filteredShortcut.Id) { - shortcut.IsVisible = false; - } - - if(shortcut.IsVisible) { - isSubElementVisible = true; - } - } - - // Hide category if it doesn't have any visible sub-elements - category.IsVisible = isSubElementVisible; - - return category.IsVisible; - } - - /// - /// Filter gestures matching provided key gesture template - /// - /// Hides add-ins and sub-categories if there are no sub-elements left - /// - /// Gesture template which should match shortcut gesture partly to make it visible - /// Filtering mode - public void FilterGesture(InputGesture inputGestureTemplate, GestureCompareMode mode) - { - FilterGesture(new InputGestureCollection(new[] { inputGestureTemplate }), mode); - } - - /// - /// Filter gestures matching one of provided gesture templates - /// - /// Hides add-ins and sub-categories if there are no sub-elements left - /// - /// Collection of gesture templates which (atleast one) should match shortcut gesture partly to make it visible - /// Filtering mode - public void FilterGesture(InputGestureCollection inputGestureTemplateCollection, GestureCompareMode mode) - { - Console.WriteLine("FilterGesture: {0}, mode={1}", new InputGestureCollectionConverter().ConvertToInvariantString(inputGestureTemplateCollection), mode); - foreach (var entry in RootEntries) - { - var subCategoryIsVisible = false; - - // Filter root addin and sub-elements - var rootAddIn = entry as AddIn; - if (rootAddIn != null) { - foreach (var category in rootAddIn.Categories) { - if (FilterGesture(category, inputGestureTemplateCollection, mode)) { - subCategoryIsVisible = true; - } - } - - // Hide add-in if it doesn't have any visible sub-elements - rootAddIn.IsVisible = subCategoryIsVisible; - } - - // Filter root category and sub-elements - var rootCategory = entry as ShortcutCategory; - if (rootCategory != null) { - FilterGesture(rootCategory, inputGestureTemplateCollection, mode); - } - - // Filter root shortcut - var rootShortcut = entry as Shortcut; - if (rootShortcut != null) { - rootShortcut.IsVisible = false; - foreach (InputGesture template in inputGestureTemplateCollection) { - if (template.IsTemplateForAny(new InputGestureCollection(rootShortcut.Gestures), mode)) { - rootShortcut.IsVisible = true; - break; - } - } - } - } - } - - /// - /// Filter gestures matching one of provided gesture templates from templates collection - /// - /// Category to filter - /// Collection of gesture templates which (atleast one) should match shortcut gesture partly to make it visible - /// Filtering mode - /// - private static bool FilterGesture(ShortcutCategory category, InputGestureCollection inputGestureTemplateCollection, GestureCompareMode mode) - { - // Apply filter to sub-categories - var isSubElementVisible = false; - foreach (var subCategory in category.SubCategories) { - if (FilterGesture(subCategory, inputGestureTemplateCollection, mode)) - { - isSubElementVisible = true; - } - } - - // Apply filter to shortcuts - foreach (var shortcut in category.Shortcuts) { - var gestureMatched = inputGestureTemplateCollection.ContainsTemplateForAny(new InputGestureCollection(shortcut.Gestures), mode); - - if (gestureMatched) { - shortcut.IsVisible = true; - isSubElementVisible = true; - } - else { - shortcut.IsVisible = false; - } - } - - // Hide category if it doesn't have any visible sub-elements - category.IsVisible = isSubElementVisible; - return category.IsVisible; - } - - /// - /// Filter addins, child categories and shortcuts where item name - /// contains filter string - /// - /// Hides add-ins and sub-categories if there are no sub-elements left - /// - /// Filter string - public void Filter(string filterString) - { - foreach (var entry in RootEntries) { - var rootAddIn = entry as AddIn; - if (rootAddIn != null) { - // If add-in name matches filter string show all sub-elements - var addInNameContainsFilterString = !string.IsNullOrEmpty(filterString) && rootAddIn.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0; - - // Apply filter to categories - var subCategoryIsVisible = false; - - foreach (var category in rootAddIn.Categories) { - if (Filter(category, filterString, addInNameContainsFilterString ? (bool?) true : null)) { - subCategoryIsVisible = true; - } - } - - // If last category in add-in was hidden and addin name does not contain - // part of the filter then hide add-in - rootAddIn.IsVisible = addInNameContainsFilterString || subCategoryIsVisible; - } - - var rootCategory = entry as ShortcutCategory; - if (rootCategory != null) { - Filter(rootCategory, filterString, null); - } - - var rootShortcut = entry as Shortcut; - if (rootShortcut != null) { - rootShortcut.IsVisible = filterString == null || rootShortcut.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0; - } - } - } - - /// - /// Filter category and child elements where item name contains - /// filter string - /// - /// Category to filter - /// Filter string - /// If set to true all sub-elements are visible - /// - private static bool Filter(ShortcutCategory category, string filterString, bool? forseMatch) - { - // If category name matches filter show all sub-categories and shortcuts - if (!string.IsNullOrEmpty(filterString) && category.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) - { - forseMatch = true; - } - - // Apply filter to sub-categories - var isSubElementVisible = false; - foreach (var subCategory in category.SubCategories) { - if(Filter(subCategory, filterString, forseMatch)) { - isSubElementVisible = true; - } - } - - // Filter shortcuts which text match the filter - foreach (var shortcut in category.Shortcuts) { - if ((forseMatch.HasValue && forseMatch.Value) || filterString == null || shortcut.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) - { - shortcut.IsVisible = true; - isSubElementVisible = true; - } - else { - shortcut.IsVisible = false; - } - } - - // Show category if has sub elements, forced or matches search filter - return category.IsVisible = (forseMatch.HasValue && forseMatch.Value && (category.SubCategories.Count > 0 || category.Shortcuts.Count > 0)) || isSubElementVisible; - } - } + /// + /// Filters and hides shortcuts from add-in collection + /// + public class ShortcutsFinder + { + /// + /// Gets and sets collection of add-ins, shortcut categories and shortcuts from shortcuts tree root level + /// + public ICollection RootEntries + { + get; set; + } + + /// + /// Create new instance of + /// + /// + public ShortcutsFinder(ICollection rootEntries) + { + RootEntries = rootEntries; + } + + /// + /// Hides shortcut by setting to false + /// + /// This also function hides parent categories and Add-in if it has no sub-elements + /// left + /// + /// Shortcut to be hidden + public void HideShortcut(Shortcut shortcut) + { + foreach (var entry in RootEntries) { + var subCategoryIsVisible = false; + + var rootAddIn = entry as AddIn; + if (rootAddIn != null) { + foreach (var category in rootAddIn.Categories) { + if (HideShortcut(category, shortcut)) { + subCategoryIsVisible = true; + } + } + + // Hide add-in if it doesn't have any visible sub-elements + rootAddIn.IsVisible = subCategoryIsVisible; + } + + var rootCategory = entry as ShortcutCategory; + if(rootCategory != null) { + HideShortcut(rootCategory, shortcut); + } + + var rootShortcut = entry as Shortcut; + if (rootShortcut != null) { + shortcut.IsVisible = false; + } + } + } + + private static bool HideShortcut(ShortcutCategory category, Shortcut filteredShortcut) + { + // Check if this shortcut is in subcategories + var isSubElementVisible = false; + foreach (var subCategory in category.SubCategories) { + if (HideShortcut(subCategory, filteredShortcut)) { + isSubElementVisible = true; + } + } + + // Determine whether provided shortcut is in provided category and + // hide it if so + foreach (var shortcut in category.Shortcuts) { + if (shortcut.Id == filteredShortcut.Id) { + shortcut.IsVisible = false; + } + + if(shortcut.IsVisible) { + isSubElementVisible = true; + } + } + + // Hide category if it doesn't have any visible sub-elements + category.IsVisible = isSubElementVisible; + + return category.IsVisible; + } + + /// + /// Filters gestures matching provided key gesture template + /// + /// Hides add-ins and sub-categories if there are no sub-elements left + /// + /// Gesture template which should match shortcut gesture partly to make it visible + /// Filtering mode + public void FilterGesture(InputGesture inputGestureTemplate, GestureCompareMode mode) + { + FilterGesture(new InputGestureCollection(new[] { inputGestureTemplate }), mode); + } + + /// + /// Filter gestures matching one of provided gesture templates + /// + /// Hides add-ins and sub-categories if there are no sub-elements left + /// + /// Collection of gesture templates which (atleast one) should match shortcut gesture partly to make it visible + /// Filtering mode + public void FilterGesture(InputGestureCollection inputGestureTemplateCollection, GestureCompareMode mode) + { + foreach (var entry in RootEntries) { + var subCategoryIsVisible = false; + + // Filter root addin and sub-elements + var rootAddIn = entry as AddIn; + if (rootAddIn != null) { + foreach (var category in rootAddIn.Categories) { + if (FilterGesture(category, inputGestureTemplateCollection, mode)) { + subCategoryIsVisible = true; + } + } + + // Hide add-in if it doesn't have any visible sub-elements + rootAddIn.IsVisible = subCategoryIsVisible; + } + + // Filter root category and sub-elements + var rootCategory = entry as ShortcutCategory; + if (rootCategory != null) { + FilterGesture(rootCategory, inputGestureTemplateCollection, mode); + } + + // Filter root shortcut + var rootShortcut = entry as Shortcut; + if (rootShortcut != null) { + rootShortcut.IsVisible = false; + foreach (InputGesture template in inputGestureTemplateCollection) { + if (template.IsTemplateForAny(new InputGestureCollection(rootShortcut.Gestures), mode)) { + rootShortcut.IsVisible = true; + break; + } + } + } + } + } + + /// + /// Filter gestures matching one of provided gesture templates from templates collection + /// + /// Category to filter + /// Collection of gesture templates which (atleast one) should match shortcut gesture partly to make it visible + /// Filtering mode + /// true if found any gestur matching provided template; otherwise false + private static bool FilterGesture(ShortcutCategory category, InputGestureCollection inputGestureTemplateCollection, GestureCompareMode mode) + { + // Apply filter to sub-categories + var isSubElementVisible = false; + foreach (var subCategory in category.SubCategories) { + if (FilterGesture(subCategory, inputGestureTemplateCollection, mode)) { + isSubElementVisible = true; + } + } + + // Apply filter to shortcuts + foreach (var shortcut in category.Shortcuts) { + var gestureMatched = inputGestureTemplateCollection.ContainsTemplateForAny(new InputGestureCollection(shortcut.Gestures), mode); + + if (gestureMatched) { + shortcut.IsVisible = true; + isSubElementVisible = true; + } + else { + shortcut.IsVisible = false; + } + } + + // Hide category if it doesn't have any visible sub-elements + category.IsVisible = isSubElementVisible; + return category.IsVisible; + } + + /// + /// Filter addins, child categories and shortcuts where item name + /// contains filter string + /// + /// Hides add-ins and sub-categories if there are no sub-elements left + /// + /// Filter string + public void Filter(string filterString) + { + foreach (var entry in RootEntries) { + var rootAddIn = entry as AddIn; + if (rootAddIn != null) { + // If add-in name matches filter string show all sub-elements + var addInNameContainsFilterString = !string.IsNullOrEmpty(filterString) && rootAddIn.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0; + + // Apply filter to categories + var subCategoryIsVisible = false; + + foreach (var category in rootAddIn.Categories) { + if (Filter(category, filterString, addInNameContainsFilterString ? (bool?) true : null)) { + subCategoryIsVisible = true; + } + } + + // If last category in add-in was hidden and addin name does not contain + // part of the filter then hide add-in + rootAddIn.IsVisible = addInNameContainsFilterString || subCategoryIsVisible; + } + + var rootCategory = entry as ShortcutCategory; + if (rootCategory != null) { + Filter(rootCategory, filterString, null); + } + + var rootShortcut = entry as Shortcut; + if (rootShortcut != null) { + rootShortcut.IsVisible = filterString == null || rootShortcut.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0; + } + } + } + + /// + /// Filter categorys and child elements where item name contains filter string + /// + /// Category to filter + /// Filter string + /// If set to true all sub-elements are visible + /// + private static bool Filter(ShortcutCategory category, string filterString, bool? forseMatch) + { + // If category name matches filter show all sub-categories and shortcuts + if (!string.IsNullOrEmpty(filterString) && category.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) { + forseMatch = true; + } + + // Apply filter to sub-categories + var isSubElementVisible = false; + foreach (var subCategory in category.SubCategories) { + if(Filter(subCategory, filterString, forseMatch)) { + isSubElementVisible = true; + } + } + + // Filter shortcuts which text match the filter + foreach (var shortcut in category.Shortcuts) { + if ((forseMatch.HasValue && forseMatch.Value) || filterString == null || shortcut.Name.IndexOf(filterString, StringComparison.InvariantCultureIgnoreCase) >= 0) { + shortcut.IsVisible = true; + isSubElementVisible = true; + } else { + shortcut.IsVisible = false; + } + } + + // Show category if has sub elements, forced or matches search filter + return category.IsVisible = (forseMatch.HasValue && forseMatch.Value && (category.SubCategories.Count > 0 || category.Shortcuts.Count > 0)) || isSubElementVisible; + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/UserGestureProfileAction.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/UserGestureProfileAction.cs index 0ce761a09f8..da11b9cf003 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/UserGestureProfileAction.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/UserGestureProfileAction.cs @@ -1,12 +1,12 @@ namespace ICSharpCode.ShortcutsManagement.Data { /// - /// Represents action over UserGestureProfile + /// Represents action action /// class UserGestureProfileAction { /// - /// Action name + /// Gets or sets action name /// public string Name { @@ -15,7 +15,7 @@ public string Name } /// - /// Action text + /// Gets or sets action text /// public object Text { diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/CreateNewProfilePrompt.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/CreateNewProfilePrompt.xaml.cs index 2005c6f1ee3..bb7dc76a8a7 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/CreateNewProfilePrompt.xaml.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/CreateNewProfilePrompt.xaml.cs @@ -4,136 +4,128 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs { - /// - /// Window prompting user to enter new or existing profile name - /// and base profile - /// - public partial class CreateNewProfilePrompt : Window - { - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty BaseProfileProperty = DependencyProperty.Register( - "BaseProfile", - typeof(UserGestureProfile), - typeof(CreateNewProfilePrompt), - new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specifies profile which new profile will be based on - /// - public UserGestureProfile BaseProfile - { - get - { - return (UserGestureProfile)GetValue(BaseProfileProperty); - } - set - { - SetValue(BaseProfileProperty, value); - } - } - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty BaseProfilesVisibilityProperty = DependencyProperty.Register( - "BaseProfilesVisibility", - typeof(Visibility), - typeof(CreateNewProfilePrompt), - new FrameworkPropertyMetadata(Visibility.Visible, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Base profiles combo box visibility - /// - public Visibility BaseProfilesVisibility - { - get - { - return (Visibility)GetValue(BaseProfilesVisibilityProperty); - } - set - { - SetValue(BaseProfilesVisibilityProperty, value); - } - } - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty AvailableBaseProfilesProperty = DependencyProperty.Register( - "AvailableBaseProfiles", - typeof(ICollection), - typeof(CreateNewProfilePrompt), - new FrameworkPropertyMetadata(new List(), FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Profiles user can choose from when selecting base profile - /// - public ICollection AvailableBaseProfiles - { - get - { - return (ICollection)GetValue(AvailableBaseProfilesProperty); - } - set - { - SetValue(AvailableBaseProfilesProperty, value); - } - } - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty TextProperty = DependencyProperty.Register( - "Text", - typeof(string), - typeof(CreateNewProfilePrompt), - new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specifies text entered in window text box - /// - public string Text - { - get - { - return (string)GetValue(TextProperty); - } - set - { - SetValue(TextProperty, value); - } - } - - /// - /// Creates new instance of - /// - public CreateNewProfilePrompt() - { - InitializeComponent(); - } - - /// - /// Occurs when user clicks on OK button - /// - /// Sender object - /// Event argument - private void OkButton_Click(object sender, RoutedEventArgs e) - { - DialogResult = true; - Close(); - } - - /// - /// Occurs when user clicks on Cancel buttons - /// - /// Sender obect - /// Event argument - private void CancelButton_Click(object sender, RoutedEventArgs e) - { - DialogResult = false; - Close(); - } - } + /// + /// Window prompting user to enter new or existing profile name + /// and base profile + /// + public partial class CreateNewProfilePrompt : Window + { + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty BaseProfileProperty = DependencyProperty.Register( + "BaseProfile", + typeof(UserGestureProfile), + typeof(CreateNewProfilePrompt), + new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets profile which new profile will be based on + /// + public UserGestureProfile BaseProfile + { + get { + return (UserGestureProfile)GetValue(BaseProfileProperty); + } + set { + SetValue(BaseProfileProperty, value); + } + } + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty BaseProfilesVisibilityProperty = DependencyProperty.Register( + "BaseProfilesVisibility", + typeof(Visibility), + typeof(CreateNewProfilePrompt), + new FrameworkPropertyMetadata(Visibility.Visible, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets base profiles combo box visibility + /// + public Visibility BaseProfilesVisibility + { + get { + return (Visibility)GetValue(BaseProfilesVisibilityProperty); + } + set { + SetValue(BaseProfilesVisibilityProperty, value); + } + } + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty AvailableBaseProfilesProperty = DependencyProperty.Register( + "AvailableBaseProfiles", + typeof(ICollection), + typeof(CreateNewProfilePrompt), + new FrameworkPropertyMetadata(new List(), FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Profiles user can choose from when selecting base profile + /// + public ICollection AvailableBaseProfiles + { + get { + return (ICollection)GetValue(AvailableBaseProfilesProperty); + } + set { + SetValue(AvailableBaseProfilesProperty, value); + } + } + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + "Text", + typeof(string), + typeof(CreateNewProfilePrompt), + new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets text entered in window text box + /// + public string Text + { + get { + return (string)GetValue(TextProperty); + } + set { + SetValue(TextProperty, value); + } + } + + /// + /// Creates new instance of + /// + public CreateNewProfilePrompt() + { + InitializeComponent(); + } + + /// + /// Executed when user clicks on OK button + /// + /// Sender object + /// Event argument + private void OkButton_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + Close(); + } + + /// + /// Executed when user clicks on Cancel buttons + /// + /// Sender obect + /// Event argument + private void CancelButton_Click(object sender, RoutedEventArgs e) + { + DialogResult = false; + Close(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/MultiKeyGestureTextBox.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/MultiKeyGestureTextBox.xaml.cs index e243469e49c..dadbf5c376c 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/MultiKeyGestureTextBox.xaml.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/MultiKeyGestureTextBox.xaml.cs @@ -9,300 +9,286 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs { - /// - /// Notification type enumeration - /// - public enum NotificationType - { - /// - /// A valid gesture is entered so far - /// - Valid, - - /// - /// Gesture is being entered, but is not valid yet - /// - Invalid, - - /// - /// Gesture was successfully added to gestures collection - /// - Added, - - /// - /// Failed to add gesture to gestures collection - /// - Failed, - - /// - /// Notification message is not displayed - /// - None - } - - /// - /// Represents a textbox suited for entering key gestures - /// - public partial class MultiKeyGestureTextBox : UserControl - { - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty TextBoxBorderThicknessProperty = DependencyProperty.Register( - "TextBoxBorderThickness", - typeof(int), - typeof(MultiKeyGestureTextBox), - new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specifies text box border thickness - /// - public int TextBoxBorderThickness - { - get { - return (int)GetValue(TextBoxBorderThicknessProperty); - } - set { - SetValue(TextBoxBorderThicknessProperty, value); - } - } - - /// - /// Key gesture entered in text box - /// - public KeyGesture Gesture - { - get { - if (enteredKeyGestureSequence == null || enteredKeyGestureSequence.Count == 0) { - return null; - } - - if (enteredKeyGestureSequence.Count == 1) { - return new PartialKeyGesture(enteredKeyGestureSequence.First()); - } - - return new MultiKeyGesture(enteredKeyGestureSequence); - } - } - - /// - /// Event which is raised when gesture entered in text box changes - /// - public event EventHandler GestureChanged; - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty NotificationVisibilityProperty = DependencyProperty.Register( - "NotificationVisibility", - typeof(Visibility), - typeof(MultiKeyGestureTextBox), - new FrameworkPropertyMetadata(Visibility.Visible, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Whether notifications are displayed under textbox control - /// - public Visibility NotificationVisibility - { - get { - return (Visibility)GetValue(NotificationVisibilityProperty); - } - set { - SetValue(NotificationVisibilityProperty, value); - } - } - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty NotificationTypeProperty = DependencyProperty.Register( - "NotificationType", - typeof(NotificationType), - typeof(MultiKeyGestureTextBox), - new FrameworkPropertyMetadata(NotificationType.None, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specifies displayed notification type - /// - public NotificationType NotificationType - { - get { - return (NotificationType)GetValue(NotificationTypeProperty); - } - set { - SetValue(NotificationTypeProperty, value); - } - } - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty NotificationTextProperty = DependencyProperty.Register( - "NotificationText", - typeof(string), - typeof(MultiKeyGestureTextBox), - new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specifies displayed notification text - /// - public string NotificationText - { - get { - return (string)GetValue(NotificationTextProperty); - } - set { - SetValue(NotificationTextProperty, value); - } - } - - /// - /// Last entered chords - /// - private List enteredKeyGestureSequence = new List(); - - /// - /// Time when last successfull chord was entered - /// - private DateTime lastEnterTime = DateTime.Now; - - /// - /// Creates instance of - /// - public MultiKeyGestureTextBox() - { - InitializeComponent(); - } - - /// - /// Displays notifications under gesture text box - /// - /// Notification text - /// Notification type - public void DisplayNotification(string notificationText, NotificationType type) - { - NotificationText = notificationText; - NotificationType = type; - } - - /// - /// Clears all text area, chords and hides notification - /// - public void Clear() - { - enteredKeyGestureSequence = new List(); - shortcutTextBox.Text = ""; - DisplayNotification("", NotificationType.None); - } - - /// - /// Raised when clicked on "Clear" button to the right from gesture text box - /// - /// - /// - private void clearTextBox_Click(object sender, RoutedEventArgs e) - { - Clear(); - } - - - /// - /// Raised when text inside textbox changes - /// - /// Sender object - /// Event arguments - void shortcutTextBox_TextChanged(object sender, TextChangedEventArgs e) - { - if (GestureChanged != null) { - GestureChanged.Invoke(sender, new EventArgs()); - } - } - - /// - /// Raised before user presses any key inside text box - /// - /// Sender object - /// Event argument - private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e) - { - e.Handled = true; - - // If a key is holded for a longer time key event is raised repeatedly. - // We don't want to handle this kind of events - if (e.IsRepeat) { - return; - } - - // If delete or backspace button is pressed - if (e.Key == Key.Back || e.Key == Key.Delete) { - Clear(); - return; - } - - // Check whether time given for chord entry haven't expired yet - if (DateTime.Now - lastEnterTime > MultiKeyGesture.DelayBetweenChords) { - if (enteredKeyGestureSequence.Count > 0) { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.TimeExpired}"), NotificationType.Invalid); - } - - Clear(); - lastEnterTime = DateTime.Now; - } - - var partialKeyGesture = new PartialKeyGesture(e); - - var lastGesture = enteredKeyGestureSequence.Count > 0 ? enteredKeyGestureSequence.LastOrDefault() : null; - var isLastGestureSpecialKey = lastGesture != null && (lastGesture.Key >= Key.F1) && (lastGesture.Key <= Key.F24); - - var isLastGestureComplete = lastGesture != null && (lastGesture.Key != Key.None || isLastGestureSpecialKey); - var isContinuedGesture = lastGesture != null && partialKeyGesture.Modifiers - (partialKeyGesture.Modifiers ^ lastGesture.Modifiers) >= 0; - - // If continuing previous chord - if (!isLastGestureComplete && isContinuedGesture) - { - enteredKeyGestureSequence.RemoveAt(enteredKeyGestureSequence.Count - 1); - } - - // If previous chord is unfinished and second chord is already entered - // start from scratch. - else if (!isLastGestureComplete) - { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.SequenceIsNotCoherent}"), NotificationType.Invalid); - Clear(); - } - - // If successfully finished another chord give more time - if (partialKeyGesture.Key != Key.None) - { - lastEnterTime = DateTime.Now; - } - - enteredKeyGestureSequence.Add(partialKeyGesture); - - // Create a multi key gesture if entered more than one chord - if (enteredKeyGestureSequence.Count > 0) - { - var multiKeyGesture = new MultiKeyGesture(enteredKeyGestureSequence); - var multiKeyGestureString = new MultiKeyGestureConverter().ConvertToInvariantString(multiKeyGesture); - shortcutTextBox.Text = multiKeyGestureString; - } - else - { - Clear(); - } - - if (!enteredKeyGestureSequence[0].IsFull) - { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.FirstChordIsIncomplete}"), NotificationType.Invalid); - } - else if (partialKeyGesture.Key == Key.None) - { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.LastChordIsIncomplete}"), NotificationType.Invalid); - } - else - { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.GestureIsValid}"), NotificationType.Valid); - } - } - } + /// + /// Notification type enumeration + /// + public enum NotificationType + { + /// + /// A valid gesture is entered so far + /// + Valid, + + /// + /// Gesture is being entered, but is not valid yet + /// + Invalid, + + /// + /// Gesture was successfully added to gestures collection + /// + Added, + + /// + /// Failed to add gesture to gestures collection + /// + Failed, + + /// + /// Notification message is not displayed + /// + None + } + + /// + /// Represents a textbox suited for entering key gestures + /// + public partial class MultiKeyGestureTextBox : UserControl + { + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty TextBoxBorderThicknessProperty = DependencyProperty.Register( + "TextBoxBorderThickness", + typeof(int), + typeof(MultiKeyGestureTextBox), + new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets text box border thickness + /// + public int TextBoxBorderThickness + { + get { + return (int)GetValue(TextBoxBorderThicknessProperty); + } + set { + SetValue(TextBoxBorderThicknessProperty, value); + } + } + + /// + /// Gets entered in text box + /// + public KeyGesture Gesture + { + get { + if (enteredKeyGestureSequence == null || enteredKeyGestureSequence.Count == 0) { + return null; + } + + if (enteredKeyGestureSequence.Count == 1) { + return new PartialKeyGesture(enteredKeyGestureSequence.First()); + } + + return new MultiKeyGesture(enteredKeyGestureSequence); + } + } + + /// + /// Occurs when gesture entered in text box changes + /// + public event EventHandler GestureChanged; + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty NotificationVisibilityProperty = DependencyProperty.Register( + "NotificationVisibility", + typeof(Visibility), + typeof(MultiKeyGestureTextBox), + new FrameworkPropertyMetadata(Visibility.Visible, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets value which specifies whether notifications are displayed under textbox control + /// + public Visibility NotificationVisibility + { + get { + return (Visibility)GetValue(NotificationVisibilityProperty); + } + set { + SetValue(NotificationVisibilityProperty, value); + } + } + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty NotificationTypeProperty = DependencyProperty.Register( + "NotificationType", + typeof(NotificationType), + typeof(MultiKeyGestureTextBox), + new FrameworkPropertyMetadata(NotificationType.None, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets notification type + /// + public NotificationType NotificationType + { + get { + return (NotificationType)GetValue(NotificationTypeProperty); + } + set { + SetValue(NotificationTypeProperty, value); + } + } + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty NotificationTextProperty = DependencyProperty.Register( + "NotificationText", + typeof(string), + typeof(MultiKeyGestureTextBox), + new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets displayed notification text + /// + public string NotificationText + { + get { + return (string)GetValue(NotificationTextProperty); + } + set { + SetValue(NotificationTextProperty, value); + } + } + + /// + /// Last entered chords + /// + private List enteredKeyGestureSequence = new List(); + + /// + /// Time when last successfull chord was entered + /// + private DateTime lastEnterTime = DateTime.Now; + + /// + /// Creates instance of + /// + public MultiKeyGestureTextBox() + { + InitializeComponent(); + } + + /// + /// Displays notifications under gesture text box + /// + /// Notification text + /// Notification type + public void DisplayNotification(string notificationText, NotificationType type) + { + NotificationText = notificationText; + NotificationType = type; + } + + /// + /// Clears all text area, chords and hides notification + /// + public void Clear() + { + enteredKeyGestureSequence = new List(); + shortcutTextBox.Text = ""; + DisplayNotification("", NotificationType.None); + } + + /// + /// Executed when clicked on "Clear" button to the right from gesture text box + /// + /// Sender object + /// supporting data + private void clearTextBox_Click(object sender, RoutedEventArgs e) + { + Clear(); + } + + /// + /// Executed when text inside textbox changes + /// + /// Sender object + /// Event arguments + void shortcutTextBox_TextChanged(object sender, TextChangedEventArgs e) + { + if (GestureChanged != null) { + GestureChanged.Invoke(sender, new EventArgs()); + } + } + + /// + /// Raised before user presses any key inside text box + /// + /// Sender object + /// Event argument + private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e) + { + e.Handled = true; + + // If a key is holded for a longer time key event is raised repeatedly. + // We don't want to handle this kind of events + if (e.IsRepeat) { + return; + } + + // If delete or backspace button is pressed + if (e.Key == Key.Back || e.Key == Key.Delete) { + Clear(); + return; + } + + // Check whether time given for chord entry haven't expired yet + if (DateTime.Now - lastEnterTime > MultiKeyGesture.DelayBetweenChords) { + if (enteredKeyGestureSequence.Count > 0) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.TimeExpired}"), NotificationType.Invalid); + } + + Clear(); + lastEnterTime = DateTime.Now; + } + + var partialKeyGesture = new PartialKeyGesture(e); + + var lastGesture = enteredKeyGestureSequence.Count > 0 ? enteredKeyGestureSequence.LastOrDefault() : null; + var isLastGestureSpecialKey = lastGesture != null && (lastGesture.Key >= Key.F1) && (lastGesture.Key <= Key.F24); + + var isLastGestureComplete = lastGesture != null && (lastGesture.Key != Key.None || isLastGestureSpecialKey); + var isContinuedGesture = lastGesture != null && partialKeyGesture.Modifiers - (partialKeyGesture.Modifiers ^ lastGesture.Modifiers) >= 0; + + // If continuing previous chord + if (!isLastGestureComplete && isContinuedGesture) { + enteredKeyGestureSequence.RemoveAt(enteredKeyGestureSequence.Count - 1); + } else if (!isLastGestureComplete) { + // If previous chord is unfinished and second chord is already entered + // start from scratch. + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.SequenceIsNotCoherent}"), NotificationType.Invalid); + Clear(); + } + + // If successfully finished another chord give more time + if (partialKeyGesture.Key != Key.None) { + lastEnterTime = DateTime.Now; + } + + enteredKeyGestureSequence.Add(partialKeyGesture); + + // Create a multi key gesture if entered more than one chord + if (enteredKeyGestureSequence.Count > 0) { + var multiKeyGesture = new MultiKeyGesture(enteredKeyGestureSequence); + var multiKeyGestureString = new MultiKeyGestureConverter().ConvertToInvariantString(multiKeyGesture); + shortcutTextBox.Text = multiKeyGestureString; + } else { + Clear(); + } + + if (!enteredKeyGestureSequence[0].IsFull) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.FirstChordIsIncomplete}"), NotificationType.Invalid); + } else if (partialKeyGesture.Key == Key.None) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.LastChordIsIncomplete}"), NotificationType.Invalid); + } else { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.GestureIsValid}"), NotificationType.Valid); + } + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml.cs index 38b0659dfab..bf4bbe9a9c4 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml.cs @@ -10,210 +10,213 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs { - /// - /// This window allows user to modify shortcuts registered in application - /// - public partial class ShortcutManagementWindow : Window - { - /// - /// Modified shortcut copy - /// - public Shortcut Shortcut - { - get; private set; - } - - /// - /// Deep copy of addins list (including copies of categories and shortcuts) - /// - public ICollection RootEntries - { - get; private set; - } - - /// - /// List of modified shortcuts. - /// - /// This list is used to optimize performance. Shortcuts not in this list are not saved. - /// Allways add modified shortcut to this list. - /// - public List ModifiedShortcuts - { - get; private set; - } - - /// - /// Initializes new class - /// - /// Shortcut - /// List of all other add-ins containing shortcuts and categories. This list is used to find dupliate shortcuts - public ShortcutManagementWindow(Shortcut shortcut, ICollection rootEntries) - { - ModifiedShortcuts = new List(); - - Shortcut = shortcut; - RootEntries = rootEntries; - - shortcut.Gestures.CollectionChanged += Gestures_CollectionChanged; - ModifiedShortcuts.Add(shortcut); - DataContext = shortcut; - - InitializeComponent(); - - // Display similar shortcuts (Shortcuts with the same input gestures assigned to them) - shortcutsManagementOptionsPanel.DataContext = rootEntries; - shortcutsManagementOptionsPanel.Loaded += delegate { FilterSimilarShortcuts(); }; - } - - /// - /// Filter shortcuts using same gestures as modified shortcut - /// - private void FilterSimilarShortcuts() - { - var templates = new InputGestureCollection(Shortcut.Gestures); - - // Find shortcuts with same gesture and hide them. - // Also hide modified shortcut from this list - var finder = new ShortcutsFinder(RootEntries); - finder.FilterGesture(templates, GestureCompareMode.Conflicting); - finder.HideShortcut(Shortcut); - - shortcutsManagementOptionsPanel.ExpandAll(); - shortcutsManagementOptionsPanel.SelectFirstVisibleShortcut(false); - } - - /// - /// Executed when adding or removing gestures used to call modified shortcut - /// - /// Sender object - /// Event arguments - void Gestures_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) - { - FilterSimilarShortcuts(); - } - - /// - /// Executed when "Remove" button next to gesture is pressed - /// - /// Object sender - /// Event arguments - private void removeGestureButton_Click(object sender, RoutedEventArgs e) - { - var tag = ((Button) sender).Tag as InputGesture; - Shortcut.Gestures.Remove(tag); - } - - /// - /// Executed when "Add Gesture" button is clicked - /// - /// Object sender - /// Event arguments - private void addGestureButton_Click(object sender, RoutedEventArgs e) - { - // Check if any chords are entered - if (gestureTextBox.Gesture == null) { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedNoChords}"), NotificationType.Failed); - return; - } - - // Check whether first chord is unfinished - var partialKeyGesture = gestureTextBox.Gesture as PartialKeyGesture; - if (partialKeyGesture != null && !partialKeyGesture.IsFull) { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedFirstChordIsIncomplete}"), NotificationType.Failed); - return; - } - - // Check whether last chord is finished - var multiKeyGesture = gestureTextBox.Gesture as MultiKeyGesture; - if (multiKeyGesture != null && multiKeyGesture.Chords.Last().Key == Key.None) { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedLastChordIsIncompete}"), NotificationType.Failed); - return; - } - - // Check whether gesture exist in shortcut gestures collection - foreach (var existingGesture in Shortcut.Gestures) { - if (gestureTextBox.Gesture.IsTemplateFor(existingGesture, GestureCompareMode.ExactlyMatches)) { - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AddingExistingGesture}"), NotificationType.Failed); - return; - } - } - - // Add gesture - if (partialKeyGesture != null) { - try { - var keyGesture = new KeyGesture(partialKeyGesture.Key, partialKeyGesture.Modifiers); - Shortcut.Gestures.Add(keyGesture); - } catch (NotSupportedException) { - Shortcut.Gestures.Add(partialKeyGesture); - } - } else { - Shortcut.Gestures.Add(gestureTextBox.Gesture); - } - - DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionIsSuccessfull}"), NotificationType.Added); - } - - /// - /// Executed when "Remove" button next to similar shortcut is pressed - /// - /// Sender object - /// Event argument - private void shortcutsManagementOptionsPanel_RemoveShortcutClick(object sender, RoutedRemoveShortcutEventArgs e) - { - e.Handled = true; - - // Remove gestures registered in modified shortcut from deleted shortcut - var removedShortcutGestures = e.RemovedShortcut.Gestures; - for (int i = removedShortcutGestures.Count - 1; i >= 0; i--) { - foreach (var modifiedInputGesture in Shortcut.Gestures) { - if (removedShortcutGestures[i].IsTemplateFor(modifiedInputGesture, GestureCompareMode.StartsWith)) { - removedShortcutGestures.RemoveAt(i); - FilterSimilarShortcuts(); - - if (!ModifiedShortcuts.Contains(e.RemovedShortcut)) - { - ModifiedShortcuts.Add(e.RemovedShortcut); - } - - break; - } - } - } - } - - /// - /// Save changes to shortcuts - /// - /// Sender object - /// Event arguments - private void saveButton_Click(object sender, RoutedEventArgs e) - { - DialogResult = true; - - Close(); - } - - /// - /// Display message describing shortcut addition result - /// - /// Displayed message text - /// Message type - public void DisplayNotification(string notificationText, NotificationType type) - { - gestureTextBox.NotificationText = notificationText; - gestureTextBox.NotificationType = type; - } - - /// - /// Execute this method when Reset button is clicked. - /// - /// Modifications are not saved - /// - /// Sender object - /// Event arguments - private void resetButton_Click(object sender, RoutedEventArgs e) - { - Close(); - } - } + /// + /// This window allows user to modify shortcuts registered in application + /// + public partial class ShortcutManagementWindow : Window + { + private HashSet modifiedShortcuts = new HashSet(); + + /// + /// Gets modified shortcut copy + /// + public Shortcut Shortcut + { + get; private set; + } + + /// + /// Gets deep copy of addins list (including copies of categories and shortcuts) + /// + public ICollection RootEntries + { + get; private set; + } + + /// + /// Gets list of modified shortcuts. + /// + /// This list is used to optimize performance. Shortcuts not in this list are not saved. + /// Allways add modified shortcut to this list. + /// + public ICollection ModifiedShortcuts + { + get { + return modifiedShortcuts; + } + } + + /// + /// Initializes new class + /// + /// Shortcut + /// List of all other add-ins containing shortcuts and categories. This list is used to find dupliate shortcuts + public ShortcutManagementWindow(Shortcut shortcut, ICollection rootEntries) + { + Shortcut = shortcut; + RootEntries = rootEntries; + + shortcut.Gestures.CollectionChanged += Gestures_CollectionChanged; + ModifiedShortcuts.Add(shortcut); + DataContext = shortcut; + + InitializeComponent(); + + // Display similar shortcuts (Shortcuts with the same input gestures assigned to them) + shortcutsManagementOptionsPanel.DataContext = rootEntries; + shortcutsManagementOptionsPanel.Loaded += delegate { FilterSimilarShortcuts(); }; + } + + /// + /// Filter shortcuts using same gestures as modified shortcut + /// + private void FilterSimilarShortcuts() + { + var templates = new InputGestureCollection(Shortcut.Gestures); + + // Find shortcuts with same gesture and hide them. + // Also hide modified shortcut from this list + var finder = new ShortcutsFinder(RootEntries); + finder.FilterGesture(templates, GestureCompareMode.Conflicting); + finder.HideShortcut(Shortcut); + + shortcutsManagementOptionsPanel.ExpandAll(); + shortcutsManagementOptionsPanel.SelectFirstVisibleShortcut(false); + } + + /// + /// Executed when adding or removing gestures used to call modified shortcut + /// + /// Sender object + /// Event arguments + void Gestures_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + FilterSimilarShortcuts(); + } + + /// + /// Executed when "Remove" button next to gesture is pressed + /// + /// Object sender + /// Event arguments + private void removeGestureButton_Click(object sender, RoutedEventArgs e) + { + var tag = ((Button) sender).Tag as InputGesture; + Shortcut.Gestures.Remove(tag); + } + + /// + /// Executed when "Add Gesture" button is clicked + /// + /// Object sender + /// Event arguments + private void addGestureButton_Click(object sender, RoutedEventArgs e) + { + // Check if any chords are entered + if (gestureTextBox.Gesture == null) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedNoChords}"), NotificationType.Failed); + return; + } + + // Check whether first chord is unfinished + var partialKeyGesture = gestureTextBox.Gesture as PartialKeyGesture; + if (partialKeyGesture != null && !partialKeyGesture.IsFull) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedFirstChordIsIncomplete}"), NotificationType.Failed); + return; + } + + // Check whether last chord is finished + var multiKeyGesture = gestureTextBox.Gesture as MultiKeyGesture; + if (multiKeyGesture != null && multiKeyGesture.Chords.Last().Key == Key.None) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedLastChordIsIncompete}"), NotificationType.Failed); + return; + } + + // Check whether gesture exist in shortcut gestures collection + foreach (var existingGesture in Shortcut.Gestures) { + if (gestureTextBox.Gesture.IsTemplateFor(existingGesture, GestureCompareMode.ExactlyMatches)) { + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AddingExistingGesture}"), NotificationType.Failed); + return; + } + } + + // Add gesture + if (partialKeyGesture != null) { + try { + var keyGesture = new KeyGesture(partialKeyGesture.Key, partialKeyGesture.Modifiers); + Shortcut.Gestures.Add(keyGesture); + } catch (NotSupportedException) { + Shortcut.Gestures.Add(partialKeyGesture); + } + } else { + Shortcut.Gestures.Add(gestureTextBox.Gesture); + } + + DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionIsSuccessfull}"), NotificationType.Added); + } + + private Shortcut prevShortcut; + + /// + /// Executed when "Remove" button next to similar shortcut is pressed + /// + /// Sender object + /// Event argument + private void shortcutsManagementOptionsPanel_RemoveShortcutClick(object sender, RoutedRemoveShortcutEventArgs e) + { + e.Handled = true; + + // Remove gestures registered in modified shortcut from deleted shortcut + var removedShortcutGestures = e.RemovedShortcut.Gestures; + + for (int i = removedShortcutGestures.Count - 1; i >= 0; i--) { + foreach (var modifiedInputGesture in Shortcut.Gestures) { + if (removedShortcutGestures[i].IsTemplateFor(modifiedInputGesture, GestureCompareMode.StartsWith)) { + removedShortcutGestures.RemoveAt(i); + + modifiedShortcuts.Add(e.RemovedShortcut); + + break; + } + } + } + + FilterSimilarShortcuts(); + } + + /// + /// Save changes to shortcuts + /// + /// Sender object + /// Event arguments + private void saveButton_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + + Close(); + } + + /// + /// Display message describing shortcut addition result + /// + /// Displayed message text + /// Message type + public void DisplayNotification(string notificationText, NotificationType type) + { + gestureTextBox.NotificationText = notificationText; + gestureTextBox.NotificationType = type; + } + + /// + /// Execute this method when Reset button is clicked. + /// + /// Modifications are not saved + /// + /// Sender object + /// Event arguments + private void resetButton_Click(object sender, RoutedEventArgs e) + { + Close(); + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs index c52f31713b8..81fc559482f 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs @@ -131,9 +131,8 @@ private void BindProfiles() profilesTextBox.SelectedIndex = -1; profilesTextBox.Text = ""; } - } - + private void BindShortcuts() { shortcutsMap.Clear(); @@ -154,11 +153,10 @@ private void BindShortcuts() var categoryName = Regex.Replace(StringParser.Parse(bindingCategory.Text), @"&([^\s])", @"$1"); var shortcutCategory = new ShortcutCategory(categoryName); categoriesMap.Add(bindingCategory, shortcutCategory); - + AddCategory: var currentDepth = bindingCategory.Path.Split('/').Length - 1; - if (currentDepth > previousDepth) - { + if (currentDepth > previousDepth) { previousDepth++; if (previousDepth > 1) { @@ -173,7 +171,7 @@ private void BindShortcuts() parentCategories.RemoveLast(); previousDepth--; } - + goto AddCategory; } } @@ -251,7 +249,9 @@ public object Owner public object Control { - get { return this; } + get { + return this; + } } private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEventArgs e) @@ -264,9 +264,9 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve if (userGestureProfileAction != null) { if (userGestureProfileAction.Name == "Delete" && SelectedProfile != null) { var result = MessageBox.Show( - StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.ConfirmDeleteProfileMessage}"), - StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.ConfirmDeleteProfileMessageWindowName}"), - MessageBoxButton.YesNo); + StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.ConfirmDeleteProfileMessage}"), + StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.ConfirmDeleteProfileMessageWindowName}"), + MessageBoxButton.YesNo); if(MessageBoxResult.Yes == result) { profiles.Remove(SelectedProfile); @@ -299,7 +299,7 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve SelectedProfile = loadedProfile; } } - + if (userGestureProfileAction.Name == "Reset") { SelectedProfile = null; } @@ -324,7 +324,7 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve newProfile[pair.Key] = pair.Value; } } - + profiles.Add(newProfile); SelectedProfile = newProfile; @@ -345,29 +345,23 @@ private void shortcutsManagementOptionsPanel_ShortcutModified(object sender, Eve { var selectedShortcut = (Shortcut)shortcutsManagementOptionsPanel.shortcutsTreeView.SelectedItem; - if(SelectedProfile == null) - { + if(SelectedProfile == null) { MessageBox.Show(StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.NoProfileSelectedMessage}")); return; } - if(SelectedProfile.ReadOnly) - { + if(SelectedProfile.ReadOnly) { MessageBox.Show(StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.SelectedProfileIsReadOnlyMessage}")); return; } Shortcut shortcutCopy = null; - ICollection rootEntriesCopy = new ObservableCollection(); - // Make a deep copy of all add-ins, categories and shortcuts - foreach (var entry in rootEntries) { - var clonedRootEntry = (IShortcutTreeEntry)entry.Clone(); - rootEntriesCopy.Add(clonedRootEntry); - - // Find copy of modified shortcut in copied add-ins collection + var cloner = new IShortcutTreeEntryCloner(); + var rootEntriesCopy = cloner.CloneShortcutTree(rootEntries); + foreach(var clonedEntry in rootEntriesCopy) { if (shortcutCopy == null) { - shortcutCopy = clonedRootEntry.FindShortcut(selectedShortcut.Id); + shortcutCopy = clonedEntry.FindShortcut(selectedShortcut.Id); } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsTreeView.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsTreeView.xaml.cs index 18ab46d6a99..161d0fbaf98 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsTreeView.xaml.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsTreeView.xaml.cs @@ -10,309 +10,311 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs { - /// - /// This panel is used in SharpDevelop options window to manage shortcuts - /// - public partial class ShortcutsTreeView : UserControl - { - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty IsSearchableProperty = DependencyProperty.Register( - "IsSearchable", - typeof(Boolean), - typeof(ShortcutsTreeView), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specifies whether shortcuts tree can be searched using part of the shortcut's name or - /// gesture - /// - public Boolean IsSearchable - { - get { - return (Boolean)GetValue(IsSearchableProperty); - } - set { - SetValue(IsSearchableProperty, value); - } - } - - /// - /// Identifies dependency property - /// - public static readonly DependencyProperty IsRemovableShortcutsEnabledProperty = DependencyProperty.Register( - "IsRemovableShortcutsEnabled", - typeof(Boolean), - typeof(ShortcutsTreeView), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); - - /// - /// Specify whether shortcuts can be removed from the tree. - /// - /// If this value set to true will be raised when - /// shortcut is deleted - /// - public Boolean IsRemovableShortcutsEnabled - { - get { - return (Boolean)GetValue(IsSearchableProperty); - } - set { - SetValue(IsSearchableProperty, value); - } - } - - /// - /// Occurs when user tries to remove shortcut from shortcuts tree - /// - public event RemoveShortcutRoutedHandler RemoveShortcutClick; - - /// - /// List of add-ins containing shortcut categories and shortcuts - /// - private ICollection RootEntries - { - get { - return (ICollection)DataContext; - } - } - - /// - /// Constructor - /// - public ShortcutsTreeView() - { - InitializeComponent(); - } - - /// - /// Select first enabled shortcut in shortcut tree - /// - /// Set focus to this shortcut entry - public void SelectFirstVisibleShortcut(bool setFocus) - { - var path = new List(); - foreach (var entry in RootEntries) { - if (entry != null && entry.IsVisible) { - path.Add(entry); - FindFirstVisibleItemPath(entry, path); - shortcutsTreeView.SelectItem(path.Cast().ToList(), setFocus); - - return; - } - } - } - /// - /// Find path to first with true - /// - /// Starting node - /// Accumulated path - private void FindFirstVisibleItemPath(IShortcutTreeEntry parent, List path) - { - // Find first visible add-in - var addIn = parent as AddIn; - if(addIn != null) { - var selectedCategory = addIn.Categories.FirstOrDefault(a => a.IsVisible); - if (selectedCategory != null) { - path.Add(selectedCategory); - FindFirstVisibleItemPath(selectedCategory, path); - return; - } - } - - // Find first visible category - var category = parent as ShortcutCategory; - if (category != null) { - var selectedCategory = category.SubCategories.FirstOrDefault(a => a.IsVisible); - if (selectedCategory != null) { - path.Add(selectedCategory); - FindFirstVisibleItemPath(selectedCategory, path); - return; - } - - // Find first visible shortcut - var selectedShortcut = category.Shortcuts.FirstOrDefault(a => a.IsVisible); - if (selectedShortcut != null) { - path.Add(selectedShortcut); - FindFirstVisibleItemPath(selectedShortcut, path); - return; - } - } - } - - /// - /// Expand all elements of the tree - /// - public void ExpandAll() - { - shortcutsTreeView.SetExpandAll(true); - } - - /// - /// Raised when user starts to type inside shortcuts tree - /// - /// Sender object - /// Event arguments - private void shortcutsTreeView_PreviewKeyDown(object sender, KeyEventArgs e) - { - // If not navigating tree set focus to search text box - var keyboardDevice = (KeyboardDevice)e.Device; - if (keyboardDevice.Modifiers != ModifierKeys.None || Array.IndexOf(new[] { Key.Up, Key.Right, Key.Down, Key.Left }, e.Key) < 0) { - searchTextBox.Text = ""; - Keyboard.Focus(searchTextBox); - return; - } - } - - /// - /// Raised when user tries to remove a shortcut from shortcut tree - /// - /// Sender object - /// Event arguments - private void removeShortcutButton_Click(object sender, RoutedEventArgs e) - { - if(RemoveShortcutClick != null) { - var removeButton = (Button) sender; - var routedRemoveShortcutEventArgs = new RoutedRemoveShortcutEventArgs(e.RoutedEvent, e.OriginalSource, (Shortcut)removeButton.Tag); - - // Forward event - RemoveShortcutClick.Invoke(sender, routedRemoveShortcutEventArgs); - } - } - - - /// - /// Raised when user changes text in search textbox - /// - /// Object sender - /// Event arguments - private void searchTextBox_TextChanged(object sender, TextChangedEventArgs e) - { - if (!searchTypeToggleButton.IsChecked.HasValue || searchTypeToggleButton.IsChecked.Value) return; - - new ShortcutsFinder(RootEntries).Filter(searchTextBox.Text); - - if (!string.IsNullOrEmpty(searchTextBox.Text)) { - SelectFirstVisibleShortcut(false); - } else { - shortcutsTreeView.SetExpandAll(false); - } - } - - /// - /// Raised when changing search type - /// - /// Sender object - /// Event arguments - private void searchTypeToggleButton_Click(object sender, RoutedEventArgs e) - { - searchTextBox.Text = ""; - gestureTextBox.shortcutTextBox.Text = ""; - - new ShortcutsFinder(RootEntries).Filter(""); - shortcutsTreeView.SetExpandAll(false); - - if(!searchTypeToggleButton.IsChecked.HasValue || !searchTypeToggleButton.IsChecked.Value) { - Keyboard.Focus(searchTextBox); - } else { - Keyboard.Focus(gestureTextBox.shortcutTextBox); - } - } - - public event EventHandler ShortcutModified; - - - /// - /// Raised when user presses a key inside search box - /// - /// Sender object - /// Event arguments - private void searchTextBox_PreviewKeyDown(object sender, KeyEventArgs e) - { - var keyboardDevice = (KeyboardDevice)e.Device; - - // If Up/Down is pressed switch focus to shortcuts tree - if (keyboardDevice.Modifiers == ModifierKeys.None && Array.IndexOf(new[] { Key.Up, Key.Down }, e.Key) >= 0) { - SelectFirstVisibleShortcut(true); - return; - } - - // If enter is pressed open shortcut configuration - if (keyboardDevice.Modifiers == ModifierKeys.None && e.Key == Key.Enter && shortcutsTreeView.SelectedItem is Shortcut) { - e.Handled = true; - if(ShortcutModified != null) - { - ShortcutModified.Invoke(sender, null); - } - return; - } - } - - /// - /// Raised if gestures entered in gesture text box change - /// - /// Senrer object - /// Event arguments - private void gestureTextBox_GestureChanged(object sender, EventArgs e) - { - // Exit if filtering by text (Handled in searchTextBox_TextChanged) - if (searchTypeToggleButton.IsChecked.HasValue && !searchTypeToggleButton.IsChecked.Value) { - return; - } - - if (gestureTextBox.Gesture != null) { - new ShortcutsFinder(RootEntries).FilterGesture(gestureTextBox.Gesture, GestureCompareMode.PartlyMatches); - SelectFirstVisibleShortcut(false); - } else { - new ShortcutsFinder(RootEntries).Filter(""); - } - } - - /// - /// Raised when user double click on shortcut tree item - /// - /// Sender object - /// Event arguments - private void shortcutEntry_MouseDown(object sender, MouseButtonEventArgs e) - { - if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { - if (shortcutsTreeView.SelectedItem is Shortcut) { - if(ShortcutModified != null) - { - ShortcutModified.Invoke(sender, null); - } - } - } - } - } - - public delegate void RemoveShortcutRoutedHandler(object sender, RoutedRemoveShortcutEventArgs args); - - /// - /// Contains state information and event data associated with - /// - public class RoutedRemoveShortcutEventArgs : RoutedEventArgs - { - /// - /// Reference to shortcut being removed - /// - public Shortcut RemovedShortcut - { - get; - private set; - } - - /// - /// Constructor - /// - /// The routed event identifier for this instance of RoutedRemoveShortcutEventArgs - /// Source which will be reported when event is handled - /// Shortcut being removed - public RoutedRemoveShortcutEventArgs(RoutedEvent routedEvent, object source, Shortcut removedShortcut) - : base(routedEvent, source) - { - RemovedShortcut = removedShortcut; - } - } + /// + /// This panel is used in SharpDevelop options window to manage shortcuts + /// + public partial class ShortcutsTreeView : UserControl + { + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty IsSearchableProperty = DependencyProperty.Register( + "IsSearchable", + typeof(Boolean), + typeof(ShortcutsTreeView), + new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Gets or sets property specifying whether shortcuts tree can be searched using part of the shortcut's name or + /// gesture + /// + public Boolean IsSearchable + { + get { + return (Boolean)GetValue(IsSearchableProperty); + } + set { + SetValue(IsSearchableProperty, value); + } + } + + /// + /// Identifies dependency property + /// + public static readonly DependencyProperty IsRemovableShortcutsEnabledProperty = DependencyProperty.Register( + "IsRemovableShortcutsEnabled", + typeof(Boolean), + typeof(ShortcutsTreeView), + new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); + + /// + /// Specify whether shortcuts can be removed from the tree. + /// + /// If this value set to true will be Executed when + /// shortcut is deleted + /// + public Boolean IsRemovableShortcutsEnabled + { + get { + return (Boolean)GetValue(IsSearchableProperty); + } + set { + SetValue(IsSearchableProperty, value); + } + } + + /// + /// Occurs when user tries to remove shortcut from shortcuts tree + /// + public event RemoveShortcutRoutedHandler RemoveShortcutClick; + + /// + /// List of add-ins containing shortcut categories and shortcuts + /// + private ICollection RootEntries + { + get { + return (ICollection)DataContext; + } + } + + /// + /// Creates new instance of + /// + public ShortcutsTreeView() + { + InitializeComponent(); + } + + /// + /// Selects first enabled shortcut in shortcut tree + /// + /// Set focus to this shortcut entry + public void SelectFirstVisibleShortcut(bool setFocus) + { + var path = new List(); + foreach (var entry in RootEntries) { + if (entry != null && entry.IsVisible) { + path.Add(entry); + FindFirstVisibleItemPath(entry, path); + shortcutsTreeView.SelectItem(path.Cast().ToList(), setFocus); + + return; + } + } + } + + /// + /// Find path to first with true + /// + /// Starting node + /// Accumulated path + private void FindFirstVisibleItemPath(IShortcutTreeEntry parent, List path) + { + // Find first visible add-in + var addIn = parent as AddIn; + if(addIn != null) { + var selectedCategory = addIn.Categories.FirstOrDefault(a => a.IsVisible); + if (selectedCategory != null) { + path.Add(selectedCategory); + FindFirstVisibleItemPath(selectedCategory, path); + return; + } + } + + // Find first visible category + var category = parent as ShortcutCategory; + if (category != null) { + var selectedCategory = category.SubCategories.FirstOrDefault(a => a.IsVisible); + if (selectedCategory != null) { + path.Add(selectedCategory); + FindFirstVisibleItemPath(selectedCategory, path); + return; + } + + // Find first visible shortcut + var selectedShortcut = category.Shortcuts.FirstOrDefault(a => a.IsVisible); + if (selectedShortcut != null) { + path.Add(selectedShortcut); + FindFirstVisibleItemPath(selectedShortcut, path); + return; + } + } + } + + /// + /// Expands all elements of the tree + /// + public void ExpandAll() + { + shortcutsTreeView.SetExpandAll(true); + } + + /// + /// Executed when user starts to type inside shortcuts tree + /// + /// Sender object + /// Event arguments + private void shortcutsTreeView_PreviewKeyDown(object sender, KeyEventArgs e) + { + // If not navigating tree set focus to search text box + var keyboardDevice = (KeyboardDevice)e.Device; + if (keyboardDevice.Modifiers != ModifierKeys.None || Array.IndexOf(new[] { Key.Up, Key.Right, Key.Down, Key.Left }, e.Key) < 0) { + searchTextBox.Text = ""; + Keyboard.Focus(searchTextBox); + return; + } + } + + /// + /// Executed when user tries to remove a shortcut from shortcut tree + /// + /// Sender object + /// Event arguments + private void removeShortcutButton_Click(object sender, RoutedEventArgs e) + { + if(RemoveShortcutClick != null) { + var removeButton = (Button) sender; + var routedRemoveShortcutEventArgs = new RoutedRemoveShortcutEventArgs(e.RoutedEvent, e.OriginalSource, (Shortcut)removeButton.Tag); + + // Forward event + RemoveShortcutClick.Invoke(sender, routedRemoveShortcutEventArgs); + } + } + + + /// + /// Executed when user changes text in search textbox + /// + /// Object sender + /// Event arguments + private void searchTextBox_TextChanged(object sender, TextChangedEventArgs e) + { + if (!searchTypeToggleButton.IsChecked.HasValue || searchTypeToggleButton.IsChecked.Value) return; + + new ShortcutsFinder(RootEntries).Filter(searchTextBox.Text); + + if (!string.IsNullOrEmpty(searchTextBox.Text)) { + SelectFirstVisibleShortcut(false); + } else { + shortcutsTreeView.SetExpandAll(false); + } + } + + /// + /// Executed when changing search type + /// + /// Sender object + /// Event arguments + private void searchTypeToggleButton_Click(object sender, RoutedEventArgs e) + { + searchTextBox.Text = ""; + gestureTextBox.shortcutTextBox.Text = ""; + + new ShortcutsFinder(RootEntries).Filter(""); + shortcutsTreeView.SetExpandAll(false); + + if(!searchTypeToggleButton.IsChecked.HasValue || !searchTypeToggleButton.IsChecked.Value) { + Keyboard.Focus(searchTextBox); + } else { + Keyboard.Focus(gestureTextBox.shortcutTextBox); + } + } + + /// + /// Occurs when shortcut is modified + /// + public event EventHandler ShortcutModified; + + /// + /// Executed when user presses a key inside search box + /// + /// Sender object + /// Event arguments + private void searchTextBox_PreviewKeyDown(object sender, KeyEventArgs e) + { + var keyboardDevice = (KeyboardDevice)e.Device; + + // If Up/Down is pressed switch focus to shortcuts tree + if (keyboardDevice.Modifiers == ModifierKeys.None && Array.IndexOf(new[] { Key.Up, Key.Down }, e.Key) >= 0) { + SelectFirstVisibleShortcut(true); + return; + } + + // If enter is pressed open shortcut configuration + if (keyboardDevice.Modifiers == ModifierKeys.None && e.Key == Key.Enter && shortcutsTreeView.SelectedItem is Shortcut) { + e.Handled = true; + if(ShortcutModified != null) { + ShortcutModified.Invoke(sender, null); + } + + return; + } + } + + /// + /// Raised if gestures entered in gesture text box change + /// + /// Senrer object + /// Event arguments + private void gestureTextBox_GestureChanged(object sender, EventArgs e) + { + // Exit if filtering by text (Handled in searchTextBox_TextChanged) + if (searchTypeToggleButton.IsChecked.HasValue && !searchTypeToggleButton.IsChecked.Value) { + return; + } + + if (gestureTextBox.Gesture != null) { + new ShortcutsFinder(RootEntries).FilterGesture(gestureTextBox.Gesture, GestureCompareMode.PartlyMatches); + SelectFirstVisibleShortcut(false); + } else { + new ShortcutsFinder(RootEntries).Filter(""); + } + } + + /// + /// Executed when user double click on shortcut tree item + /// + /// Sender object + /// Event arguments + private void shortcutEntry_MouseDown(object sender, MouseButtonEventArgs e) + { + if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { + if (shortcutsTreeView.SelectedItem is Shortcut) { + if(ShortcutModified != null) { + ShortcutModified.Invoke(sender, null); + } + } + } + } + } + + public delegate void RemoveShortcutRoutedHandler(object sender, RoutedRemoveShortcutEventArgs args); + + /// + /// Contains state information and event data associated with + /// + public class RoutedRemoveShortcutEventArgs : RoutedEventArgs + { + /// + /// Reference to shortcut being removed + /// + public Shortcut RemovedShortcut + { + get; + private set; + } + + /// + /// Creates new isntance of + /// + /// Associated routed event + /// Source which will be reported when event is handled + /// Shortcut being removed + public RoutedRemoveShortcutEventArgs(RoutedEvent routedEvent, object source, Shortcut removedShortcut) + : base(routedEvent, source) + { + RemovedShortcut = removedShortcut; + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TextBlockBehavior.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TextBlockBehavior.cs index 0224f5f7504..59285d9fd92 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TextBlockBehavior.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TextBlockBehavior.cs @@ -6,85 +6,85 @@ namespace ICSharpCode.ShortcutsManagement.Extensions { - /// - /// Contains attached properties - /// - public static class TextBlockBehavior - { - /// - /// Get "TextBlockBehavior.SearchedText" attached property value - /// - /// Attached property host - /// Attached property value - public static string GetSearchedText(TextBlock textBlock) - { - return (string)textBlock.GetValue(SearchedTextProperty); - } - - /// - /// Set "TextBlockBehavior.SearchedText" attached property value - /// - /// Attached property host - /// New attached property value - public static void SetSearchedText(TextBlock textBlock, string value) - { - textBlock.SetValue(SearchedTextProperty, value); - } - - /// - /// Identifies SearchedText dependency property - /// - public static readonly DependencyProperty SearchedTextProperty = - DependencyProperty.RegisterAttached( - "SearchedText", - typeof(string), - typeof(TextBlockBehavior), - new UIPropertyMetadata(null, OnSearchedTextChanged)); - - /// - /// On SearchedText changed highlight text in TextBlock which matches - /// attached property value - /// - /// - /// - private static void OnSearchedTextChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e) - { - var textBlock = (TextBlock) depObj; - var textBlockText = textBlock.Text; - - // Remove all text from text block - textBlock.Inlines.Clear(); - - // Split text contained in text block to three parts: before the match, the match and after the match - var matches = Regex.Matches(textBlockText, @"(.*)(" + Regex.Escape((string)e.NewValue) + @")(.*)", RegexOptions.IgnoreCase); - if (matches.Count > 0) { - foreach (Match match in matches) { - // Add what is found before match back to the block without modifications - var matchedTextPrefix = match.Groups[1].Value; - if (!string.IsNullOrEmpty(matchedTextPrefix)) { - textBlock.Inlines.Add(new Run(matchedTextPrefix)); - } - - // Higlight the match and add back to textblock - var matchedText = match.Groups[2].Value; - if (!string.IsNullOrEmpty(matchedText)) { - var matchedRun = new Run(matchedText); - - matchedRun.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CEDEF7")); - matchedRun.Foreground = new SolidColorBrush((Color) ColorConverter.ConvertFromString("#000000")); - textBlock.Inlines.Add(matchedRun); - } - - // Add what is found after match back to the block without modifications - var matchedTextSuffix = match.Groups[3].Value; - if (!string.IsNullOrEmpty(matchedTextSuffix)) { - textBlock.Inlines.Add(new Run(matchedTextSuffix)); - } - } - } else { - // If filter string is not found put the original text back without modifications - textBlock.Inlines.Add(new Run(textBlockText)); - } - } - } + /// + /// Contains attached properties + /// + public static class TextBlockBehavior + { + /// + /// Gets "TextBlockBehavior.SearchedText" attached property value + /// + /// Attached property host + /// Attached property value + public static string GetSearchedText(TextBlock textBlock) + { + return (string)textBlock.GetValue(SearchedTextProperty); + } + + /// + /// Set "TextBlockBehavior.SearchedText" attached property value + /// + /// Attached property host + /// New attached property value + public static void SetSearchedText(TextBlock textBlock, string value) + { + textBlock.SetValue(SearchedTextProperty, value); + } + + /// + /// Identifies SearchedText dependency property + /// + public static readonly DependencyProperty SearchedTextProperty = + DependencyProperty.RegisterAttached( + "SearchedText", + typeof(string), + typeof(TextBlockBehavior), + new UIPropertyMetadata(null, OnSearchedTextChanged)); + + /// + /// On SearchedText changed highlight text in TextBlock which matches + /// attached property value + /// + /// + /// + private static void OnSearchedTextChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e) + { + var textBlock = (TextBlock) depObj; + var textBlockText = textBlock.Text; + + // Remove all text from text block + textBlock.Inlines.Clear(); + + // Split text contained in text block to three parts: before the match, the match and after the match + var matches = Regex.Matches(textBlockText, @"(.*)(" + Regex.Escape((string)e.NewValue) + @")(.*)", RegexOptions.IgnoreCase); + if (matches.Count > 0) { + foreach (Match match in matches) { + // Add what is found before match back to the block without modifications + var matchedTextPrefix = match.Groups[1].Value; + if (!string.IsNullOrEmpty(matchedTextPrefix)) { + textBlock.Inlines.Add(new Run(matchedTextPrefix)); + } + + // Higlight the match and add back to textblock + var matchedText = match.Groups[2].Value; + if (!string.IsNullOrEmpty(matchedText)) { + var matchedRun = new Run(matchedText); + + matchedRun.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CEDEF7")); + matchedRun.Foreground = new SolidColorBrush((Color) ColorConverter.ConvertFromString("#000000")); + textBlock.Inlines.Add(matchedRun); + } + + // Add what is found after match back to the block without modifications + var matchedTextSuffix = match.Groups[3].Value; + if (!string.IsNullOrEmpty(matchedTextSuffix)) { + textBlock.Inlines.Add(new Run(matchedTextSuffix)); + } + } + } else { + // If filter string is not found put the original text back without modifications + textBlock.Inlines.Add(new Run(textBlockText)); + } + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TreeViewExtensions.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TreeViewExtensions.cs index bad9e1503ca..9a73df2e3b5 100644 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TreeViewExtensions.cs +++ b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Extensions/TreeViewExtensions.cs @@ -11,74 +11,71 @@ namespace ICSharpCode.ShortcutsManagement.Extensions /// /// extention methods /// - public static class TreeViewExtensions - { - /// - /// Expand TreeView items according to provided path and select element - /// on the lowest level - /// - /// TreeView instance - /// Path to the selected item - /// - public static void SelectItem(this ItemsControl parentContainer, List path, bool setFocus) - { - if(path == null || path.Count == 0) - { - return; - } - - var head = path.First(); - var tail = path.GetRange(1, path.Count - 1); - - // Get TreeViewItem which wraps first element from path - var itemContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(head) as TreeViewItem; - - if (itemContainer != null && itemContainer.Items.Count == 0) { - // If item container doesn't have any sub-elements select it - itemContainer.IsSelected = true; - - if(setFocus) { - Keyboard.Focus(itemContainer); - } - - var selectMethod = typeof(TreeViewItem).GetMethod("Select", BindingFlags.NonPublic | BindingFlags.Instance); - selectMethod.Invoke(itemContainer, new object[] { true }); - } else if (itemContainer != null) { - // If item container have sub-elements expand it and select item from this container - itemContainer.IsExpanded = true; - - if (itemContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) { - // If item container is not generated yet register a delegate which would be called when container is generated - itemContainer.ItemContainerGenerator.StatusChanged += delegate { - SelectItem(itemContainer, tail, setFocus); - }; - } else { - // If item container already generated select sub-element from this container - SelectItem(itemContainer, tail, setFocus); - } - } - } - - /// - /// Expand/Collapse all tree view items - /// - /// TreeView or TreeViewItem - /// True - expand, False - collapse - public static void SetExpandAll(this ItemsControl parentContainer, bool value) - { - foreach (Object item in parentContainer.Items) { - var currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem; - if (currentContainer != null && currentContainer.Items.Count > 0) { - currentContainer.IsExpanded = value; - if (currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) { - currentContainer.ItemContainerGenerator.StatusChanged += delegate { - SetExpandAll(currentContainer, value); - }; - } else { - SetExpandAll(currentContainer, value); - } - } - } - } - } + public static class TreeViewExtensions + { + /// + /// Expand TreeView items according to provided path and select element + /// on the lowest level + /// + /// TreeView instance + /// Path to the selected item + /// + public static void SelectItem(this ItemsControl parentContainer, List path, bool setFocus) + { + if(path == null || path.Count == 0) { + return; + } + + var head = path.First(); + var tail = path.GetRange(1, path.Count - 1); + + // Get TreeViewItem which wraps first element from path + var itemContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(head) as TreeViewItem; + + if (itemContainer != null && itemContainer.Items.Count == 0) { + // If item container doesn't have any sub-elements select it + itemContainer.IsSelected = true; + + if(setFocus) { + Keyboard.Focus(itemContainer); + } + + var selectMethod = typeof(TreeViewItem).GetMethod("Select", BindingFlags.NonPublic | BindingFlags.Instance); + selectMethod.Invoke(itemContainer, new object[] { true }); + } else if (itemContainer != null) { + // If item container have sub-elements expand it and select item from this container + itemContainer.IsExpanded = true; + + if (itemContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) { + // If item container is not generated yet register a delegate which would be called when container is generated + itemContainer.ItemContainerGenerator.StatusChanged += delegate { + SelectItem(itemContainer, tail, setFocus); + }; + } else { + // If item container already generated select sub-element from this container + SelectItem(itemContainer, tail, setFocus); + } + } + } + + /// + /// Expand/Collapse all tree view items + /// + /// TreeView or TreeViewItem + /// True - expand, False - collapse + public static void SetExpandAll(this ItemsControl parentContainer, bool value) + { + foreach (Object item in parentContainer.Items) { + var currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem; + if (currentContainer != null && currentContainer.Items.Count > 0) { + currentContainer.IsExpanded = value; + if (currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) { + currentContainer.ItemContainerGenerator.StatusChanged += delegate { SetExpandAll(currentContainer, value); }; + } else { + SetExpandAll(currentContainer, value); + } + } + } + } + } } diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Window1.xaml b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Window1.xaml deleted file mode 100644 index 6171d69a7b5..00000000000 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Window1.xaml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Window1.xaml.cs b/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Window1.xaml.cs deleted file mode 100644 index abd791b913c..00000000000 --- a/src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Window1.xaml.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.ObjectModel; -using System.Windows; -using System.Windows.Input; -using ICSharpCode.Core.Presentation; -using ICSharpCode.ShortcutsManagement.Data; -using AddInSection = ICSharpCode.ShortcutsManagement.Data.AddIn; - -namespace ICSharpCode.ShortcutsManagement -{ - /// - /// Interaction logic for Window1.xaml - /// - public partial class Window1 : Window - { - public Window1() - { - InitializeComponent(); - - // Test data - var rootEntries = new ObservableCollection(); - - var addin1 = new AddInSection("SharpDevelop"); - rootEntries.Add(addin1); - addin1.Categories.Add(new ShortcutCategory("Editing")); - addin1.Categories[0].Shortcuts.Add(new Shortcut("MultiKey", GetGestures("Ctrl+N, Ctrl+F"))); - addin1.Categories[0].Shortcuts.Add(new Shortcut("Copy", GetGestures(""))); - addin1.Categories[0].Shortcuts.Add(new Shortcut("Paste", GetGestures("Ctrl + N, Ctrl+S"))); - - //addin1.Categories[0].Shortcuts.Add(new Shortcut("Cut", GetGestures("Ctrl + X"))); - //addin1.Categories[0].Shortcuts.Add(new Shortcut("Undo", GetGestures("Ctrl + Z"))); - //addin1.Categories[0].Shortcuts.Add(new Shortcut("Redo", GetGestures("Ctrl + Y"))); - //addin1.Categories.Add(new ShortcutCategory("Building")); - //addin1.Categories[1].Shortcuts.Add(new Shortcut("Build", GetGestures("Ctrl + Shift+B"))); - //addin1.Categories[1].Shortcuts.Add(new Shortcut("Run", GetGestures("F5"))); - //addin1.Categories[1].Shortcuts.Add(new Shortcut("Run without debuger", GetGestures("Ctrl + F5"))); - //addin1.Categories[1].Shortcuts.Add(new Shortcut("Attach debuger", GetGestures("Ctrl + F8"))); - //addin1.Categories.Add(new ShortcutCategory("Uncategorized")); - //addin1.Categories[2].Shortcuts.Add(new Shortcut("Attach debuger", GetGestures("Ctrl + F8"))); - - //var addin2 = new AddInSection("Search & replace"); - //rootEntries.Add(addin2); - //addin2.Categories.Add(new ShortcutCategory("Uncategorized")); - //addin2.Categories[0].Shortcuts.Add(new Shortcut("Quick find", GetGestures("Ctrl + F"))); - //addin2.Categories[0].Shortcuts.Add(new Shortcut("Quick replace", GetGestures("Ctrl + H"))); - //addin2.Categories[0].SubCategories.Add(new ShortcutCategory("Subcategory 3")); - //addin2.Categories[0].SubCategories[0].SubCategories.Add(new ShortcutCategory("Subcategory 4")); - //addin2.Categories[0].SubCategories[0].SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut N", GetGestures("Ctrl + N"))); - //addin2.Categories[0].SubCategories[0].SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut O", GetGestures("Ctrl + O"))); - //addin2.Categories[0].SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut L", GetGestures("Ctrl + L"))); - //addin2.Categories[0].SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut M", GetGestures("Ctrl + M"))); - //addin2.Categories[0].Shortcuts.Add(new Shortcut("Find in files", GetGestures("Ctrl + Shift + F | Ctrl + Shift + H | Ctrl + I"))); - //addin2.Categories[0].Shortcuts.Add(new Shortcut("Replace in files", GetGestures("Ctrl + Shift + H"))); - //addin2.Categories[0].Shortcuts.Add(new Shortcut("Find symbol", null)); - - //var addin3 = new AddInSection("Unspecified"); - //rootEntries.Add(addin3); - //addin3.Categories.Add(new ShortcutCategory("Uncategorized")); - //addin3.Categories[0].Shortcuts.Add(new Shortcut("Test regex expression", null)); - - //var rootCategory = new ShortcutCategory("Without addin"); - //rootEntries.Add(rootCategory); - //rootCategory.SubCategories.Add(new ShortcutCategory("Subcategory 1")); - //rootCategory.SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut H", GetGestures("Ctrl + H"))); - //rootCategory.SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut I", GetGestures("Ctrl + I"))); - //rootCategory.SubCategories.Add(new ShortcutCategory("Subcategory 2")); - //rootCategory.SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut J", GetGestures("Ctrl + J"))); - //rootCategory.SubCategories[0].Shortcuts.Add(new Shortcut("Shortcut K", GetGestures("Ctrl + K"))); - //rootCategory.Shortcuts.Add(new Shortcut("Shortcut A", GetGestures("Ctrl + A"))); - //rootCategory.Shortcuts.Add(new Shortcut("Shortcut B", GetGestures("Ctrl + B"))); - //rootCategory.Shortcuts.Add(new Shortcut("Shortcut C", GetGestures("Ctrl + C"))); - //rootCategory.Shortcuts.Add(new Shortcut("Shortcut D", GetGestures("Ctrl + D"))); - //rootCategory.Shortcuts.Add(new Shortcut("Shortcut E", null)); - - //rootEntries.Add(new Shortcut("Shortcut F", GetGestures("Ctrl + F"))); - //rootEntries.Add(new Shortcut("Shortcut G", GetGestures("Ctrl + G"))); - - optionsPanel.DataContext = rootEntries; - } - - private static InputGestureCollection GetGestures(string gesturesString) - { - var converter = new InputGestureCollectionConverter(); - return (InputGestureCollection)converter.ConvertFromInvariantString(gesturesString); - } - } -} diff --git a/src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs b/src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs index ca339130b42..b4e50b323b5 100644 --- a/src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs +++ b/src/Main/ICSharpCode.Core.Presentation/CommandsService/CommandManager.cs @@ -403,6 +403,11 @@ public static void RegisterInputBindingInfo(InputBindingInfo inputBindingInfo) throw new ArgumentException("Routed command name must be specified"); } + if(inputBindingInfo.RoutedCommandName == "SDBuildCommands.BuildSolution") + { + + } + var similarTemplate = BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo); var similarInputBinding = FindInputBindingInfos(similarTemplate, null).FirstOrDefault();