示例#1
0
        public void VsTextViewCreated(Microsoft.VisualStudio.TextManager.Interop.IVsTextView textViewAdapter)
        {
            var view = this.EditorAdaptersFactory.GetWpfTextView(textViewAdapter);

            view.Options.OptionChanged += OnOptionsChanged;
            view.LostAggregateFocus    += OnLostAggregateFocus;

            IOleCommandTarget nextCommandTarget;

            if (view.Roles.Contains(PredefinedTextViewRoles.PrimaryDocument))
            {
                CommandRouter commandRouter = CommandRouterProvider.GetCommandRouter(view);

                // Register internal handlers with the command router

                // Register the filter to execute emacs commands
                commandRouter.AddCommandTarget(new EmacsCommandsFilter(view, this.Manager, commandRouter));

                // Register the mark session
                commandRouter.AddCommandTarget(this.Manager.GetOrCreateMarkSession(view));

                // Register the universal argument session
                commandRouter.AddCommandTarget(this.Manager.GetOrCreateUniversalArgumentSession(view));
            }
            else
            {
                // Register the filter to execute emacs commands
                var commandFilter = new InteractiveRoleWorkAroundFilter(view, this.Manager);
                textViewAdapter.AddCommandFilter(commandFilter, out nextCommandTarget);
                commandFilter.NextCommandTarget = nextCommandTarget;
            }
        }
        public CommandRouter GetCommandRouter(ITextView view)
        {
            return(view.Properties.GetOrCreateSingletonProperty <CommandRouter>(
                       () =>
            {
                IOleCommandTarget nextCommandTarget = null;
                IVsTextView textViewAdapter = EditorAdapterFactoryService.GetViewAdapter(view);
                DTE dte = ServiceProvider.GetService <DTE>();

                // create a new router and add it to the view's command chain
                CommandRouter router = new CommandRouter(view, textViewAdapter as IOleCommandTarget, CompletionBroker, dte);

                System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(textViewAdapter.AddCommandFilter(router, out nextCommandTarget));

                router.Next = nextCommandTarget;

                return router;
            }));
        }
 public EmacsCommandsFilter(ITextView view, EmacsCommandsManager manager, CommandRouter router)
 {
     this.view    = view;
     this.manager = manager;
     this.router  = router;
 }