Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to create popup menu on Folder only when there is a specified file in it?
How to create popup menu on Folder only when there is a specified file in it? [message #183251] Wed, 06 December 2006 15:13 Go to next message
Tanyu Trifonov is currently offline Tanyu TrifonovFriend
Messages: 73
Registered: July 2009
Member
Hi,

I want to to create a popup menu visible when the user clicks over
specified folder and there is no file with specified file name in the
folder. (When the user run that action it will create a file, but if the
file already exsists the action shouln't be visible).I created popup menu
visible for the folder using nameFiler. I looked at enablement/visibility
but I don't know how I can get the contents of the folder to check for the
file name.

Best regards,
Trifonov
Re: How to create popup menu on Folder only when there is a specified file in it? [message #183921 is a reply to message #183251] Tue, 12 December 2006 07:40 Go to previous message
Bjorn Freeman-Benson is currently offline Bjorn Freeman-BensonFriend
Messages: 334
Registered: July 2009
Senior Member
Trifonov,
Here's one way to enable/disable the menu (it still shows, but it's grey):
1. New > Project > Plug-in Project > "myproject" > Plug-in with popup
menu > Finish
2. Open "myproject.popup.actions" and modify selectionChanged:

public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof TreeSelection) {
TreeSelection sel = (TreeSelection) selection;
Object obj = sel.getFirstElement();
if (obj instanceof IFolder) {
IFolder f = (IFolder) obj;
try {
IResource[] members = f.members();
for (int i = 0; i < members.length; i++) {
String s = members[i].getName();
if (s.equals("foo")) {
action.setEnabled(false);
return;
}
}
} catch (CoreException x) {
// ignore
}
}
}
action.setEnabled(true);
}

This has the drawback of running code for each menu popup, but if the
code is fast enough, it shouldn't be a problem.

Hope this helps,
Bjorn
Previous Topic:Help stopped working
Next Topic:Breakpoints not recognized, or hang
Goto Forum:
  


Current Time: Tue May 14 08:04:56 GMT 2024

Powered by FUDForum. Page generated in 0.10490 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top