Add button area for primary actions and promote primary actions
- NodeOperations should move to toolbar when listed as primary - NodeOperations should disappear from overflow when promoted - Issue MatterHackers/MCCentral#4820 Add primary actions to objects in the properties panel
This commit is contained in:
parent
27e0d8e0b1
commit
0f370d9bc1
3 changed files with 58 additions and 5 deletions
|
|
@ -268,8 +268,14 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private Dictionary<Type, HashSet<IObject3DEditor>> objectEditorsByType;
|
||||
|
||||
public PopupMenu GetActionMenuForSceneItem(IObject3D selectedItem, InteractiveScene scene, bool addInSubmenu)
|
||||
public PopupMenu GetActionMenuForSceneItem(IObject3D selectedItem, InteractiveScene scene, bool addInSubmenu, IEnumerable<NodeOperation> nodeOperations = null)
|
||||
{
|
||||
// If parameter was not supplied, fall back to unfiltered list of operations
|
||||
if (nodeOperations == null)
|
||||
{
|
||||
nodeOperations = this.Graph.Operations.Values;
|
||||
}
|
||||
|
||||
var popupMenu = new PopupMenu(this.MenuTheme);
|
||||
|
||||
var menuItem = popupMenu.CreateMenuItem("Rename".Localize());
|
||||
|
|
@ -305,7 +311,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
popupMenu.CreateSubMenu("Modify".Localize(), this.MenuTheme, (modifyMenu) =>
|
||||
{
|
||||
foreach (var nodeOperation in this.Graph.Operations.Values)
|
||||
foreach (var nodeOperation in nodeOperations)
|
||||
{
|
||||
foreach (var type in nodeOperation.MappedTypes)
|
||||
{
|
||||
|
|
@ -325,7 +331,7 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
else
|
||||
{
|
||||
foreach (var nodeOperation in this.Graph.Operations.Values)
|
||||
foreach (var nodeOperation in nodeOperations)
|
||||
{
|
||||
foreach (var type in nodeOperation.MappedTypes)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
{
|
||||
public string OperationID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public List<Type> MappedTypes { get; set; }
|
||||
public IEnumerable<Type> MappedTypes { get; set; }
|
||||
public Func<IObject3D, InteractiveScene, Task> Operation { get; set; }
|
||||
public Func<IObject3D, bool> IsEnabled { get; set; }
|
||||
public Func<IObject3D, bool> IsVisible { get; set; }
|
||||
|
|
@ -54,6 +54,8 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public Dictionary<string, NodeOperation> Operations { get; } = new Dictionary<string, NodeOperation>();
|
||||
|
||||
public Dictionary<Type, List<NodeOperation>> PrimaryOperations { get; } = new Dictionary<Type, List<NodeOperation>>();
|
||||
|
||||
public GraphConfig(ApplicationController applicationController)
|
||||
{
|
||||
this.applicationController = applicationController;
|
||||
|
|
|
|||
|
|
@ -125,13 +125,23 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
};
|
||||
toolbar.AddChild(removeButton);
|
||||
|
||||
primaryActionsPanel = new FlowLayoutWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Fit,
|
||||
VAnchor = VAnchor.Center | VAnchor.Fit
|
||||
};
|
||||
|
||||
toolbar.AddChild(primaryActionsPanel);
|
||||
|
||||
overflowButton = new OverflowBar.OverflowMenuButton(theme)
|
||||
{
|
||||
Enabled = scene.SelectedItem != null,
|
||||
};
|
||||
overflowButton.DynamicPopupContent = () =>
|
||||
{
|
||||
return ApplicationController.Instance.GetActionMenuForSceneItem(item, sceneContext.Scene, false);
|
||||
var remainingOperations = ApplicationController.Instance.Graph.Operations.Values.Except(primaryActions);
|
||||
|
||||
return ApplicationController.Instance.GetActionMenuForSceneItem(item, sceneContext.Scene, false, remainingOperations);
|
||||
};
|
||||
toolbar.AddChild(overflowButton);
|
||||
|
||||
|
|
@ -172,6 +182,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private IconButton removeButton;
|
||||
private OverflowBar.OverflowMenuButton overflowButton;
|
||||
private InteractiveScene scene;
|
||||
private FlowLayoutWidget primaryActionsPanel;
|
||||
|
||||
private List<NodeOperation> primaryActions;
|
||||
|
||||
public void SetActiveItem(IObject3D selectedItem)
|
||||
{
|
||||
|
|
@ -192,6 +205,38 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
var selectedItemType = selectedItem.GetType();
|
||||
|
||||
primaryActionsPanel.RemoveAllChildren();
|
||||
|
||||
var graph = ApplicationController.Instance.Graph;
|
||||
if (!graph.PrimaryOperations.TryGetValue(selectedItemType, out primaryActions))
|
||||
{
|
||||
primaryActions = new List<NodeOperation>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loop over primary actions creating a button for each
|
||||
foreach(var primaryAction in primaryActions)
|
||||
{
|
||||
// TODO: Run visible/enable rules on actions, conditionally add/enable as appropriate
|
||||
var button = new IconButton(primaryAction.IconCollector(theme), theme)
|
||||
{
|
||||
//Name = namedAction.Title + " Button",
|
||||
//ToolTipText = namedAction.Title,
|
||||
Margin = theme.ButtonSpacing,
|
||||
BackgroundColor = theme.ToolbarButtonBackground,
|
||||
HoverColor = theme.ToolbarButtonHover,
|
||||
MouseDownColor = theme.ToolbarButtonDown,
|
||||
};
|
||||
|
||||
button.Click += (s, e) =>
|
||||
{
|
||||
primaryAction.Operation.Invoke(item, scene);
|
||||
};
|
||||
|
||||
primaryActionsPanel.AddChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name;
|
||||
|
||||
HashSet<IObject3DEditor> mappedEditors = ApplicationController.Instance.GetEditorsForType(selectedItemType);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue