Esempio n. 1
0
        internal static bool RemoveCommandFilter(IWpfTextView textView, TranslationCommandFilter commandFilter)
        {
            if (commandFilter == null)
            {
                return(false);
            }

            if (commandFilter.m_added)
            {
                var vsEditorAdaptersFactoryService =
                    ServicesHelper.GetServiceFromComponentModel <IVsEditorAdaptersFactoryService>(false);

                //get the view adapter from the editor factory
                if (vsEditorAdaptersFactoryService != null)
                {
                    var view = vsEditorAdaptersFactoryService.GetViewAdapter(textView);
                    var hr   = view.RemoveCommandFilter(commandFilter);
                    if (hr == VSConstants.S_OK)
                    {
                        commandFilter.m_added = false;
                    }
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
        internal static bool AddCommandFilter(IWpfTextView textView, TranslationCommandFilter commandFilter)
        {
            if (commandFilter == null)
            {
                return(false);
            }

            if (commandFilter.m_added == false)
            {
                var vsEditorAdaptersFactoryService =
                    ServicesHelper.GetServiceFromComponentModel <IVsEditorAdaptersFactoryService>(false);

                //get the view adapter from the editor factory
                if (vsEditorAdaptersFactoryService != null)
                {
                    var view = vsEditorAdaptersFactoryService.GetViewAdapter(textView);
                    IOleCommandTarget next;

                    var hr = view.AddCommandFilter(commandFilter, out next);
                    if (hr == VSConstants.S_OK)
                    {
                        commandFilter.m_added = true;
                        //you'll need the next target for Exec and QueryStatus
                        if (next != null)
                        {
                            commandFilter.m_nextTarget = next;
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }