Skip to content

Commit

Permalink
mra/MRAMenuBar: Fix to show open folders based on the last opened.
Browse files Browse the repository at this point in the history
paulosousadias committed Nov 11, 2024
1 parent cfc1ad7 commit afa64ba
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/java/pt/lsts/neptus/mra/MRAMenuBar.java
Original file line number Diff line number Diff line change
@@ -178,23 +178,7 @@ private void setUpFileMenu() {

@Override
public void actionPerformed(ActionEvent e) {
File lastFile = null;
try {
lastFile = miscFilesOpened.size() == 0 ? null : miscFilesOpened.values().iterator().next();
if (lastFile != null && !lastFile.isDirectory())
lastFile = lastFile.getParentFile();
} catch (Exception ex) {
ex.printStackTrace();
}

File currentDirectory;
if(lastFile != null && lastFile.isDirectory() && lastFile.canRead()) {
currentDirectory = lastFile;
}
else if (!new File(ConfigFetch.getLogsDownloadedFolder()).canRead())
currentDirectory = new File(ConfigFetch.getConfigFile());
else
currentDirectory = new File(ConfigFetch.getLogsDownloadedFolder());
File currentDirectory = getLastOpenedLogFolder();

JFileChooser fileChooser = GuiUtils.getFileChooser(currentDirectory, I18n.text("LSF log files"),
FileUtil.FILE_TYPE_LSF, FileUtil.FILE_TYPE_LSF_COMPRESSED, FileUtil.FILE_TYPE_LSF_COMPRESSED_BZIP2);
@@ -256,6 +240,27 @@ public void actionPerformed(ActionEvent e) {
fileMenu.add(exit);
}

private File getLastOpenedLogFolder() {
File lastFile = null;
try {
lastFile = miscFilesOpened.size() == 0 ? null : miscFilesOpened.values().iterator().next();
if (lastFile != null && !lastFile.isDirectory())
lastFile = lastFile.getParentFile();
} catch (Exception ex) {
ex.printStackTrace();
}

File currentDirectory;
if(lastFile != null && lastFile.isDirectory() && lastFile.canRead()) {
currentDirectory = lastFile;
}
else if (!new File(ConfigFetch.getLogsDownloadedFolder()).canRead())
currentDirectory = new File(ConfigFetch.getConfigFile());
else
currentDirectory = new File(ConfigFetch.getLogsDownloadedFolder());
return currentDirectory;
}

/**
* This method initializes jMenu
*
@@ -542,10 +547,11 @@ public void actionPerformed(ActionEvent e) {

@Override
public void actionPerformed(ActionEvent e) {
File[] folders = ConcatenateLsfLog.chooseFolders(mra, new File(".").getAbsolutePath());
File currentDirectory = getLastOpenedLogFolder();
File[] folders = ConcatenateLsfLog.chooseFolders(mra, currentDirectory.getAbsolutePath());

if (folders != null) {
JFileChooser chooser = GuiUtils.getFileChooser(ConfigFetch.getConfigFile());
if (folders != null && folders.length > 0) {
JFileChooser chooser = GuiUtils.getFileChooser(folders[0].getParentFile().getAbsoluteFile());
chooser.setDialogTitle(I18n.text("Select folder where to save concatenated log"));
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int op = chooser.showOpenDialog(mra);

0 comments on commit afa64ba

Please sign in to comment.