Lines 41-52
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.modules.project.ui.actions; |
42 |
package org.netbeans.modules.project.ui.actions; |
43 |
|
43 |
|
|
|
44 |
import java.util.Arrays; |
45 |
import java.util.Collection; |
44 |
import javax.swing.Action; |
46 |
import javax.swing.Action; |
45 |
import javax.swing.Icon; |
47 |
import javax.swing.Icon; |
46 |
import org.netbeans.api.project.Project; |
48 |
import org.netbeans.api.project.Project; |
47 |
import org.netbeans.spi.project.ActionProvider; |
49 |
import org.netbeans.spi.project.ActionProvider; |
48 |
import org.openide.awt.Actions; |
50 |
import org.openide.awt.Actions; |
49 |
import org.openide.filesystems.FileObject; |
51 |
import org.openide.filesystems.FileObject; |
|
|
52 |
import org.openide.loaders.DataObject; |
50 |
import org.openide.util.ImageUtilities; |
53 |
import org.openide.util.ImageUtilities; |
51 |
import org.openide.util.Lookup; |
54 |
import org.openide.util.Lookup; |
52 |
|
55 |
|
Lines 73-80
Link Here
|
73 |
Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() ); |
76 |
Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() ); |
74 |
|
77 |
|
75 |
if ( projects.length != 1 ) { |
78 |
if ( projects.length != 1 ) { |
76 |
setEnabled( false ); // Zero or more than one projects found or command not supported |
79 |
if (projects.length == 0 && globalProvider(context) != null) { |
77 |
presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); |
80 |
setEnabled(true); |
|
|
81 |
Collection<? extends DataObject> files = context.lookupAll(DataObject.class); |
82 |
presenterName = ActionsUtil.formatName(getNamePattern(), files.size(), |
83 |
files.isEmpty() ? "" : files.iterator().next().getPrimaryFile().getNameExt()); // NOI18N |
84 |
} else { |
85 |
setEnabled(false); // Zero or more than one projects found or command not supported |
86 |
presenterName = ActionsUtil.formatName(getNamePattern(), 0, ""); |
87 |
} |
78 |
} |
88 |
} |
79 |
else { |
89 |
else { |
80 |
FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] ); |
90 |
FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] ); |
Lines 93-100
Link Here
|
93 |
if ( projects.length == 1 ) { |
103 |
if ( projects.length == 1 ) { |
94 |
ActionProvider ap = projects[0].getLookup().lookup(ActionProvider.class); |
104 |
ActionProvider ap = projects[0].getLookup().lookup(ActionProvider.class); |
95 |
ap.invokeAction( getCommand(), context ); |
105 |
ap.invokeAction( getCommand(), context ); |
|
|
106 |
return; |
96 |
} |
107 |
} |
97 |
|
108 |
|
|
|
109 |
ActionProvider provider = globalProvider(context); |
110 |
if (provider != null) { |
111 |
provider.invokeAction(getCommand(), context); |
112 |
} |
98 |
} |
113 |
} |
99 |
|
114 |
|
100 |
@Override |
115 |
@Override |
Lines 102-105
Link Here
|
102 |
return new FileCommandAction( getCommand(), getNamePattern(), (Icon)getValue( SMALL_ICON ), actionContext ); |
117 |
return new FileCommandAction( getCommand(), getNamePattern(), (Icon)getValue( SMALL_ICON ), actionContext ); |
103 |
} |
118 |
} |
104 |
|
119 |
|
|
|
120 |
private ActionProvider globalProvider(Lookup context) { |
121 |
for (ActionProvider ap : Lookup.getDefault().lookupAll(ActionProvider.class)) { |
122 |
if (Arrays.asList(ap.getSupportedActions()).contains(getCommand()) && ap.isActionEnabled(getCommand(), context)) { |
123 |
return ap; |
124 |
} |
125 |
} |
126 |
return null; |
127 |
} |
128 |
|
105 |
} |
129 |
} |