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

Commit

Permalink
Fixed profiles bugs and bug in new gesture window when first chord ha…
Browse files Browse the repository at this point in the history
…d to be full even it's function key

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4423 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
  • Loading branch information
sandrejev committed Jul 10, 2009
1 parent c151e98 commit dcb940d
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 63 deletions.
2 changes: 1 addition & 1 deletion AddIns/ICSharpCode.SharpDevelop.addin
Expand Up @@ -152,7 +152,7 @@
<CommandBinding
command="SDBuildCommands.BuildSolution"
class="ICSharpCode.SharpDevelop.Project.Commands.Build"
gestures="Ctrl+Alt+R,R;Ctrl+B,B"
gestures="F8"
categories="/Building"
/>
<CommandBinding
Expand Down
9 changes: 8 additions & 1 deletion SharpDevelop.Tests.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 10
# SharpDevelop 4.0.0.4289
# SharpDevelop 4.0.0.4395
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
Expand Down Expand Up @@ -58,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartUp", "src\Main\StartUp
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core.Presentation.Tests", "src\Main\ICSharpCode.Core.Presentation\Test\ICSharpCode.Core.Presentation.Tests.csproj", "{FFA7988E-7348-4669-9E9D-27E629C873A2}"
EndProject
Project("{00000000-0000-0000-0000-000000000000}") = "Tools", "src\Tools\Tools.build", "{3DF4060F-5EE0-41CF-8096-F27355FD5511}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{2A232EF1-EB95-41C6-B63A-C106E0C95D3C}"
Expand Down Expand Up @@ -751,11 +753,16 @@ Global
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}.Release|Any CPU.Build.0 = Release|Any CPU
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFA7988E-7348-4669-9E9D-27E629C873A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFA7988E-7348-4669-9E9D-27E629C873A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FFA7988E-7348-4669-9E9D-27E629C873A2}.Release|Any CPU.Build.0 = Release|Any CPU
{FFA7988E-7348-4669-9E9D-27E629C873A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FFA7988E-7348-4669-9E9D-27E629C873A2} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{1152B71B-3C05-4598-B20D-823B5D40559E} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{8035765F-D51F-4A0C-A746-2FD100E19419} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{2748AD25-9C63-4E12-877B-4DCE96FBED54} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
Expand Down
Expand Up @@ -291,7 +291,7 @@ private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
Clear();
}

if (enteredKeyGestureSequence[0].Modifiers == ModifierKeys.None)
if (!enteredKeyGestureSequence[0].IsFull)
{
DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.GestureTextBox.FirstChordIsIncomplete}"), NotificationType.Invalid);
}
Expand Down
Expand Up @@ -116,9 +116,9 @@ private void addGestureButton_Click(object sender, RoutedEventArgs e)
return;
}

// Check whether first chord is finished
// Check whether first chord is unfinished
var partialKeyGesture = gestureTextBox.Gesture as PartialKeyGesture;
if (partialKeyGesture != null && partialKeyGesture.Modifiers == ModifierKeys.None) {
if (partialKeyGesture != null && !partialKeyGesture.IsFull) {
DisplayNotification(StringParser.Parse("${res:ShortcutsManagement.ModificationWindow.AdditionFailedFirstChordIsIncomplete}"), NotificationType.Failed);
return;
}
Expand Down
Expand Up @@ -85,12 +85,13 @@ public void LoadOptions()

if (UserDefinedGesturesManager.CurrentProfile != null && profile.Name == UserDefinedGesturesManager.CurrentProfile.Name)
{
profilesTextBox.SelectedItem = profile;
SelectedProfile = profile;
}
}
}

BindProfiles();
BindShortcuts();
}

private void BindProfiles()
Expand Down Expand Up @@ -125,6 +126,20 @@ private void BindProfiles()
profilesTextBoxItemsSource.Add(resetItem);

profilesTextBox.DataContext = profilesTextBoxItemsSource;

if (SelectedProfile != null)
{
if(profilesTextBox.SelectedItem != SelectedProfile) {
profilesTextBox.Text = SelectedProfile.Text;
profilesTextBox.SelectedItem = SelectedProfile;
}
}
else
{
profilesTextBox.SelectedIndex = -1;
profilesTextBox.Text = "";
}

}

private void BindShortcuts()
Expand Down Expand Up @@ -195,7 +210,12 @@ private void BindShortcuts()
// Strip this sign from shortcut entry text
shortcutText = Regex.Replace(shortcutText, @"&([^\s])", @"$1");

var shortcut = new Shortcut(shortcutText, new InputGestureCollection(inputBindingInfo.ActiveGestures));
var shortcutGestures = new InputGestureCollection(inputBindingInfo.DefaultGestures);
if(SelectedProfile != null && SelectedProfile[inputBindingInfo.Identifier] != null) {
shortcutGestures = new InputGestureCollection(SelectedProfile[inputBindingInfo.Identifier]);
}

var shortcut = new Shortcut(shortcutText, shortcutGestures);
shortcutsMap.Add(shortcut, inputBindingInfo);

// Assign shortcut to all categories it is registered in
Expand Down Expand Up @@ -266,23 +286,10 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve
return;
}

if (!(e.AddedItems[0] is UserGesturesProfile))
{
if (e.RemovedItems != null && e.RemovedItems.Count > 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}"),
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
Expand Up @@ -107,7 +107,6 @@ public PartialKeyGesture(Key key)
_modifiers = ModifierKeys.None;
}


/// <summary>
/// Create new instance of<see cref="PartialKeyGesture"/> having only key and no modifiers
/// </summary>
Expand Down Expand Up @@ -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;
}
}

/// <summary>
/// Returns string that represents <see cref="PartialKeyGesture"/>
Expand Down
@@ -1,22 +1,26 @@
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{18FD5FC0-C57D-4A8F-8972-AC467B4FE83E}</ProjectGuid>
<ProjectGuid>{FFA7988E-7348-4669-9E9D-27E629C873A2}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.Core.Presentation.Tests</RootNamespace>
<AssemblyName>ICSharpCode.Core.Presentation.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\Administrator\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
Expand All @@ -26,31 +30,43 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\Tools\NUnit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="InputGestureTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserDefinedGestureProfileTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
</ProjectReference>
<ProjectReference Include="..\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
23 changes: 22 additions & 1 deletion src/Main/ICSharpCode.Core.Presentation/Test/InputGestureTests.cs
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit dcb940d

Please sign in to comment.