export config filename
This commit is contained in:
parent
609e96145d
commit
5762e24df6
@ -6,6 +6,8 @@ import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
@ -706,17 +708,37 @@ public class SettingsDialog extends JDialog {
|
||||
gbc.gridwidth = 2; // Span across the rest
|
||||
JButton browseBtn = new JButton("Browse...");
|
||||
browseBtn.addActionListener(e -> {
|
||||
String hostname = "localhost";
|
||||
try {
|
||||
hostname = InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception ex) {
|
||||
// ignore
|
||||
}
|
||||
String defaultFileName = "kfmanager-" + hostname + ".backup";
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
String currentPath = pathField.getText();
|
||||
|
||||
File lastDir = null;
|
||||
String lastDirPath = config.getLastFileChooserDirectory();
|
||||
if (lastDirPath != null && !lastDirPath.isEmpty()) {
|
||||
lastDir = new File(lastDirPath);
|
||||
}
|
||||
if (lastDir == null || !lastDir.exists()) {
|
||||
lastDir = new File(System.getProperty("user.home"));
|
||||
}
|
||||
|
||||
if (!currentPath.isEmpty()) {
|
||||
File f = new File(currentPath);
|
||||
if (f.exists()) {
|
||||
chooser.setSelectedFile(f);
|
||||
} else {
|
||||
chooser.setSelectedFile(new File(f.getParentFile(), "kfmanager.backup"));
|
||||
File parent = f.getParentFile();
|
||||
if (parent == null) parent = lastDir;
|
||||
chooser.setSelectedFile(new File(parent, defaultFileName));
|
||||
}
|
||||
} else {
|
||||
chooser.setSelectedFile(new File("kfmanager.backup"));
|
||||
chooser.setSelectedFile(new File(lastDir, defaultFileName));
|
||||
}
|
||||
if (FileChooserUtils.showOpenDialog(this, chooser, config) == JFileChooser.APPROVE_OPTION) {
|
||||
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user