Browse Source

Reset single shortcut gestures to default value

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4644 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts^2
Sergej Andrejev 16 years ago
parent
commit
689386287d
  1. 3
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Resources/StringResources.resx
  2. 3
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj
  3. 12
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntryCloner.cs
  4. 84
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs
  5. 192
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml
  6. 5
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml.cs
  7. 9
      src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutsManagementOptionsPanel.xaml.cs
  8. 6
      src/Main/ICSharpCode.Core.Presentation/CommandsService/Profile/UserGestureProfile.cs
  9. 25
      src/Main/ICSharpCode.Core.Presentation/Input/InputGestureCollectionExtensions.cs

3
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Resources/StringResources.resx

@ -203,6 +203,9 @@ @@ -203,6 +203,9 @@
<data name="ShortcutsManagement.ShortcutsManagementOptionsPanel.ProfileResetAction" xml:space="preserve">
<value>Reset to defaults</value>
</data>
<data name="ShortcutsManagement.ShortcutManagementWindow.ResetToDefaults" xml:space="preserve">
<value>Reset</value>
</data>
<data name="ShortcutsManagement.ShortcutsManagementOptionsPanel.ProfilesLabel" xml:space="preserve">
<value>Profiles:</value>
</data>

3
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/ShortcutsManagement.csproj

@ -55,6 +55,9 @@ @@ -55,6 +55,9 @@
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase">

12
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/IShortcutTreeEntryCloner.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Windows.Input;
namespace ICSharpCode.ShortcutsManagement.Data
{
@ -86,12 +87,11 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -86,12 +87,11 @@ namespace ICSharpCode.ShortcutsManagement.Data
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);
}
var clonedShortcut = new Shortcut(
shortcut.Id,
shortcut.Name,
new InputGestureCollection(shortcut.Gestures),
new InputGestureCollection(shortcut.DefaultGestures));
clonedShortcuts.Add(clonedShortcut.Id, clonedShortcut);

84
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Data/Shortcut.cs

@ -1,8 +1,11 @@ @@ -1,8 +1,11 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Input;
using ICSharpCode.Core.Presentation;
using System.Linq;
using System.Collections.Specialized;
namespace ICSharpCode.ShortcutsManagement.Data
{
@ -20,6 +23,27 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -20,6 +23,27 @@ namespace ICSharpCode.ShortcutsManagement.Data
private set;
}
/// <summary>
/// Gets collection of default input suggested assigned by developer
/// </summary>
public ReadOnlyCollection<InputGesture> DefaultGestures
{
get;
private set;
}
private bool _doesUseDefault;
/// <summary>
/// Gets or sets value which specifies whether default gestures should be used or those assigned by user
/// </summary>
public bool DoesUseDefault
{
get {
return _doesUseDefault;
}
}
private string _name;
/// <summary>
@ -82,16 +106,38 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -82,16 +106,38 @@ namespace ICSharpCode.ShortcutsManagement.Data
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Create new instance of shortcut
/// Create new instance of <see cref="Shortcut" />
/// </summary>
/// <param name="id">Shortcut id. Used to identify shortcut clones</param>
/// <param name="gestures">Active gestures</param>
/// <param name="defaultGestures">Default gestures suggest by developer</param>
public Shortcut(string shortcutText, InputGestureCollection gestures, InputGestureCollection defaultGestures)
: this(Guid.NewGuid().ToString(), shortcutText, gestures, defaultGestures)
{
}
/// <summary>
/// Create new instance of <see cref="Shortcut" />
/// </summary>
/// <param name="id">Shortcut id. Used to identify shortcut clones</param>
/// <param name="shortcutText">Shortcut action name (displayed to user)</param>
/// <param name="gestures">Gestures</param>
public Shortcut(string shortcutText, InputGestureCollection gestures)
/// <param name="gestures">Active gestures</param>
/// <param name="defaultGestures">Default gestures suggest by developer</param>
public Shortcut(string id, string shortcutText, InputGestureCollection gestures, InputGestureCollection defaultGestures)
{
IsVisible = true;
Id = Guid.NewGuid().ToString();
Id = id;
Name = shortcutText;
if(defaultGestures != null) {
var defaultGesturesArray = new InputGesture[defaultGestures.Count];
defaultGestures.CopyTo(defaultGesturesArray, 0);
DefaultGestures = new ReadOnlyCollection<InputGesture>(defaultGesturesArray);
} else {
DefaultGestures = new ReadOnlyCollection<InputGesture>(new List<InputGesture>());
}
Gestures = new ObservableCollection<InputGesture>();
if(gestures != null) {
foreach (InputGesture gesture in gestures) {
@ -99,8 +145,19 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -99,8 +145,19 @@ namespace ICSharpCode.ShortcutsManagement.Data
}
}
// On changes in gestures collection notify that whole property has changed
Gestures.CollectionChanged += delegate { InvokePropertyChanged("Gestures"); };
_doesUseDefault = new InputGestureCollection(Gestures).ContainsTemplateForAny(new InputGestureCollection(DefaultGestures), GestureCompareMode.ExactlyMatches);
Gestures.CollectionChanged += Gestures_CollectionChanged;
}
void Gestures_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
var newDoesUseDefaultValue = new InputGestureCollection(Gestures).ContainsTemplateForAny(new InputGestureCollection(DefaultGestures), GestureCompareMode.ExactlyMatches);
if(_doesUseDefault != newDoesUseDefaultValue) {
_doesUseDefault = newDoesUseDefaultValue;
InvokePropertyChanged("DoesUseDefault");
}
InvokePropertyChanged("Gestures");
}
/// <summary>
@ -161,5 +218,18 @@ namespace ICSharpCode.ShortcutsManagement.Data @@ -161,5 +218,18 @@ namespace ICSharpCode.ShortcutsManagement.Data
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// Resets active gestures assigned to this shortcut to default <see cref="InputGestureCollection" /> suggested by developer
/// </summary>
public void ResetToDefaults()
{
_doesUseDefault = true;
Gestures.Clear();
foreach(var gesture in DefaultGestures) {
Gestures.Add(gesture);
}
}
}
}

192
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml

@ -1,94 +1,104 @@ @@ -1,94 +1,104 @@
<Window x:Class="ICSharpCode.ShortcutsManagement.Dialogs.ShortcutManagementWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:Dialogs="clr-namespace:ICSharpCode.ShortcutsManagement.Dialogs"
Title="{Binding Text}"
MinHeight="400"
MinWidth="400"
x:Name="_this">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:Dialogs="clr-namespace:ICSharpCode.ShortcutsManagement.Dialogs"
Title="{Binding Text}"
MinHeight="400"
MinWidth="400"
x:Name="_this">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml" />
<ResourceDictionary>
<Style x:Key="ValidationTextBox" TargetType="TextBlock"></Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
<RowDefinition Height="2" />
<RowDefinition />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<!-- Field for entering a gesture -->
<Label x:Name="shortcutLabel" Grid.Column="0" Grid.Row="0" Target="{Binding ElementName=gestureTextBox}" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="{core:Localize ShortcutsManagement.EnterGestureLabel}" />
</Label>
<Grid Grid.Column="2" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Dialogs:MultiKeyGestureTextBox x:Name="gestureTextBox" Grid.Column="0" Margin="3" TextBoxBorderThickness="1" />
<Button x:Name="addGestureButton" Grid.Column="1" Style="{StaticResource AddButton}" Height="25" VerticalAlignment="Top" Margin="3" Click="addGestureButton_Click" />
</Grid>
<!-- List of gestures assigned to modified shortcut -->
<Label x:Name="otherShortcutsLabel" Grid.Column="0" Grid.Row="1" Target="{Binding ElementName=otherShortcutsListBox}" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="{core:Localize ShortcutsManagement.ShortcutGesturesLabel}" />
</Label>
<ListBox x:Name="otherShortcutsListBox" Grid.Column="1" Grid.Row="1" ItemContainerStyle="{StaticResource GesturesListBox}" ItemsSource="{Binding Path=Gestures}" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type InputGesture}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Converter={StaticResource InputGestureConverter}}" Grid.Column="0" />
<Button x:Name="removeGestureButton" Style="{StaticResource RemoveButton}" Grid.Column="1" Visibility="Hidden" Click="removeGestureButton_Click" Tag="{Binding}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter Property="Visibility" TargetName="removeGestureButton" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<GridSplitter Grid.Row="2" Grid.Column="2" ResizeDirection="Rows"
Width="Auto"
Height="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="White"
Margin="0"/>
<!-- List of shortcuts which have same gestures assigned to them -->
<Label x:Name="otherCommandsLabel" Grid.Row="3" Grid.Column="0" Target="{Binding ElementName=shortcutsManagementOptionsPanel}" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="{core:Localize ShortcutsManagement.SimilarShortcutsLabel}" />
</Label>
<Dialogs:ShortcutsTreeView Grid.Row="3" Grid.Column="1" x:Name="shortcutsManagementOptionsPanel" IsSearchable="False" Padding="3" RemoveShortcutClick="shortcutsManagementOptionsPanel_RemoveShortcutClick" IsRemovableShortcutsEnabled="True" />
<!-- Defaults/Ok/Cancel buttons -->
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml" />
<ResourceDictionary>
<Style x:Key="ValidationTextBox" TargetType="TextBlock"></Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
<RowDefinition Height="2" />
<RowDefinition />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<!-- Field for entering a gesture -->
<Label x:Name="shortcutLabel" Grid.Column="0" Grid.Row="0" Target="{Binding ElementName=gestureTextBox}" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="{core:Localize ShortcutsManagement.EnterGestureLabel}" />
</Label>
<Grid Grid.Column="2" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Dialogs:MultiKeyGestureTextBox x:Name="gestureTextBox" Grid.Column="0" Margin="3" TextBoxBorderThickness="1" />
<Button x:Name="addGestureButton" Grid.Column="1" Style="{StaticResource AddButton}" Height="25" VerticalAlignment="Top" Margin="3" Click="addGestureButton_Click" />
</Grid>
<!-- List of gestures assigned to modified shortcut -->
<Label x:Name="otherShortcutsLabel" Grid.Column="0" Grid.Row="1" Target="{Binding ElementName=otherShortcutsListBox}" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="{core:Localize ShortcutsManagement.ShortcutGesturesLabel}" />
</Label>
<ListBox x:Name="otherShortcutsListBox" Grid.Column="1" Grid.Row="1" ItemContainerStyle="{StaticResource GesturesListBox}" ItemsSource="{Binding Path=Gestures}" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type InputGesture}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Converter={StaticResource InputGestureConverter}}" Grid.Column="0" />
<Button x:Name="removeGestureButton" Style="{StaticResource RemoveButton}" Grid.Column="1" Visibility="Hidden" Click="removeGestureButton_Click" Tag="{Binding}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter Property="Visibility" TargetName="removeGestureButton" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<GridSplitter Grid.Row="2" Grid.Column="2" ResizeDirection="Rows"
Width="Auto"
Height="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="White"
Margin="0"/>
<!-- List of shortcuts which have same gestures assigned to them -->
<Label x:Name="otherCommandsLabel" Grid.Row="3" Grid.Column="0" Target="{Binding ElementName=shortcutsManagementOptionsPanel}" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock TextWrapping="Wrap" Text="{core:Localize ShortcutsManagement.SimilarShortcutsLabel}" />
</Label>
<Dialogs:ShortcutsTreeView Grid.Row="3" Grid.Column="1" x:Name="shortcutsManagementOptionsPanel" IsSearchable="False" Padding="3" RemoveShortcutClick="shortcutsManagementOptionsPanel_RemoveShortcutClick" IsRemovableShortcutsEnabled="True" />
<!-- Ok/Cancel buttons -->
<StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="4" HorizontalAlignment="Right" >
<Button Click="saveButton_Click" x:Name="saveButton" Margin="3" Width="80" Content="{core:Localize Global.OKButtonText}" />
<Button Click="resetButton_Click" x:Name="resetButton" Margin="3" Width="80" Content="{core:Localize Global.CancelButtonText}" />
</StackPanel>
</Grid>
<!-- Reset/Ok/Cancel buttons -->
<Grid Grid.Column="2" Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Click="DefaultButton_Click" x:Name="defaultButton" Margin="3" Width="80" Content="{core:Localize ShortcutsManagement.ShortcutManagementWindow.ResetToDefaults}" />
<Button Grid.Column="2" Click="saveButton_Click" x:Name="saveButton" Margin="3" Width="80" Content="{core:Localize Global.OKButtonText}" />
<Button Grid.Column="3" Click="resetButton_Click" x:Name="resetButton" Margin="3" Width="80" Content="{core:Localize Global.CancelButtonText}" />
</Grid>
</Grid>
</Window>

5
src/AddIns/Misc/ShortcutsManagement/ShortcutsManagement/Src/Dialogs/ShortcutManagementWindow.xaml.cs

@ -218,5 +218,10 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -218,5 +218,10 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
{
Close();
}
void DefaultButton_Click(object sender, RoutedEventArgs e)
{
Shortcut.ResetToDefaults();
}
}
}

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

@ -191,12 +191,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -191,12 +191,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
// Strip this sign from shortcut entry text
shortcutText = Regex.Replace(shortcutText, @"&([^\s])", @"$1");
var shortcutGestures = inputBindingInfo.DefaultGestures.InputGesturesCollection;
if(SelectedProfile != null && SelectedProfile[BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo)] != null) {
shortcutGestures = new InputGestureCollection(SelectedProfile[BindingInfoTemplate.CreateFromIBindingInfo(inputBindingInfo)]);
}
var shortcut = new Shortcut(shortcutText, shortcutGestures);
var shortcut = new Shortcut(shortcutText, inputBindingInfo.ActiveGestures, inputBindingInfo.DefaultGestures.InputGesturesCollection);
shortcutsMap.Add(shortcut, inputBindingInfo);
// Assign shortcut to all categories it is registered in
@ -378,7 +373,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs @@ -378,7 +373,7 @@ namespace ICSharpCode.ShortcutsManagement.Dialogs
originalRelatedShortcut.Gestures.AddRange(relatedShortcutCopy.Gestures);
var id = BindingInfoTemplate.CreateFromIBindingInfo(shortcutsMap.MapForward(originalRelatedShortcut));
SelectedProfile[id] = new InputGestureCollection(relatedShortcutCopy.Gestures);
SelectedProfile[id] = relatedShortcutCopy.DoesUseDefault ? null : new InputGestureCollection(relatedShortcutCopy.Gestures);
}
}
}

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

@ -206,7 +206,11 @@ namespace ICSharpCode.Core.Presentation @@ -206,7 +206,11 @@ namespace ICSharpCode.Core.Presentation
var args = new NotifyGesturesChangedEventArgs(
new GesturesModificationDescription(identifier, oldGestures, newGestures));
userDefinedGestures[identifier] = inputGestureCollection;
if(inputGestureCollection != null) {
userDefinedGestures[identifier] = inputGestureCollection;
} else {
userDefinedGestures.Remove(identifier);
}
InvokeGesturesChanged(this, args);
}

25
src/Main/ICSharpCode.Core.Presentation/Input/InputGestureCollectionExtensions.cs

@ -11,22 +11,25 @@ namespace ICSharpCode.Core.Presentation @@ -11,22 +11,25 @@ namespace ICSharpCode.Core.Presentation
public static class InputGestureCollectionExtensions
{
public static bool ContainsTemplateForAny(this InputGestureCollection inputGestureTemplateCollection, InputGestureCollection testedInputGestureCollection, GestureCompareMode mode) {
foreach (InputGesture template in inputGestureTemplateCollection) {
if (template.IsTemplateForAny(testedInputGestureCollection, mode)) {
return true;
}
}
if((inputGestureTemplateCollection == null || inputGestureTemplateCollection.Count == 0) && (testedInputGestureCollection == null || testedInputGestureCollection.Count == 0)) {
return true;
}
foreach (InputGesture template in inputGestureTemplateCollection) {
if (template.IsTemplateForAny(testedInputGestureCollection, mode)) {
return true;
}
}
return false;
}
public static bool ContainsTemplateFor(this InputGestureCollection inputGestureTemplateCollection, InputGesture testedGesture, GestureCompareMode mode) {
foreach (InputGesture template in inputGestureTemplateCollection) {
if (template.IsTemplateFor(testedGesture, mode)) {
return true;
}
}
if (template.IsTemplateFor(testedGesture, mode)) {
return true;
}
}
return false;
}
@ -46,7 +49,7 @@ namespace ICSharpCode.Core.Presentation @@ -46,7 +49,7 @@ namespace ICSharpCode.Core.Presentation
{
var xInputBinding = (InputBinding)x;
var yInputBinding = (InputBinding)y;
var xMultiKeyGesture = xInputBinding.Gesture as MultiKeyGesture;
var yMultiKeyGesture = yInputBinding.Gesture as MultiKeyGesture;

Loading…
Cancel
Save