Skip to content

Commit

Permalink
Only open files if not already opened
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Aug 3, 2016
1 parent 84e3e6c commit 70c09e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -149,11 +150,10 @@
* The main window of the application.
*/
public class JabRefFrame extends JFrame implements OutputPrinter {
private static final Log LOGGER = LogFactory.getLog(JabRefFrame.class);

// Frame titles.
private static final String FRAME_TITLE = "JabRef";

private static final Log LOGGER = LogFactory.getLog(JabRefFrame.class);
private static final String ELLIPSES = "...";

private final JSplitPane splitPane = new JSplitPane();
Expand Down Expand Up @@ -1379,22 +1379,38 @@ public static JMenu subMenu(String name) {
return res;
}

public void addParserResult(ParserResult pr, boolean raisePanel) {
public void addParserResult(ParserResult pr, boolean focusPanel) {
if (pr.toOpenTab()) {
// Add the entries to the open tab.
BasePanel panel = getCurrentBasePanel();
if (panel == null) {
// There is no open tab to add to, so we create a new tab:
addTab(pr.getDatabaseContext(), raisePanel);
addTab(pr.getDatabaseContext(), focusPanel);
} else {
List<BibEntry> entries = new ArrayList<>(pr.getDatabase().getEntries());
addImportedEntries(panel, entries, false);
}
} else {
addTab(pr.getDatabaseContext(), raisePanel);
// only add tab if DB is not already open
Optional<BasePanel> panel = isOpened(pr.getFile());

if (panel.isPresent()) {
tabbedPane.setSelectedComponent(panel.get());
} else {
addTab(pr.getDatabaseContext(), focusPanel);
}
}
}

private Optional<BasePanel> isOpened(File file) {
for (BasePanel panel : getBasePanelList()) {
if (panel.getBibDatabaseContext().getDatabaseFile().equals(file)) {
return Optional.of(panel);
}
}
return Optional.empty();
}

private void createToolBar() {
tlb.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
tlb.setBorder(null);
Expand Down Expand Up @@ -1644,6 +1660,7 @@ public void addTab(BasePanel bp, boolean raisePanel) {

public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) {
Objects.requireNonNull(databaseContext);

BasePanel bp = new BasePanel(JabRefFrame.this, databaseContext);
addTab(bp, raisePanel);
return bp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import org.apache.commons.logging.LogFactory;

public class RemoteListenerServer implements Runnable {
private static final Log LOGGER = LogFactory.getLog(RemoteListenerServer.class);

private static final int BACKLOG = 1;
private static final int ONE_SECOND_TIMEOUT = 1000;

private static final Log LOGGER = LogFactory.getLog(RemoteListenerServer.class);
private static final int ONE_SECOND_TIMEOUT = 1000;

private final MessageHandler messageHandler;
private final ServerSocket serverSocket;
Expand Down

0 comments on commit 70c09e7

Please sign in to comment.