[#1100] Implement multi-document behavior for macOS
Note: this is not yet "final" there are still a number of fixes that need to happen, such as fixing the application menu (which is not responsive after closing everyhing) and a high memory usage even in closed down mode
This commit is contained in:
parent
9e73f6e4e2
commit
fa10dcd019
@ -34,6 +34,7 @@ import javax.swing.tree.TreeSelectionModel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.appearance.DecalImage;
|
||||
import net.sf.openrocket.arch.SystemInfo;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||
import net.sf.openrocket.document.StorageOptions;
|
||||
@ -1687,7 +1688,8 @@ public class BasicFrame extends JFrame {
|
||||
ComponentAnalysisDialog.hideDialog();
|
||||
|
||||
frames.remove(this);
|
||||
if (frames.isEmpty()) {
|
||||
// Don't quit the application on macOS
|
||||
if (frames.isEmpty() && (SystemInfo.getPlatform() != SystemInfo.Platform.MAC_OS)) {
|
||||
log.info("Last frame closed, exiting");
|
||||
System.exit(0);
|
||||
}
|
||||
@ -1704,6 +1706,31 @@ public class BasicFrame extends JFrame {
|
||||
new PrintDialog(this, document, rotation).setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new design file or the last design file, if set in the preferences.
|
||||
* Can be used for reopening the application or opening it the first time.
|
||||
*/
|
||||
public static void reopen() {
|
||||
if (!Application.getPreferences().isAutoOpenLastDesignOnStartupEnabled()) {
|
||||
BasicFrame.newAction();
|
||||
} else {
|
||||
String lastFile = MRUDesignFile.getInstance().getLastEditedDesignFile();
|
||||
if (lastFile != null) {
|
||||
log.info("Opening last design file: " + lastFile);
|
||||
if (!BasicFrame.open(new File(lastFile), null)) {
|
||||
MRUDesignFile.getInstance().removeFile(lastFile);
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
else {
|
||||
MRUDesignFile.getInstance().addFile(lastFile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BasicFrame.newAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open a new design window with a basic rocket+stage.
|
||||
|
@ -5,6 +5,7 @@ import java.awt.desktop.AboutHandler;
|
||||
import java.awt.desktop.OpenFilesHandler;
|
||||
import java.awt.desktop.PreferencesHandler;
|
||||
import java.awt.desktop.QuitHandler;
|
||||
import java.awt.desktop.AppReopenedListener;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -50,6 +51,11 @@ final class OSXSetup {
|
||||
r.cancelQuit();
|
||||
};
|
||||
|
||||
private static final AppReopenedListener APP_REOPENED_HANDLER = (e) -> {
|
||||
log.info("App re-opened");
|
||||
BasicFrame.reopen();
|
||||
};
|
||||
|
||||
/**
|
||||
* The handler for the About item in the OSX app menu
|
||||
*/
|
||||
@ -92,6 +98,7 @@ final class OSXSetup {
|
||||
osxDesktop.setAboutHandler(ABOUT_HANDLER);
|
||||
osxDesktop.setPreferencesHandler(PREFERENCES_HANDLER);
|
||||
osxDesktop.setQuitHandler(QUIT_HANDLER);
|
||||
osxDesktop.addAppEventListener(APP_REOPENED_HANDLER);
|
||||
|
||||
// Set the dock icon to the largest icon
|
||||
final Image dockIcon = Toolkit.getDefaultToolkit().getImage(
|
||||
|
@ -220,23 +220,7 @@ public class SwingStartup {
|
||||
// Starting action (load files or open new document)
|
||||
log.info("Opening main application window");
|
||||
if (!handleCommandLine(args)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
BasicFrame.reopen();
|
||||
}
|
||||
|
||||
// Check whether update info has been fetched or whether it needs more time
|
||||
|
Loading…
x
Reference in New Issue
Block a user