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

Show window before loading files #5363

Merged
merged 1 commit into from
Oct 3, 2019
Merged
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
96 changes: 48 additions & 48 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Iterator;
import java.util.List;

import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.stage.Stage;

Expand Down Expand Up @@ -42,20 +43,11 @@ public class JabRefGUI {
private final List<ParserResult> failed = new ArrayList<>();
private final List<ParserResult> toOpenTab = new ArrayList<>();

private final String focusedFile;

public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBlank) {
this.bibDatabases = argsDatabases;
public JabRefGUI(Stage mainStage, List<ParserResult> databases, boolean isBlank) {
this.bibDatabases = databases;
this.isBlank = isBlank;
mainFrame = new JabRefFrame(mainStage);

// passed file (we take the first one) should be focused
focusedFile = argsDatabases.stream()
.findFirst()
.flatMap(ParserResult::getFile)
.map(File::getAbsolutePath)
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));

openWindow(mainStage);
new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), Globals.TASK_EXECUTOR)
.checkForNewVersionAsync(false);
Expand All @@ -64,15 +56,56 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
private void openWindow(Stage mainStage) {
applyFontRenderingTweak();

GUIGlobals.init();

LOGGER.debug("Initializing frame");
mainFrame.init();

// Restore window location and/or maximised state
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));
}

// We create a decoration pane ourselves for performance reasons
// (otherwise it has to be injected later, leading to a complete redraw/relayout of the complete scene)
DecorationPane root = new DecorationPane();
root.getChildren().add(JabRefGUI.mainFrame);

Scene scene = new Scene(root, 800, 800);
Globals.getThemeLoader().installCss(scene, Globals.prefs);
mainStage.setTitle(JabRefFrame.FRAME_TITLE);
mainStage.getIcons().addAll(IconTheme.getLogoSetFX());
mainStage.setScene(scene);
mainStage.show();

mainStage.setOnCloseRequest(event -> {
saveWindowState(mainStage);
boolean reallyQuit = mainFrame.quit();
if (!reallyQuit) {
event.consume();
}
});

Platform.runLater(this::openDatabases);
}

private void openDatabases() {
// If the option is enabled, open the last edited libraries, if any.
if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
openLastEditedDatabases();
}

GUIGlobals.init();

LOGGER.debug("Initializing frame");
mainFrame.init();
// passed file (we take the first one) should be focused
String focusedFile = bibDatabases.stream()
.findFirst()
.flatMap(ParserResult::getFile)
.map(File::getAbsolutePath)
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));

// Add all bibDatabases databases to the frame:
boolean first = false;
Expand Down Expand Up @@ -119,44 +152,11 @@ private void openWindow(Stage mainStage) {
first = false;
}

// If we are set to remember the window location, we also remember the maximised
// state. This needs to be set after the window has been made visible, so we
// 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));
}

// We create a decoration pane ourselves for performance reasons
// (otherwise it has to be injected later, leading to a complete redraw/relayout of the complete scene)
DecorationPane root = new DecorationPane();
root.getChildren().add(JabRefGUI.mainFrame);

Scene scene = new Scene(root, 800, 800);
Globals.getThemeLoader().installCss(scene, Globals.prefs);
mainStage.setTitle(JabRefFrame.FRAME_TITLE);
mainStage.getIcons().addAll(IconTheme.getLogoSetFX());
mainStage.setScene(scene);
mainStage.show();

mainStage.setOnCloseRequest(event -> {
saveWindowState(mainStage);
boolean reallyQuit = mainFrame.quit();
if (!reallyQuit) {
event.consume();
}
});

for (ParserResult pr : failed) {
String message = Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "\n"
+ pr.getErrorMessage();

mainFrame.getDialogService().showErrorDialogAndWait(Localization.lang("Error opening file"), message);

}

// Display warnings, if any
Expand Down