/// <summary> /// Retrieves base command target that is chained to the main controller /// attached to a given view. This is typically a core editor command target. /// </summary> /// <param name="textView">Text view</param> /// <returns>Chained command target</returns> private ICommandTarget GetBaseCommandTarget(ITextView textView) { var controller = MdMainController.FromTextView(textView); // If there is no chained target yet, create a simple proxy target // for now. Real target will be set later. return(controller?.ChainedController ?? CommandTargetProxy.GetProxyTarget(textView)); }
/// <summary> /// Retrieves base command target that is chained to the main controller /// attached to a given view. This is typically a core editor command target. /// </summary> /// <param name="textView">Text view</param> /// <returns>Chained command target</returns> private ICommandTarget GetBaseCommandTarget(ITextView textView) { var controller = MdMainController.FromTextView(textView); // If there is no chained target yet, create a simple proxy target // for now. Real target will be set later. if (controller != null && controller.ChainedController != null) { return(controller.ChainedController); } return(CommandTargetProxy.GetProxyTarget(textView, _coreShell)); }
/// <summary> /// Retrieves document instance from text buffer /// </summary> public static IEditorDocument TryFromTextBuffer(ITextBuffer textBuffer) { IEditorDocument document = ServiceManager.GetService <IEditorDocument>(textBuffer); if (document == null) { TextViewData viewData = TextViewConnectionListener.GetTextViewDataForBuffer(textBuffer); if (viewData != null && viewData.LastActiveView != null) { MdMainController controller = MdMainController.FromTextView(viewData.LastActiveView); if (controller != null && controller.TextBuffer != null) { document = ServiceManager.GetService <MdEditorDocument>(controller.TextBuffer); } } } return(document); }
protected override void OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer) { // Only attach controllers if the document is editable if (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. MdMainController mainController = MdMainController.FromTextView(textView); if (textBuffer == mainController.TextBuffer) { // Connect main controller to VS text view filter chain. The chain looks like // VS IDE -> HTML 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. IVsEditorAdaptersFactoryService adapterService = VsAppShell.Current.ExportProvider.GetExport <IVsEditorAdaptersFactoryService>().Value; IVsTextView 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. CommandTargetToOleShim oleController = new CommandTargetToOleShim(textView, mainController); 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. ICommandTarget nextCommandTarget = VsAppShell.Current.TranslateCommandTarget(textView, nextOleTarget); mainController.ChainedController = nextCommandTarget; } } } 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.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. var mainController = MdMainController.FromTextView(textView); if (textBuffer == mainController.TextBuffer) { // Connect main controller to VS text view filter chain. The chain looks like // VS IDE -> HTML 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. OleControllerChain.ConnectController(Services, textView, mainController); } } base.OnTextViewGotAggregateFocus(textView, textBuffer); }
/// <summary> /// Retrieves editor instance command target for a particular view /// </summary> public override ICommandTarget GetCommandTarget(IEditorView editorView) => MdMainController.FromTextView(editorView.As <ITextView>());
/// <summary> /// Retrieves editor instance command target for a particular view /// </summary> public override ICommandTarget GetCommandTarget(ITextView textView) { return(MdMainController.FromTextView(textView)); }