This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 102081
Collapse All | Expand All

(-)a/projectapi/src/org/netbeans/spi/project/ActionProvider.java (+6 lines)
Lines 46-51 Link Here
46
/**
46
/**
47
 * Ability for a project to have various actions (e.g. Build) invoked on it.
47
 * Ability for a project to have various actions (e.g. Build) invoked on it.
48
 * Should be registered in a project's lookup and will be used by UI infrastructure.
48
 * Should be registered in a project's lookup and will be used by UI infrastructure.
49
 * <p>
50
 * Implementations supporting single file commands (command constants ending with
51
 * {@code _SINGLE}) can also be registered in default lookup. If a provider in project
52
 * lookup does not enable the action for a given command on the selected file then
53
 * the first implementation found in default lookup that is enabled will be used.
54
 * </p>
49
 * @see org.netbeans.api.project.Project#getLookup
55
 * @see org.netbeans.api.project.Project#getLookup
50
 * @see <a href="@org-apache-tools-ant-module@/org/apache/tools/ant/module/api/support/ActionUtils.html"><code>ActionUtils</code></a>
56
 * @see <a href="@org-apache-tools-ant-module@/org/apache/tools/ant/module/api/support/ActionUtils.html"><code>ActionUtils</code></a>
51
 * @see <a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/support/ProjectSensitiveActions.html#projectCommandAction(java.lang.String,%20java.lang.String,%20javax.swing.Icon)"><code>ProjectSensitiveActions.projectCommandAction(...)</code></a>
57
 * @see <a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/support/ProjectSensitiveActions.html#projectCommandAction(java.lang.String,%20java.lang.String,%20javax.swing.Icon)"><code>ProjectSensitiveActions.projectCommandAction(...)</code></a>
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/FileCommandAction.java (-2 / +26 lines)
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
}

Return to bug 102081