Exemplo n.º 1
0
        public IOleCommandTarget GetCommandTarget(IWpfTextView textView, IOleCommandTarget nextTarget)
        {
            EditorView.Create(textView);
            var target = textView.GetService <IOleCommandTarget>();

            if (target == null)
            {
                var controller = ReplCommandController.Attach(textView, textView.TextBuffer, _shell.Services);
                var es         = _shell.GetService <IEditorSupport>();
                // Wrap controller into OLE command target
                target = es.TranslateToHostCommandTarget(textView.ToEditorView(), controller) as IOleCommandTarget;
                Debug.Assert(target != null);

                textView.AddService(target);

                // Wrap next OLE target in the chain into ICommandTarget so we can have
                // chain like: OLE Target -> Shim -> ICommandTarget -> Shim -> Next OLE target
                var nextCommandTarget = es.TranslateCommandTarget(textView.ToEditorView(), nextTarget);
                controller.ChainedController = nextCommandTarget;

                // We need to listed when R projected buffer is attached and
                // create R editor document over it.
                textView.BufferGraph.GraphBuffersChanged += OnGraphBuffersChanged;
                var pb = textView.TextBuffer as IProjectionBuffer;
                if (pb != null)
                {
                    pb.SourceBuffersChanged += OnSourceBuffersChanged;
                }

                textView.Closed += TextView_Closed;
            }
            return(target);
        }