Search in sources :

Example 1 with MoveFilesCleanup

use of org.jabref.logic.cleanup.MoveFilesCleanup in project jabref by JabRef.

the class MoveFileAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    int selected = editor.getSelectedRow();
    if (selected == -1) {
        return;
    }
    FileListEntry entry = editor.getTableModel().getEntry(selected);
    LinkedFile field = entry.toParsedFileField();
    if (field.isOnlineLink()) {
        // TODO: notify that this operation cannot be done on remote links
        return;
    }
    // Get an absolute path representation:
    Optional<Path> fileDir = frame.getCurrentBasePanel().getBibDatabaseContext().getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences());
    if (!fileDir.isPresent()) {
        JOptionPane.showMessageDialog(frame, Localization.lang("File directory is not set or does not exist!"), Localization.lang("Move file"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Check if the current file exists:
    Optional<Path> file = field.findIn(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences());
    if ((file.isPresent()) && Files.exists(file.get())) {
        MoveFilesCleanup moveFiles = new MoveFilesCleanup(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getCleanupPreferences(Globals.journalAbbreviationLoader).getFileDirPattern(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader), field);
        String[] options = { Localization.lang("Move file"), Localization.lang("Cancel") };
        int dialogResult = JOptionPane.showOptionDialog(frame, Localization.lang("Move file to file directory?") + " " + fileDir.get(), Localization.lang("Move file"), JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[0]);
        if (dialogResult == JOptionPane.YES_OPTION) {
            moveFiles.cleanup((eEditor.getEntry()));
        }
    } else {
        // File doesn't exist, so we can't move it.
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not find file '%0'.", entry.getLink()), Localization.lang("File not found"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Path(java.nio.file.Path) LinkedFile(org.jabref.model.entry.LinkedFile) MoveFilesCleanup(org.jabref.logic.cleanup.MoveFilesCleanup) FileListEntry(org.jabref.gui.filelist.FileListEntry)

Aggregations

Path (java.nio.file.Path)1 FileListEntry (org.jabref.gui.filelist.FileListEntry)1 MoveFilesCleanup (org.jabref.logic.cleanup.MoveFilesCleanup)1 LinkedFile (org.jabref.model.entry.LinkedFile)1