public void CreateLines(params string[] lines)
 {
     var tuple = EditorUtil.CreateViewAndOperations(lines);
     _view = tuple.Item1;
     _buffer = _view.TextBuffer;
     _operations = tuple.Item2;
 }
        public InformationBarMargin(IWpfTextView textView, ITextDocument document, IEditorOperations editorOperations, ITextUndoHistory undoHistory, DTE dte)
        {
            _textView = textView;
            _document = document;
            _operations = editorOperations;
            _undoHistory = undoHistory;
            _dte = dte;

            _informationBarControl = new InformationBarControl();
            _informationBarControl.Hide.Click += Hide;
            _informationBarControl.DontShowAgain.Click += DontShowAgain;
            var format = new Action(() => this.FormatDocument());
            _informationBarControl.Tabify.Click += (s, e) => this.Dispatcher.Invoke(format);

            this.Height = 0;
            this.Content = _informationBarControl;
            this.Name = MarginName;

            document.FileActionOccurred += FileActionOccurred;
            textView.Closed += TextViewClosed;

            // Delay the initial check until the view gets focus
            textView.GotAggregateFocus += GotAggregateFocus;

            this._tabDirectiveParser = new TabDirectiveParser(textView, document, dte);
            this._fileHeuristics = new FileHeuristics(textView, document, dte);

            var fix = new Action(() => this.FixFile());
            this._tabDirectiveParser.Change += (s, e) => this.Dispatcher.Invoke(fix);
        }
Exemple #3
0
		public OutputBufferVM(IEditorOperationsFactoryService editorOperationsFactoryService, Guid guid, string name, ILogEditor logEditor) {
			editorOperations = editorOperationsFactoryService.GetEditorOperations(logEditor.TextView);
			Guid = guid;
			Name = name;
			this.logEditor = logEditor;
			index = -1;
			needTimestamp = true;
		}
        public TemplateTypingCommandHandler(
            ITextView textView,
            ITextBuffer textBuffer,
            IEditorOptions editorOptions,
            IEditorOperations editorOperations)
#if DEV14_OR_LATER
            : base(textView, _ => textBuffer)
#else
            : base(textView, textBuffer)
 /// <summary>
 /// Attaches events for invoking Statement completion 
 /// </summary>
 public IntellisenseController(IntellisenseControllerProvider provider, ITextView textView) {
     _textView = textView;
     _provider = provider;
     _classifier = _provider._classifierAgg.GetClassifier(_textView.TextBuffer);
     _editOps = provider._EditOperationsFactory.GetEditorOperations(textView);
     _incSearch = provider._IncrementalSearch.GetIncrementalSearch(textView);
     _textView.MouseHover += TextViewMouseHover;
     textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
 }
 /// <summary>
 /// Attaches events for invoking Statement completion 
 /// </summary>
 public IntellisenseController(IntellisenseControllerProvider provider, ITextView textView)
 {
     _textView = textView;
     _provider = provider;
     _editOps = provider._EditOperationsFactory.GetEditorOperations(textView);
     _incSearch = provider._IncrementalSearch.GetIncrementalSearch(textView);
     _textView.MouseHover += new EventHandler<MouseHoverEventArgs>(TextViewMouseHover);
     textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
 }
        public void Initialize(ITextView view, IEditorOperations editorOperations, ITextBufferUndoManager undoManager) {
            Debug.Assert(view != null, "view must not be null");
            Debug.Assert(editorOperations != null, "editor operations must not be null");

            _view = view;
            _editorOperations = editorOperations;
            _undoManager = undoManager;
            _braceCompletionTarget = new BraceCompletionCommandTarget(view);
        }
Exemple #8
0
        public CompoundUndoAction(ITextView textView, IEditorShell editorShell, bool addRollbackOnCancel = true) {
            if (!editorShell.IsUnitTestEnvironment) {
                IEditorOperationsFactoryService operationsService = editorShell.ExportProvider.GetExportedValue<IEditorOperationsFactoryService>();
                ITextBufferUndoManagerProvider undoProvider = editorShell.ExportProvider.GetExportedValue<ITextBufferUndoManagerProvider>();

                _editorOperations = operationsService.GetEditorOperations(textView);
                _undoManager = undoProvider.GetTextBufferUndoManager(_editorOperations.TextView.TextBuffer);
                _addRollbackOnCancel = addRollbackOnCancel;
            }
        }
 public TemplateTypingCommandHandler(
     ITextView textView,
     ITextBuffer textBuffer,
     IEditorOptions editorOptions,
     IEditorOperations editorOperations)
     : base(textView, _ => textBuffer)
 {
     _editorOperations = editorOperations;
     _editorOptions = editorOptions;
 }
Exemple #10
0
        public EditFilter(ITextView textView, IEditorOperations editorOps, IServiceProvider serviceProvider)
        {
            _textView = textView;
            _textView.Properties[typeof(EditFilter)] = this;
            _editorOps = editorOps;
            _serviceProvider = serviceProvider;
            //_componentModel = _serviceProvider.GetComponentModel();

            //BraceMatcher.WatchBraceHighlights(textView, _componentModel);
        }
        public RenameTrackingTestState(
            string markup,
            string languageName,
            bool onBeforeGlobalSymbolRenamedReturnValue = true,
            bool onAfterGlobalSymbolRenamedReturnValue = true)
        {
            this.Workspace = CreateTestWorkspace(markup, languageName, TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic());

            _hostDocument = Workspace.Documents.First();
            _view = _hostDocument.GetTextView();
            _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value));
            _editorOperations = Workspace.GetService<IEditorOperationsFactoryService>().GetEditorOperations(_view);
            _historyRegistry = Workspace.ExportProvider.GetExport<ITextUndoHistoryRegistry>().Value;
            _mockRefactorNotifyService = new MockRefactorNotifyService
            {
                OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue,
                OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue
            };

            var optionService = this.Workspace.Services.GetService<IOptionService>();

            // Mock the action taken by the workspace INotificationService
            var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback;
            var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message);
            notificationService.NotificationCallback = callback;

            var tracker = new RenameTrackingTaggerProvider(
                _historyRegistry,
                Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value,
                Workspace.ExportProvider.GetExport<IInlineRenameService>().Value,
                Workspace.ExportProvider.GetExport<IDiagnosticAnalyzerService>().Value,
                SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService),
                Workspace.ExportProvider.GetExports<IAsynchronousOperationListener, FeatureMetadata>());

            _tagger = tracker.CreateTagger<RenameTrackingTag>(_hostDocument.GetTextBuffer());

            if (languageName == LanguageNames.CSharp)
            {
                _codeFixProvider = new CSharpRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else if (languageName == LanguageNames.VisualBasic)
            {
                _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else
            {
                throw new ArgumentException("Invalid langauge name: " + languageName, "languageName");
            }
        }
Exemple #12
0
        /// <summary>
        /// Initializes this ExtensionService using the provided IEditorOperations
        /// implementation for future interaction with the host editor.
        /// </summary>
        /// <param name="editorOperations">An IEditorOperations implementation.</param>
        /// <returns>A Task that can be awaited for completion.</returns>
        public async Task Initialize(IEditorOperations editorOperations)
        {
            this.EditorObject = new EditorObject(this, editorOperations);

            // Register the editor object in the runspace
            PSCommand variableCommand = new PSCommand();

            using (RunspaceHandle handle = await this.PowerShellContext.GetRunspaceHandle())
            {
                handle.Runspace.SessionStateProxy.PSVariable.Set(
                    "psEditor",
                    this.EditorObject);
            }

            // Load the cmdlet interface
            Type   thisType       = this.GetType();
            Stream resourceStream =
                thisType.Assembly.GetManifestResourceStream(
                    thisType.Namespace + ".CmdletInterface.ps1");

            using (StreamReader reader = new StreamReader(resourceStream))
            {
                // Create a temporary folder path
                string randomFileNamePart =
                    Path.GetFileNameWithoutExtension(
                        Path.GetRandomFileName());

                string tempScriptPath =
                    Path.Combine(
                        Path.GetTempPath(),
                        "PSES_ExtensionCmdlets_" + randomFileNamePart + ".ps1");

                Logger.Write(
                    LogLevel.Verbose,
                    "Executing extension API cmdlet script at path: " + tempScriptPath);

                // Read the cmdlet interface script and write it to a temporary
                // file so that we don't have to execute the full file contents
                // directly.  This keeps the script execution from creating a
                // lot of noise in the verbose logs.
                string cmdletInterfaceScript = reader.ReadToEnd();
                File.WriteAllText(
                    tempScriptPath,
                    cmdletInterfaceScript);

                await this.PowerShellContext.ExecuteScriptString(
                    ". " + tempScriptPath,
                    writeInputToHost : false,
                    writeOutputToHost : false);

                // Delete the temporary file
                File.Delete(tempScriptPath);
            }
        }
Exemple #13
0
        public EditFilter(ITextView textView, IEditorOperations editorOps, IServiceProvider serviceProvider)
        {
            _textView = textView;
            _textView.Properties[typeof(EditFilter)] = this;
            _editorOps       = editorOps;
            _serviceProvider = serviceProvider;
            _componentModel  = _serviceProvider.GetComponentModel();
            _pyService       = _serviceProvider.GetPythonToolsService();

            BraceMatcher.WatchBraceHighlights(textView, _componentModel);
        }
        /// <summary>
        /// Creates a new instance of the EditorObject class.
        /// </summary>
        /// <param name="extensionService">An ExtensionService which handles command registration.</param>
        /// <param name="editorOperations">An IEditorOperations implementation which handles operations in the host editor.</param>
        public EditorObject(
            ExtensionService extensionService,
            IEditorOperations editorOperations)
        {
            this.extensionService = extensionService;
            this.editorOperations = editorOperations;

            // Create API area objects
            this.Workspace = new EditorWorkspace(this.editorOperations);
            this.Window    = new EditorWindow(this.editorOperations);
        }
		public LeftSelectionMargin(IWpfTextViewMarginProviderCollectionProvider wpfTextViewMarginProviderCollectionProvider, IWpfTextViewHost wpfTextViewHost, IEditorOperations editorOperations)
			: base(wpfTextViewMarginProviderCollectionProvider, wpfTextViewHost, PredefinedMarginNames.LeftSelection, false) {
			if (editorOperations == null)
				throw new ArgumentNullException(nameof(editorOperations));
			Cursor = Cursors.Arrow;//TODO: Use an arrow pointing to the right
			this.wpfTextViewHost = wpfTextViewHost;
			this.editorOperations = editorOperations;
			wpfTextViewHost.TextView.ZoomLevelChanged += TextView_ZoomLevelChanged;
			// Make sure that the user can click anywhere in this margin so we'll get mouse events
			Background = Brushes.Transparent;
		}
 /// <summary>
 /// Creates a new instance of the EditorContext class.
 /// </summary>
 /// <param name="editorOperations">An IEditorOperations implementation which performs operations in the editor.</param>
 /// <param name="currentFile">The ScriptFile that is in the active editor buffer.</param>
 /// <param name="cursorPosition">The position of the user's cursor in the active editor buffer.</param>
 /// <param name="selectedRange">The range of the user's selection in the active editor buffer.</param>
 public EditorContext(
     IEditorOperations editorOperations,
     ScriptFile currentFile,
     BufferPosition cursorPosition,
     BufferRange selectedRange)
 {
     this.editorOperations = editorOperations;
     this.CurrentFile      = new FileContext(currentFile, this, editorOperations);
     this.SelectedRange    = selectedRange;
     this.CursorPosition   = new FilePosition(currentFile, cursorPosition);
 }
        public RenameTrackingTestState(
            TestWorkspace workspace,
            string languageName,
            bool onBeforeGlobalSymbolRenamedReturnValue = true,
            bool onAfterGlobalSymbolRenamedReturnValue  = true)
        {
            this.Workspace = workspace;

            _hostDocument = Workspace.Documents.First();
            _view         = _hostDocument.GetTextView();
            _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value));
            _editorOperations          = Workspace.GetService <IEditorOperationsFactoryService>().GetEditorOperations(_view);
            _historyRegistry           = Workspace.ExportProvider.GetExport <ITextUndoHistoryRegistry>().Value;
            _mockRefactorNotifyService = new MockRefactorNotifyService
            {
                OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue,
                OnAfterSymbolRenamedReturnValue  = onAfterGlobalSymbolRenamedReturnValue
            };

            // Mock the action taken by the workspace INotificationService
            var notificationService = Workspace.Services.GetService <INotificationService>() as INotificationServiceCallback;
            var callback            = new Action <string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message);

            notificationService.NotificationCallback = callback;

            var tracker = new RenameTrackingTaggerProvider(
                _historyRegistry,
                Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value,
                Workspace.ExportProvider.GetExport <IInlineRenameService>().Value,
                Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value,
                SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService),
                Workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>());

            _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer());

            if (languageName == LanguageNames.CSharp)
            {
                _codeFixProvider = new CSharpRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else if (languageName == LanguageNames.VisualBasic)
            {
                _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider(
                    Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value,
                    _historyRegistry,
                    SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService));
            }
            else
            {
                throw new ArgumentException("Invalid language name: " + languageName, nameof(languageName));
            }
        }
Exemple #18
0
 public NSIntellisenseController(NSIntellisenseControllerProvider nsicprovider, ITextView textview)
 {
     _nsicprovider    = nsicprovider;
     _serviceprovider = nsicprovider._serviceprovider_vs;
     _textview        = textview;
     _ivstextview     = _nsicprovider._adaptersfactory.GetViewAdapter(_textview);
     _editops         = nsicprovider._editoperationsfactory.GetEditorOperations(textview);
     //nsicprovider._textdocumentfactoryservice.TryGetTextDocument(_textview.TextDataModel.DocumentBuffer, out _textdocument);
     _textview.Properties.AddProperty(typeof(NSIntellisenseController), this);
     //_ivstextview.AddCommandFilter(this, out m_commandhandler_next);
 }
 /// <summary>
 /// Attaches events for invoking Statement completion 
 /// </summary>
 /// <param name="subjectBuffers"></param>
 /// <param name="textView"></param>
 /// <param name="completionBrokerMap"></param>
 public IntellisenseController(IntellisenseControllerProvider provider, IList<ITextBuffer> subjectBuffers, ITextView textView)
 {
     _subjectBuffers = subjectBuffers;
     _textView = textView;
     _provider = provider;
     _editOps = provider._EditOperationsFactory.GetEditorOperations(textView);
     #if FEATURE_INTELLISENSE
     _textView.MouseHover += new EventHandler<MouseHoverEventArgs>(TextViewMouseHover);
     #endif
     textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
 }
Exemple #20
0
        public KeyProcessor GetAssociatedProcessor(IWpfTextView textView)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            IIntellisenseSessionStack stackForTextView = this.StackMapService.GetStackForTextView(textView);
            IEditorOperations         editorOperations = EditorOperationsFactoryService.GetEditorOperations(textView);

            return(new CALKeyProcessor(textView, editorOperations));
        }
Exemple #21
0
 public IncrementalSearch(ITextView textView, ITextSearchService textSearchService, IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     if (editorOperationsFactoryService == null)
     {
         throw new ArgumentNullException(nameof(editorOperationsFactoryService));
     }
     TextView = textView ?? throw new ArgumentNullException(nameof(textView));
     this.textSearchService = textSearchService ?? throw new ArgumentNullException(nameof(textSearchService));
     editorOperations       = editorOperationsFactoryService.GetEditorOperations(textView);
     SearchString           = string.Empty;
 }
 internal DefaultKeyProcessor(
     IWpfTextView textView,
     IEditorOperations editorOperations,
     ITextUndoHistoryRegistry undoHistoryRegistry,
     IEditorCommandHandlerService editorCommandHandlerService)
 {
     this._textView                    = textView;
     this._editorOperations            = editorOperations;
     this._undoHistoryRegistry         = undoHistoryRegistry;
     this._editorCommandHandlerService = editorCommandHandlerService;
 }
        /// <summary>
        /// Attaches events for invoking Statement completion
        /// </summary>
        /// <param name="subjectBuffers"></param>
        /// <param name="textView"></param>
        /// <param name="completionBrokerMap"></param>
        public IntellisenseController(IntellisenseControllerProvider provider, IList <ITextBuffer> subjectBuffers, ITextView textView)
        {
            _subjectBuffers = subjectBuffers;
            _textView       = textView;
            _provider       = provider;
            _editOps        = provider._EditOperationsFactory.GetEditorOperations(textView);
#if FEATURE_INTELLISENSE
            _textView.MouseHover += new EventHandler <MouseHoverEventArgs>(TextViewMouseHover);
#endif
            textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
        }
        public MockVsTextView(IServiceProvider serviceProvier, MockVs vs, MockTextView view)
        {
            _view            = view;
            _serviceProvider = serviceProvier;
            _vs = vs;
            var compModel     = (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel));
            var editorOpsFact = compModel.GetService <IEditorOperationsFactoryService>();

            _editorOps     = editorOpsFact.GetEditorOperations(_view);
            _commandTarget = new EditorCommandTarget(this);
        }
 internal EmacsCommandContext(EmacsCommandsManager manager,
                              ITextStructureNavigatorSelectorService textStructureNavigatorSelectorService,
                              IEditorOperations editorOperations, ITextView view, CommandRouter commandRouter)
 {
     Manager                = manager;
     EditorOperations       = editorOperations;
     TextView               = view;
     CommandRouter          = commandRouter;
     Clipboard              = new StringBuilder();
     TextStructureNavigator = textStructureNavigatorSelectorService.GetTextStructureNavigator(view.TextBuffer);
     MarkSession            = MarkSession.GetSession(view);
 }
Exemple #26
0
        public CompoundUndoAction(ITextView textView, IEditorShell editorShell, bool addRollbackOnCancel = true)
        {
            if (!editorShell.IsUnitTestEnvironment)
            {
                IEditorOperationsFactoryService operationsService = editorShell.GlobalServices.GetService <IEditorOperationsFactoryService>();
                ITextBufferUndoManagerProvider  undoProvider      = editorShell.GlobalServices.GetService <ITextBufferUndoManagerProvider>();

                _editorOperations    = operationsService.GetEditorOperations(textView);
                _undoManager         = undoProvider.GetTextBufferUndoManager(_editorOperations.TextView.TextBuffer);
                _addRollbackOnCancel = addRollbackOnCancel;
            }
        }
        public VisualRustAutoindent(
            IVsTextView textViewAdapter,
            IWpfTextView textView,
            IEditorOperations operations,
            ITextUndoHistory undoHistory)
        {
            _textView    = textView;
            _operations  = operations;
            _undoHistory = undoHistory;

            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
        }
        public VisualRustAutoindent(
            IVsTextView textViewAdapter,
            IWpfTextView textView,
            IEditorOperations operations,
            ITextUndoHistory undoHistory)
        {
            _textView = textView;
            _operations = operations;
            _undoHistory = undoHistory;

            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
        }
 internal ReplWindowProxy(PythonVisualStudioApp app, ReplWindow window, ReplWindowProxySettings settings)
 {
     Assert.IsNotNull(app, "app is required");
     Assert.IsNotNull(window, "window is required");
     _app                   = app;
     _window                = window;
     _settings              = settings;
     _replWindowInfo        = _replWindows.GetOrCreateValue(_window);
     _window.ReadyForInput += _replWindowInfo.OnReadyForInput;
     _editorOperations      = _app.ComponentModel.GetService <IEditorOperationsFactoryService>()
                              .GetEditorOperations(_window.TextView);
 }
Exemple #30
0
 /// <summary>
 /// Attaches events for invoking Statement completion
 /// </summary>
 /// <param name="subjectBuffers"></param>
 /// <param name="textView"></param>
 /// <param name="completionBrokerMap"></param>
 public IntellisenseController(IntellisenseControllerProvider provider, IList <ITextBuffer> subjectBuffers, ITextView textView, BufferParser bufferParser)
 {
     _subjectBuffers       = subjectBuffers;
     _textView             = textView;
     _provider             = provider;
     _editOps              = provider._EditOperationsFactory.GetEditorOperations(textView);
     _incSearch            = provider._IncrementalSearch.GetIncrementalSearch(textView);
     _textView.MouseHover += new EventHandler <MouseHoverEventArgs>(TextViewMouseHover);
     _bufferParser         = bufferParser;
     textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
     AttachKeyboardFilter();
 }
        public CaretPreservingEditTransaction(string description, ITextUndoHistory?undoHistory, IEditorOperations editorOperations)
        {
            _editorOperations = editorOperations;
            _undoHistory      = undoHistory;
            _active           = true;

            if (_undoHistory != null)
            {
                _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(_undoHistory.CreateTransaction(description));
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
        public void NavigateTo(IWpfTextView textView, Span span, bool selectSpan, bool deferNavigationWithOutlining)
        {
            Validate.IsNotNull(textView, nameof(textView));

            Debug.Assert(span.End <= textView.TextSnapshot.Length, string.Format("span.End ({0}) > textView.TextSnapshot.Length ({1})", span.End, textView.TextSnapshot.Length));

            IEditorOperations   editorOperations    = this.singletons.EditorOperationsFactory.GetEditorOperations(textView);
            SnapshotSpan        snapshotSpan        = EditorUtilities.CreateSnapshotSpan(textView.TextSnapshot, span.Start, span.Length);
            VirtualSnapshotSpan virtualSnapshotSpan = new VirtualSnapshotSpan(snapshotSpan);

            Navigate(editorOperations, virtualSnapshotSpan, selectSpan);
        }
		public IncrementalSearch(ITextView textView, ITextSearchService textSearchService, IEditorOperationsFactoryService editorOperationsFactoryService) {
			if (textView == null)
				throw new ArgumentNullException(nameof(textView));
			if (textSearchService == null)
				throw new ArgumentNullException(nameof(textSearchService));
			if (editorOperationsFactoryService == null)
				throw new ArgumentNullException(nameof(editorOperationsFactoryService));
			TextView = textView;
			this.textSearchService = textSearchService;
			editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
			SearchString = string.Empty;
		}
Exemple #34
0
        public KeyProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
        {
            // Create the key processor only if the target buffer is of content type "regex"
            if (wpfTextView.TextBuffer.ContentType.TypeName == RegexContentType.ContentTypeName)
            {
                IEditorOperations editorOperations = this.EditorOperationsFactoryService.GetEditorOperations(wpfTextView);

                return(new RegexEditorKeyProcessor(editorOperations));
            }

            return(null);
        }
Exemple #35
0
        public IRHistoryWindowVisualComponent GetOrCreateVisualComponent(IRHistoryVisualComponentContainerFactory visualComponentContainerFactory, int instanceId = 0)
        {
            if (VisualComponent != null)
            {
                return(VisualComponent);
            }

            VisualComponent    = visualComponentContainerFactory.GetOrCreate(_historyTextBuffer, instanceId).Component;
            _textViewSelection = VisualComponent.TextView.Selection;
            _editorOperations  = _editorOperationsFactory.GetEditorOperations(VisualComponent.TextView);
            return(VisualComponent);
        }
Exemple #36
0
        private int ActivateGoToBufferPosnCmd(IWpfTextView textView, IEditorOperations editorOperations)
        {
            // Show input box to receive buffer position
            var    stringInputWindow    = new StringInputWindow();
            string desiredBufferPosnStr = stringInputWindow.ShowDialog("Go To Buffer Position", "Enter position (int)", "");
            // TODO: Validate value returned (must be a number between 0 and textBuffer.length)
            // convert it to an int
            int desiredBufferPosn = int.Parse(desiredBufferPosnStr);

            textView.Caret.MoveTo(new SnapshotPoint(textView.TextSnapshot, desiredBufferPosn));
            return(VSConstants.S_OK);
        }
Exemple #37
0
        public CompoundUndoAction(ITextView textView, ITextBuffer textBuffer, bool addRollbackOnCancel = true)
        {
            if (!EditorShell.Current.IsUnitTestEnvironment)
            {
                IEditorOperationsFactoryService operationsService = EditorShell.Current.ExportProvider.GetExport <IEditorOperationsFactoryService>().Value;
                ITextBufferUndoManagerProvider  undoProvider      = EditorShell.Current.ExportProvider.GetExport <ITextBufferUndoManagerProvider>().Value;

                _editorOperations    = operationsService.GetEditorOperations(textView);
                _undoManager         = undoProvider.GetTextBufferUndoManager(_editorOperations.TextView.TextBuffer);
                _addRollbackOnCancel = addRollbackOnCancel;
            }
        }
 /// <summary>
 /// Creates a new instance of the EditorContext class.
 /// </summary>
 /// <param name="editorOperations">An IEditorOperations implementation which performs operations in the editor.</param>
 /// <param name="currentFile">The ScriptFile that is in the active editor buffer.</param>
 /// <param name="cursorPosition">The position of the user's cursor in the active editor buffer.</param>
 /// <param name="selectedRange">The range of the user's selection in the active editor buffer.</param>
 /// <param name="language">Determines the language of the file.false If it is not specified, then it defaults to "Unknown"</param>
 internal EditorContext(
     IEditorOperations editorOperations,
     ScriptFile currentFile,
     BufferPosition cursorPosition,
     BufferRange selectedRange,
     string language = "Unknown")
 {
     this.editorOperations = editorOperations;
     this.CurrentFile      = new FileContext(currentFile, this, editorOperations, language);
     this.SelectedRange    = new BufferFileRange(selectedRange);
     this.CursorPosition   = new BufferFilePosition(cursorPosition);
 }
        public static void ReplaceSelectedLines(ITextView textView, IEditorOperations editorOperations)
        {
            if (textView.Selection.IsEmpty)
            {
                return;
            }

            var selectedSpan = textView.Selection.SelectedSpans[0];

            string origin, change;
            string title = "Replace With Preserve Sensitive Case";

            origin = Prompt.ShowDialog("Replace From : ", title);
            if (origin.Length == 0)
            {
                return;
            }

            change = Prompt.ShowDialog("Replace To : ", title);
            if (origin.Length != change.Length)
            {
                return;
            }

            string trans = Regex.Replace(selectedSpan.GetText(), origin,
                                         new MatchEvaluator((Match match) =>
            {
                string val      = match.Value;
                char[] arrayVal = val.ToCharArray();

                int len = val.Length;
                for (int i = 0; i < len; ++i)
                {
                    if (char.IsUpper(arrayVal[i]))
                    {
                        arrayVal[i] = char.ToUpper(change[i]);
                    }
                    else
                    {
                        arrayVal[i] = char.ToLower(change[i]);
                    }
                }

                return(new string(arrayVal));
            })
                                         , RegexOptions.IgnoreCase);

            textView.TextBuffer.Replace(selectedSpan, trans);
            //editorOperations.MoveToEndOfLine(extendSelection: false);
            //editorOperations.Delete();
            editorOperations.DeleteHorizontalWhiteSpace();
        }
        /// <summary>
        /// Starts a debug-only session using the provided IConsoleHost implementation
        /// for the ConsoleService.
        /// </summary>
        /// <param name="powerShellContext"></param>
        /// <param name="editorOperations">
        /// An IEditorOperations implementation used to interact with the editor.
        /// </param>
        public void StartDebugSession(
            PowerShellContext powerShellContext,
            IEditorOperations editorOperations)
        {
            this.PowerShellContext = powerShellContext;

            // Initialize all services
            this.RemoteFileManager = new RemoteFileManager(this.PowerShellContext, editorOperations, logger);
            this.DebugService      = new DebugService(this.PowerShellContext, this.RemoteFileManager, logger);

            // Create a workspace to contain open files
            this.Workspace = new Workspace(this.PowerShellContext.LocalPowerShellVersion.Version, this.logger);
        }
Exemple #41
0
        /// <summary>
        /// Creates a new instance of the EditorObject class.
        /// </summary>
        /// <param name="extensionService">An ExtensionService which handles command registration.</param>
        /// <param name="editorOperations">An IEditorOperations implementation which handles operations in the host editor.</param>
        /// <param name="componentRegistry">An IComponentRegistry instance which provides components in the session.</param>
        public EditorObject(
            ExtensionService extensionService,
            IEditorOperations editorOperations,
            IComponentRegistry componentRegistry)
        {
            this.extensionService = extensionService;
            this.editorOperations = editorOperations;
            this.Components       = componentRegistry;

            // Create API area objects
            this.Workspace = new EditorWorkspace(this.editorOperations);
            this.Window    = new EditorWindow(this.editorOperations);
        }
Exemple #42
0
        public EditFilter(ITextView textView, IEditorOperations editorOps, IEditorOptions editorOptions, IIntellisenseSessionStack intellisenseStack, IComponentModel compModel)
        {
            _textView          = textView;
            _editorOps         = editorOps;
            _intellisenseStack = intellisenseStack;
            _compModel         = compModel;
            var agg = _compModel.GetService <IClassifierAggregatorService>();

            _classifier    = agg.GetClassifier(textView.TextBuffer);
            _incSearch     = _compModel.GetService <IIncrementalSearchFactoryService>().GetIncrementalSearch(_textView);
            _broker        = _compModel.GetService <ICompletionBroker>();
            _editorOptions = editorOptions;
        }
        public CALKeyProcessor(ITextView textView, IEditorOperations editorOperations)
        {
            _zoomUpdated = false;

            this.InputProcessors  = new List <InputProcessor>();
            this.TextView         = textView;
            this.EditorOperations = editorOperations;

            this.NavConnector  = new Connector(textView);
            this.MethodManager = this.NavConnector.MethodManager;

            CreateInputProcessors();
        }
        /// <summary>
        /// Creates a new instance of the EditorObject class.
        /// </summary>
        /// <param name="extensionService">An ExtensionService which handles command registration.</param>
        /// <param name="editorOperations">An IEditorOperations implementation which handles operations in the host editor.</param>
        public EditorObject(
            IServiceProvider serviceProvider,
            ExtensionService extensionService,
            IEditorOperations editorOperations)
        {
            this._serviceProvider  = serviceProvider;
            this._extensionService = extensionService;
            this._editorOperations = editorOperations;

            // Create API area objects
            this.Workspace = new EditorWorkspace(this._editorOperations);
            this.Window    = new EditorWindow(this._editorOperations);
        }
        /// <summary>
        /// This can use input files with an (optionally) annotated span 'Selection' and a cursor position ($$),
        /// and use it to create a selected span in the TextView.
        ///
        /// For instance, the following will create a TextView that has a multiline selection with the cursor at the end.
        ///
        /// Sub Foo
        ///     {|Selection:SomeMethodCall()
        ///     AnotherMethodCall()$$|}
        /// End Sub
        /// </summary>
        public AbstractCommandHandlerTestState(
            XElement workspaceElement,
            ExportProvider exportProvider,
            string workspaceKind)
        {
            this.Workspace = TestWorkspaceFactory.CreateWorkspace(
                workspaceElement,
                exportProvider: exportProvider,
                workspaceKind: workspaceKind);

            var cursorDocument = this.Workspace.Documents.First(d => d.CursorPosition.HasValue);

            _textView      = cursorDocument.GetTextView();
            _subjectBuffer = cursorDocument.GetTextBuffer();

            IList <Text.TextSpan> selectionSpanList;

            if (cursorDocument.AnnotatedSpans.TryGetValue("Selection", out selectionSpanList))
            {
                var span           = selectionSpanList.First();
                var cursorPosition = cursorDocument.CursorPosition.Value;

                Assert.True(cursorPosition == span.Start || cursorPosition == span.Start + span.Length,
                            "cursorPosition wasn't at an endpoint of the 'Selection' annotated span");

                _textView.Selection.Select(
                    new SnapshotSpan(_subjectBuffer.CurrentSnapshot, new Span(span.Start, span.Length)),
                    isReversed: cursorPosition == span.Start);

                if (selectionSpanList.Count > 1)
                {
                    _textView.Selection.Mode = TextSelectionMode.Box;
                    foreach (var additionalSpan in selectionSpanList.Skip(1))
                    {
                        _textView.Selection.Select(
                            new SnapshotSpan(_subjectBuffer.CurrentSnapshot, new Span(additionalSpan.Start, additionalSpan.Length)),
                            isReversed: false);
                    }
                }
            }
            else
            {
                _textView.Caret.MoveTo(
                    new SnapshotPoint(
                        _textView.TextBuffer.CurrentSnapshot,
                        cursorDocument.CursorPosition.Value));
            }

            this.EditorOperations    = GetService <IEditorOperationsFactoryService>().GetEditorOperations(_textView);
            this.UndoHistoryRegistry = GetService <ITextUndoHistoryRegistry>();
        }
        internal DefaultKeyProcessor(IWpfTextView textView, IEditorOperations editorOperations, ITextUndoHistoryRegistry undoHistoryRegistry) {
            if (textView == null)
                throw new ArgumentNullException("textView");

            if (editorOperations == null)
                throw new ArgumentNullException("editorOperations");

            if (undoHistoryRegistry == null)
                throw new ArgumentNullException("undoHistoryRegistry");

            _textView = textView;
            _editorOperations = editorOperations;
            _undoHistoryRegistry = undoHistoryRegistry;
        }
 public BraceCompletionSession(
     ITextView textView, ITextBuffer subjectBuffer,
     SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextUndoHistory undoHistory,
     IEditorOperationsFactoryService editorOperationsFactoryService, IEditorBraceCompletionSession session)
 {
     this.TextView = textView;
     this.SubjectBuffer = subjectBuffer;
     this.OpeningBrace = openingBrace;
     this.ClosingBrace = closingBrace;
     this.ClosingPoint = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _undoHistory = undoHistory;
     _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
     _session = session;
 }
Exemple #48
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommenterFilter"/> class for
        /// the specified text view and commenter.
        /// </summary>
        /// <param name="textViewAdapter"></param>
        /// <param name="textView">The text view.</param>
        /// <param name="commenter">The commenter implementation.</param>
        /// <param name="editorOperations">The <see cref="IEditorOperations"/> instance for the text view.</param>
        /// <param name="textUndoHistoryRegistry">The global <see cref="ITextUndoHistoryRegistry"/> service provided by
        /// Visual Studio.</param>
        /// <exception cref="ArgumentNullException">
        /// <para>If <paramref name="textViewAdapter"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="textView"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="commenter"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="editorOperations"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="textUndoHistoryRegistry"/> is <see langword="null"/>.</para>
        /// </exception>
        public CommenterFilter(IVsTextView textViewAdapter, ITextView textView, ICommenter commenter, IEditorOperations editorOperations, ITextUndoHistoryRegistry textUndoHistoryRegistry)
            : base(textViewAdapter)
        {
            Contract.Requires(textViewAdapter != null);
            Contract.Requires<ArgumentNullException>(textView != null, "textView");
            Contract.Requires<ArgumentNullException>(commenter != null, "commenter");
            Contract.Requires<ArgumentNullException>(editorOperations != null, "editorOperations");
            Contract.Requires<ArgumentNullException>(textUndoHistoryRegistry != null, "textUndoHistoryRegistry");

            this.TextView = textView;
            this.Commenter = commenter;
            this.EditorOperations = editorOperations;
            this.TextUndoHistoryRegistry = textUndoHistoryRegistry;
            textView.Closed += (sender, e) => Dispose();
        }
        internal EmacsCommandContext(
            EmacsCommandsManager manager,
            ITextStructureNavigatorSelectorService textStructureNavigatorSelectorService,
            IEditorOperations editorOperations,
            ITextView view,
            CommandRouter commandRouter)
        {
            this.Manager = manager;
            this.EditorOperations = editorOperations;
            this.TextView = view;
            this.CommandRouter = commandRouter;

            this.TextStructureNavigator = textStructureNavigatorSelectorService.GetTextStructureNavigator(view.TextBuffer);
            this.MarkSession = MarkSession.GetSession(view);
        }
        public BraceCompleterCommandHandler(IVsTextView textViewAdapter,
			IWpfTextView textView, IEditorOperations operations, ITextUndoHistory undoHistory)
        {
            _textView = textView;
            _operations = operations;
            _undoHistory = undoHistory;

            _textView.GotAggregateFocus += TextView_GotFocus;

            // add the command to the command chain
            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);

            // load language and indentation settings
            LoadSettings();
        }
        public CaretPreservingEditTransaction(
            string description,
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
            _undoHistory = undoHistoryRegistry.GetHistory(textView.TextBuffer);
            _active = true;

            if (_undoHistory != null)
            {
                _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(_undoHistory.CreateTransaction(description));
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
		public ZoomControlMargin(IWpfTextViewHost wpfTextViewHost, IEditorOperations editorOperations) {
			if (wpfTextViewHost == null)
				throw new ArgumentNullException(nameof(wpfTextViewHost));
			if (editorOperations == null)
				throw new ArgumentNullException(nameof(editorOperations));
			this.wpfTextViewHost = wpfTextViewHost;
			this.editorOperations = editorOperations;

			IsVisibleChanged += ZoomControlMargin_IsVisibleChanged;
			wpfTextViewHost.TextView.Options.OptionChanged += Options_OptionChanged;

			// Need to set these explicitly so our themed styles are used
			SetResourceReference(StyleProperty, typeof(ComboBox));
			SetResourceReference(ItemContainerStyleProperty, typeof(ComboBoxItem));
			MinHeight = 0;
			Margin = new Thickness(0);
			Width = 60;
			UpdateVisibility();
		}
Exemple #53
0
        /// <summary>
        /// Attaches events for invoking Statement completion 
        /// </summary>
        public IntellisenseController(IntellisenseControllerProvider provider, ITextView textView, IServiceProvider serviceProvider) {
            _textView = textView;
            _provider = provider;
            _editOps = provider._EditOperationsFactory.GetEditorOperations(textView);
            _incSearch = provider._IncrementalSearch.GetIncrementalSearch(textView);
            _textView.MouseHover += TextViewMouseHover;
            _serviceProvider = serviceProvider;
            if (textView.TextBuffer.IsPythonContent()) {
                try {
                    _expansionClient = new ExpansionClient(textView, provider._adaptersFactory, provider._ServiceProvider);
                    var textMgr = (IVsTextManager2)_serviceProvider.GetService(typeof(SVsTextManager));
                    textMgr.GetExpansionManager(out _expansionMgr);
                } catch (ArgumentException) {
                    // No expansion client for this buffer, but we can continue without it
                }
            }

            textView.Properties.AddProperty(typeof(IntellisenseController), this);  // added so our key processors can get back to us
            _textView.Closed += TextView_Closed;
        }
Exemple #54
0
        public CommandFilter(
            IVsTextView textView,
            IWpfTextView wpfTextView,
            IHtmlBuilderService htmlBuilderService,
            IRtfBuilderService rtfBuilderService,
            IEditorOperations editorOperations,
            ITextUndoHistory undoHistory,
            IEditorOptions editorOptions,
            IViewPrimitives viewPrimitives,
            ITelemetrySession telemetrySession)
        {
            _htmlBuilderService = htmlBuilderService;
            _rtfBuilderService = rtfBuilderService;
            _undoHistory = undoHistory;
            _textView = wpfTextView;
            _editorOperations = editorOperations;
            _editorOptions = editorOptions;
            _viewPrimitives = viewPrimitives;
            _telemetrySession = telemetrySession;

            textView.AddCommandFilter(this, out _nextCommandTargetInChain);
        }
        public InformationBarMargin(IWpfTextView textView, ITextDocument document, IEditorOperations editorOperations, ITextUndoHistory undoHistory)
        {
            _textView = textView;
            _document = document;
            _operations = editorOperations;
            _undoHistory = undoHistory;

            var informationBar = new InformationBarControl();
            informationBar.Tabify.Click += Tabify;
            informationBar.Untabify.Click += Untabify;
            informationBar.Hide.Click += Hide;
            informationBar.DontShowAgain.Click += DontShowAgain;

            this.Height = 0;
            this.Content = informationBar;
            this.Name = MarginName;

            document.FileActionOccurred += FileActionOccurred;

            // Delay the initial check until the view gets focus
            textView.GotAggregateFocus += GotAggregateFocus;
        }
Exemple #56
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));
            }
        }
Exemple #57
0
 internal DefaultCommandTarget(ITextView textView, IEditorOperations editorOperations)
 {
     _textView = textView;
     _editorOperatins = editorOperations;
 }
 internal OperationsImpl(ITextView view, IEditorOperations opts, IVimHost host, IJumpList jumpList)
     : base(view, opts, host, jumpList)
 {
 }
Exemple #59
0
		public SearchService(IWpfTextView wpfTextView, ITextSearchService2 textSearchService2, ISearchSettings searchSettings, IMessageBoxService messageBoxService, ITextStructureNavigator textStructureNavigator, Lazy<IReplaceListenerProvider>[] replaceListenerProviders, IEditorOperationsFactoryService editorOperationsFactoryService) {
			if (wpfTextView == null)
				throw new ArgumentNullException(nameof(wpfTextView));
			if (textSearchService2 == null)
				throw new ArgumentNullException(nameof(textSearchService2));
			if (searchSettings == null)
				throw new ArgumentNullException(nameof(searchSettings));
			if (messageBoxService == null)
				throw new ArgumentNullException(nameof(messageBoxService));
			if (textStructureNavigator == null)
				throw new ArgumentNullException(nameof(textStructureNavigator));
			if (replaceListenerProviders == null)
				throw new ArgumentNullException(nameof(replaceListenerProviders));
			this.wpfTextView = wpfTextView;
			editorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView);
			this.textSearchService2 = textSearchService2;
			this.searchSettings = searchSettings;
			this.messageBoxService = messageBoxService;
			this.textStructureNavigator = textStructureNavigator;
			this.replaceListenerProviders = replaceListenerProviders;
			listeners = new List<ITextMarkerListener>();
			searchString = string.Empty;
			replaceString = string.Empty;
			searchKind = SearchKind.None;
			searchControlPosition = SearchControlPosition.Default;
			wpfTextView.VisualElement.CommandBindings.Add(new CommandBinding(ApplicationCommands.Find, (s, e) => ShowFind()));
			wpfTextView.VisualElement.CommandBindings.Add(new CommandBinding(ApplicationCommands.Replace, (s, e) => ShowReplace()));
			wpfTextView.Closed += WpfTextView_Closed;
			UseGlobalSettings(true);
		}
 protected override void NextAction(IEditorOperations editorOperation, Action nextAction)
 {
     editorOperation.InsertNewLine();
 }