Skip to content

Commit 785d699

Browse files
committed
Custom wp-content name #14
1 parent 1084f32 commit 785d699

7 files changed

Lines changed: 330 additions & 5 deletions

File tree

src/org/netbeans/modules/php/wordpress/WordPressPhpProvider.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@
5252
import org.netbeans.modules.php.spi.editor.EditorExtender;
5353
import org.netbeans.modules.php.spi.framework.PhpFrameworkProvider;
5454
import org.netbeans.modules.php.spi.framework.PhpModuleActionsExtender;
55+
import org.netbeans.modules.php.spi.framework.PhpModuleCustomizerExtender;
5556
import org.netbeans.modules.php.spi.framework.PhpModuleExtender;
5657
import org.netbeans.modules.php.spi.framework.PhpModuleIgnoredFilesExtender;
5758
import org.netbeans.modules.php.spi.framework.commands.FrameworkCommandSupport;
59+
import org.netbeans.modules.php.wordpress.customizer.WordPressCustomizerExtender;
5860
import org.netbeans.modules.php.wordpress.editor.WordPressEditorExtender;
61+
import org.netbeans.modules.php.wordpress.preferences.WordPressPreferences;
5962
import org.openide.filesystems.FileObject;
6063
import org.openide.filesystems.FileUtil;
6164
import org.openide.util.ImageUtilities;
@@ -74,7 +77,6 @@ public class WordPressPhpProvider extends PhpFrameworkProvider {
7477

7578
static {
7679
WP_DIRS.add("wp-admin"); // NOI18N
77-
WP_DIRS.add("wp-content"); // NOI18N
7880
WP_DIRS.add("wp-includes"); // NOI18N
7981
}
8082

@@ -110,6 +112,12 @@ public boolean isInPhpModule(PhpModule pm) {
110112
return false;
111113
}
112114
}
115+
116+
// content name
117+
FileObject content = sourceDirectory.getFileObject(WordPressPreferences.getCustomContentName(pm));
118+
if (content == null) {
119+
return false;
120+
}
113121
}
114122
return true;
115123
}
@@ -155,6 +163,11 @@ public FrameworkCommandSupport getFrameworkCommandSupport(PhpModule pm) {
155163
return null;
156164
}
157165

166+
@Override
167+
public PhpModuleCustomizerExtender createPhpModuleCustomizerExtender(PhpModule phpModule) {
168+
return new WordPressCustomizerExtender(phpModule);
169+
}
170+
158171
@Override
159172
public EditorExtender getEditorExtender(PhpModule pm) {
160173
return new WordPressEditorExtender();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
WordPressCustomizerExtenderPanel.customContentNameLabel.text=custom content name:
2+
WordPressCustomizerExtenderPanel.customContentNameLabel.text=custom content name:
3+
WordPressCustomizerExtenderPanel.customContentNameTextField.text=
4+
WordPressCustomizerExtenderPanel.customContentNameTextField.text=
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2013 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+
* Portions Copyrighted 2013 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.customizer;
43+
44+
import java.util.EnumSet;
45+
import javax.swing.JComponent;
46+
import javax.swing.event.ChangeListener;
47+
import org.netbeans.modules.php.api.phpmodule.PhpModule;
48+
import org.netbeans.modules.php.api.util.StringUtils;
49+
import org.netbeans.modules.php.spi.framework.PhpModuleCustomizerExtender;
50+
import org.netbeans.modules.php.wordpress.preferences.WordPressPreferences;
51+
import org.openide.util.HelpCtx;
52+
import org.openide.util.NbBundle;
53+
54+
/**
55+
*
56+
* @author junichi11
57+
*/
58+
public class WordPressCustomizerExtender extends PhpModuleCustomizerExtender {
59+
60+
private WordPressCustomizerExtenderPanel panel;
61+
private final PhpModule phpModule;
62+
private String originalCustomeContentName;
63+
64+
public WordPressCustomizerExtender(PhpModule phpModule) {
65+
this.phpModule = phpModule;
66+
}
67+
68+
@NbBundle.Messages("WordPressCustomizerExtender.displayname=WordPress")
69+
@Override
70+
public String getDisplayName() {
71+
return Bundle.WordPressCustomizerExtender_displayname();
72+
}
73+
74+
@Override
75+
public void addChangeListener(ChangeListener cl) {
76+
}
77+
78+
@Override
79+
public void removeChangeListener(ChangeListener cl) {
80+
}
81+
82+
@Override
83+
public JComponent getComponent() {
84+
return getPanel();
85+
}
86+
87+
@Override
88+
public HelpCtx getHelp() {
89+
return null;
90+
}
91+
92+
@Override
93+
public boolean isValid() {
94+
return true;
95+
}
96+
97+
@Override
98+
public String getErrorMessage() {
99+
return null;
100+
}
101+
102+
@Override
103+
public EnumSet<Change> save(PhpModule pm) {
104+
String customContentName = getPanel().getCustomContentName();
105+
if (StringUtils.isEmpty(customContentName)) {
106+
return null;
107+
}
108+
109+
if (!originalCustomeContentName.equals(customContentName)) {
110+
WordPressPreferences.setCustomContentName(phpModule, customContentName);
111+
}
112+
113+
return EnumSet.of(Change.FRAMEWORK_CHANGE);
114+
}
115+
116+
private WordPressCustomizerExtenderPanel getPanel() {
117+
if (panel == null) {
118+
panel = new WordPressCustomizerExtenderPanel();
119+
originalCustomeContentName = WordPressPreferences.getCustomContentName(phpModule);
120+
panel.setCustomContentName(originalCustomeContentName);
121+
}
122+
123+
return panel;
124+
}
125+
126+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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" alignment="0" attributes="0">
20+
<EmptySpace max="-2" attributes="0"/>
21+
<Component id="customContentNameLabel" min="-2" max="-2" attributes="0"/>
22+
<EmptySpace max="-2" attributes="0"/>
23+
<Component id="customContentNameTextField" max="32767" attributes="0"/>
24+
<EmptySpace max="-2" attributes="0"/>
25+
</Group>
26+
</Group>
27+
</DimensionLayout>
28+
<DimensionLayout dim="1">
29+
<Group type="103" groupAlignment="0" attributes="0">
30+
<Group type="102" alignment="0" attributes="0">
31+
<EmptySpace max="-2" attributes="0"/>
32+
<Group type="103" groupAlignment="3" attributes="0">
33+
<Component id="customContentNameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
34+
<Component id="customContentNameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
35+
</Group>
36+
<EmptySpace max="32767" attributes="0"/>
37+
</Group>
38+
</Group>
39+
</DimensionLayout>
40+
</Layout>
41+
<SubComponents>
42+
<Component class="javax.swing.JLabel" name="customContentNameLabel">
43+
<Properties>
44+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
45+
<ResourceString bundle="org/netbeans/modules/php/wordpress/customizer/Bundle.properties" key="WordPressCustomizerExtenderPanel.customContentNameLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
46+
</Property>
47+
</Properties>
48+
</Component>
49+
<Component class="javax.swing.JTextField" name="customContentNameTextField">
50+
<Properties>
51+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
52+
<ResourceString bundle="org/netbeans/modules/php/wordpress/customizer/Bundle.properties" key="WordPressCustomizerExtenderPanel.customContentNameTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
53+
</Property>
54+
</Properties>
55+
</Component>
56+
</SubComponents>
57+
</Form>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2013 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+
* Portions Copyrighted 2013 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.customizer;
43+
44+
/**
45+
*
46+
* @author junichi11
47+
*/
48+
public class WordPressCustomizerExtenderPanel extends javax.swing.JPanel {
49+
50+
/**
51+
* Creates new form WordPressCustomizerExtenderPanel
52+
*/
53+
public WordPressCustomizerExtenderPanel() {
54+
initComponents();
55+
}
56+
57+
public String getCustomContentName() {
58+
return customContentNameTextField.getText().trim();
59+
}
60+
61+
public void setCustomContentName(String name) {
62+
customContentNameTextField.setText(name);
63+
}
64+
65+
/**
66+
* This method is called from within the constructor to initialize the form.
67+
* WARNING: Do NOT modify this code. The content of this method is always
68+
* regenerated by the Form Editor.
69+
*/
70+
@SuppressWarnings("unchecked")
71+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
72+
private void initComponents() {
73+
74+
customContentNameLabel = new javax.swing.JLabel();
75+
customContentNameTextField = new javax.swing.JTextField();
76+
77+
org.openide.awt.Mnemonics.setLocalizedText(customContentNameLabel, org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.customContentNameLabel.text")); // NOI18N
78+
79+
customContentNameTextField.setText(org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.customContentNameTextField.text")); // NOI18N
80+
81+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
82+
this.setLayout(layout);
83+
layout.setHorizontalGroup(
84+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
85+
.addGroup(layout.createSequentialGroup()
86+
.addContainerGap()
87+
.addComponent(customContentNameLabel)
88+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
89+
.addComponent(customContentNameTextField)
90+
.addContainerGap())
91+
);
92+
layout.setVerticalGroup(
93+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
94+
.addGroup(layout.createSequentialGroup()
95+
.addContainerGap()
96+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
97+
.addComponent(customContentNameLabel)
98+
.addComponent(customContentNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
99+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
100+
);
101+
}// </editor-fold>//GEN-END:initComponents
102+
103+
// Variables declaration - do not modify//GEN-BEGIN:variables
104+
private javax.swing.JLabel customContentNameLabel;
105+
private javax.swing.JTextField customContentNameTextField;
106+
// End of variables declaration//GEN-END:variables
107+
}

src/org/netbeans/modules/php/wordpress/preferences/WordPressPreferences.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,24 @@
5555
public class WordPressPreferences {
5656

5757
private static final List<String> WITHIN_OPTIONS = new ArrayList<String>();
58+
private static final String CUSTOM_CONTENT_NAME = "custom-content-name"; // NOI18N
5859

60+
private WordPressPreferences() {
61+
}
62+
63+
public static String getCustomContentName(PhpModule phpModule) {
64+
return getPreferences(phpModule).get(CUSTOM_CONTENT_NAME, "wp-content"); // NOI18N
65+
}
66+
67+
public static void setCustomContentName(PhpModule phpModule, String name) {
68+
getPreferences(phpModule).put(CUSTOM_CONTENT_NAME, name);
69+
}
70+
71+
private static Preferences getPreferences(PhpModule phpModule) {
72+
return phpModule.getPreferences(WordPressPreferences.class, true);
73+
}
74+
75+
// formatting
5976
static {
6077
WITHIN_OPTIONS.add(FmtOptions.SPACE_WITHIN_ARRAY_DECL_PARENS);
6178
WITHIN_OPTIONS.add(FmtOptions.SPACE_WITHIN_CATCH_PARENS);

src/org/netbeans/modules/php/wordpress/util/WPFileUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.zip.ZipInputStream;
5555
import java.util.zip.ZipOutputStream;
5656
import org.netbeans.modules.php.api.phpmodule.PhpModule;
57+
import org.netbeans.modules.php.wordpress.preferences.WordPressPreferences;
5758
import org.openide.filesystems.FileObject;
5859
import org.openide.filesystems.FileUtil;
5960

@@ -64,17 +65,17 @@
6465
public class WPFileUtils {
6566

6667
public static final String WP_CONTENT = "wp-content"; // NOI18N
67-
public static final String WP_PLUGINS = WP_CONTENT + "/plugins"; // NOI18N
68-
public static final String WP_THEMES = WP_CONTENT + "/themes"; // NOI18N
68+
public static final String WP_PLUGINS = "%s/plugins"; // NOI18N
69+
public static final String WP_THEMES = "%s/themes"; // NOI18N
6970
public static final String WP_INCLUDES = "wp-includes"; // NOI18N
7071
public static final String WP_ADMIN = "wp-admin"; // NOI18N
7172

7273
public static FileObject getPluginsDirectory(PhpModule phpModule) {
73-
return getDirectory(phpModule, WP_PLUGINS);
74+
return getDirectory(phpModule, String.format(WP_PLUGINS, WordPressPreferences.getCustomContentName(phpModule)));
7475
}
7576

7677
public static FileObject getThemesDirectory(PhpModule phpModule) {
77-
return getDirectory(phpModule, WP_THEMES);
78+
return getDirectory(phpModule, String.format(WP_THEMES, WordPressPreferences.getCustomContentName(phpModule)));
7879
}
7980

8081
public static FileObject getIncludesDirectory(PhpModule phpModule) {

0 commit comments

Comments
 (0)