From aa3132b81008cb61baa3394791160dd779c6c5c3 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Wed, 8 Apr 2020 22:46:45 +0800 Subject: [PATCH 01/11] Showing correct icon on main table linked files column --- .../org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index 471af98aa2f..f9297f5f891 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -94,7 +94,7 @@ public static LinkedFile fromFile(Path file, List fileDirectories, Externa .getExternalFileTypeByExt(fileExtension) .orElse(new UnknownExternalFileType(fileExtension)); Path relativePath = FileUtil.relativize(file, fileDirectories); - return new LinkedFile("", relativePath.toString(), suggestedFileType.getName()); + return new LinkedFile("", relativePath.toString(), suggestedFileType.getExtension()); } public LinkedFileViewModel fromFile(Path file) { From 9c9b7c1fcf5b7a90f71254df3c6a4ef59967c861 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Wed, 15 Apr 2020 17:43:36 +0800 Subject: [PATCH 02/11] Showing correct icon on both main table and linked files column --- .../org/jabref/gui/externalfiletype/ExternalFileTypes.java | 2 +- .../java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java index 7e7d2836f1b..9283c7e7fde 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java @@ -56,7 +56,7 @@ public Set getExternalFileTypeSelection() { * @return The ExternalFileType registered, or null if none. */ public Optional getExternalFileTypeByName(String name) { - Optional externalFileType = externalFileTypes.stream().filter(type -> type.getExtension().equals(name)).findFirst(); + Optional externalFileType = externalFileTypes.stream().filter(type -> type.getName().equals(name)).findFirst(); if (externalFileType.isPresent()) { return externalFileType; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index d52a24b9f95..36e59e1d9fd 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -140,7 +140,9 @@ public Optional findIn(List directories) { * org.jabref.gui.externalfiletype.ExternalFileTypes#getExternalFileTypeByName(String)} */ public JabRefIcon getTypeIcon() { - return IconTheme.JabRefIcons.PDF_FILE; + return externalFileTypes.fromLinkedFile(linkedFile, false) + .map(ExternalFileType::getIcon) + .orElse(IconTheme.JabRefIcons.FILE); } public void markAsAutomaticallyFound() { From 8090ea51ced82fa2ea514ff4258ab23f59ff92a2 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Wed, 15 Apr 2020 17:51:24 +0800 Subject: [PATCH 03/11] Showing correct icon on both main table and linked file editor list --- .../org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index f9297f5f891..471af98aa2f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -94,7 +94,7 @@ public static LinkedFile fromFile(Path file, List fileDirectories, Externa .getExternalFileTypeByExt(fileExtension) .orElse(new UnknownExternalFileType(fileExtension)); Path relativePath = FileUtil.relativize(file, fileDirectories); - return new LinkedFile("", relativePath.toString(), suggestedFileType.getExtension()); + return new LinkedFile("", relativePath.toString(), suggestedFileType.getName()); } public LinkedFileViewModel fromFile(Path file) { From 72fc91c114dc57dd1e41f189cb0bc4b1b7341102 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Wed, 15 Apr 2020 19:32:50 +0800 Subject: [PATCH 04/11] delete the TODO comments --- .../java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 36e59e1d9fd..d8c42054544 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -135,10 +135,6 @@ public Optional findIn(List directories) { return linkedFile.findIn(directories); } - /** - * TODO: Be a bit smarter and try to infer correct icon, for example using {@link - * org.jabref.gui.externalfiletype.ExternalFileTypes#getExternalFileTypeByName(String)} - */ public JabRefIcon getTypeIcon() { return externalFileTypes.fromLinkedFile(linkedFile, false) .map(ExternalFileType::getIcon) From e9796642b245badbd100cf83289cfa61ca0f4609 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Wed, 15 Apr 2020 19:46:24 +0800 Subject: [PATCH 05/11] add record in CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 149ea8d8bc7..65666240e0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939) - We fixed an issue with inconsistent capitalization of file extensions when downloading files [#6115](https://github.com/JabRef/jabref/issues/6115) - We fixed the display of language and encoding in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130) +- We fixed the display of icon both in the main table and linked file editor. [#6169](https://github.com/JabRef/jabref/issues/6169) ### Removed From 87c8b411c77d3559477156fb974d9bcaf8dab698 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Thu, 7 May 2020 18:31:28 +0800 Subject: [PATCH 06/11] Add jump in ordered author list by typing letter function --- .../org/jabref/gui/maintable/MainTable.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index e15ac98e4ce..72cb398dc34 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -12,6 +12,7 @@ import javafx.collections.ListChangeListener; import javafx.scene.control.SelectionMode; +import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import javafx.scene.input.ClipboardContent; @@ -62,6 +63,19 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { super(); + this.setOnKeyTyped(key -> { + if (this.getSortOrder().size() == 0) { + return; + } + final char keyChar = key.getCharacter().charAt(0); + final TableColumn sortedColumn = getSortOrder().get(0); + final int target_row_index = this.getEntryIndexByInput(sortedColumn, keyChar); + if (Character.isLetterOrDigit(keyChar) && target_row_index != -1) { + this.scrollTo(target_row_index); + this.getSelectionModel().clearAndSelect(target_row_index); + } + }); + this.model = model; this.database = Objects.requireNonNull(database); @@ -123,6 +137,19 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, database.getDatabase().registerListener(this); } + private int getEntryIndexByInput(TableColumn column, char target_char) { + for (int i = 0; i < this.getItems().size(); ++i) { + Object temp = column.getCellObservableValue(i).getValue(); + if (temp == null) { + continue; + } + if (temp.toString().toLowerCase().charAt(0) == target_char) { + return i; + } + } + return -1; + } + @Subscribe public void listen(EntriesAddedEvent event) { DefaultTaskExecutor.runInJavaFXThread(() -> clearAndSelect(event.getFirstEntry())); From 2a364e6287ae1b45fd6586a7e48b88834d44cc1c Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Thu, 7 May 2020 18:41:34 +0800 Subject: [PATCH 07/11] modify changelog.md supporting for jumping to target entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1d957a0507..097b7bda239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We now show the number of items found and selected to import in the online search dialog. [#6248](https://github.com/JabRef/jabref/pull/6248) - We created a new install screen for macOS. [#5759](https://github.com/JabRef/jabref/issues/5759) - We implemented an option to download fulltext files while importing. [#6381](https://github.com/JabRef/jabref/pull/6381) +- We added support for jumping to target entry when typing letter/digit after sorting a column in maintable [#6146](https://github.com/JabRef/jabref/issues/6146) ### Changed @@ -41,7 +42,6 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939) - We fixed an issue with inconsistent capitalization of file extensions when downloading files. [#6115](https://github.com/JabRef/jabref/issues/6115) - We fixed the display of language and encoding in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130) -- We fixed the display of icon both in the main table and linked file editor. [#6169](https://github.com/JabRef/jabref/issues/6169) - We fixed an error that sometimes occurred when using the context menu. [#6085](https://github.com/JabRef/jabref/issues/6085) - We fixed an issue where search full-text documents downloaded files with same name, overwriting existing files. [#6174](https://github.com/JabRef/jabref/pull/6174) - We fixed an issue when importing into current library an erroneous message "import cancelled" is displayed even though import is successful. [#6266](https://github.com/JabRef/jabref/issues/6266) From 8368aff8caf9b1ec5a65c9244ee0c23a1c91034c Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Fri, 8 May 2020 12:33:05 +0800 Subject: [PATCH 08/11] Using java stream rewrite the method and enable multiple key input --- .../org/jabref/gui/maintable/MainTable.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 72cb398dc34..1510118470b 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -58,6 +58,9 @@ public class MainTable extends TableView { private final ImportHandler importHandler; private final CustomLocalDragboard localDragboard; + private long lastKeyPressTime; + private String columnSearchTerm; + public MainTable(MainTableDataModel model, JabRefFrame frame, BasePanel panel, BibDatabaseContext database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { @@ -67,13 +70,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, if (this.getSortOrder().size() == 0) { return; } - final char keyChar = key.getCharacter().charAt(0); - final TableColumn sortedColumn = getSortOrder().get(0); - final int target_row_index = this.getEntryIndexByInput(sortedColumn, keyChar); - if (Character.isLetterOrDigit(keyChar) && target_row_index != -1) { - this.scrollTo(target_row_index); - this.getSelectionModel().clearAndSelect(target_row_index); - } + this.jumpToSearchKey(getSortOrder().get(0), key); }); this.model = model; @@ -137,17 +134,33 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, database.getDatabase().registerListener(this); } - private int getEntryIndexByInput(TableColumn column, char target_char) { - for (int i = 0; i < this.getItems().size(); ++i) { - Object temp = column.getCellObservableValue(i).getValue(); - if (temp == null) { - continue; - } - if (temp.toString().toLowerCase().charAt(0) == target_char) { - return i; - } + /** + * This is called, if a user starts typing some characters into the keyboard with focus on main table. + * The tableview will scroll to the next cell with the name of the PreviewLayout fitting those characters. + * @param sortedColumn The ListView currently focused + * @param keyEvent The pressed character + */ + + private void jumpToSearchKey(TableColumn sortedColumn, KeyEvent keyEvent) { + if (keyEvent.getCharacter() == null || sortedColumn == null) { + return; } - return -1; + + if (System.currentTimeMillis() - lastKeyPressTime < 700) { + columnSearchTerm += keyEvent.getCharacter().toLowerCase(); + } else { + columnSearchTerm = keyEvent.getCharacter().toLowerCase(); + } + + lastKeyPressTime = System.currentTimeMillis(); + + this.getItems().stream() + .filter(item -> Optional.ofNullable(sortedColumn.getCellObservableValue(item).getValue()) + .map(Object::toString) + .orElse("") + .toLowerCase().startsWith(columnSearchTerm)) + .findFirst() + .ifPresent(item -> { this.scrollTo(item); this.clearAndSelect(item.getEntry()); }); } @Subscribe From 1b427a39a923b2880dacb21b47bb5e6123b8aa38 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Fri, 8 May 2020 21:51:06 +0800 Subject: [PATCH 09/11] Update javadoc --- src/main/java/org/jabref/gui/maintable/MainTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 1510118470b..73ef48e6592 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -136,7 +136,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, /** * This is called, if a user starts typing some characters into the keyboard with focus on main table. - * The tableview will scroll to the next cell with the name of the PreviewLayout fitting those characters. + * The tableview will scroll to the cell with the same starting column value and typed string * @param sortedColumn The ListView currently focused * @param keyEvent The pressed character */ From a37b8a3b5fef62f25b00c525344260209c2bef09 Mon Sep 17 00:00:00 2001 From: Tianjian lei Date: Sat, 9 May 2020 00:01:31 +0800 Subject: [PATCH 10/11] Adjust code format in @calixtus suggestions. Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> --- src/main/java/org/jabref/gui/maintable/MainTable.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 73ef48e6592..3edb3fb9617 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -160,7 +160,10 @@ private void jumpToSearchKey(TableColumn sortedColumn .orElse("") .toLowerCase().startsWith(columnSearchTerm)) .findFirst() - .ifPresent(item -> { this.scrollTo(item); this.clearAndSelect(item.getEntry()); }); + .ifPresent(item -> { + this.scrollTo(item); + this.clearAndSelect(item.getEntry()); + }); } @Subscribe From c1073b5a14bc5fdd447a535faabcbada269711c1 Mon Sep 17 00:00:00 2001 From: leitianjian <185049857@qq.com> Date: Sat, 9 May 2020 09:49:40 +0800 Subject: [PATCH 11/11] Update code format in @koppor suggestions and update javadoc --- src/main/java/org/jabref/gui/maintable/MainTable.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 3edb3fb9617..f9a2122041a 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -67,7 +67,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, super(); this.setOnKeyTyped(key -> { - if (this.getSortOrder().size() == 0) { + if (this.getSortOrder().isEmpty()) { return; } this.jumpToSearchKey(getSortOrder().get(0), key); @@ -136,8 +136,9 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, /** * This is called, if a user starts typing some characters into the keyboard with focus on main table. - * The tableview will scroll to the cell with the same starting column value and typed string - * @param sortedColumn The ListView currently focused + * The {@link MainTable} will scroll to the cell with the same starting column value and typed string + * + * @param sortedColumn The sorted column in {@link MainTable} * @param keyEvent The pressed character */ @@ -158,7 +159,8 @@ private void jumpToSearchKey(TableColumn sortedColumn .filter(item -> Optional.ofNullable(sortedColumn.getCellObservableValue(item).getValue()) .map(Object::toString) .orElse("") - .toLowerCase().startsWith(columnSearchTerm)) + .toLowerCase() + .startsWith(columnSearchTerm)) .findFirst() .ifPresent(item -> { this.scrollTo(item);