Skip to content

Commit 1b45d0a

Browse files
committed
Remember last sources root directory
1 parent fbb42ef commit 1b45d0a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

plugins/sources/src/org/graalvm/visualvm/sources/options/SourcesOptionsPanel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.graalvm.visualvm.sources.SourcesViewer;
6464
import org.openide.awt.Mnemonics;
6565
import org.openide.util.NbBundle;
66+
import org.openide.util.NbPreferences;
6667
import org.openide.windows.WindowManager;
6768

6869
/**
@@ -87,6 +88,9 @@
8788
})
8889
final class SourcesOptionsPanel extends JPanel {
8990

91+
private static final String PROP_LAST_SOURCES_DIR = "prop_SourcesOptionsPanel_lastDir"; // NOI18N
92+
93+
9094
SourcesOptionsPanel() {
9195
initUI();
9296
}
@@ -289,14 +293,24 @@ public String getDescription() {
289293
// }
290294
// });
291295

296+
String lastDirS = NbPreferences.forModule(SourcesOptionsPanel.class).get(PROP_LAST_SOURCES_DIR, null);
297+
File lastDir = lastDirS == null ? null : new File(lastDirS);
298+
if (lastDir != null && lastDir.isDirectory()) fileChooser.setCurrentDirectory(lastDir);
299+
292300
if (fileChooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) {
293301
String first = null;
294302
for (File selected : fileChooser.getSelectedFiles()) {
295303
String path = selected.getAbsolutePath();
296304
if (!rootsListModel.contains(path)) rootsListModel.addElement(path);
297305
if (first == null) first = path;
298306
}
299-
if (first != null) rootsList.setSelectedValue(first, true);
307+
if (first != null) {
308+
rootsList.setSelectedValue(first, true);
309+
310+
File dir = new File(first).getParentFile();
311+
String dirS = dir.isDirectory() ? dir.getAbsolutePath() : null;
312+
if (dirS != null) NbPreferences.forModule(SourcesOptionsPanel.class).put(PROP_LAST_SOURCES_DIR, dirS);
313+
}
300314
}
301315
}
302316
};

0 commit comments

Comments
 (0)