Browse Source

Use key binding to trigger searching in the Add Package Reference dialog on pressing the enter key.

pull/15/head
mrward 15 years ago
parent
commit
499758b414
  1. 1
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. 9
      src/AddIns/Misc/PackageManagement/Project/Src/PackagesView.xaml
  3. 61
      src/AddIns/Misc/PackageManagement/Project/Src/TextBoxBehaviour.cs

1
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -145,7 +145,6 @@
<Compile Include="Src\SharpDevelopProjectSystem.cs" /> <Compile Include="Src\SharpDevelopProjectSystem.cs" />
<Compile Include="Src\SharpDevelopProjectSystemFactory.cs" /> <Compile Include="Src\SharpDevelopProjectSystemFactory.cs" />
<Compile Include="Src\StringToStringCollectionConverter.cs" /> <Compile Include="Src\StringToStringCollectionConverter.cs" />
<Compile Include="Src\TextBoxBehaviour.cs" />
<Compile Include="Src\ViewModelBase.cs" /> <Compile Include="Src\ViewModelBase.cs" />
<Compile Include="Src\ViewModelLocator.cs" /> <Compile Include="Src\ViewModelLocator.cs" />
</ItemGroup> </ItemGroup>

9
src/AddIns/Misc/PackageManagement/Project/Src/PackagesView.xaml

@ -285,8 +285,13 @@
<TextBox <TextBox
Grid.Row="1" Grid.Row="1"
Grid.Column="0" Grid.Column="0"
pm:TextBoxBehaviour.EnterKeyCommand="{Binding Path=SearchCommand}" Text="{Binding Path=SearchTerms, UpdateSourceTrigger=PropertyChanged}">
Text="{Binding Path=SearchTerms, UpdateSourceTrigger=PropertyChanged}"/> <TextBox.InputBindings>
<KeyBinding
Key="Enter"
Command="{Binding Path=SearchCommand}"/>
</TextBox.InputBindings>
</TextBox>
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"

61
src/AddIns/Misc/PackageManagement/Project/Src/TextBoxBehaviour.cs

@ -1,61 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace ICSharpCode.PackageManagement
{
public static class TextBoxBehaviour
{
public static readonly DependencyProperty EnterKeyCommandProperty
= DependencyProperty.RegisterAttached(
"EnterKeyCommand",
typeof(ICommand),
typeof(TextBoxBehaviour),
new FrameworkPropertyMetadata(null, OnEnterKeyCommandPropertyChanged));
public static ICommand GetEnterKeyCommand(DependencyObject dependencyObject)
{
return dependencyObject.GetValue(EnterKeyCommandProperty) as ICommand;
}
public static void SetEnterKeyCommand(DependencyObject dependencyObject, ICommand command)
{
dependencyObject.SetValue(EnterKeyCommandProperty, command);
}
static void OnEnterKeyCommandPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
TextBox textBox = dependencyObject as TextBox;
if (textBox == null) {
return;
}
ICommand command = e.NewValue as ICommand;
if (command == null) {
textBox.KeyDown -= TextBoxKeyDown;
} else {
textBox.KeyDown += TextBoxKeyDown;
}
}
static void TextBoxKeyDown(object sender, KeyEventArgs e)
{
TextBox textBox = sender as TextBox;
if (textBox == null) {
return;
}
if (e.Key == Key.Enter) {
ICommand command = GetEnterKeyCommand(textBox);
if (command != null) {
command.Execute(null);
}
}
}
}
}
Loading…
Cancel
Save