Esempio n. 1
0
        /// <summary>
        /// Run the KeyInput through IOleCommandTarget
        /// </summary>
        private bool RunInOleCommandTarget(KeyInput keyInput)
        {
            var oleCommandData = OleCommandData.Empty;

            try
            {
                // It appears that Visual Studio will not use IOleCommandTarget to process alpha
                // characters when they are combined with the control key unless they are mapped
                // to a command.  Instead it will just push the input to the window directly.
                //
                // TODO: Need to investigate why this is the case.
                if (Char.IsLetter(keyInput.Char) && keyInput.KeyModifiers == KeyModifiers.Control)
                {
                    return(false);
                }

                Guid commandGroup;
                if (!OleCommandUtil.TryConvert(keyInput, out commandGroup, out oleCommandData))
                {
                    throw new Exception("Couldn't convert the KeyInput into OleCommandData");
                }

                if (!RunQueryStatus(commandGroup, oleCommandData))
                {
                    return(false);
                }

                RunExec(commandGroup, oleCommandData);
                return(true);
            }
            finally
            {
                OleCommandData.Release(ref oleCommandData);
            }
        }
Esempio n. 2
0
        public void TryConvert_TextInputToOleCommandData()
        {
            var textView = CreateTextView("");
            var buffer   = Vim.CreateVimBuffer(textView);

            buffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
            foreach (var cur in KeyInputUtil.VimKeyInputList)
            {
                if (!buffer.InsertMode.IsDirectInsert(cur))
                {
                    continue;
                }

                var oleCommandData = OleCommandData.Empty;
                try
                {
                    Assert.True(OleCommandUtil.TryConvert(cur, out oleCommandData));

                    // We lose fidelity on these keys because they both get written out as numbers
                    // at this point
                    if (VimKeyUtil.IsKeypadKey(cur.Key))
                    {
                        continue;
                    }
                    Assert.True(OleCommandUtil.TryConvert(oleCommandData, out KeyInput converted));
                    Assert.Equal(converted, cur);
                }
                finally
                {
                    oleCommandData.Dispose();
                }
            }
        }
Esempio n. 3
0
        public void TryConvert_TextInputToOleCommandData()
        {
            var textView = EditorUtil.CreateView("");
            var buffer   = EditorUtil.FactoryService.Vim.CreateBuffer(textView);

            buffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
            foreach (var cur in KeyInputUtil.VimKeyInputList)
            {
                if (!buffer.InsertMode.IsTextInput(cur))
                {
                    continue;
                }

                Guid           commandGroup;
                OleCommandData oleCommandData = new OleCommandData();
                KeyInput       converted;
                try
                {
                    Assert.IsTrue(OleCommandUtil.TryConvert(cur, out commandGroup, out oleCommandData));

                    // We lose fidelity on these keys because they both get written out as numbers
                    // at this point
                    if (VimKeyUtil.IsKeypadKey(cur.Key))
                    {
                        continue;
                    }
                    Assert.IsTrue(OleCommandUtil.TryConvert(commandGroup, oleCommandData, out converted));
                    Assert.AreEqual(converted, cur);
                }
                finally
                {
                    OleCommandData.Release(ref oleCommandData);
                }
            }
        }
Esempio n. 4
0
        public void ArrowKey_WithModifiers()
        {
            var modifiers = VimKeyModifiers.Alt | VimKeyModifiers.Control;

            Assert.True(OleCommandUtil.TryConvert(VSConstants.VSStd2K, (uint)VSConstants.VSStd2KCmdID.LEFT, IntPtr.Zero, modifiers, out EditCommand command));
            Assert.Equal(modifiers, command.KeyInput.KeyModifiers);
        }
Esempio n. 5
0
 internal EditCommand ConvertTypeChar(char data)
 {
     using (var ptr = CharPointer.Create(data))
     {
         Assert.True(OleCommandUtil.TryConvert(VSConstants.VSStd2K, (uint)VSConstants.VSStd2KCmdID.TYPECHAR, ptr.IntPtr, VimKeyModifiers.None, out EditCommand command));
         return(command);
     }
 }
Esempio n. 6
0
        private void VerifyConvert(VSConstants.VSStd97CmdID cmd, KeyInput ki, EditCommandKind kind)
        {
            EditCommand command;

            Assert.True(OleCommandUtil.TryConvert(VSConstants.GUID_VSStandardCommandSet97, (uint)cmd, IntPtr.Zero, KeyModifiers.None, out command));
            Assert.Equal(ki, command.KeyInput);
            Assert.Equal(kind, command.EditCommandKind);
        }
Esempio n. 7
0
        private void VerifyConvert(VSConstants.VSStd2KCmdID cmd, KeyModifiers modifiers, KeyInput ki, EditCommandKind kind)
        {
            EditCommand command;

            Assert.True(OleCommandUtil.TryConvert(VSConstants.VSStd2K, (uint)cmd, IntPtr.Zero, modifiers, out command));
            Assert.Equal(ki, command.KeyInput);
            Assert.Equal(kind, command.EditCommandKind);
        }
Esempio n. 8
0
        private void VerifyConvert(VSConstants.VSStd97CmdID cmd, KeyInput ki, EditCommandKind kind)
        {
            EditCommand command;

            Assert.IsTrue(OleCommandUtil.TryConvert(VSConstants.GUID_VSStandardCommandSet97, (uint)cmd, out command));
            Assert.AreEqual(ki, command.KeyInput);
            Assert.AreEqual(kind, command.EditCommandKind);
        }
Esempio n. 9
0
        /// <summary>
        /// Verify we can convert the given VimKey to the specified command id
        /// </summary>
        private void VerifyConvert(VimKey vimKey, VSConstants.VSStd2KCmdID cmd)
        {
            var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);

            Assert.True(OleCommandUtil.TryConvert(keyInput, false, out OleCommandData oleCommandData));
            Assert.Equal(VSConstants.VSStd2K, oleCommandData.Group);
            Assert.Equal(new OleCommandData(cmd), oleCommandData);
        }
        int IOleCommandTarget.Exec(ref Guid commandGroup, uint commandId, uint commandExecOpt, IntPtr variantIn, IntPtr variantOut)
        {
            if (!OleCommandUtil.TryConvert(commandGroup, commandId, variantIn, out KeyInput keyInput, out EditCommandKind editCommandKind) ||
                !TryExec(keyInput))
            {
                return(_nextCommandTarget.Exec(ref commandGroup, commandId, commandExecOpt, variantIn, variantOut));
            }

            return(VSConstants.S_OK);
        }
Esempio n. 11
0
        /// <summary>
        /// Verify we can convert the given VimKey to the specified command id
        /// </summary>
        private void VerifyConvert(VimKey vimKey, VSConstants.VSStd2KCmdID cmd)
        {
            var            keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);
            Guid           commandGroup;
            OleCommandData oleCommandData;

            Assert.IsTrue(OleCommandUtil.TryConvert(keyInput, out commandGroup, out oleCommandData));
            Assert.AreEqual(VSConstants.VSStd2K, commandGroup);
            Assert.AreEqual(new OleCommandData(cmd), oleCommandData);
        }
Esempio n. 12
0
            int IOleCommandTarget.Exec(ref Guid commandGroup, uint cmdId, uint cmdExecOpt, IntPtr variantIn, IntPtr variantOut)
            {
                if (!OleCommandUtil.TryConvert(commandGroup, cmdId, variantIn, VimKeyModifiers.None, out EditCommand editCommand))
                {
                    _lastExecEditCommand = null;
                    return(VSConstants.E_FAIL);
                }

                _lastExecEditCommand = editCommand;
                return(TryExec(editCommand.KeyInput) ? VSConstants.S_OK : VSConstants.E_FAIL);
            }
Esempio n. 13
0
 /// <summary>
 /// Run the KeyInput value through Exec
 /// </summary>
 protected void RunExec(KeyInput keyInput)
 {
     Assert.True(OleCommandUtil.TryConvert(keyInput, out OleCommandData data));
     try
     {
         _target.Exec(data);
     }
     finally
     {
         data.Dispose();
     }
 }
Esempio n. 14
0
            int IOleCommandTarget.Exec(ref Guid commandGroup, uint cmdId, uint cmdExecOpt, IntPtr variantIn, IntPtr variantOut)
            {
                EditCommand editCommand;

                if (!OleCommandUtil.TryConvert(commandGroup, cmdId, variantIn, out editCommand) ||
                    editCommand.EditCommandKind != EditCommandKind.UserInput)
                {
                    return(VSConstants.E_FAIL);
                }

                return(TryExec(editCommand.KeyInput) ? VSConstants.S_OK : VSConstants.E_FAIL);
            }
Esempio n. 15
0
            int IOleCommandTarget.QueryStatus(ref Guid commandGroup, uint commandCount, OLECMD[] commands, IntPtr commandText)
            {
                if (1 != commandCount || !OleCommandUtil.TryConvert(commandGroup, commands[0].cmdID, commandText, VimKeyModifiers.None, out EditCommand editCommand))
                {
                    _lastQueryStatusEditCommand = null;
                    commands[0].cmdf            = 0;
                    return(NativeMethods.S_OK);
                }

                _lastQueryStatusEditCommand = editCommand;
                commands[0].cmdf            = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED);
                return(NativeMethods.S_OK);
            }
Esempio n. 16
0
        /// <summary>
        /// Try and convert the provided KeyInput value into OleCommandData.  This conversion is meant
        /// to simulate the standard converison of key input into OLE information in Visual Studio. This
        /// means we need to reproduce all of the behavior including not converting textual input
        /// here (unless it maps to a command).  Textual input typcially gets routed through WPF and
        /// is routed to IOleCommandTarget in the default handler
        /// </summary>
        private bool TryConvertToOleCommandData(KeyInput keyInput, out OleCommandData oleCommandData)
        {
            if (keyInput.RawChar.IsSome())
            {
                if (char.IsLetterOrDigit(keyInput.Char))
                {
                    oleCommandData = OleCommandData.Empty;
                    return(false);
                }
            }

            return(OleCommandUtil.TryConvert(keyInput, SimulateStandardKeyMappings, out oleCommandData));
        }
Esempio n. 17
0
        internal void RunExec(EditCommand editCommand)
        {
            var oleCommandData = OleCommandData.Empty;

            try
            {
                Assert.True(OleCommandUtil.TryConvert(editCommand, out oleCommandData));
                _target.Exec(oleCommandData);
            }
            finally
            {
                oleCommandData.Dispose();
            }
        }
Esempio n. 18
0
        public void TypeChar_WithModifiers()
        {
            var source    = @"@£$€{[]}\";
            var modifiers = VimKeyModifiers.Alt | VimKeyModifiers.Control;

            foreach (var c in source)
            {
                using (var ptr = CharPointer.Create(c))
                {
                    Assert.True(OleCommandUtil.TryConvert(VSConstants.VSStd2K, (uint)VSConstants.VSStd2KCmdID.TYPECHAR, ptr.IntPtr, modifiers, out EditCommand command));
                    Assert.Equal(c, command.KeyInput.Char);
                }
            }
        }
Esempio n. 19
0
 /// <summary>
 /// Run the KeyInput value through QueryStatus.  Returns true if the QueryStatus call
 /// indicated the command was supported
 /// </summary>
 protected bool RunQueryStatus(KeyInput keyInput)
 {
     Assert.True(OleCommandUtil.TryConvert(keyInput, out OleCommandData data));
     try
     {
         return
             (ErrorHandler.Succeeded(_target.QueryStatus(data, out OLECMD command)) &&
              command.cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED));
     }
     finally
     {
         data.Dispose();
     }
 }
Esempio n. 20
0
            int IOleCommandTarget.QueryStatus(ref Guid commandGroup, uint commandCount, OLECMD[] commands, IntPtr commandText)
            {
                EditCommand editCommand;

                if (1 != commandCount ||
                    !OleCommandUtil.TryConvert(commandGroup, commands[0].cmdID, commandText, out editCommand) ||
                    editCommand.EditCommandKind != EditCommandKind.UserInput)
                {
                    commands[0].cmdf = 0;
                    return(NativeMethods.S_OK);
                }

                commands[0].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED);
                return(NativeMethods.S_OK);
            }
Esempio n. 21
0
        /// <summary>
        /// Run the KeyInput value through Exec
        /// </summary>
        private void RunExec(KeyInput keyInput)
        {
            OleCommandData data;
            Guid           commandGroup;

            Assert.IsTrue(OleCommandUtil.TryConvert(keyInput, out commandGroup, out data));
            try
            {
                _target.Exec(ref commandGroup, data.CommandId, data.CommandExecOpt, data.VariantIn, data.VariantOut);
            }
            finally
            {
                OleCommandData.Release(ref data);
            }
        }
Esempio n. 22
0
        internal void RunExec(EditCommand editCommand)
        {
            var oleCommandData = OleCommandData.Empty;

            try
            {
                Assert.True(OleCommandUtil.TryConvert(editCommand, out oleCommandData));
                _target.Exec(oleCommandData);
            }
            finally
            {
                oleCommandData.Dispose();
            }

            TestableSynchronizationContext.RunAll();
        }
Esempio n. 23
0
        /// <summary>
        /// Run the KeyInput value through QueryStatus.  Returns true if the QueryStatus call
        /// indicated the command was supported
        /// </summary>
        private bool RunQueryStatus(KeyInput keyInput)
        {
            OleCommandData data;
            Guid           commandGroup;

            Assert.IsTrue(OleCommandUtil.TryConvert(keyInput, out commandGroup, out data));
            try
            {
                var cmds = new OLECMD[1];
                cmds[0] = new OLECMD {
                    cmdID = data.CommandId
                };
                return
                    (ErrorHandler.Succeeded(_target.QueryStatus(ref commandGroup, 1, cmds, data.VariantIn)) &&
                     cmds[0].cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED));
            }
            finally
            {
                OleCommandData.Release(ref data);
            }
        }
Esempio n. 24
0
        // [Test, Description("Make sure we don't puke on missing data"),Ignore]
        public void TypeCharNoData()
        {
            EditCommand command;

            Assert.False(OleCommandUtil.TryConvert(VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd2KCmdID.TYPECHAR, IntPtr.Zero, KeyModifiers.None, out command));
        }