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); }
private void TextView_Closed(object sender, EventArgs e) { IWpfTextView textView = sender as IWpfTextView; if (textView != null) { if (textView.BufferGraph != null) { textView.BufferGraph.GraphBuffersChanged -= OnGraphBuffersChanged; } IProjectionBuffer pb = textView.TextBuffer as IProjectionBuffer; if (pb != null) { pb.SourceBuffersChanged -= OnSourceBuffersChanged; } textView.Closed -= TextView_Closed; ReplCommandController controller = ReplCommandController.FromTextView(textView); if (controller != null) { controller.Dispose(); } } }
public IOleCommandTarget GetCommandTarget(IWpfTextView textView, IOleCommandTarget nextTarget) { IOleCommandTarget target = ServiceManager.GetService <IOleCommandTarget>(textView); if (target == null) { ReplCommandController controller = ReplCommandController.Attach(textView, textView.TextBuffer); // Wrap controller into OLE command target target = VsAppShell.Current.TranslateToHostCommandTarget(textView, controller) as IOleCommandTarget; Debug.Assert(target != null); ServiceManager.AddService(target, textView, _shell); // Wrap next OLE target in the chain into ICommandTarget so we can have // chain like: OLE Target -> Shim -> ICommandTarget -> Shim -> Next OLE target ICommandTarget nextCommandTarget = VsAppShell.Current.TranslateCommandTarget(textView, 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; IProjectionBuffer pb = textView.TextBuffer as IProjectionBuffer; if (pb != null) { pb.SourceBuffersChanged += OnSourceBuffersChanged; } textView.Closed += TextView_Closed; } return(target); }
public bool TryHandleCommand(IImmutableSet <IProjectTree> nodes, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) { if (commandId == RPackageCommandId.icmdSetDirectoryHere) { var path = nodes.GetSelectedFolderPath(_unconfiguredProject); if (!string.IsNullOrEmpty(path)) { var o = new object(); var interactiveWorkflow = _interactiveWorkflowProvider.GetOrCreate(); var controller = ReplCommandController.FromTextView(interactiveWorkflow.ActiveWindow.TextView); controller.Invoke(RGuidList.RCmdSetGuid, RPackageCommandId.icmdSetWorkingDirectory, path, ref o); return(true); } } return(false); }