示例#1
0
        void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView)
        {
            var view = _adaptersFactory.GetWpfTextView(vsView);

            if (view == null)
            {
                return;
            }

            var opt = _vim.GetBuffer(view);

            if (!opt.IsSome())
            {
                return;
            }

            var buffer = opt.Value;
            var broker = _displayWindowBrokerFactoryServcie.CreateDisplayWindowBroker(view);
            var result = VsCommandTarget.Create(buffer, vsView, _adapter, broker, _externalEditorManager);

            if (result.IsSuccess)
            {
                _filterMap.Add(buffer, result.Value);
            }

            // Try and install the IVsFilterKeys adapter.  This cannot be done synchronously here
            // because Venus projects are not fully initialized at this state.  Merely querying
            // for properties cause them to corrupt internal state and prevents rendering of the
            // view.  Occurs for aspx and .js pages
            Action install = () => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, _editorOptionsFactoryService, buffer);

            Dispatcher.CurrentDispatcher.BeginInvoke(install, null);
        }
示例#2
0
        /// <summary>
        /// Try and install the IVsFilterKeys adapter for the given ITextView.
        /// </summary>
        internal static bool TryInstallFilterKeysAdapter(
            IVsAdapter adapter,
            IEditorOptionsFactoryService optionsFactory,
            IVimBuffer buffer)
        {
            var textView = buffer.TextView;

            if (textView.Properties.ContainsProperty(s_key))
            {
                return(true);
            }

            var textLines = adapter.EditorAdapter.GetBufferAdapter(buffer.TextBuffer) as IVsTextLines;

            if (textLines == null)
            {
                return(false);
            }

            IVsCodeWindow codeWindow;

            if (!adapter.GetCodeWindow(textView).TryGetValue(out codeWindow))
            {
                return(false);
            }

            // Grab the field we need to replace.  Be wary that Venus uses a different implementation
            // and the field will not be available
            var type  = codeWindow.GetType();
            var flags = System.Reflection.BindingFlags.Instance
                        | System.Reflection.BindingFlags.NonPublic;
            var field = type.GetField(FieldName, flags);

            if (field == null)
            {
                return(false);
            }

            var oldValue = field.GetValue(codeWindow) as IVsFilterKeys;

            if (oldValue == null)
            {
                return(false);
            }

            var filterKeysAdapter = new VsFilterKeysAdapter(oldValue, codeWindow, adapter, buffer);

            field.SetValue(codeWindow, filterKeysAdapter);
            return(true);
        }
示例#3
0
        /// <summary>
        /// Raised when an IVsTextView is created.  When this occurs it means a previously created
        /// ITextView was associated with an IVsTextView shim.  This means the ITextView will be
        /// hooked into the Visual Studio command system and a host of other items.  Setup all of
        /// our plumbing here
        /// </summary>
        void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView)
        {
            // Get the ITextView created.  Shouldn't ever be null unless a non-standard Visual Studio
            // component is calling this function
            var textView = _adaptersFactory.GetWpfTextViewNoThrow(vsView);

            if (textView == null)
            {
                return;
            }

            // Sanity check. No reason for this to be null
            var opt = _vim.GetVimBuffer(textView);

            if (!opt.IsSome())
            {
                return;
            }

            var vimBuffer = opt.Value;

            // At this point Visual Studio has fully applied it's settings.  Begin the synchronization process
            BeginSettingSynchronization(vimBuffer);

            var broker            = _displayWindowBrokerFactoryServcie.CreateDisplayWindowBroker(textView);
            var bufferCoordinator = _bufferCoordinatorFactory.GetVimBufferCoordinator(vimBuffer);
            var result            = VsCommandTarget.Create(bufferCoordinator, vsView, _textManager, _adapter, broker, _resharperUtil, _keyUtil);

            if (result.IsSuccess)
            {
                // Store the value for debugging
                _vimBufferToCommandTargetMap[vimBuffer] = result.Value;
            }

            // Try and install the IVsFilterKeys adapter.  This cannot be done synchronously here
            // because Venus projects are not fully initialized at this state.  Merely querying
            // for properties cause them to corrupt internal state and prevents rendering of the
            // view.  Occurs for aspx and .js pages
            Action install = () => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, vimBuffer);

            _protectedOperations.BeginInvoke(install);
        }
示例#4
0
        private void ConnectToOleCommandTarget(IVimBuffer vimBuffer, ITextView textView, IVsTextView vsTextView)
        {
            var broker = _displayWindowBrokerFactoryServcie.GetDisplayWindowBroker(textView);
            var vimBufferCoordinator = _bufferCoordinatorFactory.GetVimBufferCoordinator(vimBuffer);
            var result = VsCommandTarget.Create(vimBufferCoordinator, vsTextView, _textManager, _adapter, broker, _keyUtil, _commandTargetFactoryList);

            if (result.IsSuccess)
            {
                // Store the value for debugging
                _vimBufferToCommandTargetMap[vimBuffer] = result.Value;
            }

            // Try and install the IVsFilterKeys adapter.  This cannot be done synchronously here
            // because Venus projects are not fully initialized at this state.  Merely querying
            // for properties cause them to corrupt internal state and prevents rendering of the
            // view.  Occurs for aspx and .js pages
            Action install = () => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, vimBuffer);

            _protectedOperations.BeginInvoke(install);
        }
示例#5
0
        /// <summary>
        /// Try and install the IVsFilterKeys adapter for the given ITextView.
        /// </summary>
        internal static bool TryInstallFilterKeysAdapter(
            IVsAdapter adapter,
            IEditorOptionsFactoryService optionsFactory,
            IVimBuffer buffer)
        {
            var textView = buffer.TextView;
            if (textView.Properties.ContainsProperty(s_key))
            {
                return true;
            }

            var textLines = adapter.EditorAdapter.GetBufferAdapter(buffer.TextBuffer) as IVsTextLines;
            if (textLines == null)
            {
                return false;
            }

            IVsCodeWindow codeWindow;
            if (!adapter.TryGetCodeWindow(textView, out codeWindow))
            {
                return false;
            }

            // Grab the field we need to replace.  Be wary that Venus uses a different implementation
            // and the field will not be available
            var type = codeWindow.GetType();
            var flags = System.Reflection.BindingFlags.Instance
                | System.Reflection.BindingFlags.NonPublic;
            var field = type.GetField(FieldName, flags);
            if (field == null)
            {
                return false;
            }

            var oldValue = field.GetValue(codeWindow) as IVsFilterKeys;
            if (oldValue == null)
            {
                return false;
            }

            var filterKeysAdapter = new VsFilterKeysAdapter(oldValue, codeWindow, adapter, buffer);
            field.SetValue(codeWindow, filterKeysAdapter);
            return true;
        }
示例#6
0
文件: HostFactory.cs 项目: sh54/VsVim
        /// <summary>
        /// Raised when an IVsTextView is created.  When this occurs it means a previously created
        /// ITextView was associated with an IVsTextView shim.  This means the ITextView will be
        /// hooked into the Visual Studio command system and a host of other items.  Setup all of
        /// our plumbing here
        /// </summary>
        void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView)
        {
            // Get the ITextView created.  Shouldn't ever be null unless a non-standard Visual Studio
            // component is calling this function
            var textView = _adaptersFactory.GetWpfTextView(vsView);

            if (textView == null)
            {
                return;
            }

            // Sanity check. No reason for this to be null
            var opt = _vim.GetVimBuffer(textView);

            if (!opt.IsSome())
            {
                return;
            }

            var        buffer = opt.Value;
            BufferData bufferData;

            if (_bufferMap.TryGetValue(buffer, out bufferData))
            {
                // During the lifetime of an IVimBuffer the local and editor settings are kept
                // in sync for tab values.  At startup though a decision has to be made about which
                // settings should "win" and this is controlled by 'UseEditorSettings'.
                //
                // Visual Studio of course makes this difficult.  It will create an ITextView and
                // then later force all of it's language preference settings down on the ITextView
                // if it does indeed have an IVsTextView.  This setting will inherently overwrite
                // the custom settings with the stored Visual Studio settings.
                //
                // To work around this we store the original values and reset them here.  This event
                // is raised after this propagation occurs so we can put them back
                if (!_vim.GlobalSettings.UseEditorSettings)
                {
                    buffer.LocalSettings.TabStop   = bufferData.TabStop;
                    buffer.LocalSettings.ExpandTab = bufferData.ExpandTab;
                    buffer.LocalSettings.Number    = bufferData.Number;
                }
            }
            else
            {
                bufferData         = new BufferData();
                _bufferMap[buffer] = bufferData;
            }

            var broker            = _displayWindowBrokerFactoryServcie.CreateDisplayWindowBroker(textView);
            var bufferCoordinator = _bufferCoordinatorFactory.GetVimBufferCoordinator(buffer);
            var result            = VsCommandTarget.Create(bufferCoordinator, vsView, _adapter, broker, _externalEditorManager);

            if (result.IsSuccess)
            {
                // Store the value for debugging
                bufferData.VsCommandTarget = result.Value;
            }

            // Try and install the IVsFilterKeys adapter.  This cannot be done synchronously here
            // because Venus projects are not fully initialized at this state.  Merely querying
            // for properties cause them to corrupt internal state and prevents rendering of the
            // view.  Occurs for aspx and .js pages
            Action install = () => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, _editorOptionsFactoryService, buffer);

            _protectedOperations.BeginInvoke(install);
        }