Example #1
0
        public void SubjectBuffersConnected(IWpfTextView textView, ConnectionReason reason, Collection <ITextBuffer> subjectBuffers)
        {
            IVsShell shell = ServiceProvider.GetService(typeof(IVsShell)) as IVsShell;

            if (shell == null)
            {
                return;
            }

            IVsPackage package = null;
            Guid       PackageToBeLoadedGuid =
                new Guid(TabAutoCallPackage.PackageGuidString);

            shell.LoadPackage(ref PackageToBeLoadedGuid, out package);

            IVsTextView       textViewAdapter = AdaptersFactory.GetViewAdapter(textView);
            IEditorOperations operations      = OperationsService.GetEditorOperations(textView);
            TrackState        state           = textView.Properties.GetOrCreateSingletonProperty(() => new TrackState());

            foreach (var item in subjectBuffers)
            {
                if (SupportedContentTypes.Contains(item.ContentType.TypeName, StringComparer.OrdinalIgnoreCase))
                {
                    textView.Properties.GetOrCreateSingletonProperty(() => new CommandFilter(state, textView, textViewAdapter, operations, ServiceProvider, CompletionBroker));
                    textView.Properties.GetOrCreateSingletonProperty(() => new CommandFilterHighPriority(state, textView, textViewAdapter, ServiceProvider, CompletionBroker));
                }
            }
        }
Example #2
0
        public CommandFilterHighPriority(TrackState state, ITextView textView, IVsTextView textViewAdapter, SVsServiceProvider service, ICompletionBroker broker)
        {
            Dispatcher.CurrentDispatcher.InvokeAsync(() =>
            {
                // needed, else you don't catch AUTOCOMPLETE/COMPLETEWORD
                ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(this, out _nextCommandTarget));
            }, DispatcherPriority.ApplicationIdle);            // needed, else you don't catch AUTOCOMPLETE/COMPLETEWORD

            _state   = state;
            TextView = textView;
            Service  = service;
            Broker   = broker;
        }
Example #3
0
        public CommandFilter(TrackState state, ITextView textView, IVsTextView textViewAdapter, IEditorOperations operations, SVsServiceProvider service, ICompletionBroker broker)
        {
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(this, out _nextCommandTarget));

            if (DTE == null)
            {
                DTE = service.GetService(typeof(DTE)) as DTE2;
            }

            _state     = state;
            TextView   = textView;
            Operations = operations;
            Broker     = broker;
            Service    = service;

            textView.Caret.PositionChanged += (s, e) =>
            {
                _state._justCompletedFunc = false;

                if (_state._justCompletedAutoBrace && !_state._justCompletedAutoBraceTrack.GetSpan(e.NewPosition.BufferPosition.Snapshot).Contains(e.NewPosition.BufferPosition))
                {
                    string txt = _state._justCompletedAutoBraceTrack.GetSpan(e.NewPosition.BufferPosition.Snapshot).GetText();
                    _state._justCompletedAutoBrace      = false;
                    _state._justCompletedAutoBraceTrack = null;
                }
            };

            textView.TextBuffer.Changed += (s, e) =>
            {
                _state._justCompletedFunc      = false;
                _state._justCompletedAutoBrace = false;

                if (_state._justCompletedWordVer != null && e.AfterVersion != _state._justCompletedWordVer)
                {
                    _state._justCompletedFunc = true;
                }

                _state._justCompletedWordVer = null;
            };
        }