Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show only one notification when cutting an entry #11724

Merged
merged 7 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the full-text search results were incomplete. [#8626](https://github.com/JabRef/jabref/issues/8626)
- We fixed an issue where search result highlighting was incorrectly highlighting the boolean operators. [#11595](https://github.com/JabRef/jabref/issues/11595)
- We fixed an issue where search result highlighting was broken at complex searches. [#8067](https://github.com/JabRef/jabref/issues/8067)
- We fixed an issue where unescaped braces in the arXiv fetcher were not treated [#11704](https://github.com/JabRef/jabref/issues/11704)
- We fixed an issue where two contradicting notifications were shown when cutting an entry in the main table. [#11724](https://github.com/JabRef/jabref/pull/11724)
- We fixed an issue where unescaped braces in the arXiv fetcher were not treated. [#11704](https://github.com/JabRef/jabref/issues/11704)

### Removed

Expand Down
254 changes: 155 additions & 99 deletions src/main/java/org/jabref/gui/LibraryTab.java

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public void execute() {
// Not sure what is selected -> copy/paste/cut selected entries except for Preview and CodeArea

switch (action) {
case COPY -> tabSupplier.get().copy();
case CUT -> tabSupplier.get().cut();
case PASTE -> tabSupplier.get().paste();
case DELETE_ENTRY -> tabSupplier.get().delete(StandardActions.DELETE_ENTRY);
case COPY -> tabSupplier.get().copyEntry();
case CUT -> tabSupplier.get().cutEntry();
case PASTE -> tabSupplier.get().pasteEntry();
case DELETE_ENTRY -> tabSupplier.get().deleteEntry();
case UNDO -> {
if (undoManager.canUndo()) {
undoManager.undo();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void close() {

@FXML
private void deleteEntry() {
libraryTab.delete(currentlyEditedEntry);
libraryTab.deleteEntry(currentlyEditedEntry);
}

@FXML
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ public void addTab(@NonNull BibDatabaseContext databaseContext, boolean raisePan
this,
dialogService,
prefs,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/importer/NewEntryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public NewEntryAction(Supplier<LibraryTab> tabSupplier, DialogService dialogServ

public NewEntryAction(Supplier<LibraryTab> tabSupplier, EntryType type, DialogService dialogService, PreferencesService preferences, StateManager stateManager) {
this(tabSupplier, dialogService, preferences, stateManager);
this.type = Optional.of(type);
this.type = Optional.ofNullable(type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ private void openTheFile(Path file) {
file,
dialogService,
preferencesService,
aiService,
stateManager,
tabContainer,
fileUpdateMonitor,
Expand Down
88 changes: 3 additions & 85 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.gui.maintable;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -45,17 +44,11 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.importer.FetcherClientException;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.FetcherServerException;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.event.EntriesAddedEvent;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.BibtexString;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

Expand All @@ -74,18 +67,14 @@ public class MainTable extends TableView<BibEntryTableViewModel> {
private static final PseudoClass NOT_MATCHING_SEARCH_AND_GROUPS = PseudoClass.getPseudoClass("not-matching-search-and-groups");

private final LibraryTab libraryTab;
private final DialogService dialogService;
private final StateManager stateManager;
private final BibDatabaseContext database;
private final MainTableDataModel model;

private final ImportHandler importHandler;
private final CustomLocalDragboard localDragboard;
private final ClipBoardManager clipBoardManager;
private final BibEntryTypesManager entryTypesManager;
private final TaskExecutor taskExecutor;
private final UndoManager undoManager;
private final FilePreferences filePreferences;
private final ImportHandler importHandler;
private long lastKeyPressTime;
private String columnSearchTerm;

Expand All @@ -100,31 +89,20 @@ public MainTable(MainTableDataModel model,
ClipBoardManager clipBoardManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
FileUpdateMonitor fileUpdateMonitor) {
ImportHandler importHandler) {
super();

this.libraryTab = libraryTab;
this.dialogService = dialogService;
this.stateManager = stateManager;
this.database = Objects.requireNonNull(database);
this.model = model;
this.clipBoardManager = clipBoardManager;
this.entryTypesManager = entryTypesManager;
this.taskExecutor = taskExecutor;
this.undoManager = libraryTab.getUndoManager();
this.filePreferences = preferencesService.getFilePreferences();
this.importHandler = importHandler;

MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences();

importHandler = new ImportHandler(
database,
preferencesService,
fileUpdateMonitor,
undoManager,
stateManager,
dialogService,
taskExecutor);

localDragboard = stateManager.getLocalDragboard();

this.setOnDragOver(this::handleOnDragOverTableView);
Expand Down Expand Up @@ -272,29 +250,6 @@ public void clearAndSelect(BibEntry bibEntry) {
});
}

public void copy() {
List<BibEntry> selectedEntries = getSelectedEntries();

if (!selectedEntries.isEmpty()) {
List<BibtexString> stringConstants = getUsedStringValues(selectedEntries);
try {
if (stringConstants.isEmpty()) {
clipBoardManager.setContent(selectedEntries, entryTypesManager);
} else {
clipBoardManager.setContent(selectedEntries, entryTypesManager, stringConstants);
}
dialogService.notify(Localization.lang("Copied %0 entry(ies)", selectedEntries.size()));
} catch (IOException e) {
LOGGER.error("Error while copying selected entries to clipboard.", e);
}
}
}

public void cut() {
copy();
libraryTab.delete(StandardActions.CUT);
}

private void scrollToNextMatchCategory() {
BibEntryTableViewModel selectedEntry = getSelectionModel().getSelectedItem();
if (selectedEntry == null) {
Expand Down Expand Up @@ -403,39 +358,6 @@ private void clearAndSelectLast() {
scrollTo(getItems().size() - 1);
}

public void paste() {
List<BibEntry> entriesToAdd;
String content = ClipBoardManager.getContents();
entriesToAdd = importHandler.handleBibTeXData(content);
if (entriesToAdd.isEmpty()) {
entriesToAdd = handleNonBibTeXStringData(content);
}
if (entriesToAdd.isEmpty()) {
return;
}

importHandler.importEntriesWithDuplicateCheck(database, entriesToAdd);
}

private List<BibEntry> handleNonBibTeXStringData(String data) {
try {
return this.importHandler.handleStringData(data);
} catch (FetcherException exception) {
if (exception instanceof FetcherClientException) {
dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("No data was found for the identifier"));
} else if (exception instanceof FetcherServerException) {
dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("Server not available"));
} else {
dialogService.showErrorDialogAndWait(exception);
}
return List.of();
}
}

public void dropEntry(List<BibEntry> entriesToAdd) {
importHandler.importEntriesWithDuplicateCheck(database, entriesToAdd);
}

private void handleOnDragOver(TableRow<BibEntryTableViewModel> row, BibEntryTableViewModel item, DragEvent event) {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.ANY);
Expand Down Expand Up @@ -558,8 +480,4 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
.filter(viewModel -> viewModel.getEntry().equals(entry))
.findFirst();
}

private List<BibtexString> getUsedStringValues(List<BibEntry> entries) {
return database.getDatabase().getUsedStrings(entries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ private void exportEntries() {
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ public LibraryTab openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnecti
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,9 @@ Ask\ every\ time=Ask every time

Value\ is\ not\ in\ Unicode's\ Normalization\ Form\ "Canonical\ Composition"\ (NFC)\ format=Value is not in Unicode's Normalization Form "Canonical Composition" (NFC) format

Copy\ failed=Copy failed
Cut\ failed=Cut failed

Group\ icons=Group icons
Redownload\ file=Redownload file
Redownload\ missing\ files=Redownload missing files
Expand Down
Loading