Can't access right-click menu items of project that have sub-menus [message #531083] |
Mon, 03 May 2010 12:23  |
Eclipse User |
|
|
|
I am trying to access some items from the right-click menu of a project in the Project Explorer view of the C/C++ Perspective.
I am able to successfully access "Open Project" and "Close Project" for my GnuProject3 project as follows:
SWTBotTreeItem node = view.bot().tree().getTreeItem("GnuProject3");
node.setFocus();
node.select().contextMenu("Close Project").click();
node.setFocus();
node.select().contextMenu("Open Project").click();
Unfortunately, I can't seem to use the same method to access two right-click items which have submenus. I can't access "Make Targets" and I also tried "Build Configurations" just to see if I could access another item with sub-menu. Both attempts resulted in a widget not found exception.
node.select().contextMenu("Make Targets").menu("Build...").click();
I also tried just referencing "Make Targets" context menu without its submenu and that failed as well. I verified the string is correct by actually looking at the plugin.properties file which is used to set the menu item in the plugin.xml extension.
There is no spybot in 536 which might make this a little easier. I realize it was omitted from the build, but it would be nice to provide it somewhere (anywhere) for manual downloading even though it is not part of the official build.
Any ideas on why this isn't working?
|
|
|
|
|
Re: Can't access right-click menu items of project that have sub-menus [message #533006 is a reply to message #532985] |
Tue, 11 May 2010 15:32   |
Eclipse User |
|
|
|
On 5/11/10 11:34 AM, Jeff Johnston wrote:
> Interestingly enough, "New" was missing. The first item found was "Go
> Into" which should be the 2nd item after "New". Also missing were "Build
> Configurations", "Make Targets", and "Index" which are all C/C++
> specific items that have visibility dependent on project nature. The
> list had 110 entries, but a vast majority of them had a toString of
> "MenuItem {*Disposed*}". The remainder were shown as "MenuItem {*Wrong
> thread*}". Those Wrong Thread items were the ones that expanded to
> meaningful items with text. Not sure if the toString info is helpful,
> but I included it just in case.
Try printing them as you find them. The menu traversal is depth first,
the menu is opened, traversed, and closed and traversal moves to the
next menu.
Closing the menu may (*cough*) dispose items within it depending on the
platform and version of eclipse you're on(*cough*).
SWTBot currently traverses the entire menu, grabs what the matcher
matches and performs click on them, but it may be too late because the
menu is disposed.
It's ugly but that was the cheap way to build it at the time when it was
built :(
The /right way/ would be to use with some ActionMatcher that uses a
ClickRunnableAction along with a real matcher to perform an action
before the menu is closed:
menuFinder.perform(action, matcher){
// keep traversing
if (matcher.matches(menuItem)){
action.perform();
}
//
}
--
Ketan
http://ketan.padegaonkar.name | http://eclipse.org/swtbot
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07183 seconds