/// <inheritdoc /> protected override void OnAfterSelect(TreeViewEventArgs e) { base.OnAfterSelect(e); _lastSelectedDataObject = e.Node.Tag; // TODO Add try-catch if (SelectionChanged != null) { SelectionChanged(this, new SelectionEventArgs { Selection = SelectedNode.Tag }); } if (ContextMenuItemProvider != null) { IContextMenuItem[] items = ContextMenuItemProvider(SelectedNode.Tag); ContextMenuStrip ctxMenuStrip = items == null ? null : new ContextMenuStrip(); SelectedNode.ContextMenuStrip = ctxMenuStrip; if (items != null) { for (int i = -1; ++i != items.Length;) { IContextMenuItem item = items[i]; ctxMenuStrip.Items.Add(new ToolStripMenuItem(item.Name, null, (sender, args) => item.Action(SelectedNode.Tag))); } } } }
private void MenuButton_Click(object sender, EventArgs e) { //Prepare IMenuButton <MapFile, IndexEntry, Xbox> menuItem = null; IContextMenuItem <MapFile, IndexEntry, Xbox> contextMenuItem = null; //Get Sender if (sender is ToolStripItem) { //Get ToolStripItem Sender = (ToolStripItem)sender; if (Sender.Tag is IMenuButton <MapFile, IndexEntry, Xbox> ) { menuItem = (IMenuButton <MapFile, IndexEntry, Xbox>)Sender.Tag; } if (Sender.Tag is IContextMenuItem <MapFile, IndexEntry, Xbox> ) { contextMenuItem = (IContextMenuItem <MapFile, IndexEntry, Xbox>)Sender.Tag; } } //Click menuItem?.OnClick(); contextMenuItem?.OnClick(); }
public void AppendContextMenuItems(System.Windows.Forms.ContextMenuStrip strip, object context) { PlugInManager compMan = new PlugInManager(); List<IOrder> items = new List<IOrder>(); foreach (XmlNode toolNode in compMan.GetPluginNodes(Plugins.Type.IExTool)) { IContextMenuItem item = compMan.CreateInstance(toolNode) as IContextMenuItem; if (item == null || !item.ShowWith(context) || !(item is IExTool)) continue; ((IExTool)item).OnCreate(_application); items.Add(item); } items.Sort(new SortByIOrder()); int l = -1; foreach (IContextMenuItem item in items) { if (Math.Abs(l - (int)(item.SortOrder / 10)) != 0) { l = item.SortOrder / 10; if (strip.Items.Count > 0) strip.Items.Add(new System.Windows.Forms.ToolStripSeparator()); } ToolMenuItem toolItem = new ToolMenuItem(item as IExTool); toolItem.Click += new EventHandler(ToolButton_Click); strip.Items.Add(toolItem); } }
private void PlatformAdd(int i, IContextMenuItem newItem) { UnderlyingContextMenu.Items.Insert(i, ToConcreteContextItem(newItem)); if (_parentItem != null) { _parentItem.DropDownItems.Insert(i, ToConcreteContextItem(newItem)); } }
public void OpenSubMenu(IContextMenuItem subMenuItem) { // Find Item ContextMenuCardController cardController = m_CardControllers[subMenuItem.Id]; Vector3 position = cardController.transform.position + new Vector3(m_size.x / 2, 0); // Create a new submenu at its spot _SubMenu = ContextMenuManager.Instance.CreateContextMenu(Camera.main.ScreenToWorldPoint(position), subMenuItem.GetSubMenu(), this); }
private void Factory_InitializeContextMenuItem(AddOnFactory factory, string assemblyName, string typeFullName, IHost host) { //Create IContextMenuItem <TMap, TEntry, TXbox> contextMenuItem = factory.CreateInstance <IContextMenuItem <TMap, TEntry, TXbox> >(assemblyName, typeFullName); contextMenuItem.Initialize(host); //Add addOns.Add(contextMenuItem); haloAddOns.Add(contextMenuItem); contextMenuItems.Add(contextMenuItem); }
public void Init(IContextMenuItem item, IContextMenuController ContextMenuController) { Item = item; m_DisplayText.text = Item.GetDisplayString(); if (Item.HasSubMenu()) { m_Button.onClick.AddListener(() => { ContextMenuController.OpenSubMenu(item); }); } else { m_Button.onClick.AddListener(() => { Item.GetAction()?.Invoke(); ContextMenuController.CloseMenu(); }); } }
private void PlatformAddSpecific(NSMenu menu, nint i, IContextMenuItem newItem) { UnderlyingContextMenu.InsertItem(ToConcreteMenuItem(newItem), i); if (newItem is IContextMenu subMenu) { NSMenu platformSubMenu = new NSMenu(); foreach (var subMenuItem in subMenu.ItemsSource) { nint subMenuIndex = 0; PlatformAddSpecific(platformSubMenu, subMenuIndex, subMenuItem); } } }
private IEnumerable <object> LoadContextMenuNodes(Type fromType) { var result = new List <object>(); OrderingCollection <IContextMenuItem> orderedItems = CompositionProvider.GetOrderedExports <IContextMenuItem>(fromType); foreach (var item in orderedItems) { IContextMenuItem menuItem = item.Value; menuItem.SetupItem(this); result.Add(menuItem); } return(result); }
private NSMenuItem ToConcreteMenuItem(IContextMenuItem item) { switch (item) { case IContextMenuButton button: return(new NSMenuItem(button.Label, button.Clicked)); case IContextMenuSeparator separator: return(NSMenuItem.SeparatorItem); case IContextMenu subMenu: return(new NSMenuItem(subMenu.Label)); default: return(null); } }
private ToolStripItem ToConcreteContextItem(IContextMenuItem item) { switch (item) { case IContextMenuButton button: return(new ToolStripMenuItem(button.Label, null, button.Clicked)); case IContextMenuSeparator separator: return(new ToolStripSeparator()); case IContextMenu menu: var convertedSubItems = menu.ItemsSource.Select(ToConcreteContextItem); var subMenu = new ToolStripMenuItem(menu.Label); subMenu.DropDownItems.AddRange(convertedSubItems.ToArray()); ContextMenu subMenuPlatformMenu = (ContextMenu)menu; subMenuPlatformMenu._parentItem = subMenu; return(subMenu); default: return(null); } }
public void AppendContextMenuItems(global::System.Windows.Forms.ContextMenuStrip strip, object context) { PlugInManager compMan = new PlugInManager(); List <IOrder> items = new List <IOrder>(); foreach (var toolType in compMan.GetPlugins(gView.Framework.system.Plugins.Type.IExTool)) { IContextMenuItem item = compMan.TryCreateInstance <IContextMenuItem>(toolType); if (item == null || !item.ShowWith(context) || !(item is IExTool)) { continue; } ((IExTool)item).OnCreate(_application); items.Add(item); } items.Sort(new SortByIOrder()); int l = -1; foreach (IContextMenuItem item in items) { if (Math.Abs(l - item.SortOrder / 10) != 0) { l = item.SortOrder / 10; if (strip.Items.Count > 0) { strip.Items.Add(new global::System.Windows.Forms.ToolStripSeparator()); } } ToolMenuItem toolItem = new ToolMenuItem(item as IExTool); toolItem.Click += new EventHandler(ToolButton_Click); strip.Items.Add(toolItem); } }
/// <summary> /// Converts the specified value. /// </summary> /// <param name="value">The value.</param> /// <param name="targetType">Type of the target.</param> /// <param name="parameter">The parameter.</param> /// <param name="culture">The culture.</param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { IContextMenuItem item = value as IContextMenuItem ?? parameter as IContextMenuItem; if (item == null) { return(null); } Grid grid = new Grid(); if (item.Icon != null) { BitmapSource source = Imaging.CreateBitmapSourceFromHIcon( ((Bitmap)Resources.ResourceManager.GetObject(item.Icon, culture)).GetHicon(), Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); grid.Children.Add(new Image { Source = source }); } return(grid); }
/// <summary> /// Удаляет элемент из списка. /// </summary> public void RemoveItem(IContextMenuItem item) { _items.Remove(item.GetControl <FrameworkElement>()); }
/// <summary> /// Добавляет элемент в список. /// </summary> public void AddItem(IContextMenuItem item) { _items.Add(item.GetControl <FrameworkElement>()); }
private void PlatformAdd(int i, IContextMenuItem newItem) => throw new NotImplementedInReferenceAssemblyException();
private void TagTree_AfterSelect(object sender, TreeViewEventArgs e) { //Check if (e.Node.Tag is TagId) { //Setup selectedEntry = map.IndexEntries[(TagId)e.Node.Tag]; TagPropertyGrid.SelectedObject = entries[selectedEntry.Id]; //Send trigger if (!Program.DebugMode) { //If not debug mode, catch exceptions. List <Exception> errors = new List <Exception>(); foreach (var addOn in container.GetHaloAddOns()) { try { addOn.OnSelectedEntryChanged(); } catch (Exception ex) { errors.Add(ex); } } } else { //If debug mode, don't catch exceptions. foreach (var addOn in container.GetHaloAddOns()) { addOn.OnSelectedEntryChanged(); } } //Check Tab Pages foreach (TabPage tabPage in tabPages) { //Get ITabPage ITabPage <MapFile, IndexEntry, Xbox> page = (ITabPage <MapFile, IndexEntry, Xbox>)tabPage.Tag; //Check if (page.ApplyFilter) { if (page.Filter.Contains(selectedEntry.Root)) { if (!tagTabControl.TabPages.ContainsKey(tabPage.Name)) { tagTabControl.TabPages.Add(tabPage); tagTabControl.SelectedTab = tabPage; } } else { tagTabControl.TabPages.RemoveByKey(tabPage.Name); } } } //Check Menu Buttons foreach (ToolStripButton menuButton in menuButtons) { //Get ITabPage IMenuButton <MapFile, IndexEntry, Xbox> button = (IMenuButton <MapFile, IndexEntry, Xbox>)menuButton.Tag; //Check if (button.ApplyFilter) { if (button.Filter.Contains(selectedEntry.Root)) { if (!mapToolStrip.Items.ContainsKey(menuButton.Name)) { mapToolStrip.Items.Add(menuButton); } } else { mapToolStrip.Items.RemoveByKey(menuButton.Name); } } } //Check Context Menu Buttons foreach (ToolStripMenuItem menuItem in contextMenuItems) { //Get IContextMenu IContextMenuItem <MapFile, IndexEntry, Xbox> item = (IContextMenuItem <MapFile, IndexEntry, Xbox>)menuItem.Tag; //Check if (item.ApplyFilter) { if (item.Filter.Contains(selectedEntry.Root)) { if (!tagContextMenu.Items.ContainsKey(menuItem.Name)) { tagContextMenu.Items.Add(menuItem); } } else { tagContextMenu.Items.RemoveByKey(menuItem.Name); } } } } else { TagPropertyGrid.SelectedObject = mapWrapper; } }
public void PlatformAdd(int i, IContextMenuItem newItem) { PlatformAddSpecific(UnderlyingContextMenu, i, newItem); }