Fix #33: Letzte Konfigurationsdatei beim Neustart automatisch laden

Nutzt java.util.prefs.Preferences mit dem Schluessel "lastConfigPath"
um den Pfad der zuletzt geladenen Konfigurationsdatei zu speichern.

Beim naechsten Start wird diese Datei automatisch geladen, sofern sie
noch existiert. Falls nicht oder falls nie eine Datei geladen wurde,
startet die GUI normal ohne Fehlermeldung.

Geaenderte Klassen:
- GuiConfigurationEditorWorkspace: Speichern des Pfads nach erfolgreichem Laden,
  neue Methode autoLoadLastConfiguration() fuer automatisches Laden beim Start
- PdfUmbenennerGuiApplication: Aufruf von autoLoadLastConfiguration() nach
  Initialisierung des Fensters

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 16:27:52 +02:00
parent 7e2fec4c7b
commit 6b078aa3e7
2 changed files with 51 additions and 0 deletions
@@ -10,6 +10,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.prefs.Preferences;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -839,6 +840,8 @@ public final class GuiConfigurationEditorWorkspace {
Thread worker = new Thread(() -> { Thread worker = new Thread(() -> {
try { try {
GuiConfigurationEditorState loadedState = configurationFileLoader.load(configFilePath); GuiConfigurationEditorState loadedState = configurationFileLoader.load(configFilePath);
// Speichern des Pfads als letzte geladene Konfiguration
saveLastConfigurationPath(configFilePath);
Platform.runLater(() -> applyEditorState(loadedState)); Platform.runLater(() -> applyEditorState(loadedState));
} catch (Exception exception) { } catch (Exception exception) {
Platform.runLater(() -> showError("Konfiguration konnte nicht geladen werden: " Platform.runLater(() -> showError("Konfiguration konnte nicht geladen werden: "
@@ -2611,4 +2614,49 @@ public final class GuiConfigurationEditorWorkspace {
? exception.getClass().getSimpleName() ? exception.getClass().getSimpleName()
: exception.getMessage(); : exception.getMessage();
} }
/**
* Speichert den Pfad einer gerade geladenen Konfigurationsdatei.
* Der Pfad wird in den Java Preferences gespeichert und beim nächsten Start
* automatisch geladen.
*
* @param configFilePath der zu speichernde Dateipfad; darf nicht null sein
*/
private void saveLastConfigurationPath(Path configFilePath) {
try {
Preferences prefs = Preferences.userNodeForPackage(GuiConfigurationEditorWorkspace.class);
prefs.put("lastConfigPath", configFilePath.toAbsolutePath().toString());
LOG.debug("GUI-Editor: Letzter Konfigurationspfad gespeichert: {}", configFilePath);
} catch (Exception exception) {
LOG.warn("GUI-Editor: Fehler beim Speichern des letzten Konfigurationspfads", exception);
}
}
/**
* Lädt die zuletzt geladene Konfigurationsdatei automatisch beim Start.
* Falls keine Konfiguration zuvor geladen wurde oder der gespeicherte Pfad
* nicht mehr existiert, erfolgt ein normaler Start ohne Fehlermeldung.
*/
public void autoLoadLastConfiguration() {
try {
Preferences prefs = Preferences.userNodeForPackage(GuiConfigurationEditorWorkspace.class);
String lastPath = prefs.get("lastConfigPath", null);
if (lastPath == null) {
LOG.debug("GUI-Editor: Keine letzte Konfiguration zum Laden vorhanden.");
return;
}
File lastFile = new File(lastPath);
if (!lastFile.exists() || !lastFile.isFile()) {
LOG.debug("GUI-Editor: Gespeicherter Konfigurationspfad existiert nicht mehr: {}", lastPath);
return;
}
LOG.info("GUI-Editor: Letzte Konfiguration wird automatisch geladen: {}", lastPath);
openConfigurationFile(lastFile.toPath());
} catch (Exception exception) {
LOG.warn("GUI-Editor: Fehler beim automatischen Laden der letzten Konfiguration", exception);
}
}
} }
@@ -61,6 +61,9 @@ public class PdfUmbenennerGuiApplication extends Application {
primaryStage.setMaximized(true); primaryStage.setMaximized(true);
primaryStage.show(); primaryStage.show();
// Versuche, die zuletzt geladene Konfigurationsdatei automatisch zu laden.
workspace.autoLoadLastConfiguration();
LOG.info("GUI: Hauptfenster erfolgreich angezeigt."); LOG.info("GUI: Hauptfenster erfolgreich angezeigt.");
} }