コード例 #1
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));
            }
        }
コード例 #2
0
ファイル: CodeWindowManager.cs プロジェクト: omnimark/PTVS
 public CodeWindowManager(IServiceProvider serviceProvider, IVsCodeWindow codeWindow) {
     _serviceProvider = serviceProvider;
     _window = codeWindow;
     _pyService = _serviceProvider.GetPythonToolsService();
 }
コード例 #3
0
ファイル: CodeWindowManager.cs プロジェクト: xNUTs/PTVS
 public CodeWindowManager(IServiceProvider serviceProvider, IVsCodeWindow codeWindow)
 {
     _serviceProvider = serviceProvider;
     _window          = codeWindow;
     _pyService       = _serviceProvider.GetPythonToolsService();
 }
コード例 #4
0
ファイル: FillParagraphCommand.cs プロジェクト: yepeiwen/PTVS
        /// <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();
            }
        }
コード例 #5
0
 public IntellisenseControllerProvider([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
 {
     _ServiceProvider = serviceProvider;
     PythonService    = serviceProvider.GetPythonToolsService();
 }
コード例 #6
0
        int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == CommonGuidList.guidWebPackgeCmdId)
            {
                if (nCmdID == 0x101 /*  EnablePublishToWindowsAzureMenuItem*/)
                {
                    var        shell = (IVsShell)((IServiceProvider)this).GetService(typeof(SVsShell));
                    var        webPublishPackageGuid = CommonGuidList.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));
        }
コード例 #7
0
 public CurrentEnvironmentListCommand(IServiceProvider serviceProvider)
     : base(null, new CommandID(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.comboIdCurrentEnvironmentList))
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _envSwitchMgr    = serviceProvider.GetPythonToolsService().EnvironmentSwitcherManager;
 }