private void AddCommandToApplicationMenu(IApplication TheApplication, string AddThisCommandGUID, string ToThisMenuGUID, bool StartGroup, string PositionAfterThisCommandGUID, string PositionBeforeThisCommandGUID, bool EndGroup) { if (AddThisCommandGUID.Trim() == "") { return; } if (ToThisMenuGUID.Trim() == "") { return; } //Then add items to the command bar: UID pCommandUID = new UIDClass(); // this references an ICommand from my extension pCommandUID.Value = AddThisCommandGUID; // the ICommand to add //Assign the UID for the menu we want to add the custom button to UID MenuUID = new UIDClass(); MenuUID.Value = ToThisMenuGUID; //Get the target menu as a ICommandBar ICommandBar pCmdBar = TheApplication.Document.CommandBars.Find(MenuUID) as ICommandBar; int iPos = pCmdBar.Count; //for the position string, if it's an empty string then default to end of menu. if (PositionAfterThisCommandGUID.Trim() != "") { UID pPositionCommandUID = new UIDClass(); pPositionCommandUID.Value = PositionAfterThisCommandGUID; iPos = pCmdBar.Find(pPositionCommandUID).Index + 1; } if (iPos == pCmdBar.Count && PositionBeforeThisCommandGUID.Trim() != "") //prioritize the "after" case { UID pPositionCommandUID = new UIDClass(); pPositionCommandUID.Value = PositionBeforeThisCommandGUID; iPos = pCmdBar.Find(pPositionCommandUID).Index; } ICommandItem pCmdItem = pCmdBar.Find(pCommandUID); //Check if it is already present on the context menu... if (pCmdItem == null) { pCmdItem = pCmdBar.Add(pCommandUID, iPos); pCmdItem.Group = StartGroup; pCmdItem.Refresh(); } }
private void AddMenu() { ICommandBar mainMenuBar = GetMainBar(); if (mainMenuBar == null) { return; } string menuID = "BathymetryTools"; ICommandItem cmdItem = mainMenuBar.Find(menuID, false); if (cmdItem != null) { return; } UID uid = new UID(); uid.Value = menuID; Object index = mainMenuBar.Count - 1; ICommandBar menuBathymetry = mainMenuBar.Add(uid, index) as ICommandBar; ICommandItem main = mainMenuBar as ICommandItem; main.Refresh(); }
private void FindGUIDOfCommandItem(IApplication TheApplication, string ParentMenuGUID) { if (ParentMenuGUID.Trim() == "") { return; } //Assign the UID for the menu we want to add the custom button to UID MenuUID = new UIDClass(); MenuUID.Value = ParentMenuGUID; //Get the target menu as a ICommandBar ICommandBar pCmdBar = TheApplication.Document.CommandBars.Find(MenuUID) as ICommandBar; IToolBarDef pToolBarDef = pCmdBar as IToolBarDef; int iCnt = pCmdBar.Count; for (int i = 0; i < iCnt; i++) { //ScrapClass itemdef = new ScrapClass(); //try{pToolBarDef.GetItemInfo(i, itemdef);} catch { continue; } ////print the UID of commandItem //Debug.Print(itemdef.ID.ToString()); //UID uid = new UIDClass(); //uid.Value = itemdef.ID.ToString(); ICommandItem commandItem = pCmdBar.Find("GxCadastralFabricContextMenu"); Debug.Print(": " + commandItem.Name); } }
/// <summary> /// Replaces the <paramref name="oldCommandUid" /> on the toolbar with the <paramref name="newCommandUid" /> /// </summary> /// <param name="source">The source.</param> /// <param name="newCommandUid">The new command uid.</param> /// <param name="oldCommandUid">The old command uid.</param> public static void Replace(this ICommandBar source, UID newCommandUid, UID oldCommandUid) { if (source != null) { ICommandItem command = source.Find(newCommandUid); if (command == null) { ICommandItem item = source.Find(oldCommandUid); if (item != null) { source.Add(newCommandUid, item.Index); item.Delete(); } } } }
/// <summary> /// Adds the command to the source. /// </summary> /// <param name="source">The source.</param> /// <param name="commandUid">The command uid.</param> public static void Add(this ICommandBar source, UID commandUid) { if (source != null) { ICommandItem command = source.Find(commandUid); if (command == null) { source.Add(commandUid); } } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add SetupContextMenu.OnClick implementation IDocument pDoc = m_application.Document; ICommandBars pCommandBars = pDoc.CommandBars; UID featureclassContextMenu = new UID(); featureclassContextMenu.Value = "esriCatalogUI.GxEnterpriseFeatureClassContextMenu"; UID getfeaturecountContextMenu = new UID(); getfeaturecountContextMenu.Value = "MyFirstFancyContextMenu.GetFeatureCountMenuContext"; ICommandBar pFeatureClassContextMenu = pCommandBars.Find(featureclassContextMenu, false, false) as ICommandBar; if (pFeatureClassContextMenu.Find(getfeaturecountContextMenu) == null) { pFeatureClassContextMenu.Add(getfeaturecountContextMenu); } }