Author: mvw Date: 2008-08-30 12:53:12-0700 New Revision: 15649 Modified: trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java
Log: Fix for issue 5356: Save All Graphics: Add a "Yes to All" button. Make the operation cancellable by adding a cancel button. Closing the dialog also cancels. Replace the wording "Yes" by "Overwrite". Resolved a TODO: this action is not undoable. Modified: trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties?view=diff&rev=15649&p1=trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties&p2=trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties&r1=15648&r2=15649 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties (original) +++ trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties 2008-08-30 12:53:12-0700 @@ -1,5 +1,5 @@ # $Id$ -# Copyright (c) 2005-2007 The Regents of the University of California. All +# Copyright (c) 2005-2008 The Regents of the University of California. All # Rights Reserved. Permission to use, copy, modify, and distribute this # software and its documentation without fee, and without a written # agreement is hereby granted, provided that the above copyright notice @@ -44,6 +44,10 @@ optionpane.confirm-overwrite = Are you sure you want to overwrite \ {0}? optionpane.confirm-overwrite-title = Confirm overwrite +optionpane.confirm-overwrite.overwrite = Overwrite +optionpane.confirm-overwrite.overwrite-all = Overwrite All +optionpane.confirm-overwrite.skip-this-one = Skip this one +optionpane.confirm-overwrite.cancel = Cancel optionpane.save-project-cant-write = A problem occurred while saving: \ file cannot be written. optionpane.save-project-cant-write-title = File not writable Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java?view=diff&rev=15649&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java&r1=15648&r2=15649 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java (original) +++ trunk/src/argouml-app/src/org/argouml/uml/ui/ActionSaveAllGraphics.java 2008-08-30 12:53:12-0700 @@ -31,6 +31,7 @@ import java.io.IOException; import java.net.MalformedURLException; +import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.JOptionPane; @@ -48,7 +49,6 @@ import org.argouml.util.ArgoFrame; import org.tigris.gef.base.Diagram; import org.tigris.gef.base.SaveGraphicsAction; -import org.tigris.gef.undo.UndoableAction; import org.tigris.gef.util.Util; /** @@ -58,14 +58,15 @@ * <p> * * TODO: Add a user choice for other formats (PNG, SVG,...) <p> - * TODO: Why is this an UndoableAction? (and how?) - tfm * * @author Leonardo Souza Mario Bueno ([EMAIL PROTECTED]) */ -public class ActionSaveAllGraphics extends UndoableAction { +public class ActionSaveAllGraphics extends AbstractAction { private static final Logger LOG = Logger.getLogger(ActionSaveAllGraphics.class); + + private boolean overwrite; /** * The constructor. @@ -79,29 +80,28 @@ Translator.localize("action.save-all-graphics")); } - @Override public void actionPerformed( ActionEvent ae ) { - super.actionPerformed(ae); trySave( false ); } /** - * @param overwrite true if we can overwrite without asking + * @param canOverwrite true if we can overwrite without asking * @return success */ - public boolean trySave(boolean overwrite) { - return trySave(overwrite, null); + public boolean trySave(boolean canOverwrite) { + return trySave(canOverwrite, null); } /** - * @param overwrite + * @param canOverwrite * true if we can overwrite without asking * @param directory * directory to save to. If null, user will be prompted to * choose. * @return success save status */ - public boolean trySave(boolean overwrite, File directory) { + public boolean trySave(boolean canOverwrite, File directory) { + overwrite = canOverwrite; Project p = ProjectManager.getManager().getCurrentProject(); TargetManager tm = TargetManager.getInstance(); File saveDir = (directory != null) ? directory : getSaveDir(p); @@ -113,7 +113,7 @@ ArgoDiagram activeDiagram = p.getActiveDiagram(); for (ArgoDiagram d : p.getDiagramList()) { tm.setTarget(d); - okSoFar = trySaveDiagram(overwrite, d, saveDir); + okSoFar = trySaveDiagram(d, saveDir); if (!okSoFar) { break; } @@ -123,12 +123,11 @@ } /** - * @param overwrite true if we can overwrite without asking * @param target the diagram * @param saveDir the directory to save to - * @return success + * @return continue exporting diagrams if true */ - protected boolean trySaveDiagram(boolean overwrite, Object target, + protected boolean trySaveDiagram(Object target, File saveDir) { if ( target instanceof Diagram ) { String defaultName = ((Diagram) target).getName(); @@ -151,9 +150,9 @@ return false; } showStatus( "Writing " + path + name + "..." ); - saveGraphicsToFile(theFile, cmd, overwrite); + boolean result = saveGraphicsToFile(theFile, cmd); showStatus( "Wrote " + path + name ); - return true; + return result; } catch ( FileNotFoundException ignore ) { LOG.error("got a FileNotFoundException", ignore); @@ -192,16 +191,46 @@ return null; } - private boolean saveGraphicsToFile(File theFile, SaveGraphicsAction cmd, - boolean overwrite) throws IOException { + /** + * @param theFile the file to write + * @param cmd the action to execute to save the graphics + * @return continue exporting diagrams if true + * @throws IOException + */ + private boolean saveGraphicsToFile(File theFile, SaveGraphicsAction cmd) + throws IOException { if ( theFile.exists() && !overwrite ) { - int response = - JOptionPane.showConfirmDialog(ArgoFrame.getInstance(), - Translator.messageFormat("optionpane.confirm-overwrite", - new Object[] {theFile}), - Translator.localize("optionpane.confirm-overwrite-title"), - JOptionPane.YES_NO_OPTION); - if (response == JOptionPane.NO_OPTION) return false; + String message = Translator.messageFormat("optionpane.confirm-overwrite", + new Object[] {theFile}); + String title = Translator.localize("optionpane.confirm-overwrite-title"); + //Custom button text: + Object[] options = {"optionpane.confirm-overwrite.overwrite", // 0 + "optionpane.confirm-overwrite.overwrite-all", // 1 + "optionpane.confirm-overwrite.skip-this-one", // 2 + "optionpane.confirm-overwrite.cancel"}; // 3 + + int response = + JOptionPane.showOptionDialog(ArgoFrame.getInstance(), + message, + title, + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, //do not use a custom Icon + options, //the titles of buttons + options[0]); //default button title + + if (response == 1) { + overwrite = true; + } + if (response == 2) { + return true; + } + if (response == 3) { + return false; + } + if (response == JOptionPane.CLOSED_OPTION) { + return false; + } } FileOutputStream fo = null; try { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
