From 15208178b11f3f0aaba2e929e42e4ff22ae18dec Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 25 Jul 2020 08:41:25 -0700 Subject: [PATCH] More work on right click text widget menu --- .../ActionBar/TemperatureWidgetExtruder.cs | 1 - .../ApplicationView/Application.cs | 56 +++++++++++++++++++ .../PartPreviewWindow/PopupMenu.cs | 2 +- Submodules/agg-sharp | 2 +- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/MatterControlLib/ActionBar/TemperatureWidgetExtruder.cs b/MatterControlLib/ActionBar/TemperatureWidgetExtruder.cs index cb0e4a209..f40755aa5 100644 --- a/MatterControlLib/ActionBar/TemperatureWidgetExtruder.cs +++ b/MatterControlLib/ActionBar/TemperatureWidgetExtruder.cs @@ -411,7 +411,6 @@ namespace MatterHackers.MatterControl.ActionBar } else // put in a temperature selector for the correct material { - } // put in the actual extruder controls diff --git a/MatterControlLib/ApplicationView/Application.cs b/MatterControlLib/ApplicationView/Application.cs index dd49e9560..5215f011f 100644 --- a/MatterControlLib/ApplicationView/Application.cs +++ b/MatterControlLib/ApplicationView/Application.cs @@ -544,9 +544,65 @@ namespace MatterHackers.MatterControl ReportStartupProgress(0, "ShowAsSystemWindow"); + AddTextWidgetRightClickMenu(); + return systemWindow; } + private static void AddTextWidgetRightClickMenu() + { + InternalTextEditWidget.DefaultRightClick += (s, e) => + { + var theme = ApplicationController.Instance.MenuTheme; + var popupMenu = new PopupMenu(theme); + + var cut = popupMenu.CreateMenuItem("Cut".Localize()); + cut.Enabled = !string.IsNullOrEmpty(s.Selection); + cut.Click += (s2, e2) => + { + if (s2 is InternalTextEditWidget textWidget) + { + textWidget.CopySelection(); + textWidget.DeleteSelection(); + } + }; + + var copy = popupMenu.CreateMenuItem("Copy".Localize()); + copy.Enabled = !string.IsNullOrEmpty(s.Selection); + copy.Click += (s2, e2) => + { + if (s2 is InternalTextEditWidget textWidget) + { + textWidget.CopySelection(); + } + }; + + var paste = popupMenu.CreateMenuItem("Paste".Localize()); + paste.Enabled = Clipboard.Instance.ContainsText; + paste.Click += (s2, e2) => + { + if (s2 is InternalTextEditWidget textWidget) + { + textWidget.PasteFromClipboard(); + } + }; + + popupMenu.CreateSeparator(); + + var selectAll = popupMenu.CreateMenuItem("Select All".Localize()); + selectAll.Enabled = Clipboard.Instance.ContainsText; + selectAll.Click += (s2, e2) => + { + if (s2 is InternalTextEditWidget textWidget) + { + textWidget.SelectAll(); + } + }; + + popupMenu.ShowMenu(s, e); + }; + } + private static void SystemWindow_KeyPressed(object sender, KeyPressEventArgs keyEvent) { if (sender is SystemWindow systemWindow) diff --git a/MatterControlLib/PartPreviewWindow/PopupMenu.cs b/MatterControlLib/PartPreviewWindow/PopupMenu.cs index 62fb2b638..54b24cde7 100644 --- a/MatterControlLib/PartPreviewWindow/PopupMenu.cs +++ b/MatterControlLib/PartPreviewWindow/PopupMenu.cs @@ -507,7 +507,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public static void ShowMenu(this PopupMenu popupMenu, GuiWidget anchorWidget, Vector2 menuPosition) { var systemWindow = anchorWidget.Parents().FirstOrDefault(); - anchorWidget.Parents().FirstOrDefault().ToolTipManager.Clear(); + systemWindow.ToolTipManager.Clear(); systemWindow.ShowPopup( new MatePoint(anchorWidget) { diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 41626f6bb..f1ecc6df8 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 41626f6bb39349208b13c0645b4f9dae3b003bd4 +Subproject commit f1ecc6df8707f9c2944c11c651e7401bf8beeb95