예제 #1
0
        public int ExecMarkerCommand(IVsTextMarker pMarker, int iItem)
        {
            var      tester   = new GTestRunner();
            TestList testList = TestPackage.GetTestList();

            tester.OnTestsUpdated += testList.UpdateTestResult;
            switch (iItem)
            {
            case (int)MarkerCommandValues2.mcvRightClickCommand:
                IVsUIShell uiShell = (IVsUIShell)TestPackage.GetGlobalService(typeof(SVsUIShell));
                Guid       context = GuidList.GUIDTestMarkerCmdSet;
                POINTS[]   menuPos = new POINTS[1];
                menuPos[0].x = (short)Cursor.Position.X;
                menuPos[0].y = (short)Cursor.Position.Y;
                var hr = uiShell.ShowContextMenu(0, ref context, (int)PkgCmdIDList.ContextMenu, menuPos, this as IOleCommandTarget);
                if (hr != VSConstants.S_OK)
                {
                    return(VSConstants.S_FALSE);
                }
                break;

            case (int)PkgCmdIDList.cmdRunTest:
                tester.RunTests(_projectMarkerBelongsTo, _testName, false);
                break;

            case (int)PkgCmdIDList.cmdDebugTest:
                tester.RunTests(_projectMarkerBelongsTo, _testName, true);
                break;

            default:

                return(VSConstants.S_FALSE);
            }
            return(VSConstants.S_OK);
        }
예제 #2
0
 public void ShowContextMenu(CommandId commandId, int x, int y, object commandTarget = null)
 {
     if (commandTarget == null)
     {
         var package = VsAppShell.EnsurePackageLoaded(RGuidList.RPackageGuid);
         if (package != null)
         {
             var sp          = (IServiceProvider)package;
             var menuService = (System.ComponentModel.Design.IMenuCommandService)sp
                               .GetService(typeof(System.ComponentModel.Design.IMenuCommandService));
             menuService.ShowContextMenu(new System.ComponentModel.Design.CommandID(commandId.Group, commandId.Id), x, y);
         }
     }
     else
     {
         var target = commandTarget as ICommandTarget;
         if (target == null)
         {
             throw new ArgumentException(Invariant($"{nameof(commandTarget)} must implement ICommandTarget"));
         }
         var pts = new POINTS[1];
         pts[0].x = (short)x;
         pts[0].y = (short)y;
         _uiShell.ShowContextMenu(0, commandId.Group, commandId.Id, pts, new CommandTargetToOleShim(null, target));
     }
 }
예제 #3
0
        private void ShowContextMenu(bool mousePosition)
        {
            // Already on main thread, but unwind callstack before showing the text menu
            ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);

                BindingPackage package = BindingPackage.Get(this.services);
                package.Telemetry.TrackEvent(Constants.EventShowContextMenu);

                FrameworkElement table = this.control.Control;
                Point point            = mousePosition
                    ? table.PointToScreen(Mouse.GetPosition(table))
                    : table.PointToScreen(new Point(table.RenderSize.Width / 2, table.RenderSize.Height / 2)); // should really get the focused entry position
                POINTS[] locationPoints = new[] { new POINTS()
                                                  {
                                                      x = (short)point.X, y = (short)point.Y
                                                  } };

                IVsUIShell shell = this.services.GetService <SVsUIShell, IVsUIShell>();
                IOleCommandTarget commandTarget = table.Tag as IOleCommandTarget;
                Guid commandSet = Constants.GuidBindingPaneCommandSet;

                shell.ShowContextMenu(0, ref commandSet, Constants.BindingPaneContextMenuId, locationPoints, commandTarget);
            }).FileAndForget(Constants.VsBindingPaneFeaturePrefix + nameof(ITableControlEventProcessor.PostprocessMouseRightButtonUp));
        }
예제 #4
0
 private static void ShowContextMenuInternal(int menuId, POINTS[] p, IOleCommandTarget commandTarget)
 {
     try
     {
         VsUIShell.ShowContextMenu(uint.MaxValue, ref CommandSetGuid, menuId, p, commandTarget);
     }
     catch (Exception ex)
     {
         int num = (int)UIHost.ShowException(ex);
     }
 }
예제 #5
0
        /// <summary>
        /// Shows the specified context menu at a specified location.
        /// </summary>
        /// <param name="menuId">The context menu ID.</param>
        /// <param name="groupGuid">The GUID of the menu group.</param>
        /// <param name="points">The location at which to show the menu.</param>
        internal int ShowContextMenu(int menuId, Guid menuGroup, POINTS points)
        {
            IVsUIShell shell = _package.GetService(typeof(SVsUIShell)) as IVsUIShell;

            Debug.Assert(shell != null, "Could not get the UI shell from the project");
            if (shell == null)
            {
                return(VSConstants.E_FAIL);
            }
            POINTS[] pnts = new POINTS[1];
            pnts[0].x = points.x;
            pnts[0].y = points.y;
            return(shell.ShowContextMenu(0, ref menuGroup, menuId, pnts, (Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget) this));
        }
예제 #6
0
        public virtual void ShowContextMenu(Guid cmdGroup, int menuId, IOleCommandTarget target)
        {
            IVsUIShell uiShell = GetService <IVsUIShell>(typeof(SVsUIShell));

            if (uiShell != null)
            {
                Point pt = Cursor.Position;
                POINTS[] where = new POINTS[1];
                where[0].x     = (short)pt.X;
                where[0].y     = (short)pt.Y;

                uiShell.ShowContextMenu(0, ref cmdGroup, menuId, where, target);
            }
        }
예제 #7
0
        /// <include file='doc\LanguageService.uex' path='docs/doc[@for="ViewFilter.ShowContextMenu"]/*' />
        public virtual void ShowContextMenu(int menuId, Guid groupGuid, IOleCommandTarget target)
        {
            IVsUIShell uiShell = this.service.GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (uiShell != null && !this.service.IsMacroRecordingOn())   // disable context menu while recording macros.
            {
                System.Drawing.Point pt   = System.Windows.Forms.Cursor.Position;
                POINTS[]             pnts = new POINTS[1];
                pnts[0].x = (short)pt.X;
                pnts[0].y = (short)pt.Y;
                int hr = uiShell.ShowContextMenu(0, ref groupGuid, menuId, pnts, target);
                if (!NativeMethods.Succeeded(hr))
                {
                    Debug.Assert(false, "uiShell.ShowContextMenu returned " + hr);
                }
            }
            uiShell = null;
        }
        private void ShowContextMenu(FrameworkElement frameworkElement, MouseButtonEventArgs mouseButtonEvent)
        {
            const string guidVSPackageContextMenuCmdSet = "c75f116c-9249-4984-8d82-d3c6025afb17";
            const int    MyContextMenuId = 0x1100;

            IVsUIShell uiShell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

            if (uiShell == null)
            {
                // TODO: Log error - Unable to access UIShell
                return;
            }

            System.Guid contextMenuGuid = new System.Guid(guidVSPackageContextMenuCmdSet);
            POINTS[]    points          = GetPointsFromMouseEvent(frameworkElement, mouseButtonEvent);

            // TODO: error handling
            uiShell.ShowContextMenu(0, ref contextMenuGuid, MyContextMenuId, points, null);
        }
예제 #9
0
        public static void LaunchWindowToolsContextMenu()
        {
            // Initialize(refresh) the OtherRecentWindows list here so that it doesn't have to be built repeatedly during each QueryStatus
            MostRecentWindowCommands.Instance.PopulateOtherRecentWindowsList();

            // Display Window manager menu
            IVsUIShell uiShell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

            if (uiShell != null)
            {
                Rect position = viewModel.Position;

                POINTS[] p = new POINTS[1];
                p[0]   = new POINTS();
                p[0].x = (short)position.TopLeft.X;
                p[0].y = (short)position.TopLeft.Y;
                Guid guidSccDisplayInformationCommandSet = WindowManagerPackageCmdSetGuid;
                uiShell.ShowContextMenu(0, ref guidSccDisplayInformationCommandSet, WindowManagerMenuCmdId, p, null);
            }
        }
예제 #10
0
        /// <summary>
        /// Handler called when the branch UI is clicked
        /// </summary>
        /// <remarks>
        /// The UI has an upward arrow visually indicating that a menu would be displayed which when clicked
        /// would lead the user to a workflow that enables the switching of branches
        /// </remarks>
        public async Task BranchUIClickedAsync(ISccUIClickedEventArgs args, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            Debug.Assert(args != null, "Branch UI coordinates were not received.");

            IVsUIShell uiShell = (IVsUIShell)_sccProvider.GetService(typeof(SVsUIShell));

            if (uiShell != null)
            {
                POINTS[] p = new POINTS[1];
                p[0]   = new POINTS();
                p[0].x = (short)args.ClickedElementPosition.TopRight.X;
                p[0].y = (short)args.ClickedElementPosition.TopRight.Y;

                Guid commandSet = GuidList.guidSccProviderCmdSet;
                uiShell.ShowContextMenu(0, ref commandSet, CommandId.BranchMenu, p, null);
            }
        }
예제 #11
0
        /// <summary>
        /// Shows the context menu when a user right-mouse clicks on the node.
        /// </summary>
        public virtual void ShowContextMenu()
        {
            int menuId = (int)this.VisualStudioContextMenuId;

            if (menuId != VsMenus.IDM_VS_CTXT_NOCOMMANDS)
            {
                // Tell the Visual Studio shell to show the context menu.
                Point    menuLocation = Cursor.Position;
                POINTS[] vsPoints     = new POINTS[1];
                vsPoints[0].x = (short)menuLocation.X;
                vsPoints[0].y = (short)menuLocation.Y;
                Guid       activeMenuGuid = VsMenus.SHLMainMenu;
                IVsUIShell uiShell        = this.ServiceProvider.GetVsUIShell(classType, "ShowContextMenu");
                int        hr             = uiShell.ShowContextMenu(0, ref activeMenuGuid, menuId, vsPoints, this.Hierarchy);
                if (NativeMethods.Failed(hr))
                {
                    Tracer.Fail("Error in showing the context menu: 0x{0:x}", hr);
                    NativeMethods.ThrowOnFailure(hr);
                }
            }
        }
예제 #12
0
        public bool ShowContextMenu(IEnumerable <object> items, Point location)
        {
            if (!_shouldShowMenu(items))
            {
                return(false);
            }

            IVsUIShell shell           = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
            Guid       guidContextMenu = Guids.RoslynGroupId;

            POINTS[] locationPoints = new[] { new POINTS()
                                              {
                                                  x = (short)location.X, y = (short)location.Y
                                              } };
            return(shell != null && ErrorHandler.Succeeded(shell.ShowContextMenu(
                                                               0,
                                                               ref guidContextMenu,
                                                               _menuId,
                                                               locationPoints,
                                                               pCmdTrgtActive: null)));
        }
        private void ShowContextMenu(object sender, EventArgs args)
        {
            // Get a reference to the UIShell.
            IVsUIShell uiShell = globalProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (null == uiShell)
            {
                return;
            }

            // Get the position of the cursor.
            System.Drawing.Point pt   = System.Windows.Forms.Cursor.Position;
            POINTS[]             pnts = new POINTS[1];
            pnts[0].x = (short)pt.X;
            pnts[0].y = (short)pt.Y;

            // Show the menu.
            Guid menuGuid = ConsoleGuidList.guidIronPythonConsoleCmdSet;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                uiShell.ShowContextMenu(0, ref menuGuid, (int)PkgCmdIDList.IPConsoleContextMenu, pnts, textView as IOleCommandTarget));
        }
예제 #14
0
        public async Task RepositoryUIClickedAsync(ISccUIClickedEventArgs args, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            Debug.Assert(args != null, "Repository UI coordinates were not received.");

            IVsUIShell uiShell = (IVsUIShell)_sccProvider.GetService(typeof(SVsUIShell));

            if (uiShell != null)
            {
                POINTS[] p = new POINTS[1];
                p[0]   = new POINTS();
                p[0].x = (short)args.ClickedElementPosition.TopLeft.X;
                p[0].y = (short)args.ClickedElementPosition.TopLeft.Y;

                Guid commandSet = GuidList.guidSccProviderCmdSet;
                uiShell.ShowContextMenu(0, ref commandSet, PackageIds.RepositoryMenu, p, _statusBarManager);
            }
            //if (uiShell != null)
            //{
            //    int result;
            //    uiShell.ShowMessageBox(dwCompRole: 0,
            //                           rclsidComp: Guid.Empty,
            //                           pszTitle: Resources.ProviderName,
            //                           pszText: string.Format(CultureInfo.CurrentUICulture, "Clicked", args.ClickedElementPosition.ToString()),
            //                           pszHelpFile: string.Empty,
            //                           dwHelpContextID: 0,
            //                           msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
            //                           msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
            //                           msgicon: OLEMSGICON.OLEMSGICON_INFO,
            //                           fSysAlert: 0,        // false = application modal; true would make it system modal
            //                           pnResult: out result);
            //}
        }
예제 #15
0
        private void TreeViewItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Make sure dragging is not initiated
            this.isDragging = false;

            // Make sure that the clicks has selected the item
            TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);

            if (treeViewItem != null)
            {
                treeViewItem.Focus();
                e.Handled = true;
            }

            /* Show Context Menu */
            IVsUIShell uiShell = (IVsUIShell)((IServiceProvider)VSMacrosPackage.Current).GetService(typeof(SVsUIShell));

            if (uiShell != null)
            {
                // Get context menu id
                int         menuID;
                MacroFSNode selectedNode = this.MacroTreeView.SelectedItem as MacroFSNode;

                if (selectedNode.IsDirectory)
                {
                    if (selectedNode == MacroFSNode.RootNode)
                    {
                        menuID = PkgCmdIDList.BrowserContextMenu;
                    }
                    else if (this.InSamples(selectedNode))
                    {
                        menuID = PkgCmdIDList.SampleFolderContextMenu;
                    }
                    else
                    {
                        menuID = PkgCmdIDList.FolderContextMenu;
                    }
                }
                else
                {
                    if (selectedNode.FullPath == Manager.CurrentMacroPath)
                    {
                        menuID = PkgCmdIDList.CurrentContextMenu;
                    }
                    else if (this.InSamples(selectedNode))
                    {
                        menuID = PkgCmdIDList.SampleMacroContextMenu;
                    }
                    else
                    {
                        menuID = PkgCmdIDList.MacroContextMenu;
                    }
                }

                // Show right context menu
                System.Drawing.Point pt   = System.Windows.Forms.Cursor.Position;
                POINTS[]             pnts = new POINTS[1];
                pnts[0].x = (short)pt.X;
                pnts[0].y = (short)pt.Y;

                uiShell.ShowContextMenu(0, GuidList.GuidVSMacrosCmdSet, menuID, pnts, null);
            }
        }