Lines 52-64
Link Here
|
52 |
import org.openide.loaders.DataObject; |
52 |
import org.openide.loaders.DataObject; |
53 |
import org.openide.util.ImageUtilities; |
53 |
import org.openide.util.ImageUtilities; |
54 |
import org.openide.util.Lookup; |
54 |
import org.openide.util.Lookup; |
|
|
55 |
import org.openide.util.Mutex; |
55 |
|
56 |
|
56 |
/** An action sensitive to selected node. Used for 1-off actions |
57 |
/** An action sensitive to selected node. Used for 1-off actions |
57 |
*/ |
58 |
*/ |
58 |
public final class FileCommandAction extends ProjectAction { |
59 |
public final class FileCommandAction extends ProjectAction { |
59 |
|
60 |
|
60 |
private String presenterName; |
|
|
61 |
|
62 |
public FileCommandAction( String command, String namePattern, String iconResource, Lookup lookup ) { |
61 |
public FileCommandAction( String command, String namePattern, String iconResource, Lookup lookup ) { |
63 |
this( command, namePattern, ImageUtilities.loadImageIcon(iconResource, false), lookup ); |
62 |
this( command, namePattern, ImageUtilities.loadImageIcon(iconResource, false), lookup ); |
64 |
} |
63 |
} |
Lines 66-99
Link Here
|
66 |
public FileCommandAction( String command, String namePattern, Icon icon, Lookup lookup ) { |
65 |
public FileCommandAction( String command, String namePattern, Icon icon, Lookup lookup ) { |
67 |
super( command, namePattern, icon, lookup ); |
66 |
super( command, namePattern, icon, lookup ); |
68 |
assert namePattern != null : "Name patern must not be null"; |
67 |
assert namePattern != null : "Name patern must not be null"; |
69 |
presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); |
68 |
String presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); |
70 |
setDisplayName( presenterName ); |
69 |
setDisplayName( presenterName ); |
71 |
putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); |
70 |
putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); |
72 |
} |
71 |
} |
73 |
|
72 |
|
74 |
@Override |
73 |
protected @Override void refresh(final Lookup context) { |
75 |
protected void refresh( Lookup context ) { |
74 |
RP.post(new Runnable() { |
|
|
75 |
public @Override void run() { |
76 |
Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() ); |
76 |
Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() ); |
77 |
|
77 |
final boolean enable; |
|
|
78 |
final String presenterName; |
78 |
if ( projects.length != 1 ) { |
79 |
if ( projects.length != 1 ) { |
79 |
if (projects.length == 0 && globalProvider(context) != null) { |
80 |
if (projects.length == 0 && globalProvider(context) != null) { |
80 |
setEnabled(true); |
81 |
enable = true; |
81 |
Collection<? extends DataObject> files = context.lookupAll(DataObject.class); |
82 |
Collection<? extends DataObject> files = context.lookupAll(DataObject.class); |
82 |
presenterName = ActionsUtil.formatName(getNamePattern(), files.size(), |
83 |
presenterName = ActionsUtil.formatName(getNamePattern(), files.size(), |
83 |
files.isEmpty() ? "" : files.iterator().next().getPrimaryFile().getNameExt()); // NOI18N |
84 |
files.isEmpty() ? "" : files.iterator().next().getPrimaryFile().getNameExt()); // NOI18N |
84 |
} else { |
85 |
} else { |
85 |
setEnabled(false); // Zero or more than one projects found or command not supported |
86 |
enable = false; // Zero or more than one projects found or command not supported |
86 |
presenterName = ActionsUtil.formatName(getNamePattern(), 0, ""); |
87 |
presenterName = ActionsUtil.formatName(getNamePattern(), 0, ""); |
87 |
} |
88 |
} |
88 |
} |
89 |
} |
89 |
else { |
90 |
else { |
90 |
FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] ); |
91 |
FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] ); |
91 |
setEnabled( true ); |
92 |
enable = true; |
92 |
presenterName = ActionsUtil.formatName( getNamePattern(), files.length, files.length > 0 ? files[0].getNameExt() : "" ); // NOI18N |
93 |
presenterName = ActionsUtil.formatName( getNamePattern(), files.length, files.length > 0 ? files[0].getNameExt() : "" ); // NOI18N |
93 |
} |
94 |
} |
94 |
|
95 |
Mutex.EVENT.writeAccess(new Runnable() { |
|
|
96 |
public @Override void run() { |
95 |
putValue("menuText", presenterName); |
97 |
putValue("menuText", presenterName); |
96 |
putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); |
98 |
putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); |
|
|
99 |
setEnabled(enable); |
100 |
} |
101 |
}); |
102 |
} |
103 |
}); |
97 |
} |
104 |
} |
98 |
|
105 |
|
99 |
@Override |
106 |
@Override |