Filter context menu to item actions only

- Issue MatterHackers/MCCentral#4333
Right click on list view items should not show container actions
This commit is contained in:
John Lewin 2018-10-24 21:10:39 -07:00
parent d4d9a42bbe
commit 5996e7a996
6 changed files with 43 additions and 31 deletions

View file

@ -500,7 +500,7 @@ namespace MatterHackers.MatterControl
private EventHandler unregisterEvents;
private Dictionary<string, List<PrintItemAction>> registeredLibraryActions = new Dictionary<string, List<PrintItemAction>>();
private Dictionary<string, List<LibraryAction>> registeredLibraryActions = new Dictionary<string, List<LibraryAction>>();
private List<SceneSelectionOperation> registeredSceneOperations;
@ -2034,12 +2034,12 @@ namespace MatterHackers.MatterControl
/// </summary>
/// <param name="section">The section to register in</param>
/// <param name="printItemAction">The action to register</param>
public void RegisterLibraryAction(string section, PrintItemAction printItemAction)
public void RegisterLibraryAction(string section, LibraryAction printItemAction)
{
List<PrintItemAction> items;
List<LibraryAction> items;
if (!registeredLibraryActions.TryGetValue(section, out items))
{
items = new List<PrintItemAction>();
items = new List<LibraryAction>();
registeredLibraryActions.Add(section, items);
}
@ -2051,15 +2051,15 @@ namespace MatterHackers.MatterControl
/// </summary>
/// <param name="section">The section to enumerate</param>
/// <returns></returns>
public IEnumerable<PrintItemAction> RegisteredLibraryActions(string section)
public IEnumerable<LibraryAction> RegisteredLibraryActions(string section)
{
List<PrintItemAction> items;
List<LibraryAction> items;
if (registeredLibraryActions.TryGetValue(section, out items))
{
return items;
}
return Enumerable.Empty<PrintItemAction>();
return Enumerable.Empty<LibraryAction>();
}
public IEnumerable<SceneSelectionOperation> RegisteredSceneOperations => registeredSceneOperations;

View file

@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
private GuiWidget providerMessageContainer;
private TextWidget providerMessageWidget;
private List<PrintItemAction> menuActions = new List<PrintItemAction>();
private List<LibraryAction> menuActions = new List<LibraryAction>();
private FolderBreadCrumbWidget breadCrumbWidget;
private GuiWidget searchInput;
@ -568,9 +568,9 @@ namespace MatterHackers.MatterControl.PrintLibrary
providerMessageContainer.AddChild(providerMessageWidget);
}
public static void CreateMenuActions(ListView libraryView, List<PrintItemAction> menuActions, PartPreviewContent partPreviewContent, ThemeConfig theme, bool allowPrint)
public static void CreateMenuActions(ListView libraryView, List<LibraryAction> menuActions, PartPreviewContent partPreviewContent, ThemeConfig theme, bool allowPrint)
{
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListView)
{
Icon = AggContext.StaticData.LoadIcon("cube.png", 16, 16, ApplicationController.Instance.MenuTheme.InvertIcons),
Title = "Add".Localize(),
@ -598,7 +598,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
IsEnabled = (s, l) => libraryView.ActiveContainer is ILibraryWritableContainer
});
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListView)
{
Title = "Create Folder".Localize(),
Icon = AggContext.StaticData.LoadIcon("fa-folder-new_16.png", 16, 16, ApplicationController.Instance.MenuTheme.InvertIcons),
@ -632,7 +632,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
if (allowPrint)
{
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Print".Localize(),
Action = (selectedLibraryItems, listView) =>
@ -686,7 +686,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
}
// Open menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Open".Localize(),
Icon = AggContext.StaticData.LoadIcon("cube.png", 16, 16, theme.InvertIcons),
@ -707,7 +707,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
});
// edit menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Add to Bed".Localize(),
Icon = AggContext.StaticData.LoadIcon("bed_add.png", 16, 16, theme.InvertIcons),
@ -747,7 +747,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
});
// edit menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Edit".Localize(),
Action = async (selectedLibraryItems, listView) =>
@ -787,7 +787,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
});
// rename menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Rename".Localize(),
Action = (selectedLibraryItems, listView) =>
@ -833,7 +833,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
});
// move menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Move".Localize(),
Action = (selectedLibraryItems, listView) =>
@ -868,7 +868,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
});
// remove menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Remove".Localize(),
Action = (selectedLibraryItems, listView) =>
@ -917,7 +917,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
menuActions.Add(new MenuSeparator("Export"));
// export menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Export".Localize(),
Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, theme.InvertIcons),
@ -938,7 +938,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
});
// share menu item
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Share".Localize(),
Action = (selectedLibraryItems, listView) =>
@ -967,7 +967,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
// PDF export is limited to Windows
if (AggContext.OperatingSystem == OSType.Windows)
{
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Create Part Sheet".Localize(),
Action = (selectedLibraryItems, listView) =>
@ -1014,7 +1014,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
}
#endif
menuActions.Add(new PrintItemAction()
menuActions.Add(new LibraryAction(ActionScope.ListItem)
{
Title = "Open Package".Localize(),
Action = (selectedItems, listView) =>

View file

@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
private Color loadingBackgroundColor;
private ImageSequenceWidget loadingIndicator;
public List<PrintItemAction> MenuActions { get; set; }
public List<LibraryAction> MenuActions { get; set; }
// Default constructor uses IconListView
public ListView(ILibraryContext context, ThemeConfig theme)

View file

@ -344,7 +344,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
var menu = new PopupMenu(ApplicationController.Instance.MenuTheme);
foreach (var menuAction in this.listViewItem.ListView.MenuActions)
foreach (var menuAction in this.listViewItem.ListView.MenuActions.Where(m => m.Scope == ActionScope.ListItem))
{
if (menuAction is MenuSeparator)
{

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, John Lewin
Copyright (c) 2018, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -30,15 +30,25 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PartPreviewWindow;
namespace MatterHackers.MatterControl.PrintQueue
{
public class PrintItemAction
public enum ActionScope
{
ListItem,
ListView,
None
}
public class LibraryAction
{
public LibraryAction(ActionScope scope)
{
this.Scope = scope;
}
public string Title { get; set; }
public Action<IEnumerable<ILibraryItem>, ListView> Action { get; set; }
@ -46,17 +56,19 @@ namespace MatterHackers.MatterControl.PrintQueue
public Func<IEnumerable<ListViewItem>, ListView, bool> IsEnabled { get; set; }
public string ToolTipText { get; internal set; }
public ImageBuffer Icon { get; internal set; }
public ActionScope Scope { get; }
}
public class MenuSeparator : PrintItemAction
public class MenuSeparator : LibraryAction
{
public MenuSeparator(string section)
: base(ActionScope.None)
{
}
}
public abstract class PrintItemMenuExtension
{
public abstract IEnumerable<PrintItemAction> GetMenuItems();
public abstract IEnumerable<LibraryAction> GetMenuItems();
}
}

View file

@ -57,7 +57,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
private GuiWidget providerMessageContainer;
private TextWidget providerMessageWidget;
private List<PrintItemAction> menuActions = new List<PrintItemAction>();
private List<LibraryAction> menuActions = new List<LibraryAction>();
private FolderBreadCrumbWidget breadCrumbWidget;
private GuiWidget searchInput;