Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saves and reloads window state on close and on open #4124

Merged
merged 4 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We added icons to the group side panel to quickly switch between `union` and `intersection` group view mode https://github.com/JabRef/jabref/issues/3269.
- We use `https` for [fetching from most online bibliographic database](https://help.jabref.org/en/#-using-online-bibliographic-database).
- Opening a new file now prompts the directory of the currently selected file, instead of the directory of the last opened file.
- Window state is saved on close and restored on start

### Fixed
- We fixed an issue where custom exports could not be selected in the 'Export (selected) entries' dialog [#4013](https://github.com/JabRef/jabref/issues/4013)
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class JabRefGUI {

private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
private static final String WINDOWS_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private static final String OSX_AQUA_LOOk_AND_FEEL = "apple.laf.AquaLookAndFeel";
private static final String OSX_AQUA_LOOK_AND_FEEL = "apple.laf.AquaLookAndFeel";

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);

Expand Down Expand Up @@ -155,6 +155,11 @@ private void openWindow(Stage mainStage) {
// do it here:
if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
mainStage.setMaximized(true);
} else {
mainStage.setX(Globals.prefs.getDouble(JabRefPreferences.POS_X));
mainStage.setY(Globals.prefs.getDouble(JabRefPreferences.POS_Y));
mainStage.setWidth(Globals.prefs.getDouble(JabRefPreferences.SIZE_X));
mainStage.setHeight(Globals.prefs.getDouble(JabRefPreferences.SIZE_Y));
}

Scene scene = new Scene(JabRefGUI.mainFrame, 800, 800);
Expand All @@ -165,6 +170,7 @@ private void openWindow(Stage mainStage) {
mainStage.show();

mainStage.setOnCloseRequest(event -> {
saveWindowState(mainStage);
boolean reallyQuit = mainFrame.quit();
if (!reallyQuit) {
event.consume();
Expand Down Expand Up @@ -203,6 +209,14 @@ private void openWindow(Stage mainStage) {
LOGGER.debug("Finished adding panels");
}

private void saveWindowState(Stage mainStage) {
Globals.prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, mainStage.isMaximized());
Globals.prefs.putDouble(JabRefPreferences.POS_X, mainStage.getX());
Globals.prefs.putDouble(JabRefPreferences.POS_Y, mainStage.getY());
Globals.prefs.putDouble(JabRefPreferences.SIZE_X, mainStage.getWidth());
Globals.prefs.putDouble(JabRefPreferences.SIZE_Y, mainStage.getHeight());
}

private void openLastEditedDatabases() {
if (Globals.prefs.get(JabRefPreferences.LAST_EDITED) == null) {
return;
Expand Down Expand Up @@ -248,7 +262,7 @@ private void setLookAndFeel() {
UIManager.setLookAndFeel(WINDOWS_LOOK_AND_FEEL);
}
if (OS.OS_X) {
UIManager.setLookAndFeel(OSX_AQUA_LOOk_AND_FEEL);
UIManager.setLookAndFeel(OSX_AQUA_LOOK_AND_FEEL);
} else {
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private JabRefPreferences() {
defaults.put(POS_Y, 0);
defaults.put(SIZE_X, 1024);
defaults.put(SIZE_Y, 768);
defaults.put(WINDOW_MAXIMISED, Boolean.FALSE);
defaults.put(WINDOW_MAXIMISED, Boolean.TRUE);
defaults.put(AUTO_RESIZE_MODE, Boolean.TRUE);
defaults.put(ENTRY_EDITOR_HEIGHT, 0.65);
defaults.put(NAMES_AS_IS, Boolean.FALSE); // "Show names unchanged"
Expand Down