From 299be27a07ff4b6183c67622cad878261607c5b7 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Mon, 22 Aug 2016 16:13:34 +0200 Subject: [PATCH 1/5] when inserting a duplicate the right entry will be selected --- CHANGELOG.md | 1 + src/main/java/net/sf/jabref/gui/BasePanel.java | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8e5a745b9..fc4b5cf0774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ### Fixed - Fixed [#1760](https://github.com/JabRef/jabref/issues/1760): Preview updated correctly when selecting a single entry after selecting multiple entries - Fixed [#1632](https://github.com/JabRef/jabref/issues/1632): User comments (@Comment) with or without brackets are now kept +- When inserting a duplicate the right entry will be selected - Preview panel height is now saved immediately, thus is shown correctly if the panel height is changed, closed and opened again - Fixed [#1264](https://github.com/JabRef/jabref/issues/1264): S with caron does not render correctly - LaTeX to Unicode converter now handles combining accents diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 43c6f441405..4d2efb42ff7 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1721,6 +1721,8 @@ public void hideBottomComponent() { public void highlightEntry(final BibEntry be) { final int row = mainTable.findEntry(be); if (row >= 0) { +// the selection has to be cleared in case that a duplicate later in the list is selected thus the editor doesn't get refreshed + mainTable.clearSelection(); mainTable.setRowSelectionInterval(row, row); mainTable.ensureVisible(row); } @@ -1840,17 +1842,6 @@ private synchronized void markChangedOrUnChanged() { frame.setWindowTitle(); } - /** - * Selects a single entry, and scrolls the table to center it. - * - * @param pos Current position of entry to select. - */ - public void selectSingleEntry(int pos) { - mainTable.clearSelection(); - mainTable.addRowSelectionInterval(pos, pos); - mainTable.scrollToCenter(pos, 0); - } - public BibDatabase getDatabase() { return bibDatabaseContext.getDatabase(); } From f43c005ec021d90576424b4e22471e93531cf82c Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 23 Aug 2016 11:59:55 +0200 Subject: [PATCH 2/5] fix issues and delete a duplicate method --- src/main/java/net/sf/jabref/gui/BasePanel.java | 4 ++-- .../net/sf/jabref/gui/exporter/SaveDatabaseAction.java | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 4d2efb42ff7..dec44571da4 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1718,8 +1718,8 @@ public void hideBottomComponent() { * This method selects the given entry, and scrolls it into view in the table. If an entryEditor is shown, it is * given focus afterwards. */ - public void highlightEntry(final BibEntry be) { - final int row = mainTable.findEntry(be); + public void highlightEntry(final BibEntry bibEntry) { + final int row = mainTable.findEntry(bibEntry); if (row >= 0) { // the selection has to be cleared in case that a duplicate later in the list is selected thus the editor doesn't get refreshed mainTable.clearSelection(); diff --git a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index 50ed37a4cc2..05bd22be2a6 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -185,7 +185,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) if (ex.specificEntry()) { BibEntry entry = ex.getEntry(); // Error occured during processing of an entry. Highlight it! - highlightEntry(entry); + panel.highlightEntry(entry); } else { LOGGER.error("A problem occured when trying to save the file", ex); } @@ -254,14 +254,6 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) return success; } - private void highlightEntry(BibEntry entry) { - int row = panel.getMainTable().findEntry(entry); - int topShow = Math.max(0, row - 3); - panel.getMainTable().setRowSelectionInterval(row, row); - panel.getMainTable().scrollTo(topShow); - panel.showEntry(entry); - } - /** * Run the "Save" operation. This method offloads the actual save operation to a background thread, but * still runs synchronously using Spin (the method returns only after completing the operation). From 01a5a3ebc36437d23a60a328c3ac8555901eb538 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 23 Aug 2016 17:06:24 +0200 Subject: [PATCH 3/5] when pasting an entry search the entry from the back, b/c we want to select the duplicate, not the original --- .../java/net/sf/jabref/gui/BasePanel.java | 28 +++++++++++++++---- .../sf/jabref/gui/maintable/MainTable.java | 4 +++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index dec44571da4..addb27c2cf5 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -845,7 +845,9 @@ private void paste() { if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { selectionListener.editSignalled(firstBE); } - highlightEntry(firstBE); + +// If we inserted a duplicate we want to select the duplicate + highlightLastEntry(firstBE); } } @@ -1719,12 +1721,26 @@ public void hideBottomComponent() { * given focus afterwards. */ public void highlightEntry(final BibEntry bibEntry) { - final int row = mainTable.findEntry(bibEntry); - if (row >= 0) { -// the selection has to be cleared in case that a duplicate later in the list is selected thus the editor doesn't get refreshed + highlightEntry(mainTable.findEntry(bibEntry)); + } + + /** + * This method selects the given entry (searches from the back), and scrolls it into view in the table. + * If an entryEditor is shown, it is given focus afterwards. + */ + public void highlightLastEntry(final BibEntry bibEntry) { + highlightEntry(mainTable.findLastEntry(bibEntry)); + } + + /** + * This method selects the entry on the given position, and scrolls it into view in the table. + * If an entryEditor is shown, it is given focus afterwards. + */ + public void highlightEntry(int pos) { + if (pos >= 0) { mainTable.clearSelection(); - mainTable.setRowSelectionInterval(row, row); - mainTable.ensureVisible(row); + mainTable.addRowSelectionInterval(pos, pos); + mainTable.ensureVisible(pos); } } diff --git a/src/main/java/net/sf/jabref/gui/maintable/MainTable.java b/src/main/java/net/sf/jabref/gui/maintable/MainTable.java index 94a70630d32..b4aea447051 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/MainTable.java +++ b/src/main/java/net/sf/jabref/gui/maintable/MainTable.java @@ -490,6 +490,10 @@ public int findEntry(BibEntry entry) { return model.getTableRows().indexOf(entry); } + public int findLastEntry(BibEntry entry) { + return model.getTableRows().lastIndexOf(entry); + } + /** * method to check whether a MainTableColumn at the modelIndex refers to the file field (either as a specific * file extension filter or not) From dd0315f5c43a4156dcfb8e6cd176c3e1e038486d Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 23 Aug 2016 17:29:25 +0200 Subject: [PATCH 4/5] fix indent --- src/main/java/net/sf/jabref/gui/BasePanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index addb27c2cf5..f5e48cd7b8d 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -846,7 +846,7 @@ private void paste() { selectionListener.editSignalled(firstBE); } -// If we inserted a duplicate we want to select the duplicate + // If we inserted a duplicate we want to select the duplicate (thus we have to search from the back) highlightLastEntry(firstBE); } } From 32f829bf9387728dc385f1f1376a9073990f1a42 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Wed, 24 Aug 2016 09:42:50 +0200 Subject: [PATCH 5/5] entry scrolling didn't work if the entry in question was just 1 row outside the table (bottom) (<; <= mistake) --- src/main/java/net/sf/jabref/gui/maintable/MainTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/gui/maintable/MainTable.java b/src/main/java/net/sf/jabref/gui/maintable/MainTable.java index b4aea447051..1d70e0a5006 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/MainTable.java +++ b/src/main/java/net/sf/jabref/gui/maintable/MainTable.java @@ -555,7 +555,7 @@ public void updateFont() { public void ensureVisible(int row) { JScrollBar vert = pane.getVerticalScrollBar(); int y = row * getRowHeight(); - if ((y < vert.getValue()) || ((y > (vert.getValue() + vert.getVisibleAmount())) + if ((y < vert.getValue()) || ((y >= (vert.getValue() + vert.getVisibleAmount())) && (model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT))) { scrollToCenter(row, 1); }