private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { var command = (OleMenuCommand)sender; Debug.WriteLine($"MenuItem_BeforeQueryStatus {command.Text} {command.CommandID.ID} "); try { switch ((uint)command.CommandID.ID) { case PackageIds.OpenCreateSnippet: command.Text = Strings.OpenOnGitLabPackage_CreateSnippet; var selectionLineRange = GetSelectionLineRange(); command.Enabled = selectionLineRange.Item1 < selectionLineRange.Item2; break; case PackageIds.IssuesToolWindowCommandId: command.Enabled = true; break; case PackageIds.OpenFromUrl: command.Enabled = Clipboard.ContainsText(TextDataFormat.Text) && Regex.IsMatch(Clipboard.GetText(TextDataFormat.Text), "[a-zA-z]+://[^\\s]*"); command.Text = Strings.OpenFormURL; break; default: // TODO:is should avoid create GitAnalysis every call? var git = GitAnalysis.GetBy(GetActiveFilePath()); if (!git.IsDiscoveredGitRepository) { command.Enabled = false; return; } var type = ToGitLabUrlType(command.CommandID.ID); var targetPath = git.GetGitLabTargetPath(type); if (type == GitLabUrlType.CurrentBranch && targetPath == "master") { command.Visible = false; } else { command.Text = git.GetGitLabTargetDescription(type); command.Enabled = true; } break; } } catch (Exception ex) { var exstr = ex.ToString(); OutputWindowHelper.ExceptionWriteLine(exstr, ex); command.Text = "error:" + ex.GetType().Name; command.Enabled = false; } }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { var command = (OleMenuCommand)sender; try { if (command.CommandID.ID == PackageCommanddIDs.CreateSnippet) { command.Text = Strings.OpenOnGiteaPackage_CreateSnippet; var selectionLineRange = GetSelectionLineRange(); command.Enabled = selectionLineRange.Item1 < selectionLineRange.Item2; } else { // TODO:is should avoid create GitAnalysis every call? using (var git = GitAnalysis.GetBy(GetActiveFilePath())) { if (!git.IsDiscoveredGitRepository) { command.Enabled = false; return; } var type = ToGiteaUrlType(command.CommandID.ID); var targetPath = git.GetGiteaTargetPath(type); if (type == GiteaUrlType.CurrentBranch && targetPath == "master") { command.Visible = false; } else { command.Text = git.GetGiteaTargetDescription(type); command.Enabled = true; } } } } catch (Exception ex) { var exstr = ex.ToString(); Debug.Write(exstr); command.Text = "error:" + ex.GetType().Name; command.Enabled = false; } }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { var command = (OleMenuCommand)sender; try { switch ((uint)command.CommandID.ID) { case PackageIds.OpenFromUrl: try { var match = Regex.Match(Clipboard.GetText(TextDataFormat.Text), "[a-zA-z]+://[^\\s]*"); command.Enabled = match.Success; if (command.Enabled) { Uri uri = new Uri(match.Value); command.Text = string.Format(Strings.OpenFrom0, uri.Host); } else { command.Text = Strings.OpenFromURL; } } catch (Exception ex) { OutputWindowHelper.WarningWriteLine($"QueryStatus:{command.CommandID.ID},{ex.Message}"); } break; case PackageIds.OpenBlame: case PackageIds.OpenBranch: case PackageIds.OpenCommits: case PackageIds.OpenMaster: case PackageIds.OpenRevision: case PackageIds.OpenRevisionFull: { try { var git = GitAnalysis.GetBy(GetActiveFilePath()); if (!git.IsDiscoveredGitRepository) { command.Enabled = false; return; } var type = ToGiteaUrlType(command.CommandID.ID); var targetPath = git.GetGiteaTargetPath(type); if (type == GiteaUrlType.CurrentBranch && targetPath == "master") { command.Visible = false; } else { command.Text = git.GetGiteaTargetDescription(type); command.Enabled = true; } } catch (Exception ex) { OutputWindowHelper.WarningWriteLine($"QueryStatus:{command.CommandID.ID},{ex.Message}"); } } break; default: break; } } catch (Exception ex) { var exstr = ex.ToString(); Debug.Write(exstr); command.Text = "error:" + ex.GetType().Name; command.Enabled = false; OutputWindowHelper.WarningWriteLine(ex.Message); } }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { var command = (OleMenuCommand)sender; try { switch ((uint)command.CommandID.ID) { case PackageIds.OpenFromUrl: try { command.Enabled = false; var match = Regex.Match(Clipboard.GetText(TextDataFormat.Text), "[a-zA-z]+://[^\\s]*"); if (match.Success) { Uri uri = new Uri(match.Value); if (uri.Host.ToLower() == "gitee.com") { command.Enabled = true; } } } catch (Exception ex) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); OutputWindowHelper.WarningWriteLine($"QueryStatus:{command.CommandID.ID},{ex.Message}"); } break; case PackageIds.OpenBlame: case PackageIds.OpenBranch: case PackageIds.OpenCommits: case PackageIds.OpenMaster: case PackageIds.OpenRevision: case PackageIds.OpenRevisionFull: case PackageIds.OpenWebIDE: { try { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); var git = GitAnalysis.GetBy(GetActiveFilePath()); if (!git.IsDiscoveredGitRepository) { command.Enabled = false; return; } var type = ToGiteaUrlType(command.CommandID.ID); var targetPath = git.GetGiteaTargetPath(type); if (type == GiteeUrlType.CurrentBranch && targetPath == "master") { command.Visible = false; } else { command.Text = git.GetGiteaTargetDescription(type); command.Enabled = true; } } catch (Exception ex) { OutputWindowHelper.WarningWriteLine($"QueryStatus:{command.CommandID.ID},{ex.Message}"); } } break; case PackageIds.OpenCreateSnippet: var selectionLineRange = GetSelectionLineRange(); command.Enabled = selectionLineRange != null && selectionLineRange.Item1 < selectionLineRange.Item2; break; default: break; } } catch (Exception ex) { var exstr = ex.ToString(); Debug.Write(exstr); command.Text = "error:" + ex.GetType().Name; command.Enabled = false; OutputWindowHelper.WarningWriteLine(ex.Message); } }