Пример #1
0
 public CurrentEnvironmentCommand(IServiceProvider serviceProvider)
     : base(null, null, QueryStatus, new CommandID(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.comboIdCurrentEnvironment))
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _envSwitchMgr    = serviceProvider.GetPythonToolsService().EnvironmentSwitcherManager;
     _logger          = serviceProvider.GetService(typeof(IPythonToolsLogger)) as IPythonToolsLogger;
 }
Пример #2
0
        private bool?QuerySetEvaluator(string newEvaluator, string newEvaluatorId)
        {
            var opts = _serviceProvider.GetPythonToolsService().SuppressDialogOptions;
            var opt  = opts.SwitchEvaluator;

            if (opt == "AlwaysSwitch")
            {
                return(true);
            }
            else if (opt == "AlwaysOpenNew")
            {
                return(false);
            }

            var td = new TaskDialog(_serviceProvider)
            {
                Title             = Strings.ProductTitle,
                MainInstruction   = Strings.ReplQuerySwitchEvaluator.FormatUI(newEvaluator),
                Content           = Strings.ReplQuerySwitchEvaluatorHint,
                VerificationText  = Strings.RememberMySelection,
                AllowCancellation = true
            };
            var sameWin = new TaskDialogButton(Strings.ReplQuerySwitchThisTab, Strings.ReplQuerySwitchThisTabHint);
            var newWin  = new TaskDialogButton(Strings.ReplQuerySwitchNewTab, Strings.ReplQuerySwitchNewTabHint);

            td.Buttons.Add(sameWin);
            td.Buttons.Add(newWin);
            td.Buttons.Add(TaskDialogButton.Cancel);
            var result = td.ShowModal();

            if (result == sameWin)
            {
                if (td.SelectedVerified)
                {
                    opts.SwitchEvaluator = "AlwaysSwitch";
                    opts.Save();
                }
                return(true);
            }
            else if (result == newWin)
            {
                if (td.SelectedVerified)
                {
                    opts.SwitchEvaluator = "AlwaysOpenNew";
                    opts.Save();
                }
                return(false);
            }
            return(null);
        }
Пример #3
0
        private ReplEditFilter(
            IVsTextView vsTextView,
            ITextView textView,
            IEditorOperations editorOps,
            IServiceProvider serviceProvider,
            IOleCommandTarget next
            )
        {
            _vsTextView      = vsTextView;
            _textView        = textView;
            _editorOps       = editorOps;
            _serviceProvider = serviceProvider;
            _componentModel  = _serviceProvider.GetComponentModel();
            _pyService       = _serviceProvider.GetPythonToolsService();
            _interactive     = _textView.TextBuffer.GetInteractiveWindow();
            _next            = next;

            if (_interactive != null)
            {
                _selectEval = _interactive.Evaluator as SelectableReplEvaluator;
            }

            if (_selectEval != null)
            {
                _selectEval.EvaluatorChanged           += EvaluatorChanged;
                _selectEval.AvailableEvaluatorsChanged += AvailableEvaluatorsChanged;
            }

            var mse = _interactive?.Evaluator as IMultipleScopeEvaluator;

            if (mse != null)
            {
                _scopeListVisible                = mse.EnableMultipleScopes;
                mse.AvailableScopesChanged      += AvailableScopesChanged;
                mse.MultipleScopeSupportChanged += MultipleScopeSupportChanged;
            }

            if (_next == null && _interactive != null)
            {
                ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next));
            }
        }
Пример #4
0
 public CodeWindowManager(IServiceProvider serviceProvider, IVsCodeWindow codeWindow)
 {
     _serviceProvider = serviceProvider;
     _window          = codeWindow;
     _pyService       = _serviceProvider.GetPythonToolsService();
 }
Пример #5
0
        int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == GuidList.guidWebPackgeCmdId)
            {
                if (nCmdID == 0x101 /*  EnablePublishToWindowsAzureMenuItem*/)
                {
                    var        shell = (IVsShell)((IServiceProvider)this).GetService(typeof(SVsShell));
                    var        webPublishPackageGuid = GuidList.guidWebPackageGuid;
                    IVsPackage package;

                    int res = shell.LoadPackage(ref webPublishPackageGuid, out package);
                    if (!ErrorHandler.Succeeded(res))
                    {
                        return(res);
                    }

                    var cmdTarget = package as IOleCommandTarget;
                    if (cmdTarget != null)
                    {
                        res = cmdTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                        if (ErrorHandler.Succeeded(res))
                        {
                            // TODO: Check flag to see if we were notified
                            // about being added as a web role.
                            if (!AddWebRoleSupportFiles())
                            {
                                VsShellUtilities.ShowMessageBox(
                                    this,
                                    Strings.AddWebRoleSupportFiles,
                                    null,
                                    OLEMSGICON.OLEMSGICON_INFO,
                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                                    );
                            }
                        }
                        return(res);
                    }
                }
            }
            else if (pguidCmdGroup == PublishCmdGuid)
            {
                if (nCmdID == PublishCmdid)
                {
                    // Approximately duplicated in DjangoProject
                    var opts = _site.GetPythonToolsService().SuppressDialogOptions;
                    if (string.IsNullOrEmpty(opts.PublishToAzure30))
                    {
                        var td = new TaskDialog(_site)
                        {
                            Title             = Strings.ProductTitle,
                            MainInstruction   = Strings.PublishToAzure30,
                            Content           = Strings.PublishToAzure30Message,
                            VerificationText  = Strings.DontShowAgain,
                            SelectedVerified  = false,
                            AllowCancellation = true,
                            EnableHyperlinks  = true
                        };
                        td.Buttons.Add(TaskDialogButton.OK);
                        td.Buttons.Add(TaskDialogButton.Cancel);
                        if (td.ShowModal() == TaskDialogButton.Cancel)
                        {
                            return(VSConstants.S_OK);
                        }

                        if (td.SelectedVerified)
                        {
                            opts.PublishToAzure30 = "true";
                            opts.Save();
                        }
                    }
                }
            }

            return(_menuService.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Пример #6
0
        /// <summary>
        /// FillCommentParagraph fills the text in a contiguous block of comment lines,
        ///   each having the same [whitespace][commentchars][whitespace] prefix.  Each
        /// resulting line is as long as possible without exceeding the
        /// Config.CodeWidth.Width column.  This function also works on paragraphs
        /// within doc strings, each having the same leading whitespace.  Leading
        /// whitespace must be space characters.
        /// </summary>
        public void FillCommentParagraph(ITextView view)
        {
            var caret  = view.Caret;
            var txtbuf = view.TextBuffer;
            // don't clone Caret, need point that works at buffer level not view.
            var bufpt      = caret.Position.BufferPosition; //txtbuf.GetTextPoint(caret.CurrentPosition);
            var fillPrefix = GetFillPrefix(view, bufpt);

            // TODO: Fix doc string parsing
            if (fillPrefix.Prefix == null || fillPrefix.Prefix.Length == 0 || fillPrefix.IsDocString)
            {
                System.Windows.MessageBox.Show(Strings.FillCommentSelectionError, Strings.ProductTitle);
                return;
            }

            var    start   = FindParagraphStart(bufpt, fillPrefix);
            var    end     = FindParagraphEnd(bufpt, fillPrefix);
            string newLine = view.Options.GetNewLineCharacter();

            using (var edit = view.TextBuffer.CreateEdit()) {
                int      startLine = start.GetContainingLine().LineNumber;
                string[] lines     = new string[end.GetContainingLine().LineNumber - startLine + 1];
                for (int i = 0; i < lines.Length; i++)
                {
                    lines[i] = start.Snapshot.GetLineFromLineNumber(startLine + i).GetText();
                }

                int curLine = 0, curOffset = fillPrefix.Prefix.Length;

                int           columnCutoff        = _serviceProvider.GetPythonToolsService().GetCodeFormattingOptions().WrappingWidth - fillPrefix.Prefix.Length;
                int           defaultColumnCutoff = columnCutoff;
                StringBuilder newText             = new StringBuilder(end.Position - start.Position);
                while (curLine < lines.Length)
                {
                    string curLineText = lines[curLine];
                    int    lastSpace   = curLineText.Length;

                    // skip leading white space
                    while (curOffset < curLineText.Length && Char.IsWhiteSpace(curLineText[curOffset]))
                    {
                        curOffset++;
                    }

                    // find next word
                    for (int i = curOffset; i < curLineText.Length; i++)
                    {
                        if (Char.IsWhiteSpace(curLineText[i]))
                        {
                            lastSpace = i;
                            break;
                        }
                    }

                    if (lastSpace - curOffset < columnCutoff || columnCutoff == defaultColumnCutoff)
                    {
                        // we found a like break in the region and it's a reasonable size or
                        // we have a really long word that we need to append unbroken
                        if (columnCutoff == defaultColumnCutoff)
                        {
                            // first time we're appending to this line
                            newText.Append(fillPrefix.Prefix);
                        }

                        newText.Append(curLineText, curOffset, lastSpace - curOffset);

                        // append appropriate spacing
                        if (_sentenceTerminators.IndexOf(curLineText[lastSpace - 1]) != -1 ||   // we end in punctuation
                            ((lastSpace - curOffset) > 1 &&                                     // we close a paren that ends in punctuation
                             curLineText[lastSpace - curOffset] == ')' &&
                             _sentenceTerminators.IndexOf(curLineText[lastSpace - 2]) != -1))
                        {
                            newText.Append("  ");
                            columnCutoff -= lastSpace - curOffset + 2;
                        }
                        else
                        {
                            newText.Append(' ');
                            columnCutoff -= lastSpace - curOffset + 1;
                        }
                        curOffset = lastSpace + 1;
                    }
                    else
                    {
                        // current word is too long to append.  Start the next line.
                        while (newText.Length > 0 && newText[newText.Length - 1] == ' ')
                        {
                            newText.Length = newText.Length - 1;
                        }
                        newText.Append(newLine);
                        columnCutoff = defaultColumnCutoff;
                    }

                    if (curOffset >= lines[curLine].Length)
                    {
                        // we're not reading from the next line
                        curLine++;
                        curOffset = fillPrefix.Prefix.Length;
                    }
                }
                while (newText.Length > 0 && newText[newText.Length - 1] == ' ')
                {
                    newText.Length = newText.Length - 1;
                }

                // commit the new text
                edit.Delete(start.Position, end.Position - start.Position);
                edit.Insert(start.Position, newText.ToString());
                edit.Apply();
            }
        }