private void ExecuteCommand(object sender, EventArgs e)
        {
            var command = (OleMenuCommand)sender;

            try
            {
                if (command.CommandID.ID == PackageCommanddIDs.CreateSnippet)
                {
                }
                else
                {
                    using (var git = new GitAnalysis(GetActiveFilePath()))
                    {
                        if (!git.IsDiscoveredGitRepository)
                        {
                            return;
                        }
                        var selectionLineRange = GetSelectionLineRange();
                        var type     = ToGiteaUrlType(command.CommandID.ID);
                        var GiteaUrl = git.BuildGiteaUrl(type, selectionLineRange);
                        System.Diagnostics.Process.Start(GiteaUrl); // open browser
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }
        private void ExecuteCommand(object sender, EventArgs e)
        {
            var command = (OleMenuCommand)sender;

            try
            {
                if (command.CommandID.ID == 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.OpenOnGiteaPackage_CreateSnippet, dialog);
                    }
                    else
                    {
                        Debug.Write("未选择任何内容");
                    }
                }
                else
                {
                    using (var git = new GitAnalysis(GetActiveFilePath()))
                    {
                        if (!git.IsDiscoveredGitRepository)
                        {
                            return;
                        }
                        var selectionLineRange = GetSelectionLineRange();
                        var type     = ToGiteaUrlType(command.CommandID.ID);
                        var GiteaUrl = git.BuildGiteaUrl(type, selectionLineRange);
                        System.Diagnostics.Process.Start(GiteaUrl); // open browser
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }
Example #3
0
        private void ExecuteCommand(object sender, EventArgs e)
        {
            var command = (OleMenuCommand)sender;

            try
            {
                switch ((uint)command.CommandID.ID)
                {
                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("Can't Open {0},Exception:{1}", match.Value, ex.Message), ex);
                            }
                        }
                    }
                    break;

                case PackageIds.OpenBlame:
                case PackageIds.OpenBranch:
                case PackageIds.OpenCommits:
                case PackageIds.OpenMaster:
                case PackageIds.OpenRevision:
                case PackageIds.OpenRevisionFull:
                {
                    try
                    {
                        using (var git = new GitAnalysis(GetActiveFilePath()))
                        {
                            if (!git.IsDiscoveredGitRepository)
                            {
                                return;
                            }
                            var selectionLineRange = GetSelectionLineRange();
                            var type     = ToGiteaUrlType(command.CommandID.ID);
                            var GiteaUrl = git.BuildGiteaUrl(type, selectionLineRange);
                            System.Diagnostics.Process.Start(GiteaUrl);         // open browser
                        }
                    }
                    catch (Exception ex)
                    {
                        OutputWindowHelper.ExceptionWriteLine(string.Format("ExecuteCommand {0}", command.CommandID.ID, ex.Message), ex);
                    }
                }
                break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }
Example #4
0
        private void ExecuteCommand(object sender, EventArgs e)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            var command = (OleMenuCommand)sender;

            try
            {
                switch ((uint)command.CommandID.ID)
                {
                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("Can't Open {0},Exception:{1}", match.Value, ex.Message), ex);
                            }
                        }
                    }
                    break;

                case PackageIds.OpenBlame:
                case PackageIds.OpenBranch:
                case PackageIds.OpenCommits:
                case PackageIds.OpenMaster:
                case PackageIds.OpenRevision:
                case PackageIds.OpenRevisionFull:
                case PackageIds.OpenWebIDE:
                {
                    try
                    {
                        using (var git = new GitAnalysis(GetActiveFilePath()))
                        {
                            if (!git.IsDiscoveredGitRepository)
                            {
                                return;
                            }
                            var selectionLineRange = GetSelectionLineRange();
                            var type     = ToGiteaUrlType(command.CommandID.ID);
                            var GiteaUrl = git.BuildGiteaUrl(type, selectionLineRange);
                            System.Diagnostics.Process.Start(GiteaUrl);         // open browser
                        }
                    }
                    catch (Exception ex)
                    {
                        OutputWindowHelper.ExceptionWriteLine(string.Format("ExecuteCommand {0}", command.CommandID.ID, ex.Message), ex);
                    }
                }
                break;

                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 FileInfo(DTE.ActiveDocument.FullName).Name;
                        csm.Desc     = csm.FileName;
                        _shell.ShowDialog(Strings.CreateSnippet, dialog);
                    }
                    else
                    {
                        OutputWindowHelper.DiagnosticWriteLine(Strings.PleaseSelectCode);
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }