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> /// 获取和解析插件集合中的所有对象将其分别装入ICommand,IToll,IToolBar和IMenuDef四个集合中 /// </summary> internal void getPluginArray(PluginContainer pCtner) { foreach (IPlugin ipi in pCtner) { ICommand icmd = ipi as ICommand; if (icmd != null) { this._ICmdContainer.Add(icmd.ToString(), icmd); if (icmd.Category != null && !this._CmdCategory.Contains(icmd.Category)) { this._CmdCategory.Add(icmd.Category); } continue; } ITool itool = ipi as ITool; if (itool != null) { this._IToolContainer.Add(itool.ToString(), itool); if (itool.Category != null && !this._CmdCategory.Contains(itool.Category)) { this._CmdCategory.Add(itool.Category); } continue; } IToolBarDef itbd = ipi as IToolBarDef; if (itbd != null) { this._IToolBarDefContainer.Add(itbd.ToString(), itbd); continue; } IDockableWndDef idwd = ipi as IDockableWndDef; if (idwd != null) { this._IDockableWndContainer.Add(idwd.ToString(), idwd); continue; } IMenuDef imd = ipi as IMenuDef; if (imd != null) { this._IMenuDefContainer.Add(imd.ToString(), imd); continue; } } //throw new System.NotImplementedException(); }
private void method_4(Bar bar_0, IToolBarDef itoolBarDef_0) { Assembly assembly = itoolBarDef_0.GetType().Assembly; ItemDefClass itemDef = new ItemDefClass(); for (int i = 0; i < itoolBarDef_0.ItemCount; i++) { itoolBarDef_0.GetItemInfo(i, itemDef); string iD = itemDef.ID; ICommand command = null; command = assembly.CreateInstance(iD) as ICommand; this.method_5(bar_0, command, itemDef.Group, itemDef.SubType); } }
public List <string> ListArcCatalogToolbars(IApplication application) { List <string> toolbarList = new List <string>(); //Only work with ArcMap application types, not ArcCatalog, ArcGlobe, ArcToolBox, etc. if (!(application is ESRI.ArcGIS.ArcCatalog.Application)) { return(null); } // Set up GUID object for 'ESRI Mx Command Bars' component category UID uid_GxCommandBars = new UIDClass(); uid_GxCommandBars.Value = (System.Object)("{56C205F9-E53A-11D1-9496-080009EEBECB}");//esri gx command bars // Set up the category factory. ICategoryFactory categoryFactory = new CategoryFactoryClass(); categoryFactory.CategoryID = uid_GxCommandBars; IDocument document = application.Document; // Go through each member of the category, and if it is a toolbar try to find it in the document object object_ComponentCategory = categoryFactory.CreateNext(); ICommandBars commandBars = document.CommandBars; while (object_ComponentCategory != null) { if (object_ComponentCategory is IToolBarDef) { IToolBarDef toolbarDef = (IToolBarDef)object_ComponentCategory; //Explicit Cast toolbarList.Add(toolbarDef.Name); Debug.Print("Toolbar - " + toolbarDef.Name); if (toolbarDef.Name == "ArcGIS4LocalGovernment_AttributeAssistantToolbar") { MessageBox.Show("here"); } for (int i = 0; i < toolbarDef.ItemCount; i++) { ScrapClass itemdef = new ScrapClass(); toolbarDef.GetItemInfo(i, itemdef); //print the UID of commandItem if (itemdef.ID != null && itemdef.ID != "") { Debug.Print(itemdef.ID.ToString()); UID uid = new UIDClass(); uid.Value = itemdef.ID.ToString(); ICommandItem commandItem = commandBars.Find(uid, false, false); if (commandItem != null) { Debug.Print(i + "," + commandItem.Name + "," + commandItem.Category); } } } } object_ComponentCategory = categoryFactory.CreateNext(); } return(toolbarList); }
internal void StartCreateBar(string string_0) { try { this.list_0.Clear(); XmlDocument document = new XmlDocument(); try { document.Load(string_0); } catch { } XmlElement documentElement = document.DocumentElement; Bar bar = null; int num = 0; Label_0029: if (num >= documentElement.ChildNodes.Count) { goto Label_01EB; } XmlNode node = documentElement.ChildNodes[num]; if (!(node.Name.ToLower() == "bar")) { goto Label_01D1; } string[] strArray = this.method_8(node); IToolBarDef def = null; if ((strArray[7] != null) && (strArray[8] != null)) { def = this.method_10(strArray[7]).LoadClass(strArray[8]) as IToolBarDef; if (strArray[0] == null) { strArray[0] = def.Name; } if (strArray[1] == null) { strArray[1] = def.Caption; } } if (strArray[0] == null) { goto Label_01DA; } try { bar = this.barManager_0.Bars[strArray[0]]; goto Label_01DA; } catch { goto Label_01DA; } Label_0100: bar = new Bar(); bool flag = true; bar.BarName = this.barManager_0.GetNewBarName(); bar.DockCol = 0; bar.DockRow = this.barManager_0.Bars.Count; bar.FloatSize = new Size(288, 24); this.barManager_0.Bars.Add(bar); this.method_1(bar, strArray); if (bar.DockStyle == BarDockStyle.None) { bar.DockStyle = BarDockStyle.Top; } if (def != null) { this.method_4(bar, def); } Label_0189: this.method_3(bar, node); if (flag && (bar.ItemLinks.Count == 0)) { int index = this.barManager_0.Bars.IndexOf(bar); this.barManager_0.Bars.RemoveAt(index); } Label_01D1: num++; goto Label_0029; Label_01DA: flag = false; if (bar != null) { goto Label_0189; } goto Label_0100; Label_01EB: if ((this.bool_0 && (this.barManager_0.MainMenu == null)) && (this.barManager_0.Bars.Count > 1)) { bar = this.barManager_0.Bars[1]; this.barManager_0.MainMenu = bar; bar.OptionsBar.DisableClose = false; bar.OptionsBar.AllowQuickCustomization = false; bar.OptionsBar.DrawDragBorder = false; bar.OptionsBar.MultiLine = true; bar.OptionsBar.RotateWhenVertical = false; } if (this.OnCreateComplete != null) { this.OnCreateComplete(); } } catch (Exception exception) { MessageBox.Show(exception.ToString()); MessageBox.Show("无法创建菜单和工具栏,请检查文件" + string_0 + "是否正确!"); } }