Add menu support for OperationGroups
This commit is contained in:
parent
4eeb3964e0
commit
d38a45bea7
3 changed files with 52 additions and 15 deletions
|
|
@ -763,6 +763,7 @@ namespace MatterHackers.MatterControl
|
|||
new SceneSelectionSeparator(),
|
||||
new OperationGroup("Align")
|
||||
{
|
||||
TitleResolver = () => "Align".Localize(),
|
||||
StickySelection = true,
|
||||
Operations = new List<SceneSelectionOperation>()
|
||||
{
|
||||
|
|
@ -871,6 +872,7 @@ namespace MatterHackers.MatterControl
|
|||
},
|
||||
new OperationGroup("Array")
|
||||
{
|
||||
TitleResolver = () => "Array".Localize(),
|
||||
StickySelection = true,
|
||||
Operations = new List<SceneSelectionOperation>()
|
||||
{
|
||||
|
|
@ -914,6 +916,7 @@ namespace MatterHackers.MatterControl
|
|||
},
|
||||
new OperationGroup("ModifyMesh")
|
||||
{
|
||||
TitleResolver = () => "Mesh Modifiers".Localize(),
|
||||
StickySelection = true,
|
||||
Operations = new List<SceneSelectionOperation>()
|
||||
{
|
||||
|
|
@ -955,9 +958,9 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
new OperationGroup("Booleans")
|
||||
{
|
||||
TitleResolver = () => "Booleans".Localize(),
|
||||
StickySelection = true,
|
||||
Operations = new List<SceneSelectionOperation>()
|
||||
{
|
||||
|
|
@ -3278,7 +3281,7 @@ Support and tutorials:
|
|||
VAnchor = VAnchor.Stretch
|
||||
};
|
||||
|
||||
helpDocsTab = new ChromeTab("HelpDocs", "Help".Localize(), tabControl, helpTreePanel, theme, hasClose: false)
|
||||
helpDocsTab = new ChromeTab("HelpDocs", "Help".Localize(), tabControl, helpTreePanel, theme)
|
||||
{
|
||||
MinimumSize = new Vector2(0, theme.TabButtonHeight),
|
||||
Name = "Library Tab",
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
public class OverflowBar : Toolbar
|
||||
{
|
||||
private static HashSet<Type> ignoredTypes = new HashSet<Type> { typeof(HorizontalLine), typeof(SearchInputBox) };
|
||||
private static HashSet<Type> ignoredInMenuTypes = new HashSet<Type> { typeof(VerticalLine), typeof(HorizontalLine), typeof(SearchInputBox), typeof(HorizontalSpacer) };
|
||||
protected static HashSet<Type> ignoredTypes = new HashSet<Type> { typeof(HorizontalLine), typeof(SearchInputBox) };
|
||||
protected static HashSet<Type> ignoredInMenuTypes = new HashSet<Type> { typeof(VerticalLine), typeof(HorizontalLine), typeof(SearchInputBox), typeof(HorizontalSpacer) };
|
||||
|
||||
public OverflowBar(ThemeConfig theme)
|
||||
: this(null, theme)
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private ISceneContext sceneContext;
|
||||
private PartWorkspace workspace;
|
||||
private ViewControls3DButtons activeTransformState = ViewControls3DButtons.PartSelect;
|
||||
private List<(GuiWidget button, SceneSelectionOperation operation)> operationButtons;
|
||||
private Dictionary<GuiWidget, SceneSelectionOperation> operationButtons;
|
||||
private MainViewWidget mainViewWidget = null;
|
||||
private PopupMenuButton bedMenuButton;
|
||||
private ThemeConfig theme;
|
||||
|
|
@ -110,6 +110,43 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
view3DWidget.InteractionLayer.Focus();
|
||||
};
|
||||
|
||||
this.OverflowButton.DynamicPopupContent = () =>
|
||||
{
|
||||
var menuTheme = AppContext.MenuTheme;
|
||||
var popupMenu = new PopupMenu(theme);
|
||||
int i = 0;
|
||||
|
||||
foreach (var widget in this.ActionArea.Children.Where(c => !c.Visible && !ignoredInMenuTypes.Contains(c.GetType())))
|
||||
{
|
||||
if (operationButtons.TryGetValue(widget, out SceneSelectionOperation operation))
|
||||
{
|
||||
if (operation is OperationGroup operationGroup)
|
||||
{
|
||||
popupMenu.CreateSubMenu(
|
||||
operationGroup.Title,
|
||||
menuTheme,
|
||||
(subMenu) =>
|
||||
{
|
||||
foreach (var childOperation in operationGroup.Operations)
|
||||
{
|
||||
var menuItem = subMenu.CreateMenuItem(childOperation.Title, childOperation.Icon(menuTheme.InvertIcons));
|
||||
menuItem.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
childOperation.Action?.Invoke(sceneContext);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
popupMenu.CreateMenuItem(operation.Title, operation.Icon(menuTheme.InvertIcons));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return popupMenu;
|
||||
};
|
||||
|
||||
this.IsPrinterMode = isPrinterType;
|
||||
this.sceneContext = workspace.SceneContext;
|
||||
this.workspace = workspace;
|
||||
|
|
@ -243,7 +280,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
AddChild(partSelectButton);
|
||||
}
|
||||
|
||||
operationButtons = new List<(GuiWidget, SceneSelectionOperation)>();
|
||||
operationButtons = new Dictionary<GuiWidget, SceneSelectionOperation>();
|
||||
|
||||
// Add Selected IObject3D -> Operations to toolbar
|
||||
foreach (var namedAction in ApplicationController.Instance.RegisteredSceneOperations)
|
||||
|
|
@ -311,9 +348,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
});
|
||||
|
||||
groupButton.VisibleChanged += (s, e) => Console.WriteLine();
|
||||
|
||||
|
||||
button = groupButton;
|
||||
}
|
||||
else if (namedAction.Icon != null)
|
||||
|
|
@ -340,7 +374,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
};
|
||||
}
|
||||
|
||||
operationButtons.Add((button, namedAction));
|
||||
operationButtons.Add(button, namedAction);
|
||||
|
||||
// Only bind Click event if not a SplitButton
|
||||
if (!(button is PopupMenuButton))
|
||||
|
|
@ -600,13 +634,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private void Scene_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
// Set enabled level based on operation rules
|
||||
foreach (var item in operationButtons)
|
||||
foreach (var (button, operation) in operationButtons.Select(kvp => (kvp.Key, kvp.Value)))
|
||||
{
|
||||
item.button.Enabled = item.operation.IsEnabled?.Invoke(sceneContext) ?? false;
|
||||
button.Enabled = operation.IsEnabled?.Invoke(sceneContext) ?? false;
|
||||
|
||||
if (item.operation is OperationGroup operationGroup
|
||||
&& item.button is PopupMenuButton splitButton
|
||||
&& item.button.Descendants<IconButton>().FirstOrDefault() is IconButton iconButton)
|
||||
if (operation is OperationGroup operationGroup
|
||||
&& button is PopupMenuButton splitButton
|
||||
&& button.Descendants<IconButton>().FirstOrDefault() is IconButton iconButton)
|
||||
{
|
||||
iconButton.Enabled = operationGroup.GetDefaultOperation().IsEnabled(sceneContext);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue