Skip to content

Commit 0e8e5b4

Browse files
committed
Fix ZipAction problem #36
1 parent b057518 commit 0e8e5b4

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@
4444
import java.awt.event.ActionEvent;
4545
import java.awt.event.ActionListener;
4646
import java.io.IOException;
47+
import java.util.logging.Level;
48+
import java.util.logging.Logger;
4749
import org.netbeans.modules.php.wordpress.WordPress;
4850
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
51+
import org.openide.DialogDisplayer;
52+
import org.openide.NotifyDescriptor;
4953
import org.openide.awt.ActionID;
5054
import org.openide.awt.ActionReference;
5155
import org.openide.awt.ActionReferences;
5256
import org.openide.awt.ActionRegistration;
5357
import org.openide.filesystems.FileObject;
5458
import org.openide.loaders.DataObject;
55-
import org.openide.util.Exceptions;
5659
import org.openide.util.NbBundle.Messages;
5760

5861
@ActionID(
@@ -69,11 +72,16 @@
6972
public final class ZipAction implements ActionListener {
7073

7174
private final DataObject context;
75+
private static final Logger LOGGER = Logger.getLogger(ZipAction.class.getName());
7276

7377
public ZipAction(DataObject context) {
7478
this.context = context;
7579
}
7680

81+
@Messages({
82+
"# {0} - file name",
83+
"ZipAction.error.file.already.exist=Zip file ({0}) already exists."
84+
})
7785
@Override
7886
public void actionPerformed(ActionEvent ev) {
7987
if (!isValidDirectory()) {
@@ -85,7 +93,9 @@ public void actionPerformed(ActionEvent ev) {
8593
try {
8694
WPFileUtils.zip(target);
8795
} catch (IOException ex) {
88-
Exceptions.printStackTrace(ex);
96+
// #36
97+
LOGGER.log(Level.WARNING, ex.getMessage());
98+
showErrorDialog(Bundle.ZipAction_error_file_already_exist(target.getName() + ".zip")); // NOI18N
8999
}
90100
}
91101

@@ -110,9 +120,26 @@ private boolean isValidDirectory() {
110120
String name = parent.getNameExt();
111121
if (parent.isFolder()) {
112122
if (name.equals("plugins") || name.equals("themes")) { // NOI18N
123+
// #36
124+
String zipFileName = target.getName() + ".zip"; // NOI18N
125+
FileObject zipFile = parent.getFileObject(zipFileName);
126+
if (zipFile != null) {
127+
showErrorDialog(Bundle.ZipAction_error_file_already_exist(zipFileName));
128+
return false;
129+
}
113130
return true;
114131
}
115132
}
116133
return false;
117134
}
135+
136+
/**
137+
* Show error message dialog.
138+
*
139+
* @param errorMessage Error message
140+
*/
141+
private void showErrorDialog(String errorMessage) {
142+
NotifyDescriptor.Message message = new NotifyDescriptor.Message(errorMessage, NotifyDescriptor.ERROR_MESSAGE);
143+
DialogDisplayer.getDefault().notify(message);
144+
}
118145
}

0 commit comments

Comments
 (0)