Skip to content

Commit

Permalink
Copy entry to the selected library
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu16095 committed Jan 23, 2025
1 parent a283264 commit 4cab5de
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/jabref/gui/edit/CopyTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -16,25 +17,28 @@

public class CopyTo extends SimpleCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(CopyMoreAction.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CopyTo.class);

private final DialogService dialogService;
private final StateManager stateManager;
private final CopyToPreferences copyToPreferences;
private final LibraryTab libraryTab;
private final ImportHandler importHandler;
private final BibDatabaseContext sourceDatabaseContext;
private final BibDatabaseContext targetDatabaseContext;

public CopyTo(DialogService dialogService,
StateManager stateManager,
CopyToPreferences copyToPreferences,
LibraryTab libraryTab,
ImportHandler importHandler,
BibDatabaseContext sourceDatabaseContext,
BibDatabaseContext targetDatabaseContext) {
this.dialogService = dialogService;
this.stateManager = stateManager;
this.copyToPreferences = copyToPreferences;
this.libraryTab = libraryTab;
this.importHandler = importHandler;
this.sourceDatabaseContext = sourceDatabaseContext;
this.targetDatabaseContext = targetDatabaseContext;

Expand All @@ -51,8 +55,7 @@ public void execute() {

public void copyEntryToAnotherLibrary(BibDatabaseContext sourceDatabaseContext, BibDatabaseContext targetDatabaseContext) {
List<BibEntry> selectedEntries = stateManager.getSelectedEntries();

targetDatabaseContext.getDatabase().insertEntries(selectedEntries);
importHandler.importEntriesWithDuplicateCheck(targetDatabaseContext, selectedEntries);
}

private boolean askForCrossReferencedEntries() {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ public void importEntries(List<BibEntry> entries) {
}

public void importCleanedEntries(List<BibEntry> entries) {
dialogService.notify("cleaned" + bibDatabaseContext.getDatabasePath().toString());
bibDatabaseContext.getDatabase().insertEntries(entries);
generateKeys(entries);
setAutomaticFields(entries);
addToGroups(entries, stateManager.getSelectedGroups(bibDatabaseContext));
}

public void importCleanedEntries(BibDatabaseContext bibDatabaseContext, List<BibEntry> entries) {
bibDatabaseContext.getDatabase().insertEntries(entries);
generateKeys(entries);
setAutomaticFields(entries);
Expand All @@ -239,7 +247,7 @@ private void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext
}
finalEntry = duplicateHandledEntry.get();
}
importCleanedEntries(List.of(finalEntry));
importCleanedEntries(bibDatabaseContext, List.of(finalEntry));
downloadLinkedFiles(finalEntry);
BibEntry entryToFocus = finalEntry;
stateManager.activeTabProperty().get().ifPresent(tab -> tab.clearAndSelect(entryToFocus));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public MainTable(MainTableDataModel model,
clipBoardManager,
taskExecutor,
Injector.instantiateModelOrService(JournalAbbreviationRepository.class),
entryTypesManager))
entryTypesManager,
importHandler))
.withPseudoClass(MATCHING_SEARCH_AND_GROUPS, entry -> entry.matchCategory().isEqualTo(MatchCategory.MATCHING_SEARCH_AND_GROUPS))
.withPseudoClass(MATCHING_SEARCH_NOT_GROUPS, entry -> entry.matchCategory().isEqualTo(MatchCategory.MATCHING_SEARCH_NOT_GROUPS))
.withPseudoClass(MATCHING_GROUPS_NOT_SEARCH, entry -> entry.matchCategory().isEqualTo(MatchCategory.MATCHING_GROUPS_NOT_SEARCH))
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jabref.gui.edit.CopyTo;
import org.jabref.gui.edit.EditAction;
import org.jabref.gui.exporter.ExportToClipboardAction;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.frame.SendAsKindleEmailAction;
import org.jabref.gui.frame.SendAsStandardEmailAction;
import org.jabref.gui.keyboard.KeyBindingRepository;
Expand Down Expand Up @@ -58,7 +59,8 @@ public static ContextMenu create(BibEntryTableViewModel entry,
ClipBoardManager clipBoardManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository abbreviationRepository,
BibEntryTypesManager entryTypesManager) {
BibEntryTypesManager entryTypesManager,
ImportHandler importHandler) {
ActionFactory factory = new ActionFactory();
ContextMenu contextMenu = new ContextMenu();

Expand All @@ -70,7 +72,7 @@ public static ContextMenu create(BibEntryTableViewModel entry,
contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, () -> libraryTab, stateManager, undoManager)),
createCopySubMenu(factory, dialogService, stateManager, preferences, clipBoardManager, abbreviationRepository, taskExecutor),
createCopyToMenu(factory, dialogService, stateManager, preferences, libraryTab),
createCopyToMenu(factory, dialogService, stateManager, preferences, libraryTab, importHandler),
factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, () -> libraryTab, stateManager, undoManager)),
factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, () -> libraryTab, stateManager, undoManager)),
factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, undoManager, preferences)),
Expand Down Expand Up @@ -117,7 +119,8 @@ private static Menu createCopyToMenu(ActionFactory factory,
DialogService dialogService,
StateManager stateManager,
GuiPreferences preferences,
LibraryTab libraryTab
LibraryTab libraryTab,
ImportHandler importHandler
) {
Menu copyToMenu = factory.createMenu(StandardActions.COPY_TO);

Expand Down Expand Up @@ -147,7 +150,7 @@ private static Menu createCopyToMenu(ActionFactory factory,
copyToMenu.getItems().addAll(
factory.createCustomMenuItem(
StandardActions.COPY_TO,
new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), libraryTab, sourceDatabaseContext, bibDatabaseContext),
new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), libraryTab, importHandler, sourceDatabaseContext, bibDatabaseContext),
destinationDatabaseName
)
);
Expand Down

0 comments on commit 4cab5de

Please sign in to comment.