Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Added confirm before saving a file changed by another program.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob van Mourik committed Jun 22, 2018
1 parent f71ff4c commit e590f83
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
33 changes: 27 additions & 6 deletions src/main/java/com/jvms/i18neditor/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.google.common.collect.Maps;
import com.jvms.i18neditor.Resource;
import com.jvms.i18neditor.ResourceType;
import com.jvms.i18neditor.io.ChecksumException;
import com.jvms.i18neditor.swing.JFileDrop;
import com.jvms.i18neditor.swing.JScrollablePanel;
import com.jvms.i18neditor.swing.util.Dialogs;
Expand Down Expand Up @@ -193,7 +194,7 @@ public void importProject(Path dir, boolean showEmptyProjectError) {
project.addResource(resource);
} catch (IOException e) {
log.error("Error importing resource file " + resource.getPath(), e);
showError(MessageBundle.get("resources.import.error.single", resource.getPath().toString()));
showError(MessageBundle.get("resources.import.error.single", resource.getPath()));
}
});
project.getResources().forEach(r -> keys.putAll(r.getTranslations()));
Expand All @@ -214,12 +215,8 @@ public boolean saveProject() {
boolean error = false;
if (project != null) {
for (Resource resource : project.getResources()) {
try {
Resources.write(resource, !project.isMinifyResources(), project.isFlattenJSON());
} catch (IOException e) {
if (!saveResource(resource)) {
error = true;
log.error("Error saving resource file " + resource.getPath(), e);
showError(MessageBundle.get("resources.write.error.single", resource.getPath().toString()));
}
}
}
Expand Down Expand Up @@ -880,6 +877,30 @@ private void updateTreeNodeStatus(String key) {
translationTree.updateNode(key, hasError);
}

private boolean saveResource(Resource resource) {
if (project != null) {
try {
Resources.write(resource, !project.isMinifyResources(), project.isFlattenJSON());
} catch (ChecksumException e) {
boolean confirm = Dialogs.showConfirmDialog(this,
MessageBundle.get("dialogs.save.checksum.title"),
MessageBundle.get("dialogs.save.checksum.text", resource.getPath()),
JOptionPane.WARNING_MESSAGE);
if (confirm) {
resource.setChecksum(null);
saveResource(resource);
} else {
return false;
}
} catch (IOException e) {
log.error("Error saving resource file " + resource.getPath(), e);
showError(MessageBundle.get("resources.write.error.single", resource.getPath().toString()));
return false;
}
}
return true;
}

private void storeProjectState() {
ExtendedProperties props = new ExtendedProperties();
props.setProperty("minify_resources", project.isMinifyResources());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jvms.i18neditor.util;
package com.jvms.i18neditor.io;

import java.io.IOException;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jvms/i18neditor/util/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.gson.JsonPrimitive;
import com.jvms.i18neditor.Resource;
import com.jvms.i18neditor.ResourceType;
import com.jvms.i18neditor.io.ChecksumException;

/**
* This class provides utility functions for a {@link Resource}.
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/bundles/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dialogs.project.import.title=Import Project
dialogs.project.new.conflict.text=There are existing translations found at this location, do you want to import them instead?
dialogs.project.new.conflict.title=Conflict
dialogs.project.new.title=New Project
dialogs.save.checksum.text=<html>"{0}"<br><br>This translation file has been modified by another program.<br>Do you want to overwrite the file?</html>
dialogs.save.checksum.title=Save Translation
dialogs.save.text=You have unsaved changes, do you want to save them?
dialogs.save.title=Save Translations
dialogs.translation.add.error=The translation key you entered is invalid.
Expand Down Expand Up @@ -74,11 +76,11 @@ menu.view.expand.title=Expand All Translation Keys
menu.view.title=View
menu.view.vk=V
resources.create.error=An error occurred while creating translation files.
resources.import.empty=No translation files found in ''{0}''.
resources.import.empty=<html>No translation files found in\:<br>"{0}"</html>
resources.import.error.multiple=An error occurred while opening translation files.
resources.import.error.single=An error occurred while opening the translation file ''{0}''.
resources.import.error.single=<html>An error occurred while opening the translation file\:<br>"{0}"</html>
resources.locale.default=Default
resources.write.error.single=An error occurred while writing the translation file ''{0}''.
resources.write.error.single=<html>An error occurred while writing the translation file\:<br>"{0}"</html>
settings.checkversion.title=Check for new version on startup
settings.fieldset.editing=Editing
settings.fieldset.general=General
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/bundles/messages_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dialogs.project.import.title=Importeer Project
dialogs.project.new.conflict.text=Er zijn bestaande vertaalbestanden gevonden op deze locatie, wilt u deze importeren?
dialogs.project.new.conflict.title=Conflict
dialogs.project.new.title=Nieuw Project
dialogs.save.checksum.text=<html>"{0}"<br><br>Dit vertaalbestand is gewijzigd door een ander programma.<br>Wilt u het bestand overschrijven?</html>
dialogs.save.checksum.title=Vertaling Opslaan
dialogs.save.text=U heeft nog onopgeslagen wijzigingen, wilt u deze opslaan?
dialogs.save.title=Vertalingen Opslaan
dialogs.translation.add.error=De opgegeven vertaalsleutel is niet geldig.
Expand Down Expand Up @@ -74,11 +76,11 @@ menu.view.expand.title=Alle Vertaalsleutels Uitvouwen
menu.view.title=Beeld
menu.view.vk=L
resources.create.error=Er is iets fout gegaan bij het aanmaken van de vertaalbestanden.
resources.import.empty=Geen vertaalbestanden gevonden in ''{0}''.
resources.import.empty=<html>Geen vertaalbestanden gevonden in\:<br>"{0}"</html>
resources.import.error.multiple=Er is iets fout gegaan bij het openen van de vertaalbetanden.
resources.import.error.single=Er is iets fout gegaan bij het openen van het vertaalbestand ''{0}''.
resources.import.error.single=<html>Er is iets fout gegaan bij het openen van het vertaalbestand\:<br>"{0}"</html>
resources.locale.default=Standaard
resources.write.error.single=Er is iets fout gegaan bij het opslaan van het vertaalbestand ''{0}''.
resources.write.error.single=<html>Er is iets fout gegaan bij het opslaan van het vertaalbestand\:<br>"{0}"</html>
settings.checkversion.title=Controleer op nieuwe versie bij opstarten
settings.fieldset.editing=Weergave
settings.fieldset.general=Algemeen
Expand Down
14 changes: 8 additions & 6 deletions src/main/resources/bundles/messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ dialogs.locale.add.error.create=Ocorreu um erro ao criar o nova localidade.
dialogs.locale.add.error.invalid=A localidade digitada \u00E9 inv\u00E1lida ou n\u00E3o existe.
dialogs.locale.add.text=Informe uma localidade (Ex. pt_BR)\:
dialogs.locale.add.title=Incluir localidade
dialogs.preferences.editor.title=Prefer\u00EAncias...
dialogs.preferences.project.title=Prefer\u00EAncias do Projeto...
dialogs.preferences.editor.title=Prefer\u00EAncias
dialogs.preferences.project.title=Prefer\u00EAncias do Projeto
dialogs.project.import.title=Projeto de Importa\u00E7\u00E3o
dialogs.project.new.conflict.text=Existem tradu\u00E7\u00F5es existentes neste local, voc\u00EA deseja import\u00E1-las?
dialogs.project.new.conflict.title=Conflito
dialogs.project.new.title=Novo Projeto
dialogs.save.checksum.text=<html>"{0}"<br><br>This translation file has been modified by another program.<br>Do you want to overwrite the file?</html>
dialogs.save.checksum.title=Save Translation
dialogs.save.text=Voc\u00EA tem modifica\u00E7\u00F5es n\u00E3o salvas, deseja salv\u00E1-las?
dialogs.save.title=Salvar Tradu\u00E7\u00F5es
dialogs.translation.add.error=A chave de tradu\u00E7\u00E3o inofrmada \u00E9 inv\u00E1lida.
Expand Down Expand Up @@ -74,11 +76,11 @@ menu.view.expand.title=Expandir todas as tradu\u00E7\u00F5es
menu.view.title=Ver
menu.view.vk=V
resources.create.error=Um erro ocorreu ao criar arquivos de tradu\u00E7\u00F5es.
resources.import.empty=Nenhum arquivo de tradu\u00E7\u00E3o encontrado em ''{0}''.
resources.import.empty=<html>Nenhum arquivo de tradu\u00E7\u00E3o encontrado em\:<br>"{0}"</html>
resources.import.error.multiple=Um erro ocorreu enquanto os arquivos de tradu\u00E7\u00F5es eram carregados.
resources.import.error.single=Um erro ocorreu enquanto o arquivo de tradu\u00E7\u00E3o era carregado ''{0}''.
resources.locale.default=Padr\u00E3o
resources.write.error.single=Um erro ocorreu enquanto o arquivo de tradu\u00E7\u00E3o era salvo ''{0}''.
resources.import.error.single=<html>Um erro ocorreu enquanto o arquivo de tradu\u00E7\u00E3o era carregado\:<br>"{0}"</html>
resources.locale.default=padr\u00E3o
resources.write.error.single=<html>Um erro ocorreu enquanto o arquivo de tradu\u00E7\u00E3o era salvo\:<br>"{0}"</html>
settings.checkversion.title=Verificar a nova vers\u00E3o na inicializa\u00E7\u00E3o
settings.fieldset.editing=Edi\u00E7\u00E3o
settings.fieldset.general=Geral
Expand Down

0 comments on commit e590f83

Please sign in to comment.