private void ExecuteCommand(object sender, EventArgs e) { var command = (OleMenuCommand)sender; Debug.WriteLine($"ExecuteCommand {command.Text} {command.CommandID.ID} "); try { switch ((uint)command.CommandID.ID) { case PackageCommanddIDs.CreateSnippet: var selection = DTE.ActiveDocument.Selection as TextSelection; if (selection != null) { var dialog = _viewFactory.GetView <Dialog>(ViewTypes.CreateSnippet); var cs = (CreateSnippet)dialog; var csm = cs.DataContext as CreateSnippetViewModel; csm.Code = selection.Text; csm.FileName = new System.IO.FileInfo(DTE.ActiveDocument.FullName).Name; _shell.ShowDialog(Strings.OpenOnGitLabPackage_CreateSnippet, dialog); } else { Debug.Write("未选择任何内容"); } break; default: using (var git = new GitAnalysis(GetActiveFilePath())) { if (!git.IsDiscoveredGitRepository) { return; } var selectionLineRange = GetSelectionLineRange(); var type = ToGitLabUrlType(command.CommandID.ID); var GitLabUrl = git.BuildGitLabUrl(type, selectionLineRange); System.Diagnostics.Process.Start(GitLabUrl); // open browser } break; } } catch (Exception ex) { Debug.Write(ex.ToString()); } }
private void ExecuteCommand(object sender, EventArgs e) { var command = (OleMenuCommand)sender; try { switch ((uint)command.CommandID.ID) { case PackageIds.OpenCreateSnippet: var selection = DTE.ActiveDocument.Selection as TextSelection; if (selection != null) { var dialog = _viewFactory.GetView <Dialog>(ViewTypes.CreateSnippet); var cs = (CreateSnippet)dialog; var csm = cs.DataContext as CreateSnippetViewModel; csm.Code = selection.Text; csm.FileName = new System.IO.FileInfo(DTE.ActiveDocument.FullName).Name; _shell.ShowDialog(Strings.OpenOnGitLabPackage_CreateSnippet, dialog); } else { OutputWindowHelper.DiagnosticWriteLine(GitLab.VisualStudio.Shared.Strings.PleaseCodes); } break; case PackageIds.OpenFromUrl: if (Clipboard.ContainsText(TextDataFormat.Text)) { var match = Regex.Match(Clipboard.GetText(TextDataFormat.Text), "[a-zA-z]+://[^\\s]*"); if (match.Success) { try { TryOpenFile(match.Value); } catch (Exception ex) { OutputWindowHelper.ExceptionWriteLine(string.Format(GitLab.VisualStudio.Shared.Strings.Canotopenurl, match.Value, ex.Message), ex); } } } break; default: using (var git = new GitAnalysis(GetActiveFilePath())) { if (!git.IsDiscoveredGitRepository) { return; } var selectionLineRange = GetSelectionLineRange(); var type = ToGitLabUrlType(command.CommandID.ID); var GitLabUrl = git.BuildGitLabUrl(type, selectionLineRange); System.Diagnostics.Process.Start(GitLabUrl); // open browser } break; } } catch (Exception ex) { OutputWindowHelper.ExceptionWriteLine($"Command:{command.Text},Message:{ex.Message}", ex); } }