Skip to content

Commit 9720259

Browse files
committed
Merge branch 'nb81dev'
2 parents bdde354 + d3677e6 commit 9720259

5 files changed

Lines changed: 80 additions & 48 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ This is NetBeans plugin for WordPress.
2929
- create a new child theme action (create a style.css for child theme)
3030

3131
### Important Files
32-
It contains wp-config.php
32+
33+
- wp-config.php
34+
- .htaccess (only the root directory)
3335

3436
### Create New WordPress Project
3537
You can create a new WordPress project with Wizard.

manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.modules.php.wordpress
33
OpenIDE-Module-Layer: org/netbeans/modules/php/wordpress/resources/layer.xml
44
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/wordpress/Bundle.properties
5-
OpenIDE-Module-Specification-Version: 0.8.2
5+
OpenIDE-Module-Specification-Version: 0.8.3
66
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModuleInstall.class

src/org/netbeans/modules/php/wordpress/editor/completion/FilterAndActionCompletion.java

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -121,43 +121,44 @@ protected void query(CompletionResultSet completionResultSet, Document doc, int
121121
return;
122122
}
123123
ts.move(caretOffset);
124-
ts.moveNext();
125-
Token<PHPTokenId> token = ts.token();
126-
if (token.id() != PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) {
127-
return;
128-
}
129-
String caretInput = ts.token().text().toString();
124+
if (ts.moveNext()) {
125+
Token<PHPTokenId> token = ts.token();
126+
if (token.id() != PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) {
127+
return;
128+
}
129+
String caretInput = ts.token().text().toString();
130130

131-
int startOffset = ts.offset() + 1;
132-
int removeLength = caretInput.length() - 2;
133-
if (removeLength < 0) {
134-
removeLength = 0;
135-
}
136-
int length = caretInput.length();
131+
int startOffset = ts.offset() + 1;
132+
int removeLength = caretInput.length() - 2;
133+
if (removeLength < 0) {
134+
removeLength = 0;
135+
}
136+
int length = caretInput.length();
137137

138-
// check whether funciton is add_filter
139-
if (!isValidCompletion(ts) || length < 2) {
140-
return;
141-
}
138+
// check whether funciton is add_filter
139+
if (!isValidCompletion(ts) || length < 2) {
140+
return;
141+
}
142142

143-
// filter
144-
int substrLength = caretOffset - startOffset + 1;
145-
String filter = ""; // NOI18N
146-
if (substrLength > 1) {
147-
filter = caretInput.substring(1, substrLength);
148-
}
149-
currentInput = filter;
150-
151-
// set isAction and isFilter
152-
List<WordPressCompletionItem> completions = getCodeCompletionList(phpModule);
153-
154-
if (isAction || isFilter) {
155-
for (WordPressCompletionItem completion : completions) {
156-
String text = completion.getText();
157-
if (!text.isEmpty()
158-
&& text.startsWith(filter)) {
159-
completion.setOffset(startOffset, removeLength);
160-
completionResultSet.addItem(completion);
143+
// filter
144+
int substrLength = caretOffset - startOffset + 1;
145+
String filter = ""; // NOI18N
146+
if (substrLength > 1) {
147+
filter = caretInput.substring(1, substrLength);
148+
}
149+
currentInput = filter;
150+
151+
// set isAction and isFilter
152+
List<WordPressCompletionItem> completions = getCodeCompletionList(phpModule);
153+
154+
if (isAction || isFilter) {
155+
for (WordPressCompletionItem completion : completions) {
156+
String text = completion.getText();
157+
if (!text.isEmpty()
158+
&& text.startsWith(filter)) {
159+
completion.setOffset(startOffset, removeLength);
160+
completionResultSet.addItem(completion);
161+
}
161162
}
162163
}
163164
}

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,41 @@ public ZipAction(DataObject context) {
8888

8989
@Messages({
9090
"# {0} - file name",
91-
"ZipAction.error.file.already.exist=Zip file ({0}) already exists."
91+
"ZipAction.error.file.already.exist=Zip file ({0}) already exists.\nDo you really want to overwrite it?",
92+
"ZipAction.error.not.directory=It must be selected a directory.",
93+
"ZipAction.error.invalid.parent.directory=The parent directory doesn't exist."
9294
})
9395
@Override
9496
public void actionPerformed(ActionEvent ev) {
9597
if (!isValidDirectory(getFileObject())) {
9698
return;
9799
}
98100

99-
// zip compress
100101
FileObject target = getFileObject();
102+
if (target == null || !target.isFolder()) {
103+
showErrorDialog(Bundle.ZipAction_error_not_directory());
104+
return;
105+
}
106+
107+
FileObject parent = target.getParent();
108+
if (parent == null) {
109+
showErrorDialog(Bundle.ZipAction_error_invalid_parent_directory());
110+
return;
111+
}
112+
113+
FileObject targetZip = parent.getFileObject(target.getName() + ".zip"); // NOI18N
114+
if (targetZip != null) {
115+
if (!showConfirmationDialog(Bundle.ZipAction_error_file_already_exist(target.getName() + ".zip"))) { // NOI18N
116+
return;
117+
}
118+
}
119+
120+
// zip compress
101121
try {
102122
WPFileUtils.zip(target);
103123
} catch (IOException ex) {
104124
// #36
105125
LOGGER.log(Level.WARNING, ex.getMessage());
106-
showErrorDialog(Bundle.ZipAction_error_file_already_exist(target.getName() + ".zip")); // NOI18N
107126
}
108127
}
109128

@@ -130,13 +149,6 @@ private boolean isValidDirectory(FileObject target) {
130149
String name = parent.getNameExt();
131150
if (parent.isFolder()) {
132151
if (name.equals("plugins") || name.equals("themes")) { // NOI18N
133-
// #36
134-
String zipFileName = target.getName() + ".zip"; // NOI18N
135-
FileObject zipFile = parent.getFileObject(zipFileName);
136-
if (zipFile != null) {
137-
showErrorDialog(Bundle.ZipAction_error_file_already_exist(zipFileName));
138-
return false;
139-
}
140152
return true;
141153
}
142154
}
@@ -153,6 +165,17 @@ private void showErrorDialog(String errorMessage) {
153165
DialogDisplayer.getDefault().notify(message);
154166
}
155167

168+
/**
169+
* Show confirmation message dialog.
170+
*
171+
* @param meesage the confirmation message
172+
* @return {@code true} if OK is pressed, otherwise {@code false}
173+
*/
174+
private boolean showConfirmationDialog(String meesage) {
175+
NotifyDescriptor.Confirmation message = new NotifyDescriptor.Confirmation(meesage, NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
176+
return DialogDisplayer.getDefault().notify(message) == NotifyDescriptor.OK_OPTION;
177+
}
178+
156179
@Override
157180
public Action createContextAwareInstance(Lookup actionContext) {
158181
DataObject dataObject = actionContext.lookup(DataObject.class);

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ public static void zip(FileObject target) throws IOException {
8282
}
8383
// create zip file
8484
FileObject parent = target.getParent();
85-
FileObject zipFile = parent.createData(target.getName() + ".zip"); // NOI18N
86-
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(FileUtil.toFile(zipFile)));
85+
if (parent == null) {
86+
return;
87+
}
88+
FileObject targetZip = parent.getFileObject(target.getName() + ".zip"); // NOI18N
89+
if (targetZip == null) {
90+
targetZip = parent.createData(target.getName() + ".zip"); // NOI18N
91+
}
92+
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(FileUtil.toFile(targetZip)));
8793

8894
// compress
8995
File targetDirectory = FileUtil.toFile(target);

0 commit comments

Comments
 (0)