add in - Determining which Visual Studio context menu was selected? -
i'm writing vs2012 add-in, adding command build explorer context menu (see related question). command gets added 2 different context menus:
- build explorer
- team explorer, builds page, builds section
when 1 callback called, how know of these is?
i tried focused control (using p/invoke this question suggests). however, gets me tabs container (1), , null (2). try cast control tabbed container, sounds pretty bad...
any better alternative?
my new/other idea - similar yours:
you should try monitor window activated lastly.
if create eventhandler command, may able check window active when command fired. simple evenent handler command:
void cmdevents_beforeexecute( string guid, int id, object customin, object customout, ref bool canceldefault ) { window2 teamexplorer = _applicationobject.windows.item("team explorer") window2; if (_applicationobject.activewindow.caption == teamexplorer.caption) { //you called team explorer } else { //somewhere else } } and way can subscribe:
static _dispcommandevents_beforeexecuteeventhandler _myhandler; static commandevents _cmdevents; public void onconnection(...) { command command = ...; // init command int id = command.id; string guid = command.guid; commandevents _cmdevents = _applicationobject.events.get_commandevents(guid, id); _myhandler = new _dispcommandevents_beforeexecuteeventhandler(cmdevents_beforeexecute); _cmdevents.beforeexecute += _myhandler; } you may find better way identify window(s) guid. should keep @ least _cmdevents static because when desroyed, event handler vanish (least internal commands).
in ondisconnection should unsubscribe.
Comments
Post a Comment