c# - VS 2013 SDK: Handle code window's contextmenu opening event? -


in c# or else vb.net, using visual studio package, how handle event raised when contextmenu of current code window editor opening and/or open?.

my intention arbitrary enable/disable commandbarbutton buttons inside of commandbarpopup menu evaluating condition when contextmenu opening or open.

but can't find information this, neither event name or class sdk involved in question, anything.


update

this code example following @carlos quintero indications, however, beforequerystatus event never raised until press button once , callback done, why? how fix it?.

as said, need able control button states (enabled/disabled) when contextmenu of code editor opens.

protected overrides sub initialize()      debug.writeline(string.format(cultureinfo.currentculture, "entering initialize() of: {0}", me.gettype().name))     mybase.initialize()      ' add our command handlers menu (commands must exist in .vsct file)     dim mcs olemenucommandservice = trycast(getservice(gettype(imenucommandservice)), olemenucommandservice)      if not mcs nothing          ' create command menu item.         dim menucommandid new commandid(guidlist.guidsnippettoolcmdset, cint(pkgcmdidlist.cmdidmycommand))         dim menuitem new olemenucommand(new eventhandler(addressof menuitemcallback), menucommandid)         addhandler menuitem.beforequerystatus, addressof onbeforequerystatus          mcs.addcommand(menuitem)     end if  end sub  private sub menuitemcallback(byval sender object, byval e eventargs)      ' show message box prove here     dim uishell ivsuishell = trycast(getservice(gettype(svsuishell)), ivsuishell)     dim clsid guid = guid.empty     dim result integer     microsoft.visualstudio.errorhandler.throwonfailure(uishell.showmessagebox(0, clsid, "snippet tool", string.format(cultureinfo.currentculture, "inside {0}.menuitemcallback()", me.gettype().name), string.empty, 0, olemsgbutton.olemsgbutton_ok, olemsgdefbutton.olemsgdefbutton_first, olemsgicon.olemsgicon_info, 0, result))  end sub  private sub onbeforequerystatus(byval sender object, byval e eventargs)      dim mycommand olemenucommand = trycast(sender, olemenucommand)      ' alternate command enable, testing.     mycommand.enabled = not mycommand.enabled  end sub 

there no such event context menus. when happens (such context menu shown, selection changed, solution closed, etc.), vs queries commands status.

the way want use olemenucommand, beforequerystatus event. in event (that don't know caused it) set properties (enabled, visible, etc.) of command depending on conditions. see: how to: create , handle commands in vspackages (c#)


Comments