Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        public override void Connect()
        {
            var dialog = _viewFactory.GetView <Dialog>(ViewTypes.Login);

            _shell.ShowDialog(string.Format(Strings.Login_ConnectTo, Strings.Name), dialog);
        }
        private void OnClone()
        {
            var dialog = _viewFactory.GetView <Dialog>(ViewTypes.Clone);

            _shell.ShowDialog(Strings.Common_Clone, dialog);
        }
Exemplo n.º 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());
            }
        }
        private void OnLogin()
        {
            var dialog = _viewFactory.GetView <Dialog>(ViewTypes.Login);

            _shell.ShowDialog(string.Format(Strings.Login_ConnectTo, Strings.Name), dialog);
        }
Exemplo n.º 6
0
        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);
            }
        }