diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 8ff2bfbe93..12674b5e10 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -6,6 +6,7 @@ Fixed bug 781393 - VariableNameDeclaration no longer throws ClassCastExpression Tweaked CPD time display field Made CPD text fields uneditable Added more error checking to CPD GUI input +Added "dialog cancelled" check to CPD "Save" function TODO - fix it so tests and rules don't duplicate the xpath expressions August 1, 2003 - 1.2.1: diff --git a/pmd/src/net/sourceforge/pmd/cpd/GUI.java b/pmd/src/net/sourceforge/pmd/cpd/GUI.java index 72b7eeca6c..5c4e007025 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd/src/net/sourceforge/pmd/cpd/GUI.java @@ -54,24 +54,23 @@ public class GUI implements CPDListener { FileDialog fdlg = new FileDialog(GUI.this.frame, "Save", FileDialog.SAVE); fdlg.setVisible(true); String selected = fdlg.getDirectory() + System.getProperty("file.separator") + fdlg.getFile(); - if(selected !=null){ - if(!new File(selected).canWrite()){ - try{ - PrintWriter pw = new PrintWriter(new FileOutputStream(selected)); - String report = resultsTextArea.getText(); - pw.print(report); - pw.flush(); - pw.close(); - }catch(IOException e){ - error("Couldn't save file"+new File(selected).getAbsolutePath(), e); - } - }else{ - error("Could not write to file "+new File(selected).getAbsolutePath(), null); - - } - + if (fdlg.getFile() == null) { + return; + } + if(!new File(selected).canWrite()){ + try{ + PrintWriter pw = new PrintWriter(new FileOutputStream(selected)); + String report = resultsTextArea.getText(); + pw.print(report); + pw.flush(); + pw.close(); + JOptionPane.showMessageDialog(frame, "File saved"); + }catch(IOException e){ + error("Couldn't save file"+new File(selected).getAbsolutePath(), e); + } + }else{ + error("Could not write to file "+new File(selected).getAbsolutePath(), null); } - } private void error(String message, Exception e){