From 18bc242eee17b2b5b2e7ef4a1e3240905e0f0b03 Mon Sep 17 00:00:00 2001 From: GNAQ Date: Fri, 15 Jul 2022 20:57:00 +0800 Subject: [PATCH 1/7] Add: drag'n'drop bib entries to other opened tabs --- src/main/java/org/jabref/gui/JabRefFrame.java | 28 +++++++++++++++++++ src/main/java/org/jabref/gui/LibraryTab.java | 15 ++++++---- .../org/jabref/gui/maintable/MainTable.java | 10 ++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 2bbbf8f4412..487a620a124 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -222,6 +222,34 @@ private void initDragAndDrop() { } else { tabbedPane.getTabs().remove(dndIndicator); } + // Accept drag entries from MainTable + if (event.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) { + event.acceptTransferModes(TransferMode.COPY); + event.consume(); + } + }); + + this.getScene().setOnDragEntered(event -> { + // It is necessary to setOnDragOver for newly opened tabs + tabbedPane.lookupAll(".tab").forEach(t -> { + t.setOnDragOver(tabDragEvent -> { + if(tabDragEvent.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) + { + tabDragEvent.acceptTransferModes(TransferMode.COPY); + tabDragEvent.consume(); + } + }); + t.setOnDragDropped(tabDragEvent -> { + for (Tab libraryTab : tabbedPane.getTabs()) { + if (libraryTab.getId().equals(t.getId()) && + !tabbedPane.getSelectionModel().getSelectedItem().equals(libraryTab)) { + ((LibraryTab) libraryTab).dropEntry(stateManager.getLocalDragboard().getBibEntries()); + } + } + tabDragEvent.consume(); + }); + }); + event.consume(); }); this.getScene().setOnDragExited(event -> tabbedPane.getTabs().remove(dndIndicator)); diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index c62741b37c1..04fc1ddfd09 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -2,11 +2,7 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import javafx.animation.PauseTransition; import javafx.application.Platform; @@ -153,6 +149,10 @@ public LibraryTab(JabRefFrame frame, this.entryEditor = new EntryEditor(this, externalFileTypes); + // set LibraryTab ID for drag'n'drop + // ID content doesn't matter, we only need different tabs to have different ID + this.setId(Long.valueOf(new Random().nextLong()).toString()); + Platform.runLater(() -> { EasyBind.subscribe(changedProperty, this::updateTabTitle); stateManager.getOpenDatabases().addListener((ListChangeListener) c -> @@ -758,6 +758,11 @@ public void paste() { mainTable.paste(); } + public void dropEntry(List entriesToAdd) + { + mainTable.dropEntry(entriesToAdd); + } + public void cut() { mainTable.cut(); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 51494fe6315..c1412662a51 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -314,6 +314,13 @@ public void paste() { } } + public void dropEntry(List entriesToAdd) + { + for (BibEntry entry : entriesToAdd) { + importHandler.importEntryWithDuplicateCheck(database, entry); + } + } + private void handleOnDragOver(TableRow row, BibEntryTableViewModel item, DragEvent event) { if (event.getDragboard().hasFiles()) { event.acceptTransferModes(TransferMode.ANY); @@ -350,8 +357,9 @@ private void handleOnDragDetected(TableRow row, BibEntry // The following is necesary to initiate the drag and drop in javafx, although we don't need the contents // It doesn't work without + // Drag'n'drop to other tabs use COPY TransferMode, drop to group sidepane use MOVE ClipboardContent content = new ClipboardContent(); - Dragboard dragboard = startDragAndDrop(TransferMode.MOVE); + Dragboard dragboard = startDragAndDrop(TransferMode.COPY_OR_MOVE); content.put(DragAndDropDataFormats.ENTRIES, ""); dragboard.setContent(content); From e0e14bf81e0e0e5a1db96aea8414b79c8bdc8b9e Mon Sep 17 00:00:00 2001 From: GNAQ Date: Fri, 15 Jul 2022 21:20:08 +0800 Subject: [PATCH 2/7] Add: drag'n'drop bib entries to other opened tabs (fix import) --- src/main/java/org/jabref/gui/LibraryTab.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 04fc1ddfd09..0428097d6a9 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -2,7 +2,11 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import javafx.animation.PauseTransition; import javafx.application.Platform; From c3909d1895ec626321f9268d5c27e19f7ac00bde Mon Sep 17 00:00:00 2001 From: GNAQ Date: Fri, 15 Jul 2022 21:51:15 +0800 Subject: [PATCH 3/7] Add: drag'n'drop bib entries to other opened tabs (bug fixes) --- src/main/java/org/jabref/gui/LibraryTab.java | 1 + src/main/java/org/jabref/gui/maintable/MainTable.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 0428097d6a9..f943b61d150 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.Random; import javafx.animation.PauseTransition; import javafx.application.Platform; diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index c1412662a51..5b4dc7c7c63 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -317,7 +317,7 @@ public void paste() { public void dropEntry(List entriesToAdd) { for (BibEntry entry : entriesToAdd) { - importHandler.importEntryWithDuplicateCheck(database, entry); + importHandler.importEntryWithDuplicateCheck(database, (BibEntry) entry.clone()); } } From 96ae8a6e39b2620e4589dbecbeb66d6f0c29ffeb Mon Sep 17 00:00:00 2001 From: GNAQ Date: Fri, 15 Jul 2022 22:00:02 +0800 Subject: [PATCH 4/7] Add: drag'n'drop bib entries to other opened tabs (update changelog) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b3a24c19e..cf2d0233f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added an extra option in the 'Find Unlinked Files' dialog view to ignore unnecessary files like Thumbs.db, DS_Store, etc. [koppor#373](https://github.com/koppor/jabref/issues/373) - JabRef now writes log files. Linux: `$home/.cache/jabref/logs/version`, Windows: `%APPDATA%\..\Local\harawata\jabref\version\logs`, Mac: `Users/.../Library/Logs/jabref/version` - We added an importer for Citavi backup files, support ".ctv5bak" and ".ctv6bak" file formats. [#8322](https://github.com/JabRef/jabref/issues/8322) +- We added a feature about allowing drag selected entries and drop them to other opened inactive library tabs. ### Changed From 314daefcf326da7f9eddf313d043a924199d008a Mon Sep 17 00:00:00 2001 From: GNAQ Date: Fri, 15 Jul 2022 22:33:15 +0800 Subject: [PATCH 5/7] Add: drag'n'drop bib entries to other opened tabs (fix codestyle) --- src/main/java/org/jabref/gui/JabRefFrame.java | 3 +-- src/main/java/org/jabref/gui/LibraryTab.java | 3 +-- src/main/java/org/jabref/gui/maintable/MainTable.java | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 487a620a124..32d1c3b32fa 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -233,8 +233,7 @@ private void initDragAndDrop() { // It is necessary to setOnDragOver for newly opened tabs tabbedPane.lookupAll(".tab").forEach(t -> { t.setOnDragOver(tabDragEvent -> { - if(tabDragEvent.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) - { + if(tabDragEvent.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) { tabDragEvent.acceptTransferModes(TransferMode.COPY); tabDragEvent.consume(); } diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index f943b61d150..48bc0b2a92e 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -763,8 +763,7 @@ public void paste() { mainTable.paste(); } - public void dropEntry(List entriesToAdd) - { + public void dropEntry(List entriesToAdd) { mainTable.dropEntry(entriesToAdd); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 5b4dc7c7c63..67ff3b2dcb5 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -314,8 +314,7 @@ public void paste() { } } - public void dropEntry(List entriesToAdd) - { + public void dropEntry(List entriesToAdd) { for (BibEntry entry : entriesToAdd) { importHandler.importEntryWithDuplicateCheck(database, (BibEntry) entry.clone()); } From 8e37bb9ff868542f98975d1affa3da8f440488e0 Mon Sep 17 00:00:00 2001 From: Cain Date: Fri, 15 Jul 2022 23:18:54 +0800 Subject: [PATCH 6/7] Add: drag'n'drop bib entries to other opened tabs (fix conflict with other drag'n'drop) --- src/main/java/org/jabref/gui/JabRefFrame.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 32d1c3b32fa..6e53c74ecd5 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -231,21 +231,42 @@ private void initDragAndDrop() { this.getScene().setOnDragEntered(event -> { // It is necessary to setOnDragOver for newly opened tabs + // drag'n'drop on tabs covered dnd on tabbedPane, so dnd on tabs should contain all dnds on tabbedPane tabbedPane.lookupAll(".tab").forEach(t -> { t.setOnDragOver(tabDragEvent -> { - if(tabDragEvent.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) { + if (DragAndDropHelper.hasBibFiles(tabDragEvent.getDragboard())) { + tabDragEvent.acceptTransferModes(TransferMode.ANY); + if (!tabbedPane.getTabs().contains(dndIndicator)) { + tabbedPane.getTabs().add(dndIndicator); + } + event.consume(); + } else { + tabbedPane.getTabs().remove(dndIndicator); + } + + if (tabDragEvent.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) { tabDragEvent.acceptTransferModes(TransferMode.COPY); tabDragEvent.consume(); } }); + t.setOnDragExited(event1 -> tabbedPane.getTabs().remove(dndIndicator)); t.setOnDragDropped(tabDragEvent -> { - for (Tab libraryTab : tabbedPane.getTabs()) { - if (libraryTab.getId().equals(t.getId()) && - !tabbedPane.getSelectionModel().getSelectedItem().equals(libraryTab)) { - ((LibraryTab) libraryTab).dropEntry(stateManager.getLocalDragboard().getBibEntries()); + if (DragAndDropHelper.hasBibFiles(tabDragEvent.getDragboard())) { + tabbedPane.getTabs().remove(dndIndicator); + List bibFiles = DragAndDropHelper.getBibFiles(tabDragEvent.getDragboard()); + OpenDatabaseAction openDatabaseAction = this.getOpenDatabaseAction(); + openDatabaseAction.openFiles(bibFiles, true); + tabDragEvent.setDropCompleted(true); + tabDragEvent.consume(); + } else { + for (Tab libraryTab : tabbedPane.getTabs()) { + if (libraryTab.getId().equals(t.getId()) && + !tabbedPane.getSelectionModel().getSelectedItem().equals(libraryTab)) { + ((LibraryTab) libraryTab).dropEntry(stateManager.getLocalDragboard().getBibEntries()); + } } + tabDragEvent.consume(); } - tabDragEvent.consume(); }); }); event.consume(); From ae0ff609ee6bedc28a623a6a10b9f97129b230f8 Mon Sep 17 00:00:00 2001 From: GNAQ <41422940+GNAQ@users.noreply.github.com> Date: Sun, 17 Jul 2022 13:18:26 +0800 Subject: [PATCH 7/7] Add: drag'n'drop bib entries to other opened tabs (fix changelog description) Co-authored-by: Christoph --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2d0233f51..d3f8daa73c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added an extra option in the 'Find Unlinked Files' dialog view to ignore unnecessary files like Thumbs.db, DS_Store, etc. [koppor#373](https://github.com/koppor/jabref/issues/373) - JabRef now writes log files. Linux: `$home/.cache/jabref/logs/version`, Windows: `%APPDATA%\..\Local\harawata\jabref\version\logs`, Mac: `Users/.../Library/Logs/jabref/version` - We added an importer for Citavi backup files, support ".ctv5bak" and ".ctv6bak" file formats. [#8322](https://github.com/JabRef/jabref/issues/8322) -- We added a feature about allowing drag selected entries and drop them to other opened inactive library tabs. +- We added a feature to drag selected entries and drop them to other opened inactive library tabs [koppor521](https://github.com/koppor/jabref/issues/521). ### Changed