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

Fix for delete entries should ask user #10591

Merged
merged 59 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
42cf53d
Implemented the feature that deleting files which linked to selected …
shawn-jj Oct 27, 2023
4bfc322
Merge branch 'main' of https://github.com/shawn-jj/jabref into fix-fo…
shawn-jj Oct 27, 2023
0435c91
The following features are implemented: 1.Initializes a pop-up dialog…
shawn-jj Oct 27, 2023
898c2b2
update CHANGELOG.md
shawn-jj Oct 27, 2023
482c24b
Add language keys to english language file
shawn-jj Oct 28, 2023
799c693
restore files in src/main/resources/csl-locales and src/main/resource…
shawn-jj Oct 28, 2023
13d9d38
Merge branch 'JabRef:main' into fix-for-issue-10509
shawn-jj Oct 28, 2023
7368fe2
Removed unnecessary comments and finxed some requested changes. Added…
shawn-jj Oct 29, 2023
7e282df
Add language keys to english language file
shawn-jj Oct 29, 2023
8d325ff
Modify language keys to english language file
shawn-jj Oct 29, 2023
1b7e17d
made deleteFileFromDisk method static
shawn-jj Nov 2, 2023
f1d50bb
Merge branch 'main' of https://github.com/shawn-jj/jabref into fix-fo…
shawn-jj Nov 2, 2023
4a4e81f
update comment of method deleteFileFromDisk
shawn-jj Nov 2, 2023
c9d7dd9
fixed coding styles
shawn-jj Nov 3, 2023
eef105a
restored unexpected code changes
shawn-jj Nov 3, 2023
c12cd63
Merge branch 'JabRef:main' into fix-for-issue-10509
shawn-jj Nov 3, 2023
97fa0c9
Merge remote-tracking branch 'upstream/main' into fix-for-issue-10509
Siedlerchr Nov 6, 2023
1a531e7
fix logic
Siedlerchr Nov 6, 2023
7ec812b
try null
Siedlerchr Nov 6, 2023
0652ceb
todo
Siedlerchr Nov 7, 2023
17c6a8f
Unify dialogs that confirmation deleting files
shawn-jj Nov 7, 2023
4119b38
Merge branch 'main' into fix-for-issue-10509
koppor Nov 16, 2023
35a95f2
Merge branch 'JabRef:main' into fix-for-issue-10509
shawn-jj Nov 29, 2023
3364671
Get around LinkedFile in LIbraryTab, Encapsulate LinkedFile into Link…
shawn-jj Nov 29, 2023
055f170
fix style
shawn-jj Nov 29, 2023
7bf040e
restore files
shawn-jj Nov 29, 2023
7324452
Unified the different dialogs when deleting entries, removerd unneces…
shawn-jj Nov 29, 2023
5c319cc
fix csl-styles
shawn-jj Nov 29, 2023
853d0ac
try to fix csl-styles
shawn-jj Nov 30, 2023
b4e770a
try to fix csl-styles again
shawn-jj Nov 30, 2023
db5206d
try to fix csl-styles again 2
shawn-jj Nov 30, 2023
d3f57bf
try to fix csl-styles again 3
shawn-jj Nov 30, 2023
c5d7755
Merge branch 'main' into fix-for-issue-10509
koppor Jan 2, 2024
29b7d6f
Merge branch 'JabRef:main' into fix-for-issue-10509
shawn-jj Jan 3, 2024
92b590c
Update prompts in en.properties
shawn-jj Jan 3, 2024
b5ae963
Merge remote-tracking branch 'upstream/main' into fix-for-issue-10509
koppor Jan 11, 2024
888d191
New features
koppor Jan 11, 2024
dfcbb0b
Merge branch 'main' into fix-for-issue-10509
koppor Jan 11, 2024
cb444e4
Fix architecture tests
koppor Jan 11, 2024
58215e2
Introduce list of files to delete
calixtus Jan 11, 2024
b4b84b6
Merge remote-tracking branch 'shawn-jj/fix-for-issue-10509' into fork…
calixtus Jan 11, 2024
09e1d6c
Streamline 1 vs. many files
koppor Jan 11, 2024
2a49780
Fix openRewrite
koppor Jan 11, 2024
cef7a2c
Merge remote-tracking branch 'upstream/main' into fix-for-issue-10509
koppor Jan 16, 2024
d9ccf84
Discard changes to src/test/resources/org/jabref/logic/search/test-li…
koppor Jan 16, 2024
65b63d9
Merge remote-tracking branch 'origin/main' into fix-for-issue-10509
koppor Jan 24, 2024
6c2ebc5
Adapt true/false logic according to expectations
koppor Jan 24, 2024
250e168
Add "Trash" to CHANGELOG.md
koppor Jan 24, 2024
f62fa7e
Fix localization
koppor Jan 24, 2024
9c9760c
Merge branch 'main' into fix-for-issue-10509
koppor Feb 6, 2024
e065dfe
Merge remote-tracking branch 'upstream/main' into fix-for-issue-10509
koppor Feb 18, 2024
74ee156
Fix JabRef_en.properties
koppor Feb 18, 2024
77bb7a0
Add some debug statements
koppor Feb 18, 2024
eee769c
Fix preferences
koppor Feb 18, 2024
1f13409
Separate log entries by empty line
koppor Feb 18, 2024
84f94d1
More refined dialog
koppor Feb 18, 2024
f6d413a
Merge remote-tracking branch 'upstream/main' into fix-for-issue-10509
koppor Feb 18, 2024
e06a631
Merge branch 'main' into fix-for-issue-10509
koppor Feb 19, 2024
cef4f9c
Merge remote-tracking branch 'upstream/main' into fix-for-issue-10509
Siedlerchr Feb 26, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a popup, as well as a preferences setting item, so users can choose whether to delete files linked to selected entries when they delete entries. [#10509](https://github.com/JabRef/jabref/issues/10509)
- We added a dropdown menu to let users change the reference library during AUX file import. [#10472](https://github.com/JabRef/jabref/issues/10472)
- We added a button to let users reset the cite command to the default value. [#10569](https://github.com/JabRef/jabref/issues/10569)

Expand Down
69 changes: 66 additions & 3 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jabref.gui.dialogs.AutosaveUiManager;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.gui.linkedfile.DeleteFileAction;
import org.jabref.gui.maintable.BibEntryTableViewModel;
import org.jabref.gui.maintable.MainTable;
import org.jabref.gui.maintable.MainTableDataModel;
Expand Down Expand Up @@ -419,7 +420,7 @@ public JabRefFrame frame() {
}

/**
* Removes the selected entries from the database
* Removes the selected entries and files linked to selected entries from the database
*
* @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized as "deleted". If true the action will be localized as "cut"
*/
Expand All @@ -428,7 +429,7 @@ public void delete(boolean cut) {
}

/**
* Removes the selected entries from the database
* Removes the selected entries and files linked to selected entries from the database
*
* @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized as "deleted". If true the action will be localized as "cut"
*/
Expand All @@ -440,8 +441,26 @@ private void delete(boolean cut, List<BibEntry> entries) {
return;
}

// Delete selected entries
getUndoManager().addEdit(new UndoableRemoveEntries(bibDatabaseContext.getDatabase(), entries, cut));
bibDatabaseContext.getDatabase().removeEntries(entries);

// Not delete files when user select cut
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
if (!cut) {
// Keep track of linked files from selected entries
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
List<LinkedFile> linkedFileList = new ArrayList<>();

for (BibEntry entry : entries) {
List<LinkedFile> linkedFilesFromEntry = entry.getFiles();
linkedFileList.addAll(linkedFilesFromEntry);
}
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved

// Delete files which linked to selected entries when user select deletion
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
if (linkedFileList.size() > 0 && showLinkedFileDeleteConfirmationDialog(linkedFileList)) {
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
new DeleteFileAction(dialogService, preferencesService, bibDatabaseContext, null, null).deleteFileFromDisk(linkedFileList);
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
}
}

ensureNotShowingBottomPanel(entries);

this.changedProperty.setValue(true);
Expand Down Expand Up @@ -679,6 +698,14 @@ public BibDatabase getDatabase() {
return bibDatabaseContext.getDatabase();
}

/**
* Initializes a pop-up dialog box to confirm whether the user wants to delete the selected entry
* Keep track of user preference:
* if the user prefers not to ask before deleting, delete the selected entry without displaying the dialog box
*
* @param numberOfEntries number of entries user is selecting
* @return true if user confirm to delete entry
*/
private boolean showDeleteConfirmationDialog(int numberOfEntries) {
if (preferencesService.getWorkspacePreferences().shouldConfirmDelete()) {
String title = Localization.lang("Delete entry");
Expand All @@ -692,7 +719,8 @@ private boolean showDeleteConfirmationDialog(int numberOfEntries) {
cancelButton = Localization.lang("Keep entries");
}

return dialogService.showConfirmationDialogWithOptOutAndWait(title,
return dialogService.showConfirmationDialogWithOptOutAndWait(
title,
message,
okButton,
cancelButton,
Expand All @@ -703,6 +731,41 @@ private boolean showDeleteConfirmationDialog(int numberOfEntries) {
}
}

/**
* Initializes a pop-up dialog box to confirm whether the user wants to delete attached files from selected entry
* Keep track of user preference:
* if the user prefers always delete attached files, delete the files without displaying the dialog box
*
* @param linkedFileList A list of LinkedFile to be deleted
* @return true if user confirm to delete attached files
*/
private boolean showLinkedFileDeleteConfirmationDialog(List<LinkedFile> linkedFileList) {
if (preferencesService.getFilePreferences().alwaysDeleteLinkedFile()) {
return true;
} else {
Optional<Path> file = linkedFileList.get(0).findIn(bibDatabaseContext, preferencesService.getFilePreferences());

String title = Localization.lang("Delete attached file");
String message = Localization.lang("Delete '%0'", file.get().getFileName().toString());
String okButton = Localization.lang("Delete attached file");
String cancelButton = Localization.lang("Keep attached file");
if (linkedFileList.size() > 1) {
title = Localization.lang("Delete attached files");
message = Localization.lang("Delete %0 attached files", linkedFileList.size());
okButton = Localization.lang("Delete attached files");
cancelButton = Localization.lang("Keep attached files");
}
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved

return dialogService.showConfirmationDialogWithOptOutAndWait(
title,
message,
okButton,
cancelButton,
Localization.lang("Always delete attached file(s)"),
optOut -> preferencesService.getFilePreferences().setAlwaysDeleteLinkedFile(optOut));
}
}

/**
* Depending on whether a preview or an entry editor is showing, save the current divider location in the correct preference setting.
*/
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/gui/linkedfile/DeleteFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,26 @@ private void deleteFiles(List<LinkedFileViewModel> toBeDeleted, boolean deleteFr
*/
public void deleteFileFromDisk(LinkedFileViewModel fileViewModel) {
LinkedFile linkedFile = fileViewModel.getFile();
deleteFileHelper(linkedFile);
}

/**
* Deletes files from disk without asking the user for confirmation, for a list of files
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
*
* @param filesLinkedToEntry A list of LinkedFile to be deleted
*/
public void deleteFileFromDisk(List<LinkedFile> filesLinkedToEntry) {
for (LinkedFile linkedFile : filesLinkedToEntry) {
deleteFileHelper(linkedFile);
}
}

/**
* Helper method to delete the specified file from disk
*
* @param linkedFile The LinkedFile (file which linked to an entry) to be deleted from disk
*/
private void deleteFileHelper(LinkedFile linkedFile) {
Optional<Path> file = linkedFile.findIn(databaseContext, preferences.getFilePreferences());

if (file.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@
<TextField fx:id="fileDirectoryPattern" GridPane.columnIndex="1" GridPane.rowIndex="1"
prefWidth="300" minWidth="300" maxWidth="300"/>
</GridPane>

<Label styleClass="sectionHeader" text="%Attached files"/>
<CheckBox fx:id="confirmLinkedFileDelete" text="%Always delete attached file(s)"/>

</fx:root>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class LinkedFilesTab extends AbstractPreferenceTabView<LinkedFilesTabView

@FXML private ComboBox<String> fileNamePattern;
@FXML private TextField fileDirectoryPattern;
@FXML private CheckBox confirmLinkedFileDelete;

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

Expand Down Expand Up @@ -69,6 +70,7 @@ public void initialize() {
fileNamePattern.valueProperty().bindBidirectional(viewModel.fileNamePatternProperty());
fileNamePattern.itemsProperty().bind(viewModel.defaultFileNamePatternsProperty());
fileDirectoryPattern.textProperty().bindBidirectional(viewModel.fileDirectoryPatternProperty());
confirmLinkedFileDelete.selectedProperty().bindBidirectional(viewModel.confirmLinkedFileDeleteProperty());

ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs());
actionFactory.configureIconButton(StandardActions.HELP_REGEX_SEARCH, new HelpAction(HelpFile.REGEX_SEARCH, dialogService, preferencesService.getFilePreferences()), autolinkRegexHelp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class LinkedFilesTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty fulltextIndex = new SimpleBooleanProperty();
private final StringProperty fileNamePatternProperty = new SimpleStringProperty();
private final StringProperty fileDirectoryPatternProperty = new SimpleStringProperty();
private final BooleanProperty confirmLinkedFileDeleteProperty = new SimpleBooleanProperty();

private final Validator mainFileDirValidator;

Expand Down Expand Up @@ -80,6 +81,7 @@ public void setValues() {
fulltextIndex.setValue(filePreferences.shouldFulltextIndexLinkedFiles());
fileNamePatternProperty.setValue(filePreferences.getFileNamePattern());
fileDirectoryPatternProperty.setValue(filePreferences.getFileDirectoryPattern());
confirmLinkedFileDeleteProperty.setValue(filePreferences.alwaysDeleteLinkedFile());

// Autolink preferences
switch (autoLinkPreferences.getCitationKeyDependency()) {
Expand Down Expand Up @@ -110,6 +112,7 @@ public void storeSettings() {
}

autoLinkPreferences.setRegularExpression(autolinkRegexKeyProperty.getValue());
filePreferences.setAlwaysDeleteLinkedFile(confirmLinkedFileDeleteProperty.getValue());
}

ValidationStatus mainFileDirValidationStatus() {
Expand Down Expand Up @@ -178,5 +181,9 @@ public StringProperty fileDirectoryPatternProperty() {
public BooleanProperty useMainFileDirectoryProperty() {
return useMainFileDirectoryProperty;
}

public BooleanProperty confirmLinkedFileDeleteProperty() {
return this.confirmLinkedFileDeleteProperty;
}
}

17 changes: 16 additions & 1 deletion src/main/java/org/jabref/preferences/FilePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class FilePreferences {
private final ObservableSet<ExternalFileType> externalFileTypes = FXCollections.observableSet(new TreeSet<>(Comparator.comparing(ExternalFileType::getName)));
private final BooleanProperty createBackup = new SimpleBooleanProperty();
private final ObjectProperty<Path> backupDirectory = new SimpleObjectProperty<>();
private final BooleanProperty confirmDeleteLinkedFile;

public FilePreferences(String userAndHost,
String mainFileDirectory,
Expand All @@ -47,7 +48,8 @@ public FilePreferences(String userAndHost,
Path workingDirectory,
Set<ExternalFileType> externalFileTypes,
boolean createBackup,
Path backupDirectory) {
Path backupDirectory,
boolean confirmDeleteLinkedFile) {
this.userAndHost.setValue(userAndHost);
this.mainFileDirectory.setValue(mainFileDirectory);
this.storeFilesRelativeToBibFile.setValue(storeFilesRelativeToBibFile);
Expand All @@ -59,6 +61,7 @@ public FilePreferences(String userAndHost,
this.externalFileTypes.addAll(externalFileTypes);
this.createBackup.setValue(createBackup);
this.backupDirectory.setValue(backupDirectory);
this.confirmDeleteLinkedFile = new SimpleBooleanProperty(confirmDeleteLinkedFile);
}

public String getUserAndHost() {
Expand Down Expand Up @@ -180,4 +183,16 @@ public void setBackupDirectory(Path backupPath) {
public Path getBackupDirectory() {
return this.backupDirectory.getValue();
}

public boolean alwaysDeleteLinkedFile() {
return confirmDeleteLinkedFile.get();
}

public BooleanProperty alwaysDeleteLinkedFileProperty() {
return confirmDeleteLinkedFile;
}

public void setAlwaysDeleteLinkedFile(boolean confirmLinkedFileDelete) {
this.confirmDeleteLinkedFile.set(confirmLinkedFileDelete);
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String DEFAULT_CITATION_KEY_PATTERN = "defaultBibtexKeyPattern";
public static final String UNWANTED_CITATION_KEY_CHARACTERS = "defaultUnwantedBibtexKeyCharacters";
public static final String CONFIRM_DELETE = "confirmDelete";
public static final String CONFIRM_LINKED_FILE_DELETE = "confirmLinkedFileDelete";
public static final String WARN_BEFORE_OVERWRITING_KEY = "warnBeforeOverwritingKey";
public static final String AVOID_OVERWRITING_KEY = "avoidOverwritingKey";
public static final String AUTOLINK_EXACT_KEY_ONLY = "autolinkExactKeyOnly";
Expand Down Expand Up @@ -683,6 +684,7 @@ private JabRefPreferences() {
defaults.put(AVOID_OVERWRITING_KEY, Boolean.FALSE);
defaults.put(WARN_BEFORE_OVERWRITING_KEY, Boolean.TRUE);
defaults.put(CONFIRM_DELETE, Boolean.TRUE);
defaults.put(CONFIRM_LINKED_FILE_DELETE, Boolean.FALSE);
defaults.put(DEFAULT_CITATION_KEY_PATTERN, "[auth][year]");
defaults.put(UNWANTED_CITATION_KEY_CHARACTERS, "-`ʹ:!;?^+");
defaults.put(RESOLVE_STRINGS_FOR_FIELDS, "author;booktitle;editor;editora;editorb;editorc;institution;issuetitle;journal;journalsubtitle;journaltitle;mainsubtitle;month;publisher;shortauthor;shorteditor;subtitle;titleaddon");
Expand Down Expand Up @@ -2160,7 +2162,8 @@ public FilePreferences getFilePreferences() {
ExternalFileTypes.fromString(get(EXTERNAL_FILE_TYPES)),
getBoolean(CREATE_BACKUP),
// We choose the data directory, because a ".bak" file should survive cache cleanups
getPath(BACKUP_DIRECTORY, OS.getNativeDesktop().getBackupDirectory()));
getPath(BACKUP_DIRECTORY, OS.getNativeDesktop().getBackupDirectory()),
getBoolean(CONFIRM_LINKED_FILE_DELETE));

EasyBind.listen(filePreferences.mainFileDirectoryProperty(), (obs, oldValue, newValue) -> put(MAIN_FILE_DIRECTORY, newValue));
EasyBind.listen(filePreferences.storeFilesRelativeToBibFileProperty(), (obs, oldValue, newValue) -> putBoolean(STORE_RELATIVE_TO_BIB, newValue));
Expand All @@ -2173,6 +2176,7 @@ public FilePreferences getFilePreferences() {
put(EXTERNAL_FILE_TYPES, ExternalFileTypes.toStringList(filePreferences.getExternalFileTypes())));
EasyBind.listen(filePreferences.createBackupProperty(), (obs, oldValue, newValue) -> putBoolean(CREATE_BACKUP, newValue));
EasyBind.listen(filePreferences.backupDirectoryProperty(), (obs, oldValue, newValue) -> put(BACKUP_DIRECTORY, newValue.toString()));
EasyBind.listen(filePreferences.alwaysDeleteLinkedFileProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_LINKED_FILE_DELETE, newValue));

return filePreferences;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,14 @@ Found\ match\ in\ %0=Found match in %0
On\ page\ %0=On page %0
Found\ matches\ in\ Annotations\:=Found matches in Annotations:

Attached\ files=Attached files
shawn-jj marked this conversation as resolved.
Show resolved Hide resolved
Always\ delete\ attached\ file(s)=Always delete attached file(s)
Delete\ %0\ attached\ files=Delete %0 attached files
Delete\ attached\ file=Delete attached file
Delete\ attached\ files=Delete attached files
Keep\ attached\ file=Keep attached file
Keep\ attached\ files=Keep attached files

Grobid\ URL=Grobid URL
Remote\ services=Remote services
Allow\ sending\ PDF\ files\ and\ raw\ citation\ strings\ to\ a\ JabRef\ online\ service\ (Grobid)\ to\ determine\ Metadata.\ This\ produces\ better\ results.=Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results.
Expand Down