Kategorie
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace FasdDesktopUi.Basics.UserControls
|
||||
{
|
||||
@@ -17,6 +18,10 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
private readonly Dictionary<string, HierarchicalSelectionItem> itemLookup = new Dictionary<string, HierarchicalSelectionItem>();
|
||||
private readonly DispatcherTimer searchDelayTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) };
|
||||
private string lastSearchText = string.Empty;
|
||||
|
||||
private TextBox searchTextBox;
|
||||
private TreeView treeViewControl;
|
||||
|
||||
public ObservableCollection<HierarchicalSelectionItem> VisibleItems => visibleItems;
|
||||
|
||||
public event EventHandler DropDownOpened;
|
||||
@@ -25,10 +30,18 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
public HierarchicalSelectionControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
TreeViewControl.ItemsSource = visibleItems;
|
||||
searchDelayTimer.Tick += SearchDelayTimer_Tick;
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
EnsureTemplateParts();
|
||||
if (treeViewControl != null)
|
||||
treeViewControl.ItemsSource = VisibleItems;
|
||||
UpdateDisplaySelection();
|
||||
}
|
||||
|
||||
#region DependencyProperties
|
||||
|
||||
public ObservableCollection<HierarchicalSelectionItem> ItemsSource
|
||||
@@ -93,16 +106,19 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
|
||||
#endregion
|
||||
|
||||
private void DropDownPopup_Opened(object sender, EventArgs e)
|
||||
private void ComboBoxControl_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
SearchTextBox.Focus();
|
||||
SearchTextBox.SelectAll();
|
||||
EnsureTemplateParts();
|
||||
searchTextBox?.Focus();
|
||||
searchTextBox?.SelectAll();
|
||||
LogEntry($"[CategoryPicker] DropDownOpened. Selected={SelectedItem?.FullPath ?? "<null>"}");
|
||||
DropDownOpened?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void DropDownPopup_Closed(object sender, EventArgs e)
|
||||
private void ComboBoxControl_DropDownClosed(object sender, EventArgs e)
|
||||
{
|
||||
searchDelayTimer.Stop();
|
||||
LogEntry("[CategoryPicker] DropDownClosed");
|
||||
DropDownClosed?.Invoke(this, e);
|
||||
}
|
||||
|
||||
@@ -115,7 +131,8 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
private void SearchDelayTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
searchDelayTimer.Stop();
|
||||
lastSearchText = SearchTextBox.Text ?? string.Empty;
|
||||
lastSearchText = searchTextBox?.Text ?? string.Empty;
|
||||
LogEntry($"[CategoryPicker] Search text changed: '{lastSearchText}'");
|
||||
ApplyFilter(lastSearchText);
|
||||
}
|
||||
|
||||
@@ -124,10 +141,13 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
if (e.NewValue is HierarchicalSelectionItem selected)
|
||||
{
|
||||
var original = ResolveOriginalItem(selected);
|
||||
if (original != null)
|
||||
if (original != null && !Equals(SelectedItem, original))
|
||||
{
|
||||
SelectedItem = original;
|
||||
LogEntry($"[CategoryPicker] Tree selection changed: {original.FullPath}");
|
||||
}
|
||||
|
||||
DropDownPopup.IsOpen = false;
|
||||
ComboBoxControl.IsDropDownOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +159,7 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
if (!string.IsNullOrWhiteSpace(item.Id) && itemLookup.TryGetValue(item.Id, out var original))
|
||||
return original;
|
||||
|
||||
return item;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void RebuildLookup()
|
||||
@@ -209,13 +229,29 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
private void EnsureTemplateParts()
|
||||
{
|
||||
if (!IsEnabled)
|
||||
return;
|
||||
if (treeViewControl == null)
|
||||
{
|
||||
treeViewControl = ComboBoxControl.Template.FindName("PART_TreeView", ComboBoxControl) as TreeView;
|
||||
if (treeViewControl != null)
|
||||
{
|
||||
treeViewControl.SelectedItemChanged += TreeViewControl_SelectedItemChanged;
|
||||
treeViewControl.ItemsSource = VisibleItems;
|
||||
}
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
DropDownPopup.IsOpen = !DropDownPopup.IsOpen;
|
||||
if (searchTextBox == null)
|
||||
{
|
||||
searchTextBox = ComboBoxControl.Template.FindName("PART_SearchTextBox", ComboBoxControl) as TextBox;
|
||||
if (searchTextBox != null)
|
||||
searchTextBox.TextChanged += SearchTextBox_TextChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDisplaySelection()
|
||||
{
|
||||
// Display handled by ComboBox DisplayMemberPath (FullPath).
|
||||
}
|
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
@@ -225,16 +261,16 @@ namespace FasdDesktopUi.Basics.UserControls
|
||||
if (!IsEnabled)
|
||||
return;
|
||||
|
||||
if (!DropDownPopup.IsOpen && (e.Key == Key.Enter || e.Key == Key.Down || e.Key == Key.Space))
|
||||
if (!ComboBoxControl.IsDropDownOpen && (e.Key == Key.Enter || e.Key == Key.Down || e.Key == Key.Space))
|
||||
{
|
||||
DropDownPopup.IsOpen = true;
|
||||
ComboBoxControl.IsDropDownOpen = true;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (DropDownPopup.IsOpen && e.Key == Key.Escape)
|
||||
if (ComboBoxControl.IsDropDownOpen && e.Key == Key.Escape)
|
||||
{
|
||||
DropDownPopup.IsOpen = false;
|
||||
ComboBoxControl.IsDropDownOpen = false;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user