private static OleMenuCommand RegisterOleMenuCommand( OleMenuCommandService service, MenuCmd.CmdId id, bool visible, EventHandler handler) { var commandID = new CommandID(MenuCmd.guidNemerleProjectCmdSet, (int)id); var command = new OleMenuCommand(handler, commandID); command.Visible = visible; service.AddCommand(command); //Debug.WriteLine(string.Format("Menu command {0} added", command)); return(command); }
//private List<Location> GetSelectionsStack(TextSpan span) //{ // NemerleSource source = Source as NemerleSource; // if (source != null) // { // Location current = Utils.LocationFromSpan(source.FileIndex, span); // List<Location> stack = new List<Location>(); // stack.AddRange(source.ProjectInfo.Project.GetEnclosingLocationsChain(current).ToArray()); // return stack; // } // else // return null; //} //public override int GetWordExtent(int line, int index, uint flags, TextSpan[] span) //{ // System.Diagnostics.Debug.Assert(false, "line " + line + " index " + index + " flags " + flags + " span length " + span.Length); // base.GetWordExtent(line, index, flags, span); // return 0; //} protected override int QueryCommandStatus(ref Guid guidCmdGroup, uint nCmdId) { if (guidCmdGroup == VSConstants.VSStd2K) { var cmdId = (VSConstants.VSStd2KCmdID)nCmdId; if (cmdId == VSConstants.VSStd2KCmdID.INSERTSNIPPET || cmdId == VSConstants.VSStd2KCmdID.SURROUNDWITH) { return((int)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED)); } } if (guidCmdGroup == Microsoft.VisualStudio.Shell.VsMenus.guidStandardCommandSet97) { //object objCaption; //GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Caption, out objCaption); //if (objCaption.ToString().Equals("MyItems", StringComparison.CurrentCultureIgnoreCase)) //{ // // make Properties command invisible. // prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_INVISIBLE; // return VSConstants.S_OK; //} //return (int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_INVISIBLE; //OLECMDF_SUPPORTED OLECMDF_ENABLED } //return (int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_INVISIBLE; //OLECMDF_SUPPORTED OLECMDF_ENABLED if (guidCmdGroup == MenuCmd.guidNemerleProjectCmdSet) { MenuCmd.CmdId x = (MenuCmd.CmdId)nCmdId; switch (x) { case MenuCmd.CmdId.ESC: case MenuCmd.CmdId.SetAsMain: case MenuCmd.CmdId.ExtendSelection: case MenuCmd.CmdId.ShrinkSelection: case MenuCmd.CmdId.FindInheritors: case MenuCmd.CmdId.Rename: case MenuCmd.CmdId.Inline: case MenuCmd.CmdId.Options: case MenuCmd.CmdId.AstToolWindow: case MenuCmd.CmdId.AddHighlighting: case MenuCmd.CmdId.RemoveLastHighlighting: case MenuCmd.CmdId.FindInheritorsCtxt: case MenuCmd.CmdId.GoToFile: case MenuCmd.CmdId.GoToType: case MenuCmd.CmdId.SourceOutlinerWindow: break; case MenuCmd.CmdId.IplementInterface: return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED); //OLECMDF_SUPPORTED OLECMDF_ENABLED default: break; } } return(base.QueryCommandStatus(ref guidCmdGroup, nCmdId)); }
internal void ShowSmartTag(IVsTextView textView, bool showMenu, Location loc, MenuCmd.CmdId contextMenuId, Action <MenuCmd.CmdId> exec, Func <MenuCmd.CmdId, uint> queryStatus) { ShowSmartTag(textView, showMenu, loc, MenuCmd.guidNemerleProjectCmdSet, contextMenuId, exec, queryStatus); }
internal void ShowSmartTag(IVsTextView textView, bool showMenu, Location loc, MenuCmd.CmdId contextMenuId, Action <MenuCmd.CmdId> exec) { ShowSmartTag(textView, showMenu, loc, MenuCmd.guidNemerleProjectCmdSet, contextMenuId, exec, null); }
internal void ShowSmartTag(IVsTextView textView, bool showMenu, Location loc, Guid cmdSet, MenuCmd.CmdId contextMenuId, Action <MenuCmd.CmdId> exec, Func <MenuCmd.CmdId, uint> queryStatus) { ErrorHelper.ThrowIsNull(exec, "exec"); var smartTagWin = GetSmartTagTipWindow(); var source = (NemerleSource)GetSource(textView); Debug.Assert(source != null, "source == null"); var pos = source.GetPositionOfLineIndex(loc.Line, loc.Column); var endPos = source.GetPositionOfLineIndex(loc.EndLine, loc.EndColumn); var length = endPos - pos; var smartTagData = new NemerleSmartTagData(pos, length, cmdSet, exec, queryStatus, () => IsSmartTagActive = false); ErrorHelper.ThrowOnFailure(smartTagWin.SetSmartTagData(smartTagData)); var shouContextMenu = showMenu ? (uint)TipWindowFlags2.UTW_EXPANDED : 0; var viewEx = (IVsTextViewEx)textView; ErrorHelper.ThrowOnFailure(viewEx.UpdateSmartTagWindow(smartTagWin, shouContextMenu)); IsSmartTagActive = true; }