Implements OLE command target over ICommandTarget allowing managed components to participate in OLE/COM environment like Visual Studio. While a command is executing, the current variant arguments are cached.
Inheritance: IOleCommandTarget, ICommandTarget
Ejemplo n.º 1
0
        public static CommandTargetToOleShim ConnectController(IVsEditorAdaptersFactoryService adapterService, ITextView textView, Controller controller) {
            IVsTextView viewAdapter = adapterService.GetViewAdapter(textView);
            CommandTargetToOleShim oleControllerShim = null;

            // Connect main controller to VS text view filter chain.
            // The chain looks like VS IDE -> language main controller -> Core editor
            // However, IDE wants IOleCommandTarget and core editor, although managed,
            // is represented by OLE command target as well. Since R controller
            // is not specific to VS and does not use OLE, we create OLE-to-managed target shim
            // and managed target-to-OLE shims. 
            if (viewAdapter != null) {
                // Create OLE shim that wraps main controller ICommandTarget and represents
                // it as IOleCommandTarget that is accepted by VS IDE.
                oleControllerShim = new CommandTargetToOleShim(textView, controller);

                IOleCommandTarget nextOleTarget;
                viewAdapter.AddCommandFilter(oleControllerShim, 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);
                controller.ChainedController = nextCommandTarget;
            }
            return oleControllerShim;
        }
 protected override void OnTextViewDisconnected(ITextView textView, ITextBuffer textBuffer) {
     if (textBuffer == textView.TextDataModel.DocumentBuffer && _oleController != null) {
         OleControllerChain.DisconnectController(_adapterService, textView, _oleController);
         _oleController = null;
     }
     base.OnTextViewDisconnected(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.
                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);
        }
Ejemplo n.º 4
0
 public static void DisconnectController(IVsEditorAdaptersFactoryService adapterService, ITextView textView, CommandTargetToOleShim oleControllerShim) {
     IVsTextView viewAdapter = adapterService.GetViewAdapter(textView);
     if (viewAdapter != null) {
         viewAdapter.RemoveCommandFilter(oleControllerShim);
      }
 }