Exemplo n.º 1
0
        public override bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (Guid.Equals(guidCmdGroup, Microsoft.VisualStudio.Shell.VsMenus.guidStandardCommandSet2K))
            {
                switch ((VSConstants.VSStd2KCmdID)nCmdId)
                {
                case VSStd2KCmdID.INSERTSNIPPET:
                {
                    ExpansionProvider ep = GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, "Insert snippet", type1, false, null, false);
                    }
                    return(true);
                }

                case VSStd2KCmdID.SURROUNDWITH:
                {
                    ExpansionProvider ep = GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, "Surround with", type2, false, null, false);
                    }
                }
                break;

                case VSStd2KCmdID.ECMD_LEFTCLICK:
                    Source.OnCommand(TextView, (VSConstants.VSStd2KCmdID)nCmdId, '\0');
                    break;
                }
            }
            return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut));
        }
        public override bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                if (nCmdId == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
                {
                    ExpansionProvider ep = this.GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(this.TextView, Resources.InsertSnippet, null, false, null, false);
                    }
                    return(true);   // Handled the command.
                }
                else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.SURROUNDWITH)
                {
                    ExpansionProvider ep = this.GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(this.TextView, Resources.SurroundWith, null, false, null, false);
                    }
                    return(true);   // Handled the command.
                }
            }

            // Base class handled the command.  Do nothing more here.
            return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut));
        }
Exemplo n.º 3
0
        public override bool HandlePreExec(
            ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var cmd = (VsCommands2K)nCmdId;

            //// we're goona to erase some symbol from existence.
            //// In some cases we need to know what it was (auto-deletion of paired token)
            //if (cmd == VsCommands2K.BACKSPACE)
            //  Source.RememberCharBeforeCaret(TextView);
            //else
            //  Source.ClearRememberedChar();

            _startLine = -1;

            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                if (Source.MethodData.IsDisplayed)
                {
                    TextView.GetCaretPos(out _startLine, out _startPos);
                }



                switch (cmd)
                {
                case VsCommands2K.COMPLETEWORD:
                {
                    int lintIndex;
                    int columnInxex;
                    ErrorHandler.ThrowOnFailure(TextView.GetCaretPos(out lintIndex, out columnInxex));
                    Source.Completion(TextView, lintIndex, columnInxex, false);
                    return(true);
                }

                case VsCommands2K.FORMATSELECTION:
                    ReformatSelection();
                    return(true);

                case VsCommands2K.INSERTSNIPPET:
                {
                    ExpansionProvider ep = GetExpansionProvider();

                    if (TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, Resources.InsertSnippet, null, false, null, false);
                    }

                    return(true);                                    // Handled the command.
                }

                case VsCommands2K.SURROUNDWITH:
                {
                    ExpansionProvider ep = GetExpansionProvider();

                    if (TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, Resources.SurroundWith, null, false, null, false);
                    }

                    return(true);                                    // Handled the command.
                }

                case VsCommands2K.UP:
                    if (Source.MethodData.IsDisplayed && Source.MethodData.GetCurMethod() == 0)
                    {
                        int count = Source.MethodData.GetOverloadCount();

                        if (count > 1)
                        {
                            while (Source.MethodData.NextMethod() < count - 1)
                            {
                                Source.MethodData.UpdateView();
                            }

                            return(true);
                        }
                    }

                    break;

                case VsCommands2K.DOWN:
                    if (Source.MethodData.IsDisplayed)
                    {
                        int count = Source.MethodData.GetOverloadCount();

                        if (count > 1 && Source.MethodData.GetCurMethod() == count - 1)
                        {
                            while (Source.MethodData.PrevMethod() > 0)
                            {
                                Source.MethodData.UpdateView();
                            }

                            return(true);
                        }
                    }

                    break;
                }
            }

            // Base class handled the command.  Do nothing more here.
            //
            return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut));
        }
Exemplo n.º 4
0
 public override bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId,
                                    uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (guidCmdGroup == VSConstants.VSStd2K)
     {
         if (nCmdId == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
         {
             // Handle the Insert Snippet command by showing the UI to insert a snippet.
             ExpansionProvider ep = GetExpansionProvider();
             if (ep != null && TextView != null)
             {
                 ep.DisplayExpansionBrowser(TextView, CMakeStrings.CMakeSnippet, null,
                                            false, null, false);
             }
             return(true);
         }
         else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.OPENFILE)
         {
             // Handle the Open File by opening the file specified by the current
             // token.
             string extraSearchPath;
             string fileName = GetCurrentTokenFileName(out extraSearchPath);
             if (fileName == null)
             {
                 return(false);
             }
             string curFileDir = Path.GetDirectoryName(Source.GetFilePath());
             string filePath   = Path.Combine(curFileDir, fileName);
             if (!File.Exists(filePath))
             {
                 filePath = null;
                 if (extraSearchPath != null)
                 {
                     filePath = Path.Combine(extraSearchPath, fileName);
                     if (!File.Exists(filePath))
                     {
                         filePath = null;
                     }
                 }
             }
             if (filePath != null)
             {
                 VsShellUtilities.OpenDocument(ServiceProvider.GlobalProvider,
                                               filePath);
             }
             else
             {
                 MessageBox.Show(string.Format(CMakeStrings.FileNotFound,
                                               fileName), CMakeStrings.MessageBoxTitle,
                                 MessageBoxButtons.OK, MessageBoxIcon.Stop);
             }
             return(true);
         }
         else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.TAB)
         {
             // Handle the tab key when the caret is positioned immediately after
             // the name of a snippet by inserting that snippet.
             ExpansionProvider ep = GetExpansionProvider();
             if (ep == null || TextView == null || ep.InTemplateEditingMode)
             {
                 return(false);
             }
             int line;
             int col;
             if (TextView.GetCaretPos(out line, out col) != VSConstants.S_OK)
             {
                 return(false);
             }
             TokenInfo tokenInfo = Source.GetTokenInfo(line, col);
             if (tokenInfo.StartIndex == tokenInfo.EndIndex)
             {
                 return(false);
             }
             TextSpan span     = tokenInfo.ToTextSpan(line);
             string   shortcut = Source.GetText(span);
             if (string.IsNullOrEmpty(shortcut))
             {
                 return(false);
             }
             string title;
             string path;
             if (ep.FindExpansionByShortcut(TextView, shortcut, span, true,
                                            out title, out path) != VSConstants.S_OK)
             {
                 return(false);
             }
             return(ep.InsertNamedExpansion(TextView, title, path, span, false));
         }
         else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.RETURN)
         {
             // Dismiss method tips when the user presses enter.  They interfere
             // with the proper functioning of smart indentation.
             if (Source.IsCompletorActive && !Source.CompletionSet.IsDisplayed)
             {
                 Source.DismissCompletor();
             }
         }
     }
     else if (guidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
     {
         if (nCmdId == (uint)VSConstants.VSStd97CmdID.F1Help)
         {
             DoContextHelp();
             return(true);
         }
     }
     return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn,
                               pvaOut));
 }