Ejemplo n.º 1
0
        internal static Result <VsCommandTarget> Create(
            IVimBufferCoordinator vimBufferCoordinator,
            IVsTextView vsTextView,
            ITextManager textManager,
            IVsAdapter adapter,
            IDisplayWindowBroker broker,
            IKeyUtil keyUtil,
            ReadOnlyCollection <ICommandTargetFactory> commandTargetFactoryList)
        {
            var vsCommandTarget = new VsCommandTarget(vimBufferCoordinator, textManager, adapter, broker, keyUtil);

            IOleCommandTarget nextCommandTarget;
            var hresult = vsTextView.AddCommandFilter(vsCommandTarget, out nextCommandTarget);

            if (ErrorHandler.Failed(hresult))
            {
                return(Result.CreateError(hresult));
            }

            var commandTargets = commandTargetFactoryList
                                 .Select(x => x.CreateCommandTarget(nextCommandTarget, vimBufferCoordinator))
                                 .Where(x => x != null)
                                 .ToReadOnlyCollection();

            vsCommandTarget.CompleteInit(nextCommandTarget, commandTargets);
            return(Result.CreateSuccess(vsCommandTarget));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Custom process the insert command if possible.  This is handled by VsCommandTarget
        /// </summary>
        public override bool TryCustomProcess(ITextView textView, InsertCommand command)
        {
            VsCommandTarget vsCommandTarget;

            if (VsCommandTarget.TryGet(textView, out vsCommandTarget))
            {
                return(vsCommandTarget.TryCustomProcess(command));
            }

            return(false);
        }
Ejemplo n.º 4
0
        internal static Result <VsCommandTarget> Create(
            IVimBufferCoordinator bufferCoordinator,
            IVsTextView vsTextView,
            IVsAdapter adapter,
            IDisplayWindowBroker broker,
            IExternalEditorManager externalEditorManager)
        {
            var filter  = new VsCommandTarget(bufferCoordinator, adapter, broker, externalEditorManager);
            var hresult = vsTextView.AddCommandFilter(filter, out filter._nextTarget);

            return(Result.CreateSuccessOrError(filter, hresult));
        }
Ejemplo n.º 5
0
        internal static Result <VsCommandTarget> Create(
            IVimBufferCoordinator bufferCoordinator,
            IVsTextView vsTextView,
            IVsAdapter adapter,
            IDisplayWindowBroker broker,
            IResharperUtil resharperUtil)
        {
            var vsCommandTarget = new VsCommandTarget(bufferCoordinator, adapter, broker, resharperUtil);
            var hresult         = vsTextView.AddCommandFilter(vsCommandTarget, out vsCommandTarget._nextTarget);
            var result          = Result.CreateSuccessOrError(vsCommandTarget, hresult);

            if (result.IsSuccess)
            {
                bufferCoordinator.VimBuffer.TextView.Properties[Key] = vsCommandTarget;
            }

            return(result);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 internal static Result<VsCommandTarget> Create(
     IVimBuffer buffer,
     IVsTextView vsTextView,
     IVsAdapter adapter,
     IDisplayWindowBroker broker,
     IExternalEditorManager externalEditorManager)
 {
     var filter = new VsCommandTarget(buffer, adapter, broker, externalEditorManager);
     var hresult = vsTextView.AddCommandFilter(filter, out filter._nextTarget);
     return Result.CreateSuccessOrError(filter, hresult);
 }
Ejemplo n.º 9
0
 internal static bool TryGet(ITextView textView, out VsCommandTarget vsCommandTarget)
 {
     return textView.Properties.TryGetPropertySafe(Key, out vsCommandTarget);
 }
Ejemplo n.º 10
0
        internal static Result<VsCommandTarget> Create(
            IVimBufferCoordinator bufferCoordinator,
            IVsTextView vsTextView,
            ITextManager textManager,
            IVsAdapter adapter,
            IDisplayWindowBroker broker,
            IResharperUtil resharperUtil,
            IKeyUtil keyUtil)
        {
            var vsCommandTarget = new VsCommandTarget(bufferCoordinator, textManager, adapter, broker, resharperUtil, keyUtil);
            var hresult = vsTextView.AddCommandFilter(vsCommandTarget, out vsCommandTarget._nextTarget);
            var result = Result.CreateSuccessOrError(vsCommandTarget, hresult);
            if (result.IsSuccess)
            {
                bufferCoordinator.VimBuffer.TextView.Properties[Key] = vsCommandTarget;
            }

            return result;
        }
Ejemplo n.º 11
0
 internal static bool TryGet(ITextView textView, out VsCommandTarget vsCommandTarget)
 {
     return(textView.Properties.TryGetPropertySafe(Key, out vsCommandTarget));
 }
Ejemplo n.º 12
0
        internal static Result<VsCommandTarget> Create(
            IVimBufferCoordinator vimBufferCoordinator,
            IVsTextView vsTextView,
            ITextManager textManager,
            IVsAdapter adapter,
            IDisplayWindowBroker broker,
            IKeyUtil keyUtil,
            ReadOnlyCollection<ICommandTargetFactory> commandTargetFactoryList)
        {
            var vsCommandTarget = new VsCommandTarget(vimBufferCoordinator, textManager, adapter, broker, keyUtil);

            IOleCommandTarget nextCommandTarget;
            var hresult = vsTextView.AddCommandFilter(vsCommandTarget, out nextCommandTarget);
            if (ErrorHandler.Failed(hresult))
            {
                return Result.CreateError(hresult);
            }

            var commandTargets = commandTargetFactoryList
                .Select(x => x.CreateCommandTarget(nextCommandTarget, vimBufferCoordinator))
                .Where(x => x != null)
                .ToReadOnlyCollection();
            vsCommandTarget.CompleteInit(nextCommandTarget, commandTargets);
            return Result.CreateSuccess(vsCommandTarget);
        }
Ejemplo n.º 13
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.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);
        }