-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[WIP] Create PDF file Exporter #2706
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bd508ad
First approach for implementing PDF Exporter
Siedlerchr c9eeefd
Merge remote-tracking branch 'upstream/master' into exportPDF
Siedlerchr 9ef9760
Export linked files
Siedlerchr ce4e1ac
Merge remote-tracking branch 'upstream/master' into exportPDF
Siedlerchr b035eb4
Create new Action for exporting files
Siedlerchr 01b08d9
Merge remote-tracking branch 'upstream/master' into exportPDF
Siedlerchr 3682e21
Move to Tools entry
Siedlerchr c89e6a0
Merge remote-tracking branch 'upstream/master' into exportPDF
Siedlerchr 42b0c62
try around with some background task stuf
Siedlerchr 353a1da
remove compile errro
Siedlerchr 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
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
98 changes: 98 additions & 0 deletions
98
src/main/java/org/jabref/gui/actions/ExportLinkedFilesAction.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,98 @@ | ||
| package org.jabref.gui.actions; | ||
|
|
||
| import java.awt.event.ActionEvent; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.function.BiFunction; | ||
|
|
||
| import javax.swing.AbstractAction; | ||
|
|
||
| import javafx.scene.control.ProgressBar; | ||
|
|
||
| import org.jabref.Globals; | ||
| import org.jabref.JabRefGUI; | ||
| import org.jabref.gui.DialogService; | ||
| import org.jabref.gui.FXDialogService; | ||
| import org.jabref.gui.util.BackgroundTask; | ||
| import org.jabref.gui.util.DefaultTaskExecutor; | ||
| import org.jabref.gui.util.DirectoryDialogConfiguration; | ||
| import org.jabref.gui.util.TaskExecutor; | ||
| import org.jabref.logic.l10n.Localization; | ||
| import org.jabref.logic.util.io.FileUtil; | ||
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.LinkedFile; | ||
| import org.jabref.model.util.FileHelper; | ||
| import org.jabref.model.util.OptionalUtil; | ||
| import org.jabref.preferences.JabRefPreferences; | ||
|
|
||
|
|
||
| public class ExportLinkedFilesAction extends AbstractAction { | ||
|
|
||
| private final TaskExecutor taskExecutor = Globals.taskExecutor; | ||
|
|
||
| public ExportLinkedFilesAction() { | ||
| super(Localization.lang("Export linked files")); | ||
| } | ||
|
|
||
| @Override | ||
| public void actionPerformed(ActionEvent e) { | ||
|
|
||
| DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() | ||
| .withInitialDirectory( | ||
| Paths.get(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) | ||
| .build(); | ||
| List<BibEntry> entries = JabRefGUI.getMainFrame().getCurrentBasePanel().getSelectedEntries(); | ||
|
|
||
| DialogService ds = new FXDialogService(); | ||
| Optional<Path> path = DefaultTaskExecutor | ||
| .runInJavaFXThread(() -> ds.showDirectorySelectionDialog(dirDialogConfiguration)); | ||
|
|
||
| BibDatabaseContext databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext(); | ||
|
|
||
| System.out.println("Files count " + entries.stream().flatMap(entry -> entry.getFiles().stream()).count()); | ||
|
|
||
|
|
||
| int counter = 0; | ||
| BackgroundTask<Void> task = BackgroundTask.wrap(() -> { | ||
|
|
||
|
|
||
| for (BibEntry entry : entries) { | ||
|
|
||
| List<LinkedFile> files = entry.getFiles(); | ||
| for (LinkedFile fileEntry : files) { | ||
|
|
||
| String fileName = fileEntry.getLink(); | ||
|
|
||
| Optional<Path> fileToExport = FileHelper.expandFilename(fileName, | ||
| databaseContext.getFileDirectories(Globals.prefs.getFileDirectoryPreferences())); | ||
|
|
||
| Optional<Path> newPath = OptionalUtil.combine(path, fileToExport, resolvePathFilename); | ||
|
|
||
| newPath.ifPresent(newFile -> { | ||
| System.out.println(newFile); | ||
| FileUtil.copyFile(fileToExport.get(), newFile, false); | ||
|
|
||
| }); | ||
|
|
||
| } | ||
| } | ||
| return null; | ||
| }); | ||
|
|
||
| System.out.println("Final counter " + counter); | ||
|
|
||
|
|
||
| ProgressBar bar = new ProgressBar(); | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| BiFunction<Path, Path, Path> resolvePathFilename = (p, f) -> { | ||
| return p.resolve(f.getFileName()); | ||
| }; | ||
|
|
||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer these export methods that take the file as a
Pathinstead of string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wanted to use it, too. However, the method with that signature never gets called which led to an NPE.
In ExportAction only the one with String is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change
ExpoortActionthen? For now thePathmethod can be implemented asdefaultand invoking the stringy one.