Kategorie

This commit is contained in:
Meik
2025-11-11 23:59:33 +01:00
parent 5292a2cb0c
commit 845dd1810a
3 changed files with 51 additions and 12 deletions

View File

@@ -30,14 +30,14 @@
BorderThickness="{TemplateBinding BorderThickness}"
Style="{StaticResource ComboBoxToggleButton}" />
<ContentPresenter x:Name="contentPresenter"
<TextBlock x:Name="SelectedPathText"
IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Text="{Binding SelectedItem.FullPath, RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalSelectionControl}}}"
Margin="6 0"
VerticalAlignment="Center"
HorizontalAlignment="Stretch" />
HorizontalAlignment="Stretch"
Foreground="{DynamicResource FontColor.Menu.Categories}"
TextTrimming="CharacterEllipsis" />
<Popup x:Name="PART_Popup"
Placement="Bottom"
@@ -128,9 +128,10 @@
BorderBrush="{Binding ElementName=HierarchySelector, Path=BorderBrush}"
Foreground="{DynamicResource FontColor.Menu.Categories}"
ItemsSource="{Binding VisibleItems, ElementName=HierarchySelector}"
SelectedItem="{Binding SelectedItem, ElementName=HierarchySelector, Mode=TwoWay}"
DisplayMemberPath="FullPath"
Template="{StaticResource HierarchicalComboBoxTemplate}"
SelectedIndex="-1"
IsSynchronizedWithCurrentItem="False"
DropDownOpened="ComboBoxControl_DropDownOpened"
DropDownClosed="ComboBoxControl_DropDownClosed"
IsEditable="False"

View File

@@ -18,6 +18,7 @@ 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 bool suppressTreeSelectionChanged;
private TextBox searchTextBox;
private TreeView treeViewControl;
@@ -82,6 +83,7 @@ namespace FasdDesktopUi.Basics.UserControls
{
if (d is HierarchicalSelectionControl control)
{
control.LogSelectedItemChange(e.NewValue as HierarchicalSelectionItem);
control.TryExpandToSelectedItem();
}
}
@@ -111,6 +113,7 @@ namespace FasdDesktopUi.Basics.UserControls
EnsureTemplateParts();
searchTextBox?.Focus();
searchTextBox?.SelectAll();
suppressTreeSelectionChanged = false;
LogEntry($"[CategoryPicker] DropDownOpened. Selected={SelectedItem?.FullPath ?? "<null>"}");
DropDownOpened?.Invoke(this, e);
}
@@ -118,6 +121,7 @@ namespace FasdDesktopUi.Basics.UserControls
private void ComboBoxControl_DropDownClosed(object sender, EventArgs e)
{
searchDelayTimer.Stop();
suppressTreeSelectionChanged = false;
LogEntry("[CategoryPicker] DropDownClosed");
DropDownClosed?.Invoke(this, e);
}
@@ -138,6 +142,9 @@ namespace FasdDesktopUi.Basics.UserControls
private void TreeViewControl_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (suppressTreeSelectionChanged)
return;
if (e.NewValue is HierarchicalSelectionItem selected)
{
var original = ResolveOriginalItem(selected);
@@ -147,6 +154,7 @@ namespace FasdDesktopUi.Basics.UserControls
LogEntry($"[CategoryPicker] Tree selection changed: {original.FullPath}");
}
suppressTreeSelectionChanged = true;
ComboBoxControl.IsDropDownOpen = false;
}
}
@@ -251,7 +259,20 @@ namespace FasdDesktopUi.Basics.UserControls
private void UpdateDisplaySelection()
{
// Display handled by ComboBox DisplayMemberPath (FullPath).
// Display handled by template TextBlock bound to SelectedItem.FullPath.
}
private void LogSelectedItemChange(HierarchicalSelectionItem newValue)
{
var description = "<null>";
if (newValue != null)
{
var fullPath = string.IsNullOrWhiteSpace(newValue.FullPath) ? newValue.DisplayName : newValue.FullPath;
var id = string.IsNullOrWhiteSpace(newValue.Id) ? "<null>" : newValue.Id;
description = $"{fullPath} (Id={id})";
}
LogEntry($"[CategoryPicker] DependencyProperty SelectedItem updated -> {description}");
}
protected override void OnPreviewKeyDown(KeyEventArgs e)

View File

@@ -229,11 +229,28 @@ namespace FasdDesktopUi.Basics.UserControls
private static void OnSelectedCategoryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// Reserved for future use when additional reactions are required.
if (d is CloseCaseDialogWithTicket instance)
instance.LogSelectedCategoryChanged(e.NewValue as HierarchicalSelectionItem);
}
#endregion
private void LogSelectedCategoryChanged(HierarchicalSelectionItem category)
{
try
{
var fullPath = category == null
? "<null>"
: string.IsNullOrWhiteSpace(category.FullPath) ? category.DisplayName : category.FullPath;
var id = category == null || string.IsNullOrWhiteSpace(category.Id) ? "<null>" : category.Id;
LogEntry($"[CloseCaseDialog] SelectedCategory updated -> {fullPath} (Id={id})");
}
catch (Exception ex)
{
LogException(ex);
}
}
public bool ShowServiceHasBeenChangedWarning
{
get { return ServiceHasBeenChanged && SetOrUpdateServiceInTicket; }