Example #1
0
            public void VsTextViewCreated(IVsTextView textViewAdapter)
            {
                var view = _adaptersFactory.GetWpfTextView(textViewAdapter);

                var autoCompleteCommandFilter = new AutoCompleteCommandFilter(view, _completionBroker, ServiceProvider);

                IOleCommandTarget next;

                textViewAdapter.AddCommandFilter(autoCompleteCommandFilter, out next);
                autoCompleteCommandFilter.Next = next;

                var gotoDefnCommandFilter = new GotoDefnCommandFilter(view, ServiceProvider);

                textViewAdapter.AddCommandFilter(gotoDefnCommandFilter, out next);
                gotoDefnCommandFilter.Next = next;

                var refactorCommandFilter = new RenameCommandFilter(view, ServiceProvider);

                textViewAdapter.AddCommandFilter(refactorCommandFilter, out next);
                refactorCommandFilter.Next = next;

                var findReferencesCommandFilter = new FindReferencesCommandFilter(view, ServiceProvider);

                textViewAdapter.AddCommandFilter(findReferencesCommandFilter, out next);
                findReferencesCommandFilter.Next = next;

                var formatCommandFilter = new FormatCommandFilter(view, ServiceProvider);

                textViewAdapter.AddCommandFilter(formatCommandFilter, out next);
                formatCommandFilter.Next = next;
            }
        private static void AddCommandFilter(IVsTextView viewAdapter, RenameCommandFilter commandFilter)
        {
            if (!commandFilter.IsAdded)
            {
                // Get the view adapter from the editor factory
                IOleCommandTarget next;
                int hr = viewAdapter.AddCommandFilter(commandFilter, out next);

                if (hr == VSConstants.S_OK)
                {
                    commandFilter.IsAdded = true;
                    // You'll need the next target for Exec and QueryStatus
                    if (next != null) commandFilter.NextTarget = next;
                }
            }
        }
        private static void AddCommandFilter(IVsTextView viewAdapter, RenameCommandFilter commandFilter)
        {
            if (!commandFilter.IsAdded)
            {
                // Get the view adapter from the editor factory
                IOleCommandTarget next;
                int hr = viewAdapter.AddCommandFilter(commandFilter, out next);

                if (hr == VSConstants.S_OK)
                {
                    commandFilter.IsAdded = true;
                    // You'll need the next target for Exec and QueryStatus
                    if (next != null)
                    {
                        commandFilter.NextTarget = next;
                    }
                }
            }
        }