Skip to content

Commit

Permalink
Fix #1288 Newly opened bib-file is not focused
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Aug 3, 2016
1 parent b6f328f commit 84e3e6c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#1321](https://github.com/JabRef/jabref/issues/1321): LaTeX commands in fields not displayed in the list of references
- Fixed [#1639](https://github.com/JabRef/jabref/issues/1639): Google Scholar fetching works again.
- Date fields in the BibLatex standard are now always formatted in the correct way, independent of the preferences
- Fixed [#1554]: Import dialog is no longer hidden behind main window
- Fixed [#1643]: Searching with double quotes in a specific field ignores the last character
- Fixed [#1554](https://github.com/JabRef/jabref/issues/1554): Import dialog is no longer hidden behind main window
- Fixed [#1643](https://github.com/JabRef/jabref/issues/1643): Searching with double quotes in a specific field ignores the last character
- Fixed [#1288](https://github.com/JabRef/jabref/issues/1288): Newly opened bib-file is not focused

### Removed
- It is not longer possible to choose to convert HTML sub- and superscripts to equations
Expand Down
47 changes: 30 additions & 17 deletions src/main/java/net/sf/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.sf.jabref.importer.OpenDatabaseAction;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.preferences.LastFocusedTabPreferences;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.Version;
import net.sf.jabref.logic.util.VersionPreferences;
Expand All @@ -58,16 +57,25 @@ public class JabRefGUI {

private static JabRefFrame mainFrame;

private final List<ParserResult> loadedDatabases;
private final List<ParserResult> bibDatabases;
private final boolean isBlank;

private final List<File> postponed = new ArrayList<>();
private final List<ParserResult> failed = new ArrayList<>();
private final List<ParserResult> toOpenTab = new ArrayList<>();

public JabRefGUI(List<ParserResult> loadedDatabases, boolean isBlank) {
this.loadedDatabases = loadedDatabases;
private String focusedFile;

public JabRefGUI(List<ParserResult> argsDatabases, boolean isBlank) {
this.bibDatabases = argsDatabases;
this.isBlank = isBlank;

// passed file (we take the first one) should be focused
if (!argsDatabases.isEmpty()) {
focusedFile = argsDatabases.get(0).getFile().getAbsolutePath();
} else {
focusedFile = Globals.prefs.get(JabRefPreferences.LAST_FOCUSED);
}

openWindow();
JabRefGUI.checkForNewVersion(false);
}
Expand Down Expand Up @@ -102,7 +110,7 @@ private void openWindow() {
setLookAndFeel();

// If the option is enabled, open the last edited databases, if any.
if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED) && (Globals.prefs.get(JabRefPreferences.LAST_EDITED) != null)) {
if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
openLastEditedDatabases();
}

Expand All @@ -113,13 +121,14 @@ private void openWindow() {
LOGGER.debug("Initializing frame");
JabRefGUI.mainFrame = new JabRefFrame();

// Add all loadedDatabases databases to the frame:
boolean first = true;
if (!loadedDatabases.isEmpty()) {
for (Iterator<ParserResult> parserResultIterator = loadedDatabases.iterator(); parserResultIterator.hasNext();) {
// Add all bibDatabases databases to the frame:
boolean first = false;
if (!bibDatabases.isEmpty()) {
for (Iterator<ParserResult> parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext();) {
ParserResult pr = parserResultIterator.next();

if (new LastFocusedTabPreferences(Globals.prefs).hadLastFocus(pr.getFile())) {
// Define focused tab
if (focusedFile != null && pr.getFile().getAbsolutePath().equals(focusedFile)) {
first = true;
}

Expand Down Expand Up @@ -176,7 +185,7 @@ private void openWindow() {

if (Globals.prefs.getBoolean(JabRefPreferences.DISPLAY_KEY_WARNING_DIALOG_AT_STARTUP)) {
int i = 0;
for (ParserResult pr : loadedDatabases) {
for (ParserResult pr : bibDatabases) {
ParserResultWarningDialog.showParserResultWarningDialog(pr, JabRefGUI.getMainFrame(), i++);
}
}
Expand All @@ -190,8 +199,8 @@ private void openWindow() {
// This is because importToOpen might have been used, which adds to
// loadedDatabases, but not to getBasePanelCount()

for (int i = 0; (i < loadedDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
ParserResult pr = loadedDatabases.get(i);
for (int i = 0; (i < bibDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
ParserResult pr = bibDatabases.get(i);
BasePanel panel = JabRefGUI.getMainFrame().getBasePanelAt(i);
OpenDatabaseAction.performPostOpenActions(panel, pr, true);
}
Expand All @@ -205,12 +214,16 @@ private void openWindow() {
SwingUtilities.invokeLater(asp);
}

if (!loadedDatabases.isEmpty()) {
if (!bibDatabases.isEmpty()) {
new FocusRequester(JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable());
}
}

private void openLastEditedDatabases() {
if (Globals.prefs.get(JabRefPreferences.LAST_EDITED) == null) {
return;
}

List<String> lastFiles = Globals.prefs.getStringList(JabRefPreferences.LAST_EDITED);

for (String fileName : lastFiles) {
Expand All @@ -226,13 +239,13 @@ private void openLastEditedDatabases() {
if (parsedDatabase.isNullResult()) {
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
} else {
loadedDatabases.add(parsedDatabase);
bibDatabases.add(parsedDatabase);
}
}
}

private boolean isLoaded(File fileToOpen) {
for (ParserResult pr : loadedDatabases) {
for (ParserResult pr : bibDatabases) {
if (pr.getFile() != null && pr.getFile().equals(fileToOpen)) {
return true;
}
Expand Down

0 comments on commit 84e3e6c

Please sign in to comment.