示例#1
0
        /// <summary>
        ///     Returns the command that has the specified <paramref name="commandName" />.
        /// </summary>
        /// <param name="source">The application reference.</param>
        /// <param name="commandName">Name of the command.</param>
        /// <returns>
        ///     Returns the <see cref="ESRI.ArcGIS.Framework.ICommandItem" /> representing the command item; otherwise
        ///     <c>null</c>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">commandName</exception>
        /// <exception cref="System.ArgumentException">The application framework has not been fully initialized.</exception>
        public static ICommandItem GetCommandItem(this IApplication source, string commandName)
        {
            if (source == null)
            {
                return(null);
            }
            if (commandName == null)
            {
                throw new ArgumentNullException("commandName");
            }

            var status = (IApplicationStatus)source;

            if (!status.Initialized)
            {
                throw new ArgumentException("The application framework has not been fully initialized.");
            }

            UID uid = new UID();

            uid.Value = commandName;

            ICommandBars commandBars = source.Document.CommandBars;
            ICommandItem commandItem = commandBars.Find(uid, false, true);

            return(commandItem);
        }
示例#2
0
        /// <summary>
        ///     Replaces the <paramref name="oldCommandUid" /> on the toolbar with the <paramref name="newCommandUid" />
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="toolbarUid">The toolbar uid.</param>
        /// <param name="newCommandUid">The new command uid.</param>
        /// <param name="oldCommandUid">The old command uid.</param>
        public static void Replace(this ICommandBars source, UID toolbarUid, UID newCommandUid, UID oldCommandUid)
        {
            ICommandBar toolbar = source.Find(toolbarUid) as ICommandBar;

            if (toolbar != null)
            {
                toolbar.Replace(newCommandUid, oldCommandUid);
            }
        }
示例#3
0
        /// <summary>
        ///     Adds the command to the <paramref name="toolbarUid" />
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="toolbarUid">The toolbar uid.</param>
        /// <param name="commandUid">The command uid.</param>
        public static void Add(this ICommandBars source, UID toolbarUid, UID commandUid)
        {
            ICommandBar toolbar = source.Find(toolbarUid) as ICommandBar;

            if (toolbar != null)
            {
                toolbar.Add(commandUid);
            }
        }
        private void lstPendingMessage_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && lstPendingMessage.ContextMenuStrip == null)
            {
                //Before showing the context menu, set ContextItem to be the actual dockable window
                //which represents this definition class in the framework
                IDocument doc = m_application.Document;
                IDockableWindowManager windowManager = m_application as IDockableWindowManager;
                UID dockwinID = new UIDClass();
                dockwinID.Value = this.GetType().GUID.ToString("B");
                IDockableWindow frameworkWindow = windowManager.GetDockableWindow(dockwinID);
                if (doc is IBasicDocument) //ArcMap, ArcScene and ArcGlobe
                {
                    ((IBasicDocument)doc).ContextItem = frameworkWindow;
                }

                //Get the context menu to show
                ICommandBars documentBars = m_application.Document.CommandBars;
                ICommandBar  ctxMenu      = null;
                if (radDynamic.Checked) //Create context menu dynamically
                {
                    //Disadvantage(s):
                    //1. ICommandBars.Create will set document to dirty
                    //2. Cannot insert separator
                    ctxMenu = documentBars.Create("DockableWindowCtxTemp", esriCmdBarType.esriCmdBarTypeShortcutMenu); //This sets document flag to dirty :(

                    //Add commands to context menu
                    UID    cmdID = new UIDClass();
                    object idx   = Type.Missing;

                    cmdID.Value = "{b5820a63-e3d4-42a1-91c5-d90eacc3985b}"; //ClearLoggingCommand
                    ctxMenu.Add(cmdID, ref idx);

                    cmdID.Value = "{21532172-bc21-43eb-a2ad-bb6c333eff5e}"; //LogLineMultiItemCmd
                    ctxMenu.Add(cmdID, ref idx);
                }
                else    //Use predefined context menu
                {
                    UID menuID = new UIDClass();
                    menuID.Value = "{c6238198-5a2a-4fe8-bff0-e2f574f6a6cf}"; //LoggingWindowCtxMnu
                    ICommandItem locateMenu = documentBars.Find(menuID, false, false);
                    if (locateMenu != null)
                    {
                        ctxMenu = locateMenu as ICommandBar;
                    }
                }

                //Pop up context menu at screen location
                Point scrnPoint = lstPendingMessage.PointToScreen(e.Location);
                if (ctxMenu != null)
                {
                    ctxMenu.Popup(scrnPoint.X, scrnPoint.Y);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Shows the feature attribute inspector.
        /// </summary>
        public static void ShowFeatureAttributeInspector()
        {
            log.Debug("Enter");

            string progID = "esriEditor.AttributionCommand";

            log.Debug(string.Format("progID={0}", progID));
            UID uid = new UIDClass();

            uid.Value = progID;

            log.Debug(string.Format("uid={0}", uid.ToString()));

            //Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
            //object o = Activator.CreateInstance(t);

            try
            {
                //IApplication application = o as IApplication;
                ICommandBars commandBars = ArcMap.Application.Document.CommandBars;

                if (commandBars != null)
                {
                    bool norecurse = false;
                    bool nocreate  = false;

                    log.Debug(string.Format("commandBars.Find.uid={0}", uid.Value.ToString()));
                    log.Debug(string.Format("commandBars.Find.noRecurse={0}", norecurse));
                    log.Debug(string.Format("commandBars.Find.noCreate={0}", nocreate));

                    ICommandItem commandItem = commandBars.Find(uid, norecurse, nocreate);

                    if (commandItem == null)
                    {
                        log.Error("commandItem returned null.");
                    }
                    else
                    {
                        commandItem.Execute();
                    }
                }
                else
                {
                    log.Error("ArcMap.Application.Document.CommandBars is null.");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);

                throw;
            }
        }
        public static void SetToolActiveInToolBar(string name)
        {
            IApplication application = ArcMap.Application;
            IDocument    document    = application.Document;
            ICommandBars commandBars = document.CommandBars;

            UID commandId = new UIDClass {
                Value = name
            };
            ICommandItem commandItem = commandBars.Find(commandId);

            if (commandItem != null)
            {
                application.CurrentTool = commandItem;
            }
        }
示例#7
0
 private ICommandBar GetMainBar()
 {
     try
     {
         IApplication papp = ArcMap.Application;
         UID          uid  = new UID();
         uid.Value = c_mainMenuID;
         MxDocument   mx      = papp.Document as MxDocument;
         ICommandBars cmdBars = mx.CommandBars;
         ICommandItem cmd     = cmdBars.Find(uid, false, false);
         return(cmd as ICommandBar);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
示例#8
0
 private void SetSelectToolAsCurrentTool()
 {
     if (m_application != null)
     {
         ICommandBars documentBars = m_application.Document.CommandBars;
         UID          cmdID        = new UIDClass();
         cmdID.Value = "{78FFF793-98B4-11D1-873B-0000F8751720}";//esriArcMapUI.SelectFeaturesTool
         ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
         m_application.CurrentTool = cmdItem;
     }
     if (m_mapControl != null)
     {
         ICommand tool = null;
         tool = new ControlsSelectFeaturesToolClass();
         tool.OnCreate(m_mapControl);
         m_mapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
         m_mapControl.CurrentTool  = tool as ITool;
     }
 }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            if (m_application == null)
            {
                return;
            }

            UID osmToolbarCLSID = new UIDClass();

            osmToolbarCLSID.Value = "{980ae216-f181-4fe7-95b7-6c0a7342f71b}";

            ICommandBars commandBars = m_application.Document.CommandBars;
            ICommandItem commandItem = commandBars.Find(osmToolbarCLSID, true, false);

            ICommandBar osmCommandBar = commandItem as ICommandBar;

            if (osmCommandBar != null)
            {
                osmCommandBar.Dock(esriDockFlags.esriDockToggle, null);
            }
        }
示例#10
0
        /// <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);
            }
        }
示例#11
0
        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            if (hook == null)
            {
                return;
            }

            //Get the appropriate zoom in command based on application
            m_application  = hook as IApplication;
            base.m_enabled = false;

            if (m_application != null)
            {
                UID cmdUID = new UIDClass();
                switch (m_application.Name) //or test by casting the appropriate application interface
                {
                case "ArcMap":
                    cmdUID.Value = "esriArcMapUI.ZoomInFixedCommand";
                    break;

                case "ArcGlobe":
                    cmdUID.Value = "esriArcGlobe.GMxNarrowFOVCommand";
                    break;

                case "ArcScene":
                    cmdUID.Value = "esriArcScene.SxNarrowFOVCommand";
                    break;
                }

                ICommandBars docBars = m_application.Document.CommandBars;
                m_xoomCommand = docBars.Find(cmdUID, false, false);

                //Enable only when the delegate command is available
                base.m_enabled = m_xoomCommand != null;
            }
        }
        public static void RemoveCommandItem(string menu, string command)
        {
            IApplication application = ArcMap.Application;
            IDocument    document    = application.Document;
            ICommandBars commandBars = document.CommandBars;

            var menuUid = new UID {
                Value = menu
            };
            var contextMenu = commandBars.Find(menuUid) as ICommandBar;

            if (contextMenu != null)
            {
                var commandUid = new UID {
                    Value = command
                };
                ICommandItem commandItem = contextMenu.Find(commandUid);

                if (commandItem != null)
                {
                    commandItem.Delete();
                }
            }
        }
        public static void AddCommandItem(string menu, string command, object index)
        {
            IApplication application = ArcMap.Application;
            IDocument    document    = application.Document;
            ICommandBars commandBars = document.CommandBars;

            var menuUid = new UID {
                Value = menu
            };
            var contextMenu = commandBars.Find(menuUid) as ICommandBar;

            if (contextMenu != null)
            {
                var commandUid = new UID {
                    Value = command
                };
                ICommandItem commandItem = contextMenu.Find(commandUid);

                if (commandItem == null)
                {
                    contextMenu.Add(commandUid, ref index);
                }
            }
        }
示例#14
0
文件: GPClip.cs 项目: Leopold-Z/Test
        private void SetCurrentSketchTool()
        {
            if (m_application != null)
            {
                ICommandBars documentBars = m_application.Document.CommandBars;
                UID          cmdID        = new UIDClass();
                switch (strGeometryType)
                {
                case "点":
                case "线":
                case "多边形":
                    cmdID.Value = "{B479F48A-199D-11D1-9646-0000F8037368}";    //sketch tool
                    break;

                case "矩形":
                    cmdID.Value = "{6F0ED2CC-C099-4895-BD7E-BEEC2F78ADBF}";     //esriEditor.RectangleTool
                    break;

                case "圆":
                    cmdID.Value = "{09C6F589-A3CE-48AB-81BC-46965C58F264}";    //esriEditor.CircleTool
                    break;

                default:
                    break;
                }
                ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
                m_application.CurrentTool = cmdItem;
            }
            if (m_mapControl != null)
            {
                ICommand tool = null;
                switch (strGeometryType)
                {
                case "点":
                    tool = new 空间查询与空间分析.createPointTool(tempFeatureLayer);      //CreatePointTool
                    break;

                case "线":
                    tool = new 空间查询与空间分析.CreatePolylineTool(tempFeatureLayer);      //CreatePolylineTool
                    break;

                case "多边形":
                    tool = new 空间查询与空间分析.CreatePolygonTool(tempFeatureLayer);      //CreatePolygonTool
                    break;

                case "矩形":
                    tool = new 空间查询与空间分析.CreateRectangleTool(tempFeatureLayer);      //CreateRectangleTool
                    break;

                case "圆":
                    tool = new 空间查询与空间分析.CreateCircleTool(tempFeatureLayer);     //CreateCircleTool
                    break;

                default:
                    break;
                }
                if (tool == null)
                {
                    return;
                }
                tool.OnCreate(m_mapControl);
                m_mapControl.CurrentTool  = tool as ITool;
                m_mapControl.MousePointer = esriControlsMousePointer.esriPointerHand;
            }
        }
示例#15
0
        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);
        }