/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { OleMenuCommand menuCommand = (OleMenuCommand)sender; OleMenuCmdEventArgs menuCmdEventArgs = (OleMenuCmdEventArgs)e; string inputFile = menuCmdEventArgs.InValue as String; string logFile = null; if (!String.IsNullOrWhiteSpace(inputFile)) { // If the input file is a URL, download the file. if (Uri.IsWellFormedUriString(inputFile, UriKind.Absolute)) { TryDownloadFile(inputFile, out logFile); } else { // Verify if the input file is valid. i.e. it exists and has a valid file extension. string logFileExtension = Path.GetExtension(inputFile); // Since we don't have a tool format, only accept *.sarif and *.json files as command input files. if (logFileExtension.Equals(".sarif", StringComparison.OrdinalIgnoreCase) || logFileExtension.Equals(".json", StringComparison.OrdinalIgnoreCase)) { if (File.Exists(inputFile)) { logFile = inputFile; } } } } string toolFormat = ToolFormat.None; if (logFile == null) { string title = "Open Static Analysis Results Interchange Format (SARIF) file"; string filter = "SARIF files (*.sarif)|*.sarif"; switch (menuCommand.CommandID.ID) { // These constants expressed in our VSCT case OpenSarifFileCommandId: { // Native SARIF. All our defaults above are fine break; } case OpenPREfastFileCommandId: { toolFormat = ToolFormat.PREfast; title = "Open PREfast XML log file"; filter = "PREfast log files (*.xml)|*.xml"; break; } case OpenStaticDriverVerifierFileCommandId: { toolFormat = ToolFormat.StaticDriverVerifier; title = "Open Static Driver Verifier trace log file"; filter = "Static Driver Verifier log files (*.tt)|*.tt"; break; } case OpenFxCopFileCommandId: { // FxCop. TODO. We need project file support. FxCop // fullMessages look broken. toolFormat = ToolFormat.FxCop; title = "Open FxCop XML log file"; filter = "FxCop report and project files (*.xml)|*.xml"; break; } case OpenFortifyFileCommandId: { toolFormat = ToolFormat.Fortify; title = "Open Fortify XML log file"; filter = "Fortify log files (*.xml)|*.xml"; break; } case OpenFortifyFprFileCommandId: { toolFormat = ToolFormat.FortifyFpr; title = "Open Fortify FPR log file"; filter = "Fortify FPR log files (*.fpr)|*.fpr"; break; } case OpenCppCheckFileCommandId: { toolFormat = ToolFormat.CppCheck; title = "Open CppCheck XML log file"; filter = "CppCheck log files (*.xml)|*.xml"; break; } case OpenClangFileCommandId: { toolFormat = ToolFormat.ClangAnalyzer; title = "Open Clang XML log file"; filter = "Clang log files (*.xml)|*.xml"; break; } case OpenAndroidStudioFileCommandId: { toolFormat = ToolFormat.AndroidStudio; title = "Open Android Studio XML log file"; filter = "Android Studio log files (*.xml)|*.xml"; break; } case OpenSemmleFileCommandId: { toolFormat = ToolFormat.SemmleQL; title = "Open Semmle QL CSV log file"; filter = "Semmle QL log files (*.csv)|*.csv"; break; } case OpenPylintFileCommand: { toolFormat = ToolFormat.Pylint; title = "Open Pylint JSON log file"; filter = "Pylint log files (*.json)|*.json"; break; } case OpenTSLintFileCommand: { toolFormat = ToolFormat.TSLint; title = "Open TSLint JSON log file"; filter = "TSLint log files (*.json)|*.json"; break; } } filter += "|All files (*.*)|*.*"; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = title; openFileDialog.Filter = filter; openFileDialog.RestoreDirectory = true; if (!String.IsNullOrWhiteSpace(inputFile)) { openFileDialog.FileName = Path.GetFileName(inputFile); openFileDialog.InitialDirectory = Path.GetDirectoryName(inputFile); } if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } logFile = openFileDialog.FileName; } TelemetryProvider.WriteMenuCommandEvent(toolFormat); try { ErrorListService.ProcessLogFile(logFile, SarifViewerPackage.Dte.Solution, toolFormat); } catch (InvalidOperationException) { VsShellUtilities.ShowMessageBox(SarifViewerPackage.ServiceProvider, string.Format(Resources.LogOpenFail_InvalidFormat_DialogMessage, Path.GetFileName(logFile)), null, // title OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } }
protected override Task ExecuteAsync(OleMenuCmdEventArgs e) { VS.Notifications.ShowMessage("MyCommand", "Button clicked"); return(Task.CompletedTask); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await CommandHelper.RunTortoiseSvnCommand("log"); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await CommandHelper.SaveFiles(); await ProcessHelper.RunTortoiseGitFileCommand("merge"); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { var releaseBranch = await GitHelper.GetCurrentBranchName(false); var releaseName = await GitHelper.GetCurrentBranchName(true); var gitConfig = await GitHelper.GetGitConfig(); var options = await General.GetLiveInstanceAsync(); var isGitFlow = GitHelper.IsGitFlow(gitConfig); if (!isGitFlow) { await VS.MessageBox.ShowErrorAsync("GitFlow is not initialized."); return; } if (!releaseBranch.StartsWith(gitConfig.ReleasePrefix)) { await VS.MessageBox.ShowErrorAsync("Current branch is not a release branch."); return; } var tagMessage = string.Empty; if (options.UseAnnotatedTag) { tagMessage = Interaction.InputBox("Tag message:", "Finish release"); } /* 1. Switch to the master branch * 2. Pull latest changes on master * 3. Merge the release branch to master * 4. Tag the release * 5. Switch to the develop branch * 6. Pull latest changes on develop * 7. Merge the release branch to develop * 8. Push all changes to develop * 9. Push all changes to master * 10. Push the tag * 11. Delete the local release branch * 12. Delete the remote release branch */ await ProcessHelper.StartProcessGui( "cmd.exe", $"/c cd \"{await FileHelper.GetSolutionDir()}\" && " + await GitHelper.GetSshSetup() + GitHelper.FormatCliCommand($"checkout {gitConfig.MasterBranch}") + (options.PullChanges ? GitHelper.FormatCliCommand("pull") : string.Empty) + GitHelper.FormatCliCommand($"merge --no-ff {releaseBranch}") + (options.UseAnnotatedTag ? GitHelper.FormatCliCommand($"tag -a {gitConfig.TagPrefix}{releaseName} -m \"{tagMessage}\"") : GitHelper.FormatCliCommand($"tag {gitConfig.TagPrefix}{releaseName}")) + GitHelper.FormatCliCommand($"checkout {gitConfig.DevelopBranch}") + (options.PullChanges ? GitHelper.FormatCliCommand("pull") : string.Empty) + GitHelper.FormatCliCommand($"merge --no-ff {releaseBranch}", false), $"Finishing release {releaseName}", releaseBranch, null, GitHelper.FormatCliCommand($"push origin {gitConfig.DevelopBranch}") + GitHelper.FormatCliCommand($"push origin {gitConfig.MasterBranch}") + GitHelper.FormatCliCommand($"push origin {gitConfig.TagPrefix}{releaseName}") ); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await VS.MessageBox.ShowWarningAsync("$safeprojectname$", "Button clicked"); }
protected override async Task ExecuteAsync(AsyncPackage package, OleMenuCommand cmd, OleMenuCmdEventArgs e) { EnvDTE.ProjectItem item = await ProjectHelpers.GetSelectedProjectItemAsync(); System.Windows.Forms.MessageBox.Show(item.ToString()); await StatusBar.SetTextAsync("This is great"); await Task.Delay(2000); await StatusBar.StartAnimationAsync(StatusAnimation.Find); await Task.Delay(2000); await StatusBar.EndAnimationAsync(StatusAnimation.Find); await Task.Delay(2000); await StatusBar.SetTextAsync("ost"); await Task.Delay(2000); await StatusBar.ClearAsync(); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await Helper.AdjustFontSizeAsync(FontsAndColorsCategory.DialogsAndToolWindows, -2); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await VS.MessageBox.ShowAsync("Not ready yet"); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await CommandHelper.SaveFiles(); await ProcessHelper.RunTortoiseGitFileCommand("blame", $"/line:{await FileHelper.GetActiveDocumentCurrentLine()}"); }
protected abstract void OnExecute(OleMenuCmdEventArgs args);
private void OnMenuMyDynamicCombo(object sender, EventArgs e) { if ((null == e) || (e == EventArgs.Empty)) { // We should never get here; EventArgs are required. throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown } OleMenuCmdEventArgs eventArgs = e as OleMenuCmdEventArgs; if (eventArgs != null) { object input = eventArgs.InValue; IntPtr vOut = eventArgs.OutValue; if (vOut != IntPtr.Zero && input != null) { throw (new ArgumentException(Resources.BothInOutParamsIllegal)); // force an exception to be thrown } else if (vOut != IntPtr.Zero) { // when vOut is non-NULL, the IDE is requesting the current value for the combo if (currentZoomFactor == 0) { Marshal.GetNativeVariantForObject(zoom_to_Fit, vOut); } else { string factorString = currentZoomFactor.ToString("P0", numberFormatInfo); Marshal.GetNativeVariantForObject(factorString, vOut); } } else if (input != null) { // new zoom value was selected or typed in string inputString = input.ToString(); if (inputString.Equals(zoomToFit) || inputString.Equals(zoom_to_Fit)) { currentZoomFactor = 0; ShowMessage(Resources.MyDynamicCombo, zoom_to_Fit); } else { // There doesn't appear to be any percent-parsing routines in the framework (even though you can create // a localized percentage in a string!). So, we need to remove any occurence of the localized Percent // symbol, then parse the value that's left try { float newZoom = Single.Parse(inputString.Replace(NumberFormatInfo.InvariantInfo.PercentSymbol, ""), CultureInfo.CurrentCulture); newZoom = (float)Math.Round(newZoom); if (newZoom < 0) { throw (new ArgumentException(Resources.ZoomMustBeGTZero)); // force an exception to be thrown } currentZoomFactor = newZoom / (float)100.0; ShowMessage(Resources.MyDynamicCombo, newZoom.ToString(CultureInfo.CurrentCulture)); } catch (FormatException) { // user typed in a non-numeric value, ignore it } catch (OverflowException) { // user typed in too large of a number, ignore it } } } else { // We should never get here throw (new ArgumentException(Resources.InOutParamCantBeNULL)); // force an exception to be thrown } } else { // We should never get here; EventArgs are required. throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown } }
private void OnMenuMyIndexCombo(object sender, EventArgs e) { if ((null == e) || (e == EventArgs.Empty)) { // We should never get here; EventArgs are required. throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown } OleMenuCmdEventArgs eventArgs = e as OleMenuCmdEventArgs; if (eventArgs != null) { object input = eventArgs.InValue; IntPtr vOut = eventArgs.OutValue; if (vOut != IntPtr.Zero && input != null) { throw (new ArgumentException(Resources.BothInOutParamsIllegal)); // force an exception to be thrown } if (vOut != IntPtr.Zero) { // when vOut is non-NULL, the IDE is requesting the current value for the combo Marshal.GetNativeVariantForObject(indexComboChoices[currentIndexComboChoice], vOut); } else if (input != null) { int newChoice = -1; if (!int.TryParse(input.ToString(), out newChoice)) { // user typed a string argument in command window. for (int i = 0; i < indexComboChoices.Length; i++) { if (string.Compare(indexComboChoices[i], input.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0) { newChoice = i; break; } } } // new value was selected or typed in if (newChoice != -1) { currentIndexComboChoice = newChoice; ShowMessage(Resources.MyIndexCombo, currentIndexComboChoice.ToString(CultureInfo.CurrentCulture)); } else { throw (new ArgumentException(Resources.ParamMustBeValidIndexOrStringInList)); // force an exception to be thrown } } else { // We should never get here; EventArgs are required. throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown } } else { // We should never get here; EventArgs are required. throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown } }
/// <summary>Executes asynchronously when the command is invoked and <c>Execute(object, EventArgs)</c> isn't overridden.</summary> /// <remarks>Use this method instead of <see cref="Execute"/> if you're invoking any async tasks by using async/await patterns.</remarks> protected virtual Task ExecuteAsync(OleMenuCmdEventArgs e) { return(Task.CompletedTask); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { string xporterPath = Commands.GetXsPath(@"Bin\FoxXporter.exe"); await Commands.StartProcessAsync(xporterPath); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { OleMenuCommand menuCommand = (OleMenuCommand)sender; OleMenuCmdEventArgs menuCmdEventArgs = (OleMenuCmdEventArgs)e; string inputFile = menuCmdEventArgs.InValue as String; string logFile = null; if (!String.IsNullOrWhiteSpace(inputFile)) { // If the input file is a URL, download the file. if (Uri.IsWellFormedUriString(inputFile, UriKind.Absolute)) { TryDownloadFile(inputFile, out logFile); } else { // Verify if the input file is valid. i.e. it exists and has a valid file extension. string logFileExtension = Path.GetExtension(inputFile); // Since we don't have a tool format, only accept *.sarif and *.json files as command input files. if (logFileExtension.Equals(".sarif", StringComparison.OrdinalIgnoreCase) || logFileExtension.Equals(".json", StringComparison.OrdinalIgnoreCase)) { if (File.Exists(inputFile)) { logFile = inputFile; } } } } string toolFormat = ToolFormat.None; if (logFile == null) { string title = "Open Static Analysis Results Interchange Format (SARIF) file"; string filter = "SARIF files (*.sarif)|*.sarif"; switch (menuCommand.CommandID.ID) { // These constants expressed in our VSCT case OpenSarifFileCommandId: { // Native SARIF. All our defaults above are fine break; } case OpenPREfastFileCommandId: { toolFormat = ToolFormat.PREfast; title = "Open PREfast XML log file"; filter = "PREfast log files (*.xml)|*.xml"; break; } case OpenStaticDriverVerifierFileCommandId: { toolFormat = ToolFormat.StaticDriverVerifier; title = "Open Static Driver Verifier trace log file"; filter = "Static Driver Verifier log files (*.tt)|*.tt"; break; } case OpenFxCopFileCommandId: { // FxCop. TODO. We need project file support. FxCop // fullMessages look broken. toolFormat = ToolFormat.FxCop; title = "Open FxCop XML log file"; filter = "FxCop report and project files (*.xml)|*.xml"; break; } case OpenCppCheckFileCommandId: { toolFormat = ToolFormat.CppCheck; title = "Open CppCheck XML log file"; filter = "CppCheck log files (*.xml)|*.xml"; break; } case OpenClangFileCommandId: { toolFormat = ToolFormat.ClangAnalyzer; title = "Open Clang XML log file"; filter = "Clang log files (*.xml)|*.xml"; break; } case OpenAndroidStudioFileCommandId: { toolFormat = ToolFormat.AndroidStudio; title = "Open Android Studio XML log file"; filter = "Android Studio log files (*.xml)|*.xml"; break; } case OpenSemmleFileCommandId: { toolFormat = ToolFormat.SemmleQL; title = "Open Semmle QL CSV log file"; filter = "Semmle QL log files (*.csv)|*.csv"; break; } } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = title; openFileDialog.Filter = filter; openFileDialog.RestoreDirectory = true; if (!String.IsNullOrWhiteSpace(inputFile)) { openFileDialog.FileName = Path.GetFileName(inputFile); openFileDialog.InitialDirectory = Path.GetDirectoryName(inputFile); } if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } logFile = openFileDialog.FileName; } ErrorListService.ProcessLogFile(logFile, SarifViewerPackage.Dte.Solution, toolFormat); SarifTableDataSource.Instance.BringToFront(); }