Skip to content

Commit 0e2917f

Browse files
committed
Add a wp-content directory path to a project settings #62
- First of all, search the default wp-content directory.
1 parent 0805b67 commit 0e2917f

9 files changed

Lines changed: 128 additions & 19 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void run() {
205205
return;
206206
}
207207
ValidationResult result = new WordPressModuleValidator()
208-
.validateWordPressDirectories(wordPressRoot, WordPressPreferences.getCustomContentName(phpModule))
208+
.validateWordPressDirectories(wordPressRoot, WordPressPreferences.getCustomContentName(phpModule), null)
209209
.getResult();
210210
if (result.hasWarnings()) {
211211
return;

src/org/netbeans/modules/php/wordpress/customizer/Bundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ WordPressCustomizerExtenderPanel.wordPressRootLabel.text=WordPress Root:
1212
WordPressCustomizerExtenderPanel.wordPressRootTextField.text=
1313
WordPressCustomizerExtenderPanel.themesTextField.text=
1414
WordPressCustomizerExtenderPanel.customDirectoryPathLabel.toolTipText=empty is default directory structure
15+
WordPressCustomizerExtenderPanel.wpContentLabel.text=wp-content:
16+
WordPressCustomizerExtenderPanel.wpContentTextField.text=
17+
WordPressCustomizerExtenderPanel.jLabel1.text=(If wp-content is not in the WordPress Root)

src/org/netbeans/modules/php/wordpress/customizer/WordPressCustomizerExtender.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ public class WordPressCustomizerExtender extends PhpModuleCustomizerExtender {
6969
private boolean isValid;
7070
private String originalCustomeContentName;
7171
private String errorMessage;
72+
// paths
7273
private String originalWordPressRoot;
7374
private String originalPlugins;
7475
private String originalThemes;
76+
private String originalWpContent;
7577

7678
public WordPressCustomizerExtender(PhpModule phpModule) {
7779
this.phpModule = phpModule;
@@ -125,20 +127,25 @@ private void validate() {
125127
String contentName = getPanel().getCustomContentName();
126128
FileObject sourceDirectory = phpModule.getSourceDirectory();
127129
FileObject wordPressRoot = null;
130+
FileObject wpContentDirectory = null;
128131
if (sourceDirectory != null) {
129132
wordPressRoot = sourceDirectory.getFileObject(wordPressRootDirectoryPath);
133+
if (!getPanel().getWpContentDirectory().isEmpty()) {
134+
wpContentDirectory = sourceDirectory.getFileObject(getPanel().getWpContentDirectory());
135+
}
130136
}
131137

132138
ValidationResult result = new WordPressCustomizerValidator()
133-
.validateWpContent(phpModule, wordPressRoot, contentName)
139+
.validateWpContent(phpModule, wordPressRoot, contentName, wpContentDirectory)
134140
.validateWordPressRootDirectory(phpModule, getPanel().getWordPressRootDirectory())
135141
.validatePluginsDirectory(phpModule, getPanel().getPluginsDirectory())
136142
.validateThemesDirectory(phpModule, getPanel().getThemesDirectory())
143+
.validateWpContentDirectory(phpModule, getPanel().getWpContentDirectory())
137144
.getResult();
138145

139146
if (wordPressRoot != null) {
140147
ValidationResult wpResult = new WordPressModuleValidator()
141-
.validateWordPressDirectories(wordPressRoot, contentName)
148+
.validateWordPressDirectories(wordPressRoot, contentName, wpContentDirectory)
142149
.getResult();
143150
result.merge(wpResult);
144151
}
@@ -189,6 +196,11 @@ public EnumSet<Change> save(PhpModule pm) {
189196
WordPressPreferences.setThemesPath(phpModule, themes);
190197
}
191198

199+
String wpContent = getPanel().getWpContentDirectory();
200+
if (!originalWpContent.equals(wpContent)) {
201+
WordPressPreferences.setWpContentPath(phpModule, wpContent);
202+
}
203+
192204
WordPressModule wpModule = WordPressModule.Factory.forPhpModule(phpModule);
193205
wpModule.notifyPropertyChanged(new PropertyChangeEvent(this, WordPressModule.PROPERTY_CHANGE_WP, null, null));
194206
return EnumSet.of(Change.FRAMEWORK_CHANGE);
@@ -202,12 +214,14 @@ private WordPressCustomizerExtenderPanel getPanel() {
202214
originalWordPressRoot = WordPressPreferences.getWordPressRootPath(phpModule);
203215
originalPlugins = WordPressPreferences.getPluginsPath(phpModule);
204216
originalThemes = WordPressPreferences.getThemesPath(phpModule);
217+
originalWpContent = WordPressPreferences.getWpContentPath(phpModule);
205218
panel.setPluginEnabled(originalEnabled);
206219
panel.setCustomContentName(originalCustomeContentName);
207220
panel.setComponentsEnabled(originalEnabled);
208221
panel.setWordPressRootDirectory(originalWordPressRoot);
209222
panel.setPluginsDirectory(originalPlugins);
210223
panel.setThemesDirectory(originalThemes);
224+
panel.setWpContentDirectory(originalWpContent);
211225
}
212226

213227
return panel;

src/org/netbeans/modules/php/wordpress/customizer/WordPressCustomizerExtenderPanel.form

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@
4242
<Component id="wordPressRootLabel" alignment="0" min="-2" max="-2" attributes="0"/>
4343
<Component id="pluginsLabel" alignment="0" min="-2" max="-2" attributes="0"/>
4444
<Component id="themesLabel" alignment="0" min="-2" max="-2" attributes="0"/>
45+
<Component id="wpContentLabel" alignment="0" min="-2" max="-2" attributes="0"/>
4546
</Group>
4647
<EmptySpace max="-2" attributes="0"/>
4748
<Group type="103" groupAlignment="0" attributes="0">
49+
<Group type="102" attributes="0">
50+
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
51+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
52+
</Group>
4853
<Component id="wordPressRootTextField" max="32767" attributes="0"/>
4954
<Component id="pluginsTextField" max="32767" attributes="0"/>
5055
<Component id="themesTextField" alignment="0" max="32767" attributes="0"/>
56+
<Component id="wpContentTextField" alignment="0" max="32767" attributes="0"/>
5157
</Group>
5258
</Group>
5359
</Group>
@@ -82,6 +88,13 @@
8288
<Component id="themesLabel" alignment="3" min="-2" max="-2" attributes="0"/>
8389
<Component id="themesTextField" alignment="3" min="-2" max="-2" attributes="0"/>
8490
</Group>
91+
<EmptySpace max="-2" attributes="0"/>
92+
<Group type="103" groupAlignment="3" attributes="0">
93+
<Component id="wpContentLabel" alignment="3" min="-2" max="-2" attributes="0"/>
94+
<Component id="wpContentTextField" alignment="3" min="-2" max="-2" attributes="0"/>
95+
</Group>
96+
<EmptySpace max="-2" attributes="0"/>
97+
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
8598
<EmptySpace max="32767" attributes="0"/>
8699
</Group>
87100
</Group>
@@ -164,5 +177,26 @@
164177
</Property>
165178
</Properties>
166179
</Component>
180+
<Component class="javax.swing.JLabel" name="wpContentLabel">
181+
<Properties>
182+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
183+
<ResourceString bundle="org/netbeans/modules/php/wordpress/customizer/Bundle.properties" key="WordPressCustomizerExtenderPanel.wpContentLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
184+
</Property>
185+
</Properties>
186+
</Component>
187+
<Component class="javax.swing.JTextField" name="wpContentTextField">
188+
<Properties>
189+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
190+
<ResourceString bundle="org/netbeans/modules/php/wordpress/customizer/Bundle.properties" key="WordPressCustomizerExtenderPanel.wpContentTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
191+
</Property>
192+
</Properties>
193+
</Component>
194+
<Component class="javax.swing.JLabel" name="jLabel1">
195+
<Properties>
196+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
197+
<ResourceString bundle="org/netbeans/modules/php/wordpress/customizer/Bundle.properties" key="WordPressCustomizerExtenderPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
198+
</Property>
199+
</Properties>
200+
</Component>
167201
</SubComponents>
168202
</Form>

src/org/netbeans/modules/php/wordpress/customizer/WordPressCustomizerExtenderPanel.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private void addDocumentListener(DocumentListener listener) {
7676
wordPressRootTextField.getDocument().addDocumentListener(listener);
7777
pluginsTextField.getDocument().addDocumentListener(listener);
7878
themesTextField.getDocument().addDocumentListener(listener);
79+
wpContentTextField.getDocument().addDocumentListener(listener);
7980
}
8081

8182
public boolean isPluginEnabled() {
@@ -118,6 +119,14 @@ public void setThemesDirectory(String path) {
118119
themesTextField.setText(path);
119120
}
120121

122+
public String getWpContentDirectory() {
123+
return wpContentTextField.getText().trim();
124+
}
125+
126+
public void setWpContentDirectory(String path) {
127+
wpContentTextField.setText(path);
128+
}
129+
121130
public void addChangeListener(ChangeListener cl) {
122131
changeSupport.addChangeListener(cl);
123132
}
@@ -159,6 +168,9 @@ private void initComponents() {
159168
pluginsTextField = new javax.swing.JTextField();
160169
themesLabel = new javax.swing.JLabel();
161170
themesTextField = new javax.swing.JTextField();
171+
wpContentLabel = new javax.swing.JLabel();
172+
wpContentTextField = new javax.swing.JTextField();
173+
jLabel1 = new javax.swing.JLabel();
162174

163175
setToolTipText(org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.toolTipText")); // NOI18N
164176

@@ -188,6 +200,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
188200

189201
themesTextField.setText(org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.themesTextField.text")); // NOI18N
190202

203+
org.openide.awt.Mnemonics.setLocalizedText(wpContentLabel, org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.wpContentLabel.text")); // NOI18N
204+
205+
wpContentTextField.setText(org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.wpContentTextField.text")); // NOI18N
206+
207+
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(WordPressCustomizerExtenderPanel.class, "WordPressCustomizerExtenderPanel.jLabel1.text")); // NOI18N
208+
191209
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
192210
this.setLayout(layout);
193211
layout.setHorizontalGroup(
@@ -209,12 +227,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
209227
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210228
.addComponent(wordPressRootLabel)
211229
.addComponent(pluginsLabel)
212-
.addComponent(themesLabel))
230+
.addComponent(themesLabel)
231+
.addComponent(wpContentLabel))
213232
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
214233
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234+
.addGroup(layout.createSequentialGroup()
235+
.addComponent(jLabel1)
236+
.addGap(0, 0, Short.MAX_VALUE))
215237
.addComponent(wordPressRootTextField)
216238
.addComponent(pluginsTextField)
217-
.addComponent(themesTextField))))
239+
.addComponent(themesTextField)
240+
.addComponent(wpContentTextField))))
218241
.addContainerGap())
219242
);
220243
layout.setVerticalGroup(
@@ -240,6 +263,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
240263
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
241264
.addComponent(themesLabel)
242265
.addComponent(themesTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
266+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
267+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
268+
.addComponent(wpContentLabel)
269+
.addComponent(wpContentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
270+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
271+
.addComponent(jLabel1)
243272
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
244273
);
245274
}// </editor-fold>//GEN-END:initComponents
@@ -254,12 +283,15 @@ private void enabledCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//G
254283
private javax.swing.JTextField customContentNameTextField;
255284
private javax.swing.JLabel customDirectoryPathLabel;
256285
private javax.swing.JCheckBox enabledCheckBox;
286+
private javax.swing.JLabel jLabel1;
257287
private javax.swing.JLabel pluginsLabel;
258288
private javax.swing.JTextField pluginsTextField;
259289
private javax.swing.JLabel themesLabel;
260290
private javax.swing.JTextField themesTextField;
261291
private javax.swing.JLabel wordPressRootLabel;
262292
private javax.swing.JTextField wordPressRootTextField;
293+
private javax.swing.JLabel wpContentLabel;
294+
private javax.swing.JTextField wpContentTextField;
263295
// End of variables declaration//GEN-END:variables
264296

265297
private class DefaultDocumentListener implements DocumentListener {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,17 @@ private void constructDirectories() {
168168
}
169169
if (wordPressRootDirectory == null) {
170170
if (WordPressPreferences.isEnabled(phpModule)) {
171-
LOGGER.log(Level.WARNING, "WordPress Root is invalid");
171+
LOGGER.log(Level.WARNING, "WordPress Root is invalid"); // NOI18N
172172
}
173173
return;
174174
}
175175
contentDirectory = wordPressRootDirectory.getFileObject(contentName);
176+
if (contentDirectory == null) {
177+
contentDirectory = sourceDirectory.getFileObject(WordPressPreferences.getWpContentPath(phpModule));
178+
if (contentDirectory == null && WordPressPreferences.isEnabled(phpModule)) {
179+
LOGGER.log(Level.WARNING, "wp-content directory is invalid"); // NOI18N
180+
}
181+
}
176182
includesDirectory = wordPressRootDirectory.getFileObject(WP_INCLUDES);
177183
adminDirectory = wordPressRootDirectory.getFileObject(WP_ADMIN);
178184

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class WordPressPreferences {
5757
private static final List<String> WITHIN_OPTIONS = new ArrayList<>();
5858
private static final String ENABLED = "enabled"; // NOI18N
5959
private static final String CUSTOM_CONTENT_NAME = "custom-content-name"; // NOI18N
60+
private static final String WP_CONTENT_PATH = "custom-content-path"; // NOI18N
6061
private static final String WP_ROOT = "wp-root"; // NOI18N
6162
private static final String PLUGINS = "plugins"; // NOI18N
6263
private static final String THEMES = "themes"; // NOI18N
@@ -80,6 +81,14 @@ public static void setCustomContentName(PhpModule phpModule, String name) {
8081
getPreferences(phpModule).put(CUSTOM_CONTENT_NAME, name);
8182
}
8283

84+
public static String getWpContentPath(PhpModule phpModule) {
85+
return getPreferences(phpModule).get(WP_CONTENT_PATH, ""); // NOI18N
86+
}
87+
88+
public static void setWpContentPath(PhpModule phpModule, String path) {
89+
getPreferences(phpModule).put(WP_CONTENT_PATH, path);
90+
}
91+
8392
public static String getWordPressRootPath(PhpModule phpModule) {
8493
return getPreferences(phpModule).get(WP_ROOT, ""); // NOI18N
8594
}

src/org/netbeans/modules/php/wordpress/validators/WordPressCustomizerValidator.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public final class WordPressCustomizerValidator {
6262
"WordPressCustomizerValidator.wordpress.source.dir.invalid=Project might be broken...",
6363
"WordPressCustomizerValidator.wordpress.content.name.contains.shash=The name must not contain slash."
6464
})
65-
public WordPressCustomizerValidator validateWpContent(@NonNull PhpModule phpModule, FileObject wordPressRoot, String name) {
65+
public WordPressCustomizerValidator validateWpContent(@NonNull PhpModule phpModule, FileObject wordPressRoot, String name, FileObject wpContentDirectory) {
6666
FileObject sourceDirectory = phpModule.getSourceDirectory();
6767
if (sourceDirectory == null) {
6868
result.addWarning(new ValidationResult.Message("wordpress.dir", Bundle.WordPressCustomizerValidator_wordpress_source_dir_invalid())); // NOI18N
@@ -74,17 +74,21 @@ public WordPressCustomizerValidator validateWpContent(@NonNull PhpModule phpModu
7474
return this;
7575
}
7676

77-
FileObject wpContent = wordPressRoot.getFileObject(name);
78-
if (wpContent == null
79-
|| !wpContent.isFolder()
80-
|| StringUtils.isEmpty(name)) {
81-
result.addWarning(new ValidationResult.Message("wordpress.content.name", Bundle.WordPressCustomizerValidator_wordpress_dir_invalid("content"))); // NOI18N
82-
return this;
83-
}
77+
if (wpContentDirectory == null) {
78+
FileObject wpContent = wordPressRoot.getFileObject(name);
79+
if (wpContent == null
80+
|| !wpContent.isFolder()
81+
|| StringUtils.isEmpty(name)) {
82+
result.addWarning(new ValidationResult.Message("wordpress.content.name", Bundle.WordPressCustomizerValidator_wordpress_dir_invalid("content"))); // NOI18N
83+
return this;
84+
}
85+
86+
if (name.contains("/")) { // NOI18N
87+
result.addWarning(new ValidationResult.Message("wordpress.content.name.slash", Bundle.WordPressCustomizerValidator_wordpress_content_name_contains_shash())); // NOI18N
88+
return this;
89+
}
90+
} else {
8491

85-
if (name.contains("/")) { // NOI18N
86-
result.addWarning(new ValidationResult.Message("wordpress.content.name.slash", Bundle.WordPressCustomizerValidator_wordpress_content_name_contains_shash())); // NOI18N
87-
return this;
8892
}
8993

9094
return this;
@@ -102,6 +106,13 @@ public WordPressCustomizerValidator validateThemesDirectory(@NonNull PhpModule p
102106
return validateDirectory(phpModule, path, "themes"); // NOI18N
103107
}
104108

109+
public WordPressCustomizerValidator validateWpContentDirectory(@NonNull PhpModule phpModule, @NonNull String path) {
110+
if (path.isEmpty()) {
111+
return this;
112+
}
113+
return validateDirectory(phpModule, path, "wp-content"); // NOI18N
114+
}
115+
105116
private WordPressCustomizerValidator validateDirectory(PhpModule phpModule, String path, String dirname) {
106117
FileObject sourceDirectory = phpModule.getSourceDirectory();
107118
if (sourceDirectory == null) {

src/org/netbeans/modules/php/wordpress/validators/WordPressModuleValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class WordPressModuleValidator {
5858
@NbBundle.Messages({
5959
"WordPressModuleValidator.core.dir.invalid=WordPress directories don't exit."
6060
})
61-
public WordPressModuleValidator validateWordPressDirectories(@NonNull FileObject wordPressRoot, @NonNull String customContentName) {
61+
public WordPressModuleValidator validateWordPressDirectories(@NonNull FileObject wordPressRoot, @NonNull String customContentName, FileObject wpContentDirectory) {
6262
for (String dir : WP_DIRS) {
6363
FileObject fileObject = wordPressRoot.getFileObject(dir);
6464
if (fileObject == null) {
@@ -68,7 +68,7 @@ public WordPressModuleValidator validateWordPressDirectories(@NonNull FileObject
6868

6969
// content name
7070
FileObject content = wordPressRoot.getFileObject(customContentName);
71-
if (content == null) {
71+
if (content == null && wpContentDirectory == null) {
7272
result.addWarning(new ValidationResult.Message("wp.dir", Bundle.WordPressModuleValidator_core_dir_invalid())); // NOI18N
7373
}
7474

0 commit comments

Comments
 (0)