protected override void OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer) { bool isProjected = (textBuffer != textView.TextDataModel.DocumentBuffer); // Only attach controllers if the document is editable if (!isProjected && textView.Roles.Contains(PredefinedTextViewRoles.Editable)) { // Check if another buffer already attached a command controller to the view. // Don't allow two to be attached, or commands could be run twice. // This currently can only happen with inline diff views. RMainController mainController = RMainController.FromTextView(textView); if (textBuffer == mainController?.TextBuffer) { // Connect main controller to VS text view filter chain. OleControllerChain.ConnectController(_adapterService, textView, mainController); } } base.OnTextViewGotAggregateFocus(textView, textBuffer); }
protected override void OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer) { // Only attach controllers if the document is editable if (textView.Roles.Contains(PredefinedTextViewRoles.Interactive)) { // Check if another buffer already attached a command controller to the view. // Don't allow two to be attached, or commands could be run twice. // This currently can only happen with inline diff views. RMainController mainController = RMainController.FromTextView(textView); if (textBuffer == mainController.TextBuffer) { // Connect main controller to VS text view filter chain. The chain looks like // VS IDE -> main controller -> Core editor // However, IDE wants IOleCommandTarget and core editor, although managed, // is represented by OLE command target as well. Since HTML controller // is not specific to VS and does not use OLE, we create OLE-to-managed target shim // and managed target-to-OLE shims. var adapterService = _coreShell.GetService <IVsEditorAdaptersFactoryService>(); var viewAdapter = adapterService.GetViewAdapter(textView); if (viewAdapter != null) { // Create OLE shim that wraps main controller ICommandTarget and represents // it as IOleCommandTarget that is accepted by VS IDE. var oleController = new CommandTargetToOleShim(textView, mainController); var es = _coreShell.GetService <IApplicationEditorSupport>(); IOleCommandTarget nextOleTarget; viewAdapter.AddCommandFilter(oleController, out nextOleTarget); // nextOleTarget is typically a core editor wrapped into OLE layer. // Create a wrapper that will present OLE target as ICommandTarget to // HTML main controller so controller can operate in platform-agnostic way. var nextCommandTarget = es.TranslateCommandTarget(textView, nextOleTarget); mainController.ChainedController = nextCommandTarget; } } } base.OnTextViewGotAggregateFocus(textView, textBuffer); }
/// <summary> /// Retrieves document instance from text buffer /// </summary> public static IREditorDocument TryFromTextBuffer(ITextBuffer textBuffer) { IREditorDocument document = ServiceManager.GetService <IREditorDocument>(textBuffer); if (document == null) { document = FindInProjectedBuffers(textBuffer); if (document == null) { TextViewData viewData = TextViewConnectionListener.GetTextViewDataForBuffer(textBuffer); if (viewData != null && viewData.LastActiveView != null) { RMainController controller = RMainController.FromTextView(viewData.LastActiveView); if (controller != null && controller.TextBuffer != null) { document = ServiceManager.GetService <REditorDocument>(controller.TextBuffer); } } } } return(document); }
public override ICommandTarget GetCommandTargetOfLocation(ITextView textView, int bufferPosition) { var block = GetLanguageBlockOfLocation(bufferPosition); return(block != null ? (ICommandTarget)RMainController.FromTextView(textView) : null); }
public override ICommandTarget GetCommandTarget(ITextView textView) { return(RMainController.FromTextView(textView)); }
public override ICommandTarget GetCommandTarget(IEditorView editorView) => RMainController.FromTextView(editorView.As <ITextView>());