Skip to content

Commit b9cc1a7

Browse files
committed
Add CreateMinimumBlankThemeAction #59
- Just create a style.css and an empty index.php
1 parent eeda2e2 commit b9cc1a7

File tree

6 files changed

+464
-2
lines changed

6 files changed

+464
-2
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,22 @@ add_filter('the_content', 'w[Ctrl + Space]'); // e.g. start with 'w'
7979
```
8080

8181
### Display And Change Debug Status
82-
WP_DEBUG value(wp-config.php) is displayed on bottome-right of IDE.
82+
WP_DEBUG value(wp-config.php) is displayed on bottom-right of IDE.
8383
If you click there, you can change WP_DEBUG value.
8484
WordPress version number is also displayed.
8585

8686
### Create New Theme Action
8787
Right-click Project > WordPress > Create Theme
8888

89+
#### Minimum Theme
90+
91+
Just create a style.css and an empty index.php.
92+
8993
#### Underscores
9094
Create theme from [Underscores | A Starter Theme for WordPress](http://underscores.me/). Underscores is awesome!
9195
This plugin uses [Automattic/_s · GitHub](https://github.com/automattic/_s).
9296

93-
**Please notice that license of created theme is GPLv2**
97+
**Please note that license of created theme is GPLv2**
9498

9599
#### Barebones
96100
Create theme form [welcomebrand/Barebones · GitHub](https://github.com/welcomebrand/Barebones).
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*/
40+
package org.netbeans.modules.php.wordpress.ui.actions;
41+
42+
import java.awt.EventQueue;
43+
import java.io.IOException;
44+
import java.util.ArrayList;
45+
import java.util.HashMap;
46+
import java.util.List;
47+
import java.util.Map;
48+
import java.util.logging.Level;
49+
import java.util.logging.Logger;
50+
import javax.swing.event.ChangeEvent;
51+
import javax.swing.event.ChangeListener;
52+
import org.netbeans.modules.csl.api.UiUtils;
53+
import org.netbeans.modules.php.api.phpmodule.PhpModule;
54+
import org.netbeans.modules.php.spi.framework.actions.BaseAction;
55+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
56+
import org.netbeans.modules.php.wordpress.ui.wizards.CreateMinimumBlankThemePanel;
57+
import org.netbeans.modules.php.wordpress.util.WPUtils;
58+
import org.openide.DialogDescriptor;
59+
import org.openide.DialogDisplayer;
60+
import org.openide.NotifyDescriptor;
61+
import org.openide.filesystems.FileObject;
62+
import org.openide.filesystems.FileUtil;
63+
import org.openide.loaders.DataFolder;
64+
import org.openide.loaders.DataObject;
65+
import org.openide.util.NbBundle;
66+
67+
public class CreateMinimumBlankThemeAction extends BaseAction {
68+
69+
private final List<String> themes = new ArrayList<>();
70+
private static final CreateMinimumBlankThemeAction INSTANCE = new CreateMinimumBlankThemeAction();
71+
private static final Logger LOGGER = Logger.getLogger(CreateMinimumBlankThemeAction.class.getName());
72+
73+
private CreateMinimumBlankThemeAction() {
74+
}
75+
76+
public static CreateMinimumBlankThemeAction getInstance() {
77+
return INSTANCE;
78+
}
79+
80+
@Override
81+
protected String getFullName() {
82+
return getPureName();
83+
}
84+
85+
@NbBundle.Messages("CreateMinimumBlankThemeAction.PureName=Minimum Theme")
86+
@Override
87+
protected String getPureName() {
88+
return Bundle.CreateMinimumBlankThemeAction_PureName();
89+
}
90+
91+
@NbBundle.Messages({
92+
"CreateMinimumBlankThemeAction.dialog.title=Create Minimum Theme",
93+
"CreateMinimumBlankThemeAction.existing.directoryName=It already exists."
94+
})
95+
@Override
96+
protected void actionPerformed(PhpModule phpModule) {
97+
assert EventQueue.isDispatchThread();
98+
if (!WPUtils.isWP(phpModule)) {
99+
// called via shortcut
100+
return;
101+
}
102+
themes.clear();
103+
104+
// get themes directory
105+
WordPressModule wpModule = WordPressModule.Factory.forPhpModule(phpModule);
106+
if (wpModule == null) {
107+
return;
108+
}
109+
final FileObject themesDirectory = wpModule.getThemesDirectory();
110+
if (themesDirectory == null) {
111+
return;
112+
}
113+
for (FileObject child : themesDirectory.getChildren()) {
114+
if (child.isFolder()) {
115+
themes.add(child.getNameExt());
116+
}
117+
}
118+
119+
// create a panel & descriptor
120+
final CreateMinimumBlankThemePanel panel = new CreateMinimumBlankThemePanel();
121+
final DialogDescriptor dialogDescriptor = new DialogDescriptor(
122+
panel,
123+
Bundle.CreateMinimumBlankThemeAction_dialog_title(),
124+
true,
125+
DialogDescriptor.OK_CANCEL_OPTION,
126+
null,
127+
null
128+
);
129+
130+
// add ChangeListener
131+
ChangeListener changeListener = new ChangeListener() {
132+
@Override
133+
public void stateChanged(ChangeEvent e) {
134+
String themeDirectoryName = panel.getThemeDirectoryName();
135+
boolean existsDirectory = themes.contains(themeDirectoryName);
136+
dialogDescriptor.setValid(!existsDirectory);
137+
if (existsDirectory) {
138+
panel.setErrorMessage(Bundle.CreateMinimumBlankThemeAction_existing_directoryName());
139+
} else {
140+
panel.setErrorMessage(" "); // NOI18N
141+
}
142+
}
143+
};
144+
panel.addChangeListener(changeListener);
145+
146+
// show dialog
147+
Object result = DialogDisplayer.getDefault().notify(dialogDescriptor);
148+
if (result == NotifyDescriptor.OK_OPTION) {
149+
try {
150+
createMinimumTheme(themesDirectory, panel.getThemeDirectoryName());
151+
} catch (IOException ex) {
152+
LOGGER.log(Level.WARNING, null, ex);
153+
}
154+
}
155+
panel.removeChangeListener(changeListener);
156+
}
157+
158+
@NbBundle.Messages({
159+
"CreateMinimumBlankThemePanel.notFound.themeTemplate=Not found : style.css template file",
160+
"CreateMinimumBlankThemePanel.directoryName.error=Cannot create a directory"
161+
})
162+
private void createMinimumTheme(FileObject themesDirectory, String directoryName) throws IOException {
163+
// get template
164+
FileObject template = FileUtil.getConfigFile("Templates/WordPress/style.css"); // NOI18N
165+
if (template == null) {
166+
LOGGER.log(Level.WARNING, Bundle.CreateMinimumBlankThemePanel_notFound_themeTemplate());
167+
return;
168+
}
169+
170+
// create a theme directory
171+
FileObject themeDirectory = themesDirectory.createFolder(directoryName);
172+
if (themeDirectory == null) {
173+
LOGGER.log(Level.WARNING, Bundle.CreateMinimumBlankThemePanel_directoryName_error());
174+
return;
175+
}
176+
177+
// create an empty index.php
178+
themeDirectory.createData("index", "php"); // NOI18N
179+
180+
// create a style.css
181+
DataObject templateDataObject = DataObject.find(template);
182+
DataFolder targetFolder = DataFolder.findFolder(themeDirectory);
183+
Map<String, String> parameters = new HashMap<>();
184+
// TODO add fields as well as child theme?
185+
DataObject styleCssDataObject = templateDataObject.createFromTemplate(targetFolder, "style.css", parameters); // NOI18N
186+
if (styleCssDataObject != null) {
187+
UiUtils.open(styleCssDataObject.getPrimaryFile(), 0);
188+
}
189+
}
190+
191+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private JMenuItem createMenuItem() {
9494
JMenu menu = new JMenu(getPureName());
9595
JMenuItem underscores = new JMenuItem(CreateUnderscoresThemeAction.getInstance());
9696
JMenuItem barebones = new JMenuItem(CreateBarebonesThemeAction.getInstance());
97+
menu.add(CreateMinimumBlankThemeAction.getInstance());
9798
menu.add(underscores);
9899
menu.add(barebones);
99100
return menu;

src/org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ CreateChildThemePanel.childDirectoryNameTextField.text=
5555
CreateChildThemePanel.childThemeNameLabel.text=Child Theme Name:
5656
CreateChildThemePanel.childThemeNameTextField.text=
5757
NewProjectConfigurationPanel.dbNameLabel.text=DB_NAME:
58+
CreateMinimumBlankThemePanel.errorMessageLabel.text=ERROR
59+
CreateMinimumBlankThemePanel.themeDirectoryNameTextField.text=
60+
CreateMinimumBlankThemePanel.themeDirectoryNameLabel.text=Theme Directory Name:
61+
CreateMinimumBlankThemePanel.descriptionLabel.text=Just create a style.css and an empty index.php
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4+
<AuxValues>
5+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
9+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14+
</AuxValues>
15+
16+
<Layout>
17+
<DimensionLayout dim="0">
18+
<Group type="103" groupAlignment="0" attributes="0">
19+
<Group type="102" attributes="0">
20+
<EmptySpace max="-2" attributes="0"/>
21+
<Group type="103" groupAlignment="0" attributes="0">
22+
<Group type="102" alignment="0" attributes="0">
23+
<Component id="themeDirectoryNameLabel" min="-2" max="-2" attributes="0"/>
24+
<EmptySpace max="-2" attributes="0"/>
25+
<Component id="themeDirectoryNameTextField" pref="207" max="32767" attributes="0"/>
26+
</Group>
27+
<Group type="102" attributes="0">
28+
<Group type="103" groupAlignment="0" attributes="0">
29+
<Component id="errorMessageLabel" alignment="0" min="-2" max="-2" attributes="0"/>
30+
<Component id="descriptionLabel" alignment="0" min="-2" max="-2" attributes="0"/>
31+
</Group>
32+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
33+
</Group>
34+
</Group>
35+
<EmptySpace max="-2" attributes="0"/>
36+
</Group>
37+
</Group>
38+
</DimensionLayout>
39+
<DimensionLayout dim="1">
40+
<Group type="103" groupAlignment="0" attributes="0">
41+
<Group type="102" alignment="0" attributes="0">
42+
<EmptySpace max="-2" attributes="0"/>
43+
<Group type="103" groupAlignment="3" attributes="0">
44+
<Component id="themeDirectoryNameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
45+
<Component id="themeDirectoryNameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
46+
</Group>
47+
<EmptySpace max="-2" attributes="0"/>
48+
<Component id="descriptionLabel" min="-2" max="-2" attributes="0"/>
49+
<EmptySpace max="-2" attributes="0"/>
50+
<Component id="errorMessageLabel" min="-2" max="-2" attributes="0"/>
51+
<EmptySpace max="32767" attributes="0"/>
52+
</Group>
53+
</Group>
54+
</DimensionLayout>
55+
</Layout>
56+
<SubComponents>
57+
<Component class="javax.swing.JLabel" name="themeDirectoryNameLabel">
58+
<Properties>
59+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
60+
<ResourceString bundle="org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties" key="CreateMinimumBlankThemePanel.themeDirectoryNameLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
61+
</Property>
62+
</Properties>
63+
</Component>
64+
<Component class="javax.swing.JTextField" name="themeDirectoryNameTextField">
65+
<Properties>
66+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
67+
<ResourceString bundle="org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties" key="CreateMinimumBlankThemePanel.themeDirectoryNameTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
68+
</Property>
69+
</Properties>
70+
</Component>
71+
<Component class="javax.swing.JLabel" name="errorMessageLabel">
72+
<Properties>
73+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
74+
<ResourceString bundle="org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties" key="CreateMinimumBlankThemePanel.errorMessageLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
75+
</Property>
76+
</Properties>
77+
</Component>
78+
<Component class="javax.swing.JLabel" name="descriptionLabel">
79+
<Properties>
80+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
81+
<ResourceString bundle="org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties" key="CreateMinimumBlankThemePanel.descriptionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
82+
</Property>
83+
</Properties>
84+
</Component>
85+
</SubComponents>
86+
</Form>

0 commit comments

Comments
 (0)