How to create popup menu on Folder only when there is a specified file in it? [message #183251] |
Wed, 06 December 2006 10:13  |
Eclipse User |
|
|
|
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 02:40  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.07987 seconds