Skip to content

Commit

Permalink
restored input bindings, cleaned up command bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Apr 25, 2021
1 parent 8fabb4e commit 6f026a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
14 changes: 4 additions & 10 deletions Rubberduck.Core/UI/FindSymbol/FindSymbolControl.xaml
Expand Up @@ -9,12 +9,6 @@
d:DesignHeight="24" d:DesignWidth="270"
d:DataContext="{d:DesignInstance {x:Type local:FindSymbolViewModel}, IsDesignTimeCreatable=False}">

<UserControl.CommandBindings>
<CommandBinding Command="local:FindSymbolControl.GoCommand"
Executed="CommandBinding_OnExecuted"
CanExecute="CommandBinding_OnCanExecute"/>
</UserControl.CommandBindings>

<UserControl.Resources>
<BitmapImage x:Key="ArrowImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/arrow.png" />
<local:SearchBoxMultiBindingConverter x:Key="SearchBoxTextConverter" />
Expand All @@ -35,9 +29,9 @@
IsTextSearchCaseSensitive="False"
IsTextSearchEnabled="True"
TextSearch.TextPath="IdentifierName">
<ComboBox.Resources>
<KeyBinding x:Key="EnterGo" Key="Return" Command="{Binding GoCommand}" />
</ComboBox.Resources>
<ComboBox.InputBindings>
<KeyBinding Command="{Binding GoCommand}" Key="Return" />
</ComboBox.InputBindings>
<ComboBox.Text>
<MultiBinding Converter="{StaticResource SearchBoxTextConverter}">
<Binding Path="SearchString" Mode="OneWayToSource" UpdateSourceTrigger="PropertyChanged" />
Expand All @@ -62,7 +56,7 @@
</ComboBox.ItemTemplate>
</ComboBox>

<Button Grid.Column="1" Command="local:FindSymbolControl.GoCommand">
<Button Grid.Column="1" Command="{Binding GoCommand}">
<Image Height="16" Width="16" Source="{StaticResource ArrowImage}" />
</Button>

Expand Down
18 changes: 0 additions & 18 deletions Rubberduck.Core/UI/FindSymbol/FindSymbolControl.xaml.cs
@@ -1,5 +1,4 @@
using System.Windows.Controls;
using System.Windows.Input;

namespace Rubberduck.UI.FindSymbol
{
Expand All @@ -16,26 +15,9 @@ public FindSymbolControl()

private FindSymbolViewModel ViewModel => (FindSymbolViewModel)DataContext;

public static ICommand GoCommand { get; } = new RoutedCommand();

private void CommandBinding_OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
ViewModel?.Execute();
e.Handled = true;
}

private void CommandBinding_OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = ViewModel?.CanExecute() ?? false;
e.Handled = true;
}

private void FindSymbolControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
SearchComboBox.Focus();
}

// doing this navigates on arrow-up/down, which isn't expected
//private void searchComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) => ViewModel?.Execute();
}
}
20 changes: 11 additions & 9 deletions Rubberduck.Core/UI/FindSymbol/FindSymbolViewModel.cs
Expand Up @@ -4,10 +4,13 @@
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using NLog;
using Rubberduck.Common;
using Rubberduck.Interaction.Navigation;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Properties;
using Rubberduck.UI.Command;

namespace Rubberduck.UI.FindSymbol
{
Expand All @@ -19,24 +22,23 @@ public class FindSymbolViewModel : INotifyPropertyChanged
DeclarationType.Project
};

private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

public FindSymbolViewModel(IEnumerable<Declaration> declarations)
{
_declarations = declarations.Where(declaration => !ExcludedTypes.Contains(declaration.DeclarationType)).ToList();

GoCommand = new DelegateCommand(Logger, ExecuteGoCommand, CanExecuteGoCommand);
Search(string.Empty);
}

public event EventHandler<NavigateCodeEventArgs> Navigate;

public bool CanExecute()
{
return _searchString?.Equals(_selectedItem?.IdentifierName, StringComparison.InvariantCultureIgnoreCase) ?? false;
}
public ICommand GoCommand { get; }

private bool CanExecuteGoCommand(object param) => _searchString?.Equals(_selectedItem?.IdentifierName, StringComparison.InvariantCultureIgnoreCase) ?? false;

private void ExecuteGoCommand(object param) => OnNavigate();

public void Execute()
{
OnNavigate();
}

public void OnNavigate()
{
Expand Down

0 comments on commit 6f026a8

Please sign in to comment.