From a42be48de0ce3fcfe0e3ae70fcbfc10ed2892740 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Fri, 29 May 2020 19:08:41 -0700 Subject: [PATCH] Changed cut copy past menu items into a grouped item --- MatterControl.Printing/NamedAction.cs | 5 ++ .../ApplicationView/ApplicationController.cs | 61 ++++++------- .../ApplicationView/Themes/ThemeConfig.cs | 88 +++++++++++++++---- .../PartPreviewWindow/PopupMenu.cs | 19 ++-- .../SystemWindowExtension.cs | 2 +- .../View3D/PrinterBar/PrinterActionsBar.cs | 5 +- .../PartPreviewWindow/View3D/View3DWidget.cs | 10 +-- .../PartPreviewWindow/ViewControls3D.cs | 4 +- 8 files changed, 123 insertions(+), 71 deletions(-) diff --git a/MatterControl.Printing/NamedAction.cs b/MatterControl.Printing/NamedAction.cs index 9f81d072e..ab0103aee 100644 --- a/MatterControl.Printing/NamedAction.cs +++ b/MatterControl.Printing/NamedAction.cs @@ -60,6 +60,11 @@ namespace MatterHackers.MatterControl public Action SetIsActive { get; set; } } + public class NamedActionGroup : NamedAction + { + public NamedAction[] Group { get; set; } + } + public static class NamedActionExtensions { public static void Add(this List list, string title, Action action) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 86951f40e..e23ddc131 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -319,9 +319,7 @@ namespace MatterHackers.MatterControl var actions = new[] { new ActionSeparator(), - workspaceActions["Cut"], - workspaceActions["Copy"], - workspaceActions["Paste"], + workspaceActions["Edit"], new ActionSeparator(), new NamedAction() { @@ -578,7 +576,7 @@ namespace MatterHackers.MatterControl if (e.Operation != WorkspacesChangedEventArgs.OperationType.Restore) { - UiThread.RunOnIdle(async() => + UiThread.RunOnIdle(async () => { await ApplicationController.Instance.PersistUserTabs(); }); @@ -1158,38 +1156,35 @@ namespace MatterHackers.MatterControl || (sceneContext.EditContext.SourceItem is ILibraryAsset libraryAsset && string.Equals(Path.GetExtension(libraryAsset.FileName), ".gcode", StringComparison.OrdinalIgnoreCase)) }, - new NamedAction() + new NamedActionGroup() { - ID = "Cut", - Title = "Cut".Localize(), - Shortcut = "Ctrl+X", - Action = () => + ID = "Edit", + Title = "Edit", + Group = new NamedAction[] { - sceneContext.Scene.Cut(); + new NamedAction() + { + ID = "Cut", + Title = "Cut".Localize(), + Action = () => sceneContext.Scene.Cut(), + IsEnabled = () => sceneContext.Scene.SelectedItem != null + }, + new NamedAction() + { + ID = "Copy", + Title = "Copy".Localize(), + Action = () => sceneContext.Scene.Copy(), + IsEnabled = () => sceneContext.Scene.SelectedItem != null + }, + new NamedAction() + { + ID = "Paste", + Title = "Paste".Localize(), + Action = () => sceneContext.Paste(), + IsEnabled = () => Clipboard.Instance.ContainsImage || Clipboard.Instance.GetText() == "!--IObjectSelection--!" + } }, - IsEnabled = () => sceneContext.Scene.SelectedItem != null - }, - new NamedAction() - { - ID = "Copy", - Title = "Copy".Localize(), - Shortcut = "Ctrl+C", - Action = () => - { - sceneContext.Scene.Copy(); - }, - IsEnabled = () => sceneContext.Scene.SelectedItem != null - }, - new NamedAction() - { - ID = "Paste", - Title = "Paste".Localize(), - Shortcut = "Ctrl+V", - Action = () => - { - sceneContext.Paste(); - }, - IsEnabled = () => Clipboard.Instance.ContainsImage || Clipboard.Instance.GetText() == "!--IObjectSelection--!" + IsEnabled = () => true, }, new NamedAction() { diff --git a/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs b/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs index 790772b16..c837c9c58 100644 --- a/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs +++ b/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs @@ -415,30 +415,82 @@ namespace MatterHackers.MatterControl } else { - PopupMenu.MenuItem menuItem; - - if (menuAction is NamedBoolAction boolAction) + if (menuAction is NamedActionGroup namedActionButtons) { - menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive); + var content = new FlowLayoutWidget() + { + HAnchor = HAnchor.Fit | HAnchor.Stretch + }; + + var textWidget = new TextWidget(menuAction.Title, pointSize: this.DefaultFontSize, textColor: this.TextColor) + { + // Padding = MenuPadding, + VAnchor = VAnchor.Center + }; + content.AddChild(textWidget); + + content.AddChild(new HorizontalSpacer()); + + foreach (var actionButton in namedActionButtons.Group) + { + var button = new TextButton(actionButton.Title, this) + { + Border = new BorderDouble(1, 0, 0, 0), + BorderColor = this.MinimalShade, + HoverColor = this.AccentMimimalOverlay + }; + + content.AddChild(button); + + if (actionButton.IsEnabled()) + { + button.Click += (s, e) => + { + actionButton.Action(); + popupMenu.Unfocus(); + }; + } + } + + var menuItem = new PopupMenu.MenuItem(content, this) + { + HAnchor = HAnchor.Fit | HAnchor.Stretch, + VAnchor = VAnchor.Fit, + HoverColor = Color.Transparent, + }; + popupMenu.AddChild(menuItem); + menuItem.Padding = new BorderDouble(menuItem.Padding.Left, + menuItem.Padding.Bottom, + 0, + menuItem.Padding.Top); } else { - menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut); - } + PopupMenu.MenuItem menuItem; - menuItem.Name = $"{menuAction.Title} Menu Item"; - - menuItem.Enabled = menuAction.Action != null - && menuAction.IsEnabled?.Invoke() != false; - - menuItem.ClearRemovedFlag(); - - if (menuItem.Enabled) - { - menuItem.Click += (s, e) => + if (menuAction is NamedBoolAction boolAction) { - menuAction.Action(); - }; + menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive); + } + else + { + menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut); + } + + menuItem.Name = $"{menuAction.Title} Menu Item"; + + menuItem.Enabled = menuAction is NamedActionGroup + || (menuAction.Action != null && menuAction.IsEnabled?.Invoke() != false); + + menuItem.ClearRemovedFlag(); + + if (menuItem.Enabled) + { + menuItem.Click += (s, e) => + { + menuAction.Action(); + }; + } } } } diff --git a/MatterControlLib/PartPreviewWindow/PopupMenu.cs b/MatterControlLib/PartPreviewWindow/PopupMenu.cs index 3ab89b198..8f9321557 100644 --- a/MatterControlLib/PartPreviewWindow/PopupMenu.cs +++ b/MatterControlLib/PartPreviewWindow/PopupMenu.cs @@ -123,7 +123,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { public PopupMenu SubMenu { get; set; } - public SubMenuItemButton(GuiWidget content, ThemeConfig theme) : base(content, theme) { } @@ -308,7 +307,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow UiThread.RunOnIdle(() => { populateSubMenu(subMenu); - + systemWindow.ShowPopup( new MatePoint(subMenuItemButton) { @@ -319,15 +318,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { Mate = new MateOptions(MateEdge.Left, MateEdge.Top), AltMate = new MateOptions(MateEdge.Right, MateEdge.Top) - } - );// altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1)); + }); // altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1)); }); subMenu.Closed += (s1, e1) => { subMenu.ClearRemovedFlag(); subMenuItemButton.SubMenu = null; - if(!this.ContainsFocus) + if (!this.ContainsFocus) { this.Close(); } @@ -365,7 +363,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public MenuItem CreateBoolMenuItem(GuiWidget guiWidget, string name, Func getter, Action setter, bool useRadioStyle = false, IList siblingRadioButtonList = null) { - bool isChecked = (getter?.Invoke() == true); + bool isChecked = getter?.Invoke() == true; MenuItem menuItem; @@ -397,7 +395,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow return; } - isChecked = radioMenu.Checked = !radioMenu.Checked; + isChecked = radioMenu.Checked = !radioMenu.Checked; } else if (menuItem is CheckboxMenuItem checkboxMenu) { @@ -433,10 +431,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private GuiWidget content; public MenuItem(GuiWidget content, ThemeConfig theme) - : base (theme) + : base(theme) { // Inflate padding to match the target (MenuGutterWidth) after scale operation in assignment - this.Padding = new BorderDouble(left: Math.Ceiling(theme.MenuGutterWidth / GuiWidget.DeviceScale) , right: 15); + this.Padding = new BorderDouble(left: Math.Ceiling(theme.MenuGutterWidth / DeviceScale), right: 15); this.HAnchor = HAnchor.MaxFitOrStretch; this.VAnchor = VAnchor.Fit; this.MinimumSize = new Vector2(150 * GuiWidget.DeviceScale, theme.ButtonHeight); @@ -455,6 +453,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public ImageBuffer Image { get; set; } private ImageBuffer _disabledImage; + public ImageBuffer DisabledImage { get @@ -491,7 +490,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var x = this.LocalBounds.Left + (this.GutterWidth / 2 - this.Image.Width / 2); var y = this.Size.Y / 2 - this.Image.Height / 2; - graphics2D.Render((this.Enabled) ? this.Image : this.DisabledImage, (int)x, (int)y); + graphics2D.Render(this.Enabled ? this.Image : this.DisabledImage, (int)x, (int)y); } base.OnDraw(graphics2D); diff --git a/MatterControlLib/PartPreviewWindow/SystemWindowExtension.cs b/MatterControlLib/PartPreviewWindow/SystemWindowExtension.cs index 446c659f2..ae3925ea4 100644 --- a/MatterControlLib/PartPreviewWindow/SystemWindowExtension.cs +++ b/MatterControlLib/PartPreviewWindow/SystemWindowExtension.cs @@ -191,7 +191,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // When the widgets position changes, sync the popup position systemWindow?.AddChild(popup.Widget); - if(secondsToClose > 0) + if (secondsToClose > 0) { UiThread.RunOnIdle(() => anchor_Closed(null, null), secondsToClose); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs index 2edf75138..02000e57b 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs @@ -240,6 +240,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } bool buttonIsBeingClicked; + private void SwitchModes_Click(object sender, MouseEventArgs e) { buttonIsBeingClicked = true; @@ -260,6 +261,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow printer.ViewState.ViewMode = PartViewMode.Model; } } + buttonIsBeingClicked = false; } @@ -363,7 +365,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Title = "Restore Settings".Localize(), Action = () => { - DialogWindow.Show(new PrinterProfileHistoryPage(printer)); } }, @@ -445,6 +446,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow DialogWindow.Show(repetierEEPromPage); } + break; case FirmwareTypes.Marlin: @@ -462,6 +464,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow DialogWindow.Show(marlinEEPromPage); } + break; default: diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index a44151a5d..dd05f96a8 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -1537,12 +1537,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow new MatePoint(this) { Mate = new MateOptions(MateEdge.Left, MateEdge.Top), - AltMate = new MateOptions(MateEdge.Left, MateEdge.Top) + AltMate = new MateOptions(MateEdge.Right, MateEdge.Bottom) }, new MatePoint(menu) { Mate = new MateOptions(MateEdge.Left, MateEdge.Top), - AltMate = new MateOptions(MateEdge.Left, MateEdge.Top) + AltMate = new MateOptions(MateEdge.Right, MateEdge.Bottom) }, altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1)); } @@ -1585,12 +1585,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow new MatePoint(this) { Mate = new MateOptions(MateEdge.Left, MateEdge.Bottom), - AltMate = new MateOptions(MateEdge.Left, MateEdge.Top) + AltMate = new MateOptions(MateEdge.Right, MateEdge.Top) }, new MatePoint(popupMenu) { - Mate = new MateOptions(MateEdge.Left, MateEdge.Top), - AltMate = new MateOptions(MateEdge.Left, MateEdge.Top) + Mate = new MateOptions(MateEdge.Left, MateEdge.Bottom), + AltMate = new MateOptions(MateEdge.Right, MateEdge.Top) }, altBounds: popupBounds); } diff --git a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs index a0e551cdd..0446a4c11 100644 --- a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs +++ b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs @@ -574,9 +574,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var actions = new NamedAction[] { new ActionSeparator(), - workspaceActions["Cut"], - workspaceActions["Copy"], - workspaceActions["Paste"], + workspaceActions["Edit"], new ActionSeparator(), workspaceActions["Print"], new ActionSeparator(),