@@ -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.\n Do 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 );
0 commit comments