diff --git a/AddIns/ICSharpCode.SharpDevelop.addin b/AddIns/ICSharpCode.SharpDevelop.addin index 87c767a1703..e6d51ad8b5f 100644 --- a/AddIns/ICSharpCode.SharpDevelop.addin +++ b/AddIns/ICSharpCode.SharpDevelop.addin @@ -152,7 +152,7 @@ 0) - { - profilesTextBox.SelectedItem = e.RemovedItems[0]; - } - else if (profilesTextBox.SelectedIndex >= 0) - { - profilesTextBox.SelectedIndex = -1; - profilesTextBox.Text = ""; - } - } - var userGestureProfileAction = e.AddedItems[0] as UserGestureProfileAction; if (userGestureProfileAction != null) { - if (userGestureProfileAction.Name == "Delete" && e.RemovedItems != null && e.RemovedItems.Count > 0) + if (userGestureProfileAction.Name == "Delete" && SelectedProfile != null) { var result = MessageBox.Show( StringParser.Parse("${res:ShortcutsManagement.ShortcutsManagementOptionsPanel.ConfirmDeleteProfileMessage}"), @@ -291,26 +298,20 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve if(MessageBoxResult.Yes == result) { - var removedProfile = (UserGesturesProfile)e.RemovedItems[0]; - profiles.Remove(removedProfile); - removedProfiles.Add(removedProfile); + profiles.Remove(SelectedProfile); + removedProfiles.Add(SelectedProfile); SelectedProfile = null; } } - if (userGestureProfileAction.Name == "Rename" && e.RemovedItems != null && e.RemovedItems.Count > 0) + if (userGestureProfileAction.Name == "Rename" && SelectedProfile != null) { - var renamedProfile = e.RemovedItems[0] as UserGesturesProfile; - - if (renamedProfile != null) - { - var promptWindow = new CreateNewProfilePrompt(); - promptWindow.BaseProfilesVisibility = Visibility.Collapsed; - promptWindow.Text = renamedProfile.Text; - promptWindow.ShowDialog(); + var promptWindow = new CreateNewProfilePrompt(); + promptWindow.BaseProfilesVisibility = Visibility.Collapsed; + promptWindow.Text = SelectedProfile.Text; + promptWindow.ShowDialog(); - renamedProfile.Text = promptWindow.Text; - } + SelectedProfile.Text = promptWindow.Text; } if(userGestureProfileAction.Name == "Load") @@ -370,24 +371,13 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve } var userGestureProfile = e.AddedItems[0] as UserGesturesProfile; - if (userGestureProfile != null) + if (userGestureProfile != null && userGestureProfile != SelectedProfile) { SelectedProfile = userGestureProfile; } - if (SelectedProfile != null) - { - profilesTextBox.Text = SelectedProfile.Text; - profilesTextBox.SelectedItem = SelectedProfile; - } - else - { - profilesTextBox.SelectedIndex = -1; - profilesTextBox.Text = ""; - } - - BindShortcuts(); BindProfiles(); + BindShortcuts(); } private void shortcutsManagementOptionsPanel_ShortcutModified(object sender, EventArgs e) diff --git a/src/Main/ICSharpCode.Core.Presentation/CommandsService/UserDefinedGesturesManager.cs b/src/Main/ICSharpCode.Core.Presentation/CommandsService/UserDefinedGesturesManager.cs index 4e37559cfb5..9ed7b0c0892 100644 --- a/src/Main/ICSharpCode.Core.Presentation/CommandsService/UserDefinedGesturesManager.cs +++ b/src/Main/ICSharpCode.Core.Presentation/CommandsService/UserDefinedGesturesManager.cs @@ -15,9 +15,11 @@ public static class UserDefinedGesturesManager static UserDefinedGesturesManager() { - _userGestureProfilesDirectory = Path.Combine(PropertyService.ConfigDirectory, "UserGestureProfiles"); - if(!Directory.Exists(_userGestureProfilesDirectory)) { - Directory.CreateDirectory(_userGestureProfilesDirectory); + if(PropertyService.ConfigDirectory != null) { + _userGestureProfilesDirectory = Path.Combine(PropertyService.ConfigDirectory, "UserGestureProfiles"); + if(!Directory.Exists(_userGestureProfilesDirectory)) { + Directory.CreateDirectory(_userGestureProfilesDirectory); + } } } @@ -56,6 +58,7 @@ public static UserGesturesProfile CurrentProfile set { _currentProfile = value; PropertyService.Set("ICSharpCode.Core.Presentation.UserDefinedGesturesManager.UserGestureProfilesDirectory", CurrentProfile != null ? CurrentProfile.Path : null); + _isCurrentProfileLoaded = true; } } } diff --git a/src/Main/ICSharpCode.Core.Presentation/Input/PartialKeyGesture.cs b/src/Main/ICSharpCode.Core.Presentation/Input/PartialKeyGesture.cs index 733d0aaefa6..01d7e7d1b0d 100644 --- a/src/Main/ICSharpCode.Core.Presentation/Input/PartialKeyGesture.cs +++ b/src/Main/ICSharpCode.Core.Presentation/Input/PartialKeyGesture.cs @@ -107,7 +107,6 @@ public PartialKeyGesture(Key key) _modifiers = ModifierKeys.None; } - /// /// Create new instance of having only key and no modifiers /// @@ -192,6 +191,36 @@ public override bool Matches(object targetElement, InputEventArgs inputEventArgs return modifierMatches && keyMatches; } + + public bool IsFull + { + get { + if(Key == Key.None) { + return false; + } + + // and function keys are valid without modifier + if (Key >= Key.F1 && Key <= Key.F24) { + return true; + } + + // Modifiers alone are not valid + if (Array.IndexOf(new[] { Key.LeftAlt, Key.RightAlt, + Key.LeftShift, Key.RightShift, + Key.LeftCtrl, Key.RightCtrl, + Key.LWin, Key.RWin, + Key.System}, Key) > -1) { + return false; + } + + // All other gestures must have modifier (except shift alone because it would mean uppercase) + if((Modifiers & (ModifierKeys.Windows | ModifierKeys.Control | ModifierKeys.Alt)) != ModifierKeys.None) { + return true; + } + + return false; + } + } /// /// Returns string that represents diff --git a/src/Main/ICSharpCode.Core.Presentation/Test/ICSharpCode.Core.Presentation.Tests.csproj b/src/Main/ICSharpCode.Core.Presentation/Test/ICSharpCode.Core.Presentation.Tests.csproj index 2336af5b48d..dd4507332cf 100644 --- a/src/Main/ICSharpCode.Core.Presentation/Test/ICSharpCode.Core.Presentation.Tests.csproj +++ b/src/Main/ICSharpCode.Core.Presentation/Test/ICSharpCode.Core.Presentation.Tests.csproj @@ -1,22 +1,26 @@ - + + - {18FD5FC0-C57D-4A8F-8972-AC467B4FE83E} + {FFA7988E-7348-4669-9E9D-27E629C873A2} Debug AnyCPU Library ICSharpCode.Core.Presentation.Tests ICSharpCode.Core.Presentation.Tests - v3.5 + v4.0 Properties - C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis + False + False + 4 + false - bin\Debug\ - True + true Full False True DEBUG;TRACE + bin\ bin\Release\ @@ -26,7 +30,13 @@ False TRACE - + + False + Auto + 4194304 + AnyCPU + 4096 + ..\..\..\Tools\NUnit\nunit.framework.dll @@ -34,23 +44,29 @@ 3.0 + + 3.0 + 3.5 - - 3.5 - + + + {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} + ICSharpCode.Core + {7E4A7172-7FF5-48D0-B719-7CD959DD1AC9} ICSharpCode.Core.Presentation + \ No newline at end of file diff --git a/src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs b/src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs index 4784d956252..8d31b89e8ff 100644 --- a/src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs +++ b/src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs @@ -125,7 +125,6 @@ public void MultiKeyGesturesMatchStartsWithTest() var template1 = (MultiKeyGesture)multiKeyGestureConverter.ConvertFromInvariantString("Ctrl+"); var original1 = (MultiKeyGesture)multiKeyGestureConverter.ConvertFromInvariantString("Ctrl+D"); Assert.IsTrue(template1.IsTemplateFor(original1, GestureCompareMode.StartsWith)); - Assert.IsTrue(original1.IsTemplateFor(template1, GestureCompareMode.StartsWith)); var template2 = (MultiKeyGesture)multiKeyGestureConverter.ConvertFromInvariantString("Ctrl+C"); var original2 = (MultiKeyGesture)multiKeyGestureConverter.ConvertFromInvariantString("Ctrl+C,Ctrl+D"); @@ -363,5 +362,27 @@ public void MultiKeyGesturesAreNotConflictingTest() Assert.IsFalse(template5.IsTemplateFor(original5, GestureCompareMode.Conflicting)); Assert.IsFalse(original5.IsTemplateFor(template5, GestureCompareMode.Conflicting)); } + + [Test] + public void PartialGestureIsFullTest() + { + Assert.IsTrue(((PartialKeyGesture)new PartialKeyGestureConverter().ConvertFromInvariantString("Ctrl+A")).IsFull); + Assert.IsTrue(((PartialKeyGesture)new PartialKeyGestureConverter().ConvertFromInvariantString("Ctrl+Shift+A")).IsFull); + Assert.IsTrue(((PartialKeyGesture)new PartialKeyGestureConverter().ConvertFromInvariantString("F8")).IsFull); + Assert.IsFalse(((PartialKeyGesture)new PartialKeyGestureConverter().ConvertFromInvariantString("A")).IsFull); + Assert.IsFalse(((PartialKeyGesture)new PartialKeyGestureConverter().ConvertFromInvariantString("Ctrl+")).IsFull); + Assert.IsFalse(((PartialKeyGesture)new PartialKeyGestureConverter().ConvertFromInvariantString("Shift+A")).IsFull); + } + + [Test] + public void IdentifierTest() + { + var sameBinding1 = new InputBindingInfo { OwnerTypeName="Binding", RoutedCommandName="Binding" }; + var sameBinding2 = new InputBindingInfo { OwnerTypeName="Binding", RoutedCommandName="Binding" }; + var sameBinding3 = new InputBindingInfo { OwnerTypeName="Binding3", RoutedCommandName="Binding" }; + + Assert.AreEqual(sameBinding1.Identifier, sameBinding2.Identifier); + Assert.AreNotEqual(sameBinding1.Identifier, sameBinding3.Identifier); + } } } diff --git a/src/Main/ICSharpCode.Core.Presentation/Test/UserDefinedGestureProfileTests.cs b/src/Main/ICSharpCode.Core.Presentation/Test/UserDefinedGestureProfileTests.cs new file mode 100644 index 00000000000..91a2666e89d --- /dev/null +++ b/src/Main/ICSharpCode.Core.Presentation/Test/UserDefinedGestureProfileTests.cs @@ -0,0 +1,85 @@ +/* + * Created by SharpDevelop. + * User: Administrator + * Date: 7/10/2009 + * Time: 11:19 AM + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Windows.Input; +using ICSharpCode.Core; +using ICSharpCode.Core.Presentation; +using NUnit.Framework; + +namespace ICSharpCode.Core.Presentation.Tests +{ + [TestFixture] + public class UserDefinedGestureProfileTests + { + UserGesturesProfile profile = null; + InputBindingInfo binding = null; + KeyGesture gesture = null; + + + [TestFixtureSetUp] + public void SetUpFixture() + { + PropertyService.InitializeServiceForUnitTests(); + } + + [SetUp] + public void SetuUp() + { + UserDefinedGesturesManager.CurrentProfile = null; + profile = new UserGesturesProfile(); + gesture = (KeyGesture)new KeyGestureConverter().ConvertFromInvariantString("Ctrl+A"); + binding = new InputBindingInfo { OwnerTypeName="Binding", RoutedCommandName="Binding" }; + } + + [Test] + public void NoProfileTest() + { + binding.DefaultGestures.Add(gesture); + + Assert.AreEqual(1, binding.DefaultGestures.Count); + Assert.AreEqual(gesture, binding.DefaultGestures[0]); + Assert.AreEqual(1, binding.ActiveGestures.Count); + Assert.AreEqual(gesture, binding.ActiveGestures[0]); + } + + [Test] + public void ActiveProfileTest() + { + binding.DefaultGestures.Add(gesture); + + var userDefinedGestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromInvariantString("Ctrl+B;Ctrl+C"); + profile[binding.Identifier] = userDefinedGestures; + UserDefinedGesturesManager.CurrentProfile = profile; + + // Default gestures stay the same + Assert.AreEqual(1, binding.DefaultGestures.Count); + Assert.AreEqual(gesture, binding.DefaultGestures[0]); + + // Only active gestures are modified + Assert.AreEqual(2, binding.ActiveGestures.Count); + Assert.AreEqual(userDefinedGestures[0], binding.ActiveGestures[0]); + Assert.AreEqual(userDefinedGestures[1], binding.ActiveGestures[1]); + } + + [Test] + public void NoGestureInActiveProfileTest() + { + var binding2 = new InputBindingInfo { OwnerTypeName="Binding2", RoutedCommandName="Binding2" }; + binding2.DefaultGestures.Add(gesture); + + var userDefinedGestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromInvariantString("Ctrl+B;Ctrl+C"); + profile[binding.Identifier] = userDefinedGestures; + UserDefinedGesturesManager.CurrentProfile = profile; + + // Default gestures are used because current profile doesn't contain modifications to this gesture + Assert.AreEqual(1, binding2.ActiveGestures.Count); + Assert.AreEqual(binding2.DefaultGestures[0], binding2.ActiveGestures[0]); + } + } +}