Added preference to auto-open last design file on startup.
This commit is contained in:
parent
417ef81269
commit
5b6e1ecf39
@ -220,6 +220,7 @@ MaterialModel.title.Defcustmat = Define custom material
|
||||
pref.dlg.but.add = Add
|
||||
pref.dlg.but.reset = Reset
|
||||
pref.dlg.but.checknow = Check now
|
||||
pref.dlg.but.openlast = Open last design file on startup
|
||||
pref.dlg.but.defaultmetric = Default metric
|
||||
pref.dlg.but.defaultimperial = Default imperial
|
||||
pref.dlg.title.Preferences = Preferences
|
||||
|
@ -290,7 +290,17 @@ public class PreferencesDialog extends JDialog {
|
||||
panel.add(button, "right, wrap");
|
||||
|
||||
|
||||
return panel;
|
||||
final JCheckBox autoOpenDesignFile = new JCheckBox(trans.get("pref.dlg.but.openlast"));
|
||||
autoOpenDesignFile.setSelected(Application.getPreferences().isAutoOpenLastDesignOnStartupEnabled());
|
||||
autoOpenDesignFile.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Application.getPreferences().setAutoOpenLastDesignOnStartup(autoOpenDesignFile.isSelected());
|
||||
}
|
||||
});
|
||||
panel.add(autoOpenDesignFile);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JPanel unitsPane() {
|
||||
|
@ -56,6 +56,20 @@ public class MRUDesignFile {
|
||||
return mruFileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last edited design file.
|
||||
*
|
||||
* @return an absolute file name, or null
|
||||
*/
|
||||
public String getLastEditedDesignFile() {
|
||||
if (!mruFileList.isEmpty()) {
|
||||
return mruFileList.get(0);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the most-recently-used list to the given parameter and fire change events.
|
||||
*
|
||||
|
@ -48,12 +48,13 @@ public abstract class Preferences {
|
||||
|
||||
// Node names
|
||||
public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors";
|
||||
private static final String AUTO_OPEN_LAST_DESIGN = "AUTO_OPEN_LAST_DESIGN";
|
||||
|
||||
/*
|
||||
* ******************************************************************************************
|
||||
*
|
||||
* Abstract methods which must be implemented by any derived class.
|
||||
*/
|
||||
/*
|
||||
* ******************************************************************************************
|
||||
*
|
||||
* Abstract methods which must be implemented by any derived class.
|
||||
*/
|
||||
public abstract boolean getBoolean(String key, boolean defaultValue);
|
||||
|
||||
public abstract void putBoolean(String key, boolean value);
|
||||
@ -98,6 +99,22 @@ public abstract class Preferences {
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable the auto-opening of the last edited design file on startup.
|
||||
*/
|
||||
public final void setAutoOpenLastDesignOnStartup(boolean enabled) {
|
||||
this.putBoolean(AUTO_OPEN_LAST_DESIGN, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer if the auto-opening of the last edited design file on startup is enabled.
|
||||
*
|
||||
* @return true if the application should automatically open the last edited design file on startup.
|
||||
*/
|
||||
public final boolean isAutoOpenLastDesignOnStartupEnabled() {
|
||||
return this.getBoolean(AUTO_OPEN_LAST_DESIGN, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the OpenRocket unique ID.
|
||||
*
|
||||
|
@ -17,6 +17,7 @@ import net.sf.openrocket.database.ComponentPresetDatabase;
|
||||
import net.sf.openrocket.database.Databases;
|
||||
import net.sf.openrocket.gui.dialogs.UpdateInfoDialog;
|
||||
import net.sf.openrocket.gui.main.BasicFrame;
|
||||
import net.sf.openrocket.gui.main.MRUDesignFile;
|
||||
import net.sf.openrocket.gui.main.Splash;
|
||||
import net.sf.openrocket.gui.main.SwingExceptionHandler;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
@ -140,8 +141,25 @@ public class Startup2 {
|
||||
// Starting action (load files or open new document)
|
||||
log.info("Opening main application window");
|
||||
if (!handleCommandLine(args)) {
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
if (!Application.getPreferences().isAutoOpenLastDesignOnStartupEnabled()) {
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
else {
|
||||
String lastFile = MRUDesignFile.getInstance().getLastEditedDesignFile();
|
||||
if (lastFile != null) {
|
||||
if (!BasicFrame.open(new File(lastFile), null)) {
|
||||
MRUDesignFile.getInstance().removeFile(lastFile);
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
else {
|
||||
MRUDesignFile.getInstance().addFile(lastFile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether update info has been fetched or whether it needs more time
|
||||
log.info("Checking update status");
|
||||
|
Loading…
x
Reference in New Issue
Block a user