Skip to content

Commit

Permalink
Merge pull request #1816 from bartsch-dev/fixCorrectlySelectingDuplic…
Browse files Browse the repository at this point in the history
…ates

When inserting a duplicate the right entry will be selected
  • Loading branch information
koppor authored Aug 25, 2016
2 parents 1b1e489 + 32f829b commit 280b577
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,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 (thus we have to search from the back)
highlightLastEntry(firstBE);
}
}

Expand Down Expand Up @@ -1716,11 +1718,27 @@ 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);
if (row >= 0) {
mainTable.setRowSelectionInterval(row, row);
mainTable.ensureVisible(row);
public void highlightEntry(final BibEntry bibEntry) {
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.addRowSelectionInterval(pos, pos);
mainTable.ensureVisible(pos);
}
}

Expand Down Expand Up @@ -1838,17 +1856,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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/sf/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -551,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);
}
Expand Down

0 comments on commit 280b577

Please sign in to comment.