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:
+48
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -839,6 +840,8 @@ public final class GuiConfigurationEditorWorkspace {
|
||||
Thread worker = new Thread(() -> {
|
||||
try {
|
||||
GuiConfigurationEditorState loadedState = configurationFileLoader.load(configFilePath);
|
||||
// Speichern des Pfads als letzte geladene Konfiguration
|
||||
saveLastConfigurationPath(configFilePath);
|
||||
Platform.runLater(() -> applyEditorState(loadedState));
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> showError("Konfiguration konnte nicht geladen werden: "
|
||||
@@ -2611,4 +2614,49 @@ public final class GuiConfigurationEditorWorkspace {
|
||||
? exception.getClass().getSimpleName()
|
||||
: 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -61,6 +61,9 @@ public class PdfUmbenennerGuiApplication extends Application {
|
||||
primaryStage.setMaximized(true);
|
||||
primaryStage.show();
|
||||
|
||||
// Versuche, die zuletzt geladene Konfigurationsdatei automatisch zu laden.
|
||||
workspace.autoLoadLastConfiguration();
|
||||
|
||||
LOG.info("GUI: Hauptfenster erfolgreich angezeigt.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user