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);
                }
            }
        }
Exemple #2
0
        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();
        }
        /// <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);
            }
        }
 /// <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);
         }
     }
 }
Exemple #5
0
        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 CreateContextMenu(IApplication application)
        {
            ICommandBars commandBars = application.Document.CommandBars;
            ICommandBar  commandBar  = commandBars.Create("TemporaryContextMenu", ESRI.ArcGIS.SystemUI.esriCmdBarType.esriCmdBarTypeShortcutMenu);

            System.Object optionalIndex = System.Type.Missing;
            UID           uid           = new UIDClass();

            uid.Value   = ThisAddIn.IDs.AdjSettings.ToString(); //"esriArcMapUI.ZoomInFixedCommand"; // Can use CLSID or ProgID
            uid.SubType = 0;
            commandBar.Add(uid, ref optionalIndex);

            uid.Value   = "{FBF8C3FB-0480-11D2-8D21-080009EE4E51}"; // Can use CLSID or ProgID
            uid.SubType = 1;
            commandBar.Add(uid, ref optionalIndex);

            uid.Value   = "{FBF8C3FB-0480-11D2-8D21-080009EE4E51}"; // Can use CLSID or ProgID
            uid.SubType = 2;
            commandBar.Add(uid, ref optionalIndex);

            //Show the context menu at the current mouse location
            System.Drawing.Point currentLocation = System.Windows.Forms.Form.MousePosition;
            commandBar.Popup(currentLocation.X, currentLocation.Y);
        }
 /// <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();
             }
         }
     }
 }
Exemple #8
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);
            }
        }