public override void Initialize(IServiceProvider serviceProvider) { serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.pullRequestCommand, (s, e) => Reload(new ViewWithData(UIControllerFlow.PullRequests) { ViewType = UIViewType.PRList }).Forget()); back = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.backCommand, () => !disabled && currentNavItem > 0, () => { DisableButtons(); Reload(navStack[--currentNavItem], true).Forget(); }, true); forward = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.forwardCommand, () => !disabled && currentNavItem < navStack.Count - 1, () => { DisableButtons(); Reload(navStack[++currentNavItem], true).Forget(); }, true); refresh = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.refreshCommand, () => !disabled && navStack.Count > 0, () => { DisableButtons(); Reload().Forget(); }, true); initialized = true; base.Initialize(serviceProvider); hosts.WhenAnyValue(x => x.IsLoggedInToAnyHost).Subscribe(_ => Reload().Forget()); }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { VSCodeModel codeModel = new VSCodeModel(); VSTextView textView = new VSTextView(VSTextView.ActiveTextView); if (string.IsNullOrEmpty(textView.GetSelectedText().Trim())) { MessageBox.Show("please select valid text"); return; } //需要判断选中的内容属于哪个类或结构体下面 TextSpan ts = textView.GetSelectedSpan(); CodeElement classElement = GetClassElementSelectionBelong(textView, codeModel); if (classElement == null) { MessageBox.Show("Can't detect which class or struct the selection belongs to"); return; } MoveToRegionForm form = new MoveToRegionForm(classElement); form.OnSelectRegion += form_OnSelectRegion; form.ShowDialog(); }
public override void Initialize(IServiceProvider serviceProvider) { base.Initialize(serviceProvider); ServiceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.pullRequestCommand, (s, e) => Reload(new ViewWithData { Flow = UIControllerFlow.PullRequests, ViewType = UIViewType.PRList }).Forget()); back = ServiceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.backCommand, () => !disabled && currentNavItem > 0, () => { DisableButtons(); Reload(navStack[--currentNavItem], true).Forget(); }, true); forward = ServiceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.forwardCommand, () => !disabled && currentNavItem < navStack.Count - 1, () => { DisableButtons(); Reload(navStack[++currentNavItem], true).Forget(); }, true); refresh = ServiceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.refreshCommand, () => !disabled && navStack.Count > 0, () => { DisableButtons(); Reload().Forget(); }, true); initialized = true; }
public override void Initialize(IServiceProvider serviceProvider) { serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.pullRequestCommand, (s, e) => Load(new ViewWithData(UIControllerFlow.PullRequestList)).Forget()); back = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.backCommand, () => !disabled && (navController?.HasBack ?? false), () => { DisableButtons(); navController.Back(); }, true); forward = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.forwardCommand, () => !disabled && (navController?.HasForward ?? false), () => { DisableButtons(); navController.Forward(); }, true); refresh = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.refreshCommand, () => !disabled, () => { DisableButtons(); Refresh(); }, true); initialized = true; base.Initialize(serviceProvider); hosts.WhenAnyValue(x => x.IsLoggedInToAnyHost).Subscribe(_ => LoadDefault()); }
protected override void BeforeQueryStatus(Microsoft.VisualStudio.Shell.OleMenuCommand command, SelectedItems selection) { var activeDocument = dte.ActiveDocument; if (activeDocument == null || activeDocument.ProjectItem == null) { command.Visible = false; return; } if (selection.Count != 1) { command.Enabled = false; return; } if (IsFeatureFile(activeDocument.ProjectItem)) { command.Enabled = goToStepDefinitionCommand.IsEnabled(activeDocument); command.Text = "Go To Step Definition"; } else if (IsCodeFile(activeDocument.ProjectItem)) { command.Enabled = goToStepsCommand.IsEnabled(activeDocument); command.Text = "Go To SpecFlow Step Definition Usages"; } else { command.Visible = false; } }
/// <summary> /// Initializes a new instance of the <see cref="ConvertVBToCSCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> ConvertVBToCSCommand(REConverterPackage package) { this._package = package ?? throw new ArgumentNullException(nameof(package)); _codeConversion = new CodeConversion(package, package.VsWorkspace, () => package.Options); OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) { // Command in main menu var menuCommandId = new CommandID(CommandSet, MainMenuCommandId); var menuItem = new OleMenuCommand(CodeEditorMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatus; commandService.AddCommand(menuItem); // Command in code editor's context menu var ctxMenuCommandId = new CommandID(CommandSet, CtxMenuCommandId); var ctxMenuItem = new OleMenuCommand(CodeEditorMenuItemCallback, ctxMenuCommandId); ctxMenuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatus; commandService.AddCommand(ctxMenuItem); // Command in project item context menu var projectItemCtxMenuCommandId = new CommandID(CommandSet, ProjectItemCtxMenuCommandId); var projectItemCtxMenuItem = new OleMenuCommand(ProjectItemMenuItemCallback, projectItemCtxMenuCommandId); projectItemCtxMenuItem.BeforeQueryStatus += ProjectItemMenuItem_BeforeQueryStatus; commandService.AddCommand(projectItemCtxMenuItem); // Command in project context menu var solutionOrProjectCtxMenuCommandId = new CommandID(CommandSet, SolutionOrProjectCtxMenuCommandId); var solutionOrProjectCtxMenuItem = new OleMenuCommand(SolutionOrProjectMenuItemCallback, solutionOrProjectCtxMenuCommandId); solutionOrProjectCtxMenuItem.BeforeQueryStatus += SolutionOrProjectMenuItem_BeforeQueryStatus; commandService.AddCommand(solutionOrProjectCtxMenuItem); } }
public virtual MenuCommand RegisterCommand() { // Create the command for the menu item. CommandID menuCommandID = new CommandID(PackageIDs.guidVisualStudio_LocateInTFS_VSIPCmdSet, CommandID); var menuItem = new Microsoft.VisualStudio.Shell.OleMenuCommand(Execute, menuCommandID); //menuItem.BeforeQueryStatus += new EventHandler(BeforeQueryStatus); AddToMenuCommandService(menuItem); return menuItem; }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { int curLineIndex, curColumnIndex; VSTextView textView = new VSTextView(VSTextView.ActiveTextView); if (textView == null) { MessageBox.Show("textView is null"); return; } textView.GetCursorPositon(out curLineIndex, out curColumnIndex); //帮助:http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/c62a70eb-d84c-4410-890d-b41a86b2b55f/ ILangService langService; LangService_GetInstance(out langService); if (langService == null) { MessageBox.Show("langService is null"); return; } IDECompilerHost compilerHost = new IDECompilerHost(); IProject prj; Project currentPro = VSDocument.ActiveDocument.ProjectItem.ContainingProject; LangService_GetDteProject(langService, currentPro, out prj); if (prj == null) { MessageBox.Show("prj is null"); return; } FileName fileName = new Microsoft.RestrictedUsage.CSharp.Core.FileName(VSDocument.ActiveDocument.FullName); CSRPOSDATA data = new CSRPOSDATA() { LineIndex = curLineIndex, ColumnIndex = curColumnIndex }; CSharpMember m = Utilities.GetMemberAtLocation(compilerHost, prj, fileName.Value, data); if (m != null && m.ReturnType != null) { string returnName = m.ReturnType.GetFormattedName(InteropTypeFormatFlags.TypeFormatFlags_BestNameGUI); returnName = FilterReturnName(returnName); if (string.IsNullOrEmpty(returnName)) { return; } int insertCol = GetInsertPosition(textView, curLineIndex, curColumnIndex); textView.InsertText(returnName + " v =", curLineIndex, insertCol); textView.SelectText(curLineIndex, insertCol + returnName.Length + 1, curLineIndex, insertCol + returnName.Length + 2); } }
public virtual MenuCommand RegisterCommand() { // Create the command for the menu item. CommandID menuCommandID = new CommandID(PackageIDs.guidVisualStudio_LocateInTFS_VSIPCmdSet, CommandID); var menuItem = new Microsoft.VisualStudio.Shell.OleMenuCommand(Execute, menuCommandID); //menuItem.BeforeQueryStatus += new EventHandler(BeforeQueryStatus); AddToMenuCommandService(menuItem); return(menuItem); }
protected virtual void AddToMenuCommandService(Microsoft.VisualStudio.Shell.OleMenuCommand cmd) { IMenuCommandService mcs = (IMenuCommandService)Package.GetServiceAsDynamic(typeof(IMenuCommandService)); var found = mcs.FindCommand(cmd.CommandID); if (found == null) { mcs.AddCommand(cmd); } }
protected override void Invoke(Microsoft.VisualStudio.Shell.OleMenuCommand command, SelectedItems selection) { var activeDocument = dte.ActiveDocument; if (IsFeatureFile(activeDocument.ProjectItem)) { goToStepDefinitionCommand.Invoke(activeDocument); } else if (IsCodeFile(activeDocument.ProjectItem)) { goToStepsCommand.Invoke(activeDocument); } }
protected override void OnQueryStatus(Microsoft.VisualStudio.Shell.OleMenuCommand command) { ////只有在.cs文件上单击才显示菜单 //string fullPath = VSDocument.ActiveDocument.FullName; //string fileName = fullPath.Substring(fullPath.LastIndexOf('\\') + 1); //string suffix = fileName.Substring(fileName.IndexOf('.') + 1); //if (suffix != "cs") //{ // command.Visible = false; // command.Enabled = false; //} //else //{ // command.Visible = true; // command.Enabled = true; //} }
protected override void BeforeQueryStatus(Microsoft.VisualStudio.Shell.OleMenuCommand command, SelectedItems selectedItems) { if (selectedItems.Count > 1) { return; } var selectedItem = selectedItems.Item(1); if (selectedItem == null) { return; } if (!selectedItem.Name.ToLowerInvariant().Contains("testfixture.cs")) { return; } command.Visible = true; command.Enabled = true; }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { TextSelection selection = VSTextView.ActiveTextSelection; if (selection != null) { string selectedText = selection.Text; if (string.IsNullOrEmpty(selectedText)) { VSTextView view = new VSTextView(VSTextView.ActiveTextView); if (view != null) { selectedText = view.GetOneLineText(selection.TopPoint.Line - 1); view.InsertText(selectedText, selection.TopPoint.Line, 0); } } else { selection.Insert(selectedText + "\n" + selectedText); } } }
public override void Initialize(IServiceProvider serviceProvider) { serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.pullRequestCommand, (s, e) => Reload(new ViewWithData(UIControllerFlow.PullRequests) { ViewType = UIViewType.PRList }).Forget()); back = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.backCommand, () => !disabled && currentNavItem > 0, () => { DisableButtons(); Reload(navStack[--currentNavItem], true).Forget(); }, true); forward = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.forwardCommand, () => !disabled && currentNavItem < navStack.Count - 1, () => { DisableButtons(); Reload(navStack[++currentNavItem], true).Forget(); }, true); refresh = serviceProvider.AddCommandHandler(GuidList.guidGitHubToolbarCmdSet, PkgCmdIDList.refreshCommand, () => !disabled && navStack.Count > 0, () => { DisableButtons(); Reload().Forget(); }, true); initialized = true; base.Initialize(serviceProvider); hosts.WhenAnyValue(x => x.IsLoggedInToAnyHost).Subscribe(_ => Reload().Forget()); }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { UIHierarchy solutionExplorer = VSBase.ApplicationObject.ToolWindows.SolutionExplorer; Array items = solutionExplorer.SelectedItems as Array; if (items.Length == 0) { return; } if (items.Length == 1) { //选择了一个文件 UIHierarchyItem hierarchyItem = items.GetValue(0) as UIHierarchyItem; ProjectItem prjItem = hierarchyItem.Object as ProjectItem; string prjPath = prjItem.Properties.Item("FullPath").Value.ToString(); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "explorer"; proc.StartInfo.Arguments = @"/select," + prjPath; proc.Start(); } }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { SettingFrm frm = new SettingFrm(); frm.ShowDialog(); }
public override void Initialize(IServiceProvider serviceProvider) { Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider)); serviceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.pullRequestCommand, (s, e) => Load(new ViewWithData(UIControllerFlow.PullRequestList)).Forget()); back = serviceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.backCommand, () => !disabled && (navController?.HasBack ?? false), () => { DisableButtons(); navController.Back(); }, true); forward = serviceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.forwardCommand, () => !disabled && (navController?.HasForward ?? false), () => { DisableButtons(); navController.Forward(); }, true); refresh = serviceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.refreshCommand, () => !disabled, () => { DisableButtons(); Refresh(); }, true); serviceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.githubCommand, () => !disabled && (RepositoryOrigin == RepositoryOrigin.DotCom || RepositoryOrigin == RepositoryOrigin.Enterprise), () => { switch (navController?.Current.CurrentFlow) { case UIControllerFlow.PullRequestDetail: var prDetailViewModel = control.DataContext as IPullRequestDetailViewModel; if (prDetailViewModel != null) { browser.OpenUrl(ActiveRepoUri.ToRepositoryUrl().Append("pull/" + prDetailViewModel.Model.Number)); } else { goto default; } break; case UIControllerFlow.PullRequestList: case UIControllerFlow.PullRequestCreation: browser.OpenUrl(ActiveRepoUri.ToRepositoryUrl().Append("pulls/")); break; case UIControllerFlow.Home: default: browser.OpenUrl(ActiveRepoUri.ToRepositoryUrl()); break; } }, true); serviceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.helpCommand, () => true, () => { browser.OpenUrl(new Uri(GitHubUrls.Documentation)); usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget(); }, true); initialized = true; base.Initialize(serviceProvider); hosts.WhenAnyValue(x => x.IsLoggedInToAnyHost).Subscribe(_ => LoadDefault()); }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { UpdateFrm about = new UpdateFrm(); about.ShowDialog(); }
protected override void OnQueryStatus(Microsoft.VisualStudio.Shell.OleMenuCommand command) { }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { VSBase.ReStartVS(); }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { if (VSTextView.ActiveTextView == null) { return; } long getElement = 0; long regionTime = 0; Stopwatch sw = new Stopwatch(); sw.Start(); //开始之前先格式化 VSBase.ExecuteCommand((uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT); VSStatusBar.SetText("quick region......"); using (VSUndo.StartUndo()) { SettingModel model = SettingFrm.ReadSetting(); if (model != null) { QuickRegionSettingModel quickRegionModel = model.QuickRegionModel; VSCodeModel codeModel = new VSCodeModel(); List <CodeElement> classLists = GetClassAndStructInFile(codeModel); for (int i = 0; i < classLists.Count; i++) { sw.Stop(); getElement = sw.ElapsedMilliseconds; sw.Restart(); List <CodeElement> noneEventElements = codeModel.GetNotRegionNoneEventMethodInClass(classLists[i]); if (noneEventElements.Count != 0) { RegionElement(noneEventElements, i, model.QuickRegionModel.Method); } List <CodeElement> eventElements = codeModel.GetNotRegionEventInClass(classLists[i]); if (eventElements.Count != 0) { RegionElement(eventElements, i, model.QuickRegionModel.Event); } List <CodeElement> constructorElements = codeModel.GetNotRegionConstructorInClass(classLists[i]); if (constructorElements.Count != 0) { RegionElement(constructorElements, i, model.QuickRegionModel.Constructor); } List <CodeElement> propertyElements = codeModel.GetNotRegionPropertyInClass(classLists[i]); if (propertyElements.Count != 0) { RegionElement(propertyElements, i, model.QuickRegionModel.Property); } List <CodeElement> variablesElements = codeModel.GetNotRegionVariablesInClass(classLists[i]); if (variablesElements.Count != 0) { RegionElement(variablesElements, i, model.QuickRegionModel.Variable); } sw.Stop(); regionTime = sw.ElapsedMilliseconds; } //QuickRegionpNonEventMethod(textView, quickRegionModel.Method); //QuickRegionpEventMethod(textView, quickRegionModel.Event); //QuickRegionConstructor(textView, quickRegionModel.Constructor); //QuickRegionpProperty(textView, quickRegionModel.Property); //QuickRegionDelegates(textView, "- Delegate -"); //QuickRegionVariables(textView, quickRegionModel.Variable); //CleanEmptyRegion(textView); CleanBlankLine(codeModel); VSDocument.SaveActiveDocument(); VSBase.ExecuteCommand((uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT); VSBase.ExecuteCommand((uint)VSConstants.VSStd2KCmdID.OUTLN_COLLAPSE_TO_DEF); } } VsOutput.ShowDebugMessage("region complete, get element time total: " + getElement + " milliseconds\r\n" + " region time: " + regionTime); }
protected override void Invoke(Microsoft.VisualStudio.Shell.OleMenuCommand command, SelectedItems selectedItems) { System.Windows.MessageBox.Show("Command executed"); }