Skip to content

Commit 7ada731

Browse files
committed
Add actions to plugins and themes nodes #60
1 parent cf64114 commit 7ada731

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

src/org/netbeans/modules/php/wordpress/ui/actions/CreateThemeAction.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@
4747
import org.netbeans.modules.php.spi.framework.actions.BaseAction;
4848
import org.openide.util.NbBundle;
4949
import org.openide.util.actions.Presenter;
50+
import org.openide.util.actions.Presenter.Popup;
5051

5152
/**
5253
*
5354
* @author junichi11
5455
*/
55-
public class CreateThemeAction extends BaseAction implements Presenter.Menu {
56+
public class CreateThemeAction extends BaseAction implements Presenter.Menu, Popup {
5657

5758
private static final long serialVersionUID = -1533566813298547558L;
5859
private static final CreateThemeAction INSTANCE = new CreateThemeAction();
@@ -81,6 +82,15 @@ protected void actionPerformed(PhpModule pm) {
8182

8283
@Override
8384
public JMenuItem getMenuPresenter() {
85+
return createMenuItem();
86+
}
87+
88+
@Override
89+
public JMenuItem getPopupPresenter() {
90+
return createMenuItem();
91+
}
92+
93+
private JMenuItem createMenuItem() {
8494
JMenu menu = new JMenu(getPureName());
8595
JMenuItem underscores = new JMenuItem(CreateUnderscoresThemeAction.getInstance());
8696
JMenuItem barebones = new JMenuItem(CreateBarebonesThemeAction.getInstance());

src/org/netbeans/modules/php/wordpress/ui/logicalview/MVCNode.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
import java.util.logging.Logger;
5151
import javax.swing.Action;
5252
import org.netbeans.modules.php.api.util.FileUtils;
53+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
54+
import org.netbeans.modules.php.wordpress.ui.actions.CreateChildThemeAction;
55+
import org.netbeans.modules.php.wordpress.ui.actions.CreatePluginAction;
56+
import org.netbeans.modules.php.wordpress.ui.actions.CreateThemeAction;
5357
import org.netbeans.spi.project.ui.support.CommonProjectActions;
5458
import org.netbeans.spi.project.ui.support.FileSensitiveActions;
5559
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
@@ -79,20 +83,22 @@ public class MVCNode extends FilterNode {
7983

8084
private static final String ICON_PATH = "org/netbeans/modules/php/wordpress/resources/wordpress_icon_8.png"; //NOI18N
8185
private static final Image WP_ICON = ImageUtilities.loadImage(ICON_PATH);
86+
private final WordPressModule.DIR_TYPE type;
8287

8388
/**
8489
* creates source root node based on specified DataFolder. Uses specified
8590
* name.
8691
*/
87-
MVCNode(DataFolder folder, DataFilter filter, String name) {
88-
this(folder, new FilterNode(folder.getNodeDelegate(), folder.createNodeChildren(filter)), name);
92+
MVCNode(DataFolder folder, DataFilter filter, String name, WordPressModule.DIR_TYPE type) {
93+
this(folder, new FilterNode(folder.getNodeDelegate(), folder.createNodeChildren(filter)), name, type);
8994
}
9095

91-
private MVCNode(DataFolder folder, FilterNode node, String name) {
96+
private MVCNode(DataFolder folder, FilterNode node, String name, WordPressModule.DIR_TYPE type) {
9297
super(node, new MVCNode.FolderChildren(node, false), new ProxyLookup(folder.getNodeDelegate().getLookup()));
9398

9499
disableDelegation(DELEGATE_GET_DISPLAY_NAME | DELEGATE_SET_DISPLAY_NAME | DELEGATE_GET_SHORT_DESCRIPTION | DELEGATE_GET_ACTIONS);
95100
setDisplayName(name);
101+
this.type = type;
96102
}
97103

98104
@Override
@@ -134,6 +140,18 @@ public boolean canDestroy() {
134140
public Action[] getActions(boolean context) {
135141
List<Action> actions = new ArrayList<>();
136142
actions.add(CommonProjectActions.newFileAction());
143+
// WordPress Actions
144+
switch (type) {
145+
case PLUGINS:
146+
actions.add(CreatePluginAction.getInstance());
147+
break;
148+
case THEMES:
149+
actions.add(CreateThemeAction.getInstance());
150+
actions.add(CreateChildThemeAction.getInstance());
151+
break;
152+
default:
153+
break;
154+
}
137155
actions.add(null);
138156
actions.add(FileSensitiveActions.fileCommandAction("dowonload", Bundle.LBL_DownloadCommand(), null));
139157
actions.add(FileSensitiveActions.fileCommandAction("upload", Bundle.LBL_UploadCommand(), null));

src/org/netbeans/modules/php/wordpress/ui/logicalview/MVCNodeFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ public List<Node> keys() {
9595
// plugins
9696
FileObject pluginsDirectory = module.getPluginsDirectory();
9797
if (pluginsDirectory != null) {
98-
addNode(list, pluginsDirectory);
98+
addNode(list, pluginsDirectory, WordPressModule.DIR_TYPE.PLUGINS);
9999
}
100100
// themes
101101
FileObject themesDirectory = module.getThemesDirectory();
102102
if (themesDirectory != null) {
103-
addNode(list, themesDirectory);
103+
addNode(list, themesDirectory, WordPressModule.DIR_TYPE.THEMES);
104104
}
105105
return list;
106106
}
107107
return Collections.emptyList();
108108
}
109109

110-
private void addNode(List<Node> list, FileObject fileObject) {
110+
private void addNode(List<Node> list, FileObject fileObject, WordPressModule.DIR_TYPE type) {
111111
if (fileObject != null) {
112112
DataFolder folder = getFolder(fileObject);
113113
if (folder != null) {
114-
list.add(new MVCNode(folder, null, fileObject.getName()));
114+
list.add(new MVCNode(folder, null, fileObject.getName(), type));
115115
}
116116
}
117117
}

0 commit comments

Comments
 (0)