//-------------------------------------------------------------------------------------- void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) { ContextMenuStrip.Items.Clear(); ToolStripMenuItem menuItem; TaxonTreeNode taxon = GetSelected(); if (taxon != null) { menuItem = new ToolStripMenuItem(Localization.Manager.Get("_GotoTaxon", "Goto {0}", taxon.Desc.RefMainName), null, new System.EventHandler(OnGoto)); ContextMenuStrip.Items.Add(menuItem); menuItem = new ToolStripMenuItem(Localization.Manager.Get("_SelectTaxon", "Select {0}", taxon.Desc.RefMainName), null, new System.EventHandler(OnSelect)); ContextMenuStrip.Items.Add(menuItem); menuItem = new ToolStripMenuItem(Localization.Manager.Get("_SelectTaxonAndSetAsNewRoot", "Select and set as new root {0}", taxon.Desc.RefMainName), null, new System.EventHandler(OnSelectAndSetAsNewRoot)); ContextMenuStrip.Items.Add(menuItem); menuItem = TaxonUtils.FavoritesMenuItem(taxon); if (menuItem != null) { ContextMenuStrip.Items.Add(new ToolStripSeparator()); ContextMenuStrip.Items.Add(menuItem); } } if (CanBeSorted) { List <TaxonTreeNode> list = DataSource as List <TaxonTreeNode>; if (list.Count > 1) { if (ContextMenuStrip.Items.Count > 0) { ContextMenuStrip.Items.Add(new ToolStripSeparator()); } menuItem = new ToolStripMenuItem(Localization.Manager.Get("_Sort", "Sort")); menuItem.DropDownItems.Add(Localization.Manager.Get("_SortAlpha", "Alpha"), null, new System.EventHandler(OnSort)); menuItem.DropDownItems.Add(Localization.Manager.Get("_SortReverseAlpha", "Reverse Alpha"), null, new System.EventHandler(OnSort)); menuItem.DropDownItems.Add(Localization.Manager.Get("_SortTree", "Tree"), null, new System.EventHandler(OnSort)); menuItem.DropDownItems.Add(Localization.Manager.Get("_SortReverseTree", "Reverse Tree"), null, new System.EventHandler(OnSort)); ContextMenuStrip.Items.Add(menuItem); } } e.Cancel = ContextMenuStrip.Items.Count == 0; }
public bool Build(ContextMenuStrip _menu) { if (Taxon == null) { return(false); } ToolStripMenuItem menuItem; // goto menuItem = new ToolStripMenuItem( Localization.Manager.Get("_GotoTaxon", "Goto {0}", Taxon.Desc.RefMainName), null, new System.EventHandler(OnGoto)) { Tag = Taxon }; _menu.Items.Add(menuItem); // select if (TaxonUtils.SelectedTaxon() != Taxon) { menuItem = new ToolStripMenuItem( Localization.Manager.Get("_SelectTaxon", "Select {0}", Taxon.Desc.RefMainName), null, new System.EventHandler(OnSelect)) { Tag = Taxon }; _menu.Items.Add(menuItem); } // ascendants List <TaxonTreeNode> Ascendants = new List <TaxonTreeNode>(); Taxon.GetAllParents(Ascendants, false, false, false); if (Ascendants.Count > 0) { menuItem = new ToolStripMenuItem(Localization.Manager.Get("_SelectAscendant", "Select ascendant")); _menu.Items.Add(menuItem); foreach (TaxonTreeNode node in Ascendants) { ToolStripMenuItem subMenuItem = new ToolStripMenuItem( node.Desc.RefMainName, null, new System.EventHandler(OnSelect)) { Tag = node }; menuItem.DropDownItems.Add(subMenuItem); } } // add open image if ImagePath has been setup string imagePath = ImageDesc?.GetPath(Taxon.Desc); if (imagePath != null) { _menu.Items.Add(new ToolStripSeparator()); menuItem = new ToolStripMenuItem( Localization.Manager.Get("_OpenImage", "Open image {0}", imagePath), null, new EventHandler(OnOpenImage)) { Tag = imagePath }; _menu.Items.Add(menuItem); menuItem = new ToolStripMenuItem( Localization.Manager.Get("_LocateImage", "Locate image in explorer"), null, new EventHandler(OnLocateImage)) { Tag = imagePath }; _menu.Items.Add(menuItem); } // add favorite menu menuItem = TaxonUtils.FavoritesMenuItem(Taxon); if (menuItem != null) { _menu.Items.Add(new ToolStripSeparator()); _menu.Items.Add(menuItem); } menuItem = BuildAdvanced(); if (menuItem != null) { _menu.Items.Add(new ToolStripSeparator()); _menu.Items.Add(menuItem); } return(true); }