Changed cut copy past menu items into a grouped item

This commit is contained in:
LarsBrubaker 2020-05-29 19:08:41 -07:00
parent 5455078127
commit a42be48de0
8 changed files with 123 additions and 71 deletions

View file

@ -60,6 +60,11 @@ namespace MatterHackers.MatterControl
public Action<bool> SetIsActive { get; set; }
}
public class NamedActionGroup : NamedAction
{
public NamedAction[] Group { get; set; }
}
public static class NamedActionExtensions
{
public static void Add(this List<NamedAction> list, string title, Action action)

View file

@ -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()
{

View file

@ -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();
};
}
}
}
}

View file

@ -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<bool> getter, Action<bool> setter, bool useRadioStyle = false, IList<GuiWidget> 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);

View file

@ -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);
}

View file

@ -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:

View file

@ -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);
}

View file

@ -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(),