From 61aaec2786e95023441bf218a8b8ad5c89b07a1c Mon Sep 17 00:00:00 2001 From: GID Date: Tue, 16 Sep 2025 18:48:23 +0700 Subject: [PATCH 01/10] Add tooltips for text context menu commands --- .../Controls/TextContextMenu.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs index 118c124e..c109ed14 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs @@ -1,4 +1,4 @@ -using iNKORE.UI.WPF.Modern.Common; +using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Common.IconKeys; using iNKORE.UI.WPF.Modern.Controls.Helpers; using System.Linq; @@ -252,26 +252,59 @@ private void UpdateItems(Control target) if (command == ApplicationCommands.Cut) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelCut); + var cutDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCut); + // Show only the description as tooltip (remove accelerator text) + menuItem.ToolTip = cutDescription; + ToolTipService.SetInitialShowDelay(menuItem, 700); + ToolTipService.SetShowDuration(menuItem, 10000); + ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Copy) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelCopy); + // Add a tooltip for long-hover to show description (accelerator removed) + var copyDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCopy); + menuItem.ToolTip = copyDescription; + // set tooltip timing for long-hover experience + ToolTipService.SetInitialShowDelay(menuItem, 700); + ToolTipService.SetShowDuration(menuItem, 10000); + ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Paste) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelPaste); + var pasteDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionPaste); + menuItem.ToolTip = pasteDescription; + ToolTipService.SetInitialShowDelay(menuItem, 700); + ToolTipService.SetShowDuration(menuItem, 10000); + ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Undo) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelUndo); + var undoDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionUndo); + menuItem.ToolTip = undoDescription; + ToolTipService.SetInitialShowDelay(menuItem, 700); + ToolTipService.SetShowDuration(menuItem, 10000); + ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Redo) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelRedo); + var redoDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionRedo); + menuItem.ToolTip = redoDescription; + ToolTipService.SetInitialShowDelay(menuItem, 700); + ToolTipService.SetShowDuration(menuItem, 10000); + ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.SelectAll) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelSelectAll); + var selectAllDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionSelectAll); + menuItem.ToolTip = selectAllDescription; + ToolTipService.SetInitialShowDelay(menuItem, 700); + ToolTipService.SetShowDuration(menuItem, 10000); + ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } menuItem.CommandTarget = target; From af52483637365f2a85bb3ac646812ca7c016ffe9 Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 01:07:18 +0700 Subject: [PATCH 02/10] Enhance CodePresenter context menu tooltips Added context menu tooltip for CodePresenter. --- .../Controls/SampleCodePresenter.xaml.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs index 355bc311..f05915d1 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs @@ -1,4 +1,4 @@ -using ColorCodeStandard; +using ColorCodeStandard; using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Highlighting; @@ -118,6 +118,39 @@ private void SampleCodePresenter_Loaded(object sender, RoutedEventArgs e) SampleHeader.Text = IsCSharpSample ? "C#" : "XAML"; FixAvalonEditScrolling(); + + // Ensure the CodePresenter context menu items have the same long-hover, description-only + // tooltips and placement as the library TextContextMenu for consistency. + try + { + if (CodePresenter?.ContextMenu != null) + { + foreach (var item in CodePresenter.ContextMenu.Items.OfType()) + { + if (item.Command == ApplicationCommands.Copy) + { + // Fallback tooltip text for gallery samples. These match the intent of the library descriptions. + item.Header = "Copy"; + item.ToolTip = "Copy the selected content to the clipboard"; + ToolTipService.SetInitialShowDelay(item, 700); + ToolTipService.SetShowDuration(item, 10000); + System.Windows.Controls.ToolTipService.SetPlacement(item, System.Windows.Controls.Primitives.PlacementMode.Top); + } + else if (item.Command == ApplicationCommands.SelectAll) + { + item.Header = "Select All"; + item.ToolTip = "Select all content"; + ToolTipService.SetInitialShowDelay(item, 700); + ToolTipService.SetShowDuration(item, 10000); + System.Windows.Controls.ToolTipService.SetPlacement(item, System.Windows.Controls.Primitives.PlacementMode.Top); + } + } + } + } + catch + { + // Swallow any errors here to avoid breaking the sample if localization isn't available. + } } private void CodePresenter_Loaded(object sender, RoutedEventArgs e) From 91cfebb9d50406470c6b87523d875a1b4a13fffd Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 01:28:41 +0700 Subject: [PATCH 03/10] Clean up comments in TextContextMenu.cs Removed comments related to tooltip behavior for Cut and Copy commands. --- source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs index c109ed14..419ce9b4 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs @@ -253,7 +253,6 @@ private void UpdateItems(Control target) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelCut); var cutDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCut); - // Show only the description as tooltip (remove accelerator text) menuItem.ToolTip = cutDescription; ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); @@ -262,10 +261,8 @@ private void UpdateItems(Control target) else if (command == ApplicationCommands.Copy) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelCopy); - // Add a tooltip for long-hover to show description (accelerator removed) var copyDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCopy); menuItem.ToolTip = copyDescription; - // set tooltip timing for long-hover experience ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); ToolTipService.SetPlacement(menuItem, PlacementMode.Top); From 4dab4fea5a3924f1ec5c50cd0b33c39dfdd3ed91 Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 01:29:43 +0700 Subject: [PATCH 04/10] Remove comment for copy command tooltip Removed fallback tooltip comment for copy command. --- .../Controls/SampleCodePresenter.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs index f05915d1..39e14501 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs @@ -129,7 +129,6 @@ private void SampleCodePresenter_Loaded(object sender, RoutedEventArgs e) { if (item.Command == ApplicationCommands.Copy) { - // Fallback tooltip text for gallery samples. These match the intent of the library descriptions. item.Header = "Copy"; item.ToolTip = "Copy the selected content to the clipboard"; ToolTipService.SetInitialShowDelay(item, 700); From 62e311356add806f1bf7cf11c22263d1aa03d5ac Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 01:35:34 +0700 Subject: [PATCH 05/10] Simplify comment in SampleCodePresenter.xaml.cs Removed redundant comment about tooltips in context menu. --- .../Controls/SampleCodePresenter.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs index 39e14501..8b804c78 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs @@ -119,7 +119,7 @@ private void SampleCodePresenter_Loaded(object sender, RoutedEventArgs e) FixAvalonEditScrolling(); - // Ensure the CodePresenter context menu items have the same long-hover, description-only + // Ensure the CodePresenter context menu items have the same long-hover // tooltips and placement as the library TextContextMenu for consistency. try { From 7f469d0a7c735715da1fb78be7ac8671a2ef18cf Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 16:21:07 +0700 Subject: [PATCH 06/10] Enhance recentering tooltips for CodePresenter context menu --- .../Controls/SampleCodePresenter.xaml.cs | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs index 8b804c78..27e1587b 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs @@ -119,29 +119,64 @@ private void SampleCodePresenter_Loaded(object sender, RoutedEventArgs e) FixAvalonEditScrolling(); - // Ensure the CodePresenter context menu items have the same long-hover + // Ensure the CodePresenter context menu items have the same long-hover, description-only // tooltips and placement as the library TextContextMenu for consistency. try { if (CodePresenter?.ContextMenu != null) { + ToolTip BuildCenteredMouseToolTip(string text) + { + var tt = new ToolTip + { + Content = text, + Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse + }; + tt.Opened += (s, e2) => + { + if (s is ToolTip t) + { + t.HorizontalOffset = 0; + t.VerticalOffset = 0; + void ApplyOffsets() + { + const double gap = 32; + t.HorizontalOffset = -t.ActualWidth / 2.0; + t.VerticalOffset = -(t.ActualHeight + gap); + } + + if (t.ActualWidth <= 0 || t.ActualHeight <= 0) + { + t.Dispatcher.BeginInvoke((System.Action)(() => + { + ApplyOffsets(); + })); + } + else + { + ApplyOffsets(); + } + } + }; + return tt; + } + foreach (var item in CodePresenter.ContextMenu.Items.OfType()) { if (item.Command == ApplicationCommands.Copy) { + // Fallback tooltip text for gallery samples. These match the intent of the library descriptions. item.Header = "Copy"; - item.ToolTip = "Copy the selected content to the clipboard"; + item.ToolTip = BuildCenteredMouseToolTip("Copy the selected content to the clipboard"); ToolTipService.SetInitialShowDelay(item, 700); ToolTipService.SetShowDuration(item, 10000); - System.Windows.Controls.ToolTipService.SetPlacement(item, System.Windows.Controls.Primitives.PlacementMode.Top); } else if (item.Command == ApplicationCommands.SelectAll) { item.Header = "Select All"; - item.ToolTip = "Select all content"; + item.ToolTip = BuildCenteredMouseToolTip("Select all content"); ToolTipService.SetInitialShowDelay(item, 700); ToolTipService.SetShowDuration(item, 10000); - System.Windows.Controls.ToolTipService.SetPlacement(item, System.Windows.Controls.Primitives.PlacementMode.Top); } } } From 7b0a68c2b833308772dcab64145200c21daed9af Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 16:23:01 +0700 Subject: [PATCH 07/10] Add centering function for context menu items tooltip This was to avoid the tooltips to not locked into top left corners of menu items --- .../Controls/TextContextMenu.cs | 55 +++++++++++++++---- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs index 419ce9b4..697d3402 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs @@ -249,59 +249,90 @@ private void UpdateItems(Control target) { if (menuItem.Command is RoutedUICommand command) { + // Local helper to build a tooltip that centers horizontally above the mouse cursor + ToolTip BuildCenteredMouseToolTip(string text) + { + var tt = new ToolTip + { + Content = text, + Placement = PlacementMode.Mouse + }; + tt.Opened += (s, e) => + { + if (s is ToolTip t) + { + t.HorizontalOffset = 0; + t.VerticalOffset = 0; + void ApplyOffsets() + { + const double gap = 32; + t.HorizontalOffset = -t.ActualWidth / 2.0; + t.VerticalOffset = -(t.ActualHeight + gap); + } + + if (t.ActualWidth <= 0 || t.ActualHeight <= 0) + { + t.Dispatcher.BeginInvoke((System.Action)(() => + { + ApplyOffsets(); + })); + } + else + { + ApplyOffsets(); + } + } + }; + return tt; + } + if (command == ApplicationCommands.Cut) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelCut); var cutDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCut); - menuItem.ToolTip = cutDescription; + menuItem.ToolTip = BuildCenteredMouseToolTip(cutDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); - ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Copy) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelCopy); var copyDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCopy); - menuItem.ToolTip = copyDescription; + menuItem.ToolTip = BuildCenteredMouseToolTip(copyDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); - ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Paste) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelPaste); var pasteDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionPaste); - menuItem.ToolTip = pasteDescription; + menuItem.ToolTip = BuildCenteredMouseToolTip(pasteDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); - ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Undo) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelUndo); var undoDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionUndo); - menuItem.ToolTip = undoDescription; + menuItem.ToolTip = BuildCenteredMouseToolTip(undoDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); - ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.Redo) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelRedo); var redoDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionRedo); - menuItem.ToolTip = redoDescription; + menuItem.ToolTip = BuildCenteredMouseToolTip(redoDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); - ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } else if (command == ApplicationCommands.SelectAll) { menuItem.Header = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandLabelSelectAll); var selectAllDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionSelectAll); - menuItem.ToolTip = selectAllDescription; + menuItem.ToolTip = BuildCenteredMouseToolTip(selectAllDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); ToolTipService.SetShowDuration(menuItem, 10000); - ToolTipService.SetPlacement(menuItem, PlacementMode.Top); } menuItem.CommandTarget = target; From 431e3e38cd35e0cfae1263c97857eb2fdea0cb63 Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 17:12:04 +0700 Subject: [PATCH 08/10] Remove tooltip show duration for text commands --- source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs index 697d3402..b990396e 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/TextContextMenu.cs @@ -292,7 +292,6 @@ void ApplyOffsets() var cutDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCut); menuItem.ToolTip = BuildCenteredMouseToolTip(cutDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); - ToolTipService.SetShowDuration(menuItem, 10000); } else if (command == ApplicationCommands.Copy) { @@ -300,7 +299,6 @@ void ApplyOffsets() var copyDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionCopy); menuItem.ToolTip = BuildCenteredMouseToolTip(copyDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); - ToolTipService.SetShowDuration(menuItem, 10000); } else if (command == ApplicationCommands.Paste) { @@ -308,7 +306,6 @@ void ApplyOffsets() var pasteDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionPaste); menuItem.ToolTip = BuildCenteredMouseToolTip(pasteDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); - ToolTipService.SetShowDuration(menuItem, 10000); } else if (command == ApplicationCommands.Undo) { @@ -316,7 +313,6 @@ void ApplyOffsets() var undoDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionUndo); menuItem.ToolTip = BuildCenteredMouseToolTip(undoDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); - ToolTipService.SetShowDuration(menuItem, 10000); } else if (command == ApplicationCommands.Redo) { @@ -324,7 +320,6 @@ void ApplyOffsets() var redoDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionRedo); menuItem.ToolTip = BuildCenteredMouseToolTip(redoDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); - ToolTipService.SetShowDuration(menuItem, 10000); } else if (command == ApplicationCommands.SelectAll) { @@ -332,7 +327,6 @@ void ApplyOffsets() var selectAllDescription = ResourceAccessor.GetLocalizedStringResource(SR_TextCommandDescriptionSelectAll); menuItem.ToolTip = BuildCenteredMouseToolTip(selectAllDescription); ToolTipService.SetInitialShowDelay(menuItem, 700); - ToolTipService.SetShowDuration(menuItem, 10000); } menuItem.CommandTarget = target; From 7684675f617cad83b99d6c9fc4032049b28c4223 Mon Sep 17 00:00:00 2001 From: GID Date: Wed, 17 Sep 2025 17:12:47 +0700 Subject: [PATCH 09/10] Remove tooltip show duration for text commands --- .../Controls/SampleCodePresenter.xaml.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs index 27e1587b..778d9391 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs @@ -169,14 +169,12 @@ void ApplyOffsets() item.Header = "Copy"; item.ToolTip = BuildCenteredMouseToolTip("Copy the selected content to the clipboard"); ToolTipService.SetInitialShowDelay(item, 700); - ToolTipService.SetShowDuration(item, 10000); } else if (item.Command == ApplicationCommands.SelectAll) { item.Header = "Select All"; item.ToolTip = BuildCenteredMouseToolTip("Select all content"); ToolTipService.SetInitialShowDelay(item, 700); - ToolTipService.SetShowDuration(item, 10000); } } } From a0c204758b618a68910af7b9db7847775e652170 Mon Sep 17 00:00:00 2001 From: GID Date: Sun, 21 Sep 2025 20:59:28 +0700 Subject: [PATCH 10/10] Try fixing the code conflicts --- .../Controls/SampleCodePresenter.xaml.cs | 71 ++++++++++++++----- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs index 778d9391..8abaea07 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs @@ -72,6 +72,29 @@ public SampleCodePresenter() CodePresenter.TextArea.SelectionBorder = new Pen(Brushes.Transparent, 0); CodePresenter.TextArea.SelectionCornerRadius = 0; CodePresenter.TextArea.SetResourceReference(TextArea.SelectionBrushProperty, ThemeKeys.TextControlSelectionHighlightColorKey); + + // Ensure caret never shows (keep selection & copy) + HideCaretPermanently(); + CodePresenter.TextArea.GotFocus += (s,e)=> HideCaretPermanently(); + CodePresenter.TextArea.TextView.VisualLinesChanged += (s,e)=> HideCaretPermanently(); + } + + private void HideCaretPermanently() + { + // Make sure the editor can still be clicked for selection but caret invisible. + var caret = CodePresenter.TextArea.Caret; + caret.CaretBrush = Brushes.Transparent; + // keep focus off the editor so IME/caret logic does not repaint a visible caret + if (CodePresenter.IsFocused) + { + // Move focus to parent container (still allows mouse selection highlight within AvalonEdit) + var parent = (DependencyObject)CodePresenter.Parent; + while (parent != null && parent is not Control) + { + parent = LogicalTreeHelper.GetParent(parent); + } + (parent as Control)?.Focusable.Equals(true); + } } private static void OnSubstitutionsPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) @@ -119,12 +142,11 @@ private void SampleCodePresenter_Loaded(object sender, RoutedEventArgs e) FixAvalonEditScrolling(); - // Ensure the CodePresenter context menu items have the same long-hover, description-only - // tooltips and placement as the library TextContextMenu for consistency. try { if (CodePresenter?.ContextMenu != null) { + // Local function to build centered tooltip similar to library TextContextMenu style. ToolTip BuildCenteredMouseToolTip(string text) { var tt = new ToolTip @@ -132,9 +154,9 @@ ToolTip BuildCenteredMouseToolTip(string text) Content = text, Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse }; - tt.Opened += (s, e2) => + tt.Opened += (s2, e2) => { - if (s is ToolTip t) + if (s2 is ToolTip t) { t.HorizontalOffset = 0; t.VerticalOffset = 0; @@ -147,7 +169,7 @@ void ApplyOffsets() if (t.ActualWidth <= 0 || t.ActualHeight <= 0) { - t.Dispatcher.BeginInvoke((System.Action)(() => + t.Dispatcher.BeginInvoke((Action)(() => { ApplyOffsets(); })); @@ -161,27 +183,44 @@ void ApplyOffsets() return tt; } + // Apply tooltip/header customization. foreach (var item in CodePresenter.ContextMenu.Items.OfType()) { - if (item.Command == ApplicationCommands.Copy) + if (item.Command == ApplicationCommands.Copy) + { + item.Header = "Copy"; + item.ToolTip = BuildCenteredMouseToolTip("Copy the selected content to the clipboard"); + ToolTipService.SetInitialShowDelay(item, 700); + } + else if (item.Command == ApplicationCommands.SelectAll) + { + item.Header = "Select All"; + item.ToolTip = BuildCenteredMouseToolTip("Select all content"); + ToolTipService.SetInitialShowDelay(item, 700); + } + } + + // Adjust context menu to only show 'Copy' if there is a selection; 'Select All' always visible. + CodePresenter.ContextMenu.Opened += (s, args) => + { + var hasSelection = CodePresenter?.SelectionLength > 0; + foreach (var mi in CodePresenter.ContextMenu.Items.OfType()) + { + if (mi.Command == ApplicationCommands.Copy) { - // Fallback tooltip text for gallery samples. These match the intent of the library descriptions. - item.Header = "Copy"; - item.ToolTip = BuildCenteredMouseToolTip("Copy the selected content to the clipboard"); - ToolTipService.SetInitialShowDelay(item, 700); + mi.Visibility = hasSelection == true ? Visibility.Visible : Visibility.Collapsed; } - else if (item.Command == ApplicationCommands.SelectAll) + else if (mi.Command == ApplicationCommands.SelectAll) { - item.Header = "Select All"; - item.ToolTip = BuildCenteredMouseToolTip("Select all content"); - ToolTipService.SetInitialShowDelay(item, 700); + mi.Visibility = Visibility.Visible; } - } + } + }; } } catch { - // Swallow any errors here to avoid breaking the sample if localization isn't available. + // Exception can happen if the localization resources are not loaded, ignore it. } }