-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add context menu for multi-file entries (#12567) #13726
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
Open
w0nderfu11
wants to merge
57
commits into
JabRef:main
Choose a base branch
from
w0nderfu11:feat/multi-file-context-menu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
7f72e38
Add context menu for multi-file entries (#12567)
w0nderfu11 5c3fc14
Apply OpenRewrite recipes
w0nderfu11 740cc4a
Fixed test and optimized imports
w0nderfu11 afa12f1
merge for problems with lib
w0nderfu11 02797f7
fixed library and space in catch block
w0nderfu11 8924487
Runned rewrite, fixed catch block and optimize logic of test ContextM…
w0nderfu11 f3f91e7
Fix tests: initialize JavaFX toolkit; replace empty catch with meanin…
w0nderfu11 e6ef784
Fix tests: added space after {
w0nderfu11 f31fd86
Trigger CI
w0nderfu11 650bd9e
Trigger CI
w0nderfu11 8d86798
Update jabgui/src/test/java/org/jabref/gui/copyfiles/CopyMultipleFile…
w0nderfu11 181587a
refactor(gui/contextmenu): restore Strategy pattern for linked files …
w0nderfu11 665b069
feat(gui): multi-file context menu for linked files
w0nderfu11 d100fba
merge: origin/feat/multi-file-context-menu into feat/multi-file-conte…
w0nderfu11 56bccb1
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 a926f87
Merge branch 'main' into feat/multi-file-context-menu
Siedlerchr ccc2863
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 7adefe6
Address review: Optional/map, non-null params, logger, tests, menus
w0nderfu11 60e9c86
Merge branch 'feat/multi-file-context-menu' of https://github.com/w0n…
w0nderfu11 a99821d
fixed tests
w0nderfu11 a9b9e4f
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 ed78f30
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 a429df9
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 d1933c2
Update jabgui/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAc…
w0nderfu11 8c6387d
Update jabgui/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAc…
w0nderfu11 259e37c
wip: local changes before style sync
w0nderfu11 44f084b
Fix styles
calixtus a9f21ae
Merge remote-tracking branch 'upstream/main' into fork/w0nderfu11/fea…
calixtus 79dec90
Final style and CI checks
w0nderfu11 7d5b3c6
docs: sync http-server howto; jablib: sync jspecify @Nullable from up…
w0nderfu11 514232c
Naming convention
calixtus e3eb1df
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 31af228
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 0832ba0
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 ace2a3c
feat(gui): multi-file context menu for linked files (sync on upstream…
w0nderfu11 d36dbac
sync of branches
w0nderfu11 d245346
Fix LOGGER naming (convension)
w0nderfu11 791caba
fixed submodules
w0nderfu11 88702c8
Fix submodules
w0nderfu11 19c71d4
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 668eedb
chore: reset submodules to upstream/main (csl-styles, csl-locales)
w0nderfu11 374d697
Fix submodules
w0nderfu11 91bc19a
Fix submodules
w0nderfu11 5b002c9
Merge branch 'main' into feat/multi-file-context-menu
w0nderfu11 f5dbd10
Fix test classes
w0nderfu11 796507f
Merge remote-tracking branch 'origin/feat/multi-file-context-menu' in…
w0nderfu11 b73504a
Fix test classes V2 (forget to update MultiSelectionMenuBuilderTest a…
w0nderfu11 c327bd8
Apply JSpecify annotations
calixtus 8fc6724
Fixed bot's cases and fixed submodules
w0nderfu11 19109fb
Fixed conflict and cases of bot
w0nderfu11 9cac8be
Merge remote-tracking branch 'upstream/main' into fork/w0nderfu11/fea…
calixtus dc7ad22
Fix submodules
calixtus ecbf18a
Migrate to JSpecify annotations
calixtus c2427d1
Fix wording
calixtus 189f823
Changed assert methods for readability
calixtus e281d32
interface ---< class, deleted variable
w0nderfu11 730ddd3
Refactored ContextMenuFactoryTest for readability
calixtus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
jabgui/src/main/java/org/jabref/gui/copyfiles/CopyLinkedFilesAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.jabref.gui.copyfiles; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
|
||
import javafx.beans.Observable; | ||
import javafx.beans.binding.Bindings; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.util.DirectoryDialogConfiguration; | ||
import org.jabref.logic.FilePreferences; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.util.io.FileUtil; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.LinkedFile; | ||
|
||
public class CopyLinkedFilesAction extends SimpleCommand { | ||
|
||
private final List<LinkedFile> linkedFiles; | ||
private final DialogService dialogService; | ||
private final BibDatabaseContext databaseContext; | ||
private final FilePreferences filePreferences; | ||
|
||
private final BiFunction<Path, Path, Path> resolvePathFilename = (dir, file) -> dir.resolve(file.getFileName()); | ||
|
||
public CopyLinkedFilesAction(LinkedFile linkedFile, | ||
DialogService dialogService, | ||
BibDatabaseContext databaseContext, | ||
FilePreferences filePreferences) { | ||
this(List.of(linkedFile), dialogService, databaseContext, filePreferences); | ||
} | ||
|
||
public CopyLinkedFilesAction(Collection<LinkedFile> linkedFiles, | ||
DialogService dialogService, | ||
BibDatabaseContext databaseContext, | ||
FilePreferences filePreferences) { | ||
this.linkedFiles = new ArrayList<>(linkedFiles); | ||
this.dialogService = dialogService; | ||
this.databaseContext = databaseContext; | ||
this.filePreferences = filePreferences; | ||
|
||
this.executable.bind(Bindings.createBooleanBinding( | ||
() -> this.linkedFiles.stream().anyMatch(this::isLocalExisting), | ||
dependencies(this.linkedFiles))); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() | ||
.withInitialDirectory(filePreferences.getWorkingDirectory()) | ||
.build(); | ||
|
||
Optional<Path> exportDir = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); | ||
if (exportDir.isEmpty()) { | ||
return; | ||
} | ||
|
||
int copiedFiles = 0; | ||
int failedCount = 0; | ||
|
||
for (LinkedFile file : linkedFiles) { | ||
Optional<Path> srcOpt = file.findIn(databaseContext, filePreferences); | ||
if (srcOpt.isEmpty()) { | ||
failedCount++; | ||
continue; | ||
} | ||
|
||
Path src = srcOpt.get(); | ||
Path dst = resolvePathFilename.apply(exportDir.get(), src); | ||
|
||
if (FileUtil.copyFile(src, dst, false)) { | ||
copiedFiles++; | ||
} else { | ||
failedCount++; | ||
} | ||
} | ||
|
||
String title = Localization.lang("Copy linked file"); | ||
String target = exportDir.map(Path::toString).orElse(""); | ||
|
||
if (linkedFiles.size() == 1) { | ||
if (copiedFiles == 1) { | ||
dialogService.notify(Localization.lang("Successfully copied %0 file(s) to %1.", copiedFiles, target)); | ||
} else { | ||
dialogService.showErrorDialogAndWait( | ||
title, | ||
Localization.lang("Could not copy file to %0, maybe the file is already existing?", target)); | ||
} | ||
} else { | ||
if (failedCount == 0) { | ||
dialogService.notify(Localization.lang("Successfully copied %0 file(s) to %1.", copiedFiles, target)); | ||
} else { | ||
dialogService.showErrorDialogAndWait( | ||
title, | ||
Localization.lang("Copied %0 file(s). Failed: %1", copiedFiles, failedCount)); | ||
} | ||
} | ||
} | ||
|
||
private boolean isLocalExisting(LinkedFile lf) { | ||
return !lf.isOnlineLink() && lf.findIn(databaseContext, filePreferences).isPresent(); | ||
} | ||
|
||
private static Observable[] dependencies(Collection<LinkedFile> files) { | ||
return files.stream().map(LinkedFile::linkProperty).toArray(Observable[]::new); | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
jabgui/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.