From 23e6f97f226a1025716c8da4be74a1e18900eb36 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sun, 15 Nov 2026 20:25:16 +0100 Subject: [PATCH] changes config file handling to memorize the name of a loaded file --- .../handlers/LoadStoreSettingsHandler.java | 10 ++++++++-- .../e4/application/parts/WaveformViewer.java | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java index d5108860..fb54c32e 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java @@ -48,7 +48,13 @@ public class LoadStoreSettingsHandler { boolean load = "load".equals(param); //$NON-NLS-1$ FileDialog dialog = new FileDialog(shell, load?SWT.OPEN:SWT.SAVE); dialog.setFilterExtensions (new String []{Messages.LoadStoreSettingsHandler_2}); - if(!load) dialog.setFileName(Messages.LoadStoreSettingsHandler_3); + if (!load) { + java.nio.file.Path settingsFile = ((WaveformViewer) obj).getSettingsFile(); + if (settingsFile != null) { + dialog.setFilterPath(settingsFile.getParent().toString()); + dialog.setFileName(settingsFile.getFileName().toString()); + } else dialog.setFileName(Messages.LoadStoreSettingsHandler_3); + } String fileName = null; @@ -98,4 +104,4 @@ public class LoadStoreSettingsHandler { } } } -} \ No newline at end of file +} diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 27c28033..12cd0a2a 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -176,6 +176,7 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene ArrayList filesToLoad = new ArrayList<>(); String partConfig = ""; + private Path settingsFile; /** The persisted state. */ Map persistedState; @@ -597,19 +598,32 @@ public class WaveformViewer implements IPreferenceChangeListener, DisposeListene } public void saveState(String fileName) { - try { captureSettings().write(Path.of(fileName)); } + try { + Path file = Path.of(fileName).toAbsolutePath().normalize(); + captureSettings().write(file); + settingsFile = file; + } catch (IOException | IllegalArgumentException e) { reportSettingsError("Cannot save settings", fileName + ": " + e.getMessage()); } } public void loadState(String fileName) { - try { applySettings(ViewerSettings.read(Path.of(fileName))); } + try { + Path file = Path.of(fileName).toAbsolutePath().normalize(); + applySettings(ViewerSettings.read(file)); + settingsFile = file; + } catch (IOException | IllegalArgumentException e) { reportSettingsError("Cannot load settings", fileName + ": " + e.getMessage()); } } + /** Last successfully loaded or saved settings file for this viewer. */ + public Path getSettingsFile() { + return settingsFile; + } + protected void reportSettingsError(String title, String message) { if (logger != null) logger.error(title + ": " + message); if (!disposed && myParent != null && !myParent.isDisposed())