Skip to content

Commit

Permalink
improved combobox search
Browse files Browse the repository at this point in the history
  • Loading branch information
kekejun committed Aug 4, 2023
1 parent 62809b0 commit 5d3f949
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 33 deletions.
1 change: 0 additions & 1 deletion Commands/RvtCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public override bool Equals(object obj)
{
return other.Name == Name;
}

return false;
}

Expand Down
5 changes: 0 additions & 5 deletions Helpers/UriHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;

namespace RevitGuide.Helpers
{
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("0.0.2.0")]
5 changes: 1 addition & 4 deletions Settings/ItemSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public ItemSetting(string key = null , string uri = "")
Key = key;
Uri = uri;
_allRvtCommands = new ObservableCollection<RvtCommand>(RvtCommandHelper.AllRvtCommands);
}



}
}
}
32 changes: 13 additions & 19 deletions Views/SearchComboBox.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,48 @@
using RevitGuide.Commands;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace RevitGuide.Views
{
public class SearchComboBox : ComboBox
{
TextBox editableTextBox;

TextBox _editableTextBox;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_editableTextBox = GetTemplateChild("PART_EditableTextBox") as TextBox;
this.IsTextSearchEnabled = false;
this.IsEditable = true;
editableTextBox = GetTemplateChild("PART_EditableTextBox") as TextBox;
if (editableTextBox != null)

if (_editableTextBox != null)
{
editableTextBox.TextChanged += EditableTextBox_TextChanged;
editableTextBox.PreviewTextInput += EditableTextBox_PreviewTextInput;
_editableTextBox.TextChanged += EditableTextBox_TextChanged;
_editableTextBox.GotFocus += EditableTextBox_GotFocus;
}
}

private void EditableTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
private void EditableTextBox_GotFocus(object sender, RoutedEventArgs e)
{
e.Handled = true;
if (editableTextBox.SelectionLength == editableTextBox.Text.Length)
{
editableTextBox.Text = e.Text;
}
else
{
editableTextBox.Text += e.Text;
}
editableTextBox.CaretIndex = editableTextBox.Text.Length;
string text = _editableTextBox.Text;
this.SelectedIndex = -1;
_editableTextBox.Text = text;
IsDropDownOpen = true;
}

private void EditableTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (ItemsSource is ICollectionView ICV)
{
if (string.IsNullOrEmpty(editableTextBox.Text.Trim()))
if (string.IsNullOrEmpty(_editableTextBox.Text.Trim()))
{
ICV.Filter = null;
}
else
{
ICV.Filter = new Predicate<object>(i => ((RvtCommand)i).Name.ToLower().Contains(editableTextBox.Text.ToLower()));
ICV.Filter = new Predicate<object>(i => ((RvtCommand)i).Name.ToLower().Contains(_editableTextBox.Text.ToLower()));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Views/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
<DataGrid x:Name="TriggerSettingsDataGrid"
ItemsSource="{Binding TriggerSettings,Mode=TwoWay}"
RowHeight="25"
MouseLeftButtonDown="DataGridMouseLeftButtonUp">
MouseLeftButtonDown="DataGridMouseLeftButtonUp"
EnableRowVirtualization="False"
EnableColumnVirtualization="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="COMMAND"
Width="150">
Expand Down
3 changes: 1 addition & 2 deletions Views/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
using RevitGuide.Settings;
using RevitGuide.ViewModels;
using System.Collections.Generic;
using System.Security.Policy;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace RevitGuide.Views
{

public partial class SettingsWindow : Window
{
private SettingsViewModel _settingsViewModel;
Expand Down Expand Up @@ -63,6 +61,7 @@ private void DataGridMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_activeDataGrid.CommitEdit(DataGridEditingUnit.Row, true);
_activeDataGrid.SelectedItem = null;
Keyboard.ClearFocus();
}
}

Expand Down

0 comments on commit 5d3f949

Please sign in to comment.