use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.
the class BasicFileEditor method trySaveAs.
private void trySaveAs() {
JFileChooser fileChooser = new JFileChooser();
AbstractFile currentFile = getCurrentFile();
// Sets selected file in JFileChooser to current file
if (currentFile.getURL().getScheme().equals(LocalFile.SCHEMA)) {
fileChooser.setSelectedFile(new java.io.File(currentFile.getAbsolutePath()));
}
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
int ret = fileChooser.showSaveDialog(getFrame());
if (ret == JFileChooser.APPROVE_OPTION) {
AbstractFile destFile;
try {
destFile = FileFactory.getFile(fileChooser.getSelectedFile().getAbsolutePath(), true);
} catch (IOException e) {
InformationDialog.showErrorDialog(getFrame(), Translator.get("write_error"), Translator.get("file_editor.cannot_write"));
return;
}
// Check for file collisions, i.e. if the file already exists in the destination
int collision = FileCollisionChecker.checkForCollision(null, destFile);
if (collision != FileCollisionChecker.NO_COLLISION) {
// File already exists in destination, ask the user what to do (cancel, overwrite,...) but
// do not offer the multiple files mode options such as 'skip' and 'apply to all'.
DialogAction action = new FileCollisionDialog(getFrame(), getFrame(), /*mainFrame*/
collision, null, destFile, false, false).getActionValue();
// User chose to overwrite the file
if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
// Do nothing, simply continue and file will be overwritten
} else // User chose to cancel or closed the dialog
{
return;
}
}
if (trySave(destFile)) {
setCurrentFile(destFile);
}
}
}
use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.
the class BasicFileEditor method askSave.
// Returns true if the file does not have any unsaved change or if the user refused to save the changes,
// false if the user canceled the dialog or the save failed.
public boolean askSave() {
if (!saveNeeded) {
return true;
}
QuestionDialog dialog = new QuestionDialog(getFrame(), null, Translator.get("file_editor.save_warning"), getFrame(), Arrays.asList(BasicFileAction.YES, BasicFileAction.NO, BasicFileAction.CANCEL), 0);
DialogAction ret = dialog.getActionValue();
if (ret == BasicFileAction.YES && trySave(getCurrentFile()) || ret == BasicFileAction.NO) {
setSaveNeeded(false);
return true;
}
// User canceled or the file couldn't be properly saved
return false;
}
Aggregations