Skip to content

Commit

Permalink
Finalize code, fix Localization, do some renames
Browse files Browse the repository at this point in the history
Add changelog enty and missing dots in previous entries
  • Loading branch information
Siedlerchr committed Feb 23, 2017
1 parent f8bea50 commit 76884c2
Show file tree
Hide file tree
Showing 22 changed files with 24 additions and 171 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We integrated support for the [paper recommender system Mr.DLib](http://help.jabref.org/en/EntryEditor#related-articles-tab) in a new tab in the entry editor.
- We renamed "database" to "library" to have a real distinction to SQL and NoSQL databases. [#2095](https://github.com/JabRef/jabref/issues/2095)
- Removed the apache.commons.collections library
- The `Move linked files to default file directory`-Cleanup operation respects the `File directory pattern` setting
- We separated the `Move file` and `Rename Pdfs` logic and context menu entries in the `General`-Tab for the Field `file` to improve the semantics

### Fixed
- We fixed an issue where authors with multiple surnames were not presented correctly in the main table. [#2534](https://github.com/JabRef/jabref/issues/2534)
Expand All @@ -43,11 +45,12 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- The field `issue` is now always exported to the corresponding `issue` field in MS-Office XML.
- We fixed an issue with repeated escaping of the %-sign when running the LaTeXCleanup more than once. [#2451](https://github.com/JabRef/jabref/issues/2451)
- We fixed the import of MS-Office XML files, when the `month` field contained an invalid value.
- ArXiV fetcher now checks similarity of entry when using DOI retrieval to avoid false positives [#2575](https://github.com/JabRef/jabref/issues/2575)
- Sciencedirect/Elsevier fetcher is now able to scrape new HTML structure [#2576](https://github.com/JabRef/jabref/issues/2576)
- Fixed the synchronization logic of keywords and special fields and vice versa [#2580](https://github.com/JabRef/jabref/issues/2580)


- ArXiV fetcher now checks similarity of entry when using DOI retrieval to avoid false positives. [#2575](https://github.com/JabRef/jabref/issues/2575)
- Sciencedirect/Elsevier fetcher is now able to scrape new HTML structure. [#2576](https://github.com/JabRef/jabref/issues/2576)
- Fixed the synchronization logic of keywords and special fields and vice versa. [#2580](https://github.com/JabRef/jabref/issues/2580)
- We fixed an issue introduced with Version 3.8.2 where executing the `Rename PDFs`-Cleanup operation moved the files to the file directory. [#2526](https://github.com/JabRef/jabref/issues/2526)
- We fixed an issue where the `Move linked files to default file directory`-Cleanup operation did not move the files to the location of the bib-file. [#2454](https://github.com/JabRef/jabref/issues/2454)
- We fixed an issue where executeing `Move file` on a selected file in the `General`-Tab could overwrite an existing file. [#2385](https://github.com/JabRef/jabref/issues/2358)
### Removed


Expand Down
118 changes: 5 additions & 113 deletions src/main/java/org/jabref/gui/externalfiles/MoveFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.FieldChange;
import org.jabref.model.entry.ParsedFileField;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Action for moving a file that is linked from an entry in JabRef.
*/
public class MoveFileAction extends AbstractAction {

private static final Log LOGGER = LogFactory.getLog(MoveFileAction.class);

private final JabRefFrame frame;
private final EntryEditor eEditor;
private final FileListEditor editor;
Expand All @@ -56,7 +50,6 @@ public void actionPerformed(ActionEvent event) {
}

FileListEntry entry = editor.getTableModel().getEntry(selected);

// Check if the current file exists:
String ln = entry.link;
ParsedFileField field = entry.toParsedFileField();
Expand All @@ -66,14 +59,13 @@ public void actionPerformed(ActionEvent event) {
// TODO: notify that this operation cannot be done on remote links
return;
}
System.out.println("Parsed file Field " + field);
// Get an absolute path representation:
List<String> dirs = frame.getCurrentBasePanel().getBibDatabaseContext()
.getFileDirectories(prefs.getFileDirectoryPreferences());
Optional<Path> fileDir = frame.getCurrentBasePanel().getBibDatabaseContext()
.getFirstExistingFileDir(prefs.getFileDirectoryPreferences());
if (!fileDir.isPresent()) {
JOptionPane.showMessageDialog(frame, Localization.lang("File_directory_is_not_set_or_does_not_exist!"),
JOptionPane.showMessageDialog(frame, Localization.lang("File directory is not set or does not exist!"),
Localization.lang("Move file"), JOptionPane.ERROR_MESSAGE);
return;
}
Expand All @@ -83,122 +75,22 @@ public void actionPerformed(ActionEvent event) {
}

if ((file != null) && Files.exists(file)) {
// Ok, we found the file. Now get a new name:
System.out.println("Cleanup of file " + file);

//Problem: All listed files are cleaned up
MoveFilesCleanup moveFiles = new MoveFilesCleanup(frame.getCurrentBasePanel().getBibDatabaseContext(),
prefs.getFileDirPattern(), prefs.getFileDirectoryPreferences(),
prefs.getLayoutFormatterPreferences(), field);

String[] options = {Localization.lang("Move file"), Localization.lang("Cancel")};

int dialogResult = JOptionPane.showOptionDialog(frame, "Move file to file directory" + fileDir.get(),
"Move",
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) {
List<FieldChange> fieldChanges = moveFiles.cleanup((eEditor.getEntry()));
fieldChanges.stream().findFirst().ifPresent(x -> System.out.println(x.getNewValue()));
}

//myCleanUp.cleanup();
/* File newFile = null;
boolean repeat = true;
while (repeat) {
repeat = false;
String chosenFile;
if (toFileDir) {
// Determine which name to suggest:
String suggName = FileUtil
.createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(),
Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN),
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader))
.concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : "");
CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"),
Localization.lang("Rename to '%0'", suggName),
Globals.prefs.getBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR));
int answer;
// Only ask about renaming file if the file doesn't have the proper name already:
if (suggName.equals(file.getName())) {
answer = JOptionPane.showConfirmDialog(frame, Localization.lang("Move file to file directory?"),
MOVE_RENAME, JOptionPane.YES_NO_OPTION);
} else {
answer = JOptionPane.showConfirmDialog(frame, cbm, MOVE_RENAME, JOptionPane.YES_NO_OPTION);
}
if (answer != JOptionPane.YES_OPTION) {
return;
}
Globals.prefs.putBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR, cbm.isSelected());
StringBuilder sb = new StringBuilder(dirs.get(found));
if (!dirs.get(found).endsWith(File.separator)) {
sb.append(File.separator);
}
if (cbm.isSelected()) {
// Rename:
sb.append(suggName);
} else {
// Do not rename:
sb.append(file.getName());
}
chosenFile = sb.toString();
} else {
Optional<Path> path = new FileDialog(frame, file.getPath()).saveNewFile();
if (path.isPresent()) {
chosenFile = path.get().toString();
} else {
return;
}
}
newFile = new File(chosenFile);
moveFiles.cleanup((eEditor.getEntry()));
}

if ((newFile != null) && !newFile.equals(file)) {
try {
boolean success = file.renameTo(newFile);
if (!success) {
success = FileUtil.copyFile(file.toPath(), newFile.toPath(), true);
}
if (success) {
// Remove the original file:
Files.deleteIfExists(file.toPath());
// Relativise path, if possible.
String canPath = new File(dirs.get(found)).getCanonicalPath();
if (newFile.getCanonicalPath().startsWith(canPath)) {
if ((newFile.getCanonicalPath().length() > canPath.length())
&& (newFile.getCanonicalPath().charAt(canPath.length()) == File.separatorChar)) {
String newLink = newFile.getCanonicalPath().substring(1 + canPath.length());
editor.getTableModel().setEntry(selected,
new FileListEntry(entry.description, newLink, entry.type));
} else {
String newLink = newFile.getCanonicalPath().substring(canPath.length());
editor.getTableModel().setEntry(selected,
new FileListEntry(entry.description, newLink, entry.type));
}
} else {
String newLink = newFile.getCanonicalPath();
editor.getTableModel().setEntry(selected,
new FileListEntry(entry.description, newLink, entry.type));
}
eEditor.updateField(editor);
frame.output(Localization.lang("File moved"));
} else {
JOptionPane.showMessageDialog(frame, Localization.lang("Move file failed"), MOVE_RENAME,
JOptionPane.ERROR_MESSAGE);
}
} catch (SecurityException | IOException ex) {
LOGGER.warn("Could not move file", ex);
JOptionPane.showMessageDialog(frame,
Localization.lang("Could not move file '%0'.", file.getAbsolutePath()) + ex.getMessage(),
MOVE_RENAME, JOptionPane.ERROR_MESSAGE);
}
}*/
} else {
// File doesn't exist, so we can't move it.
JOptionPane.showMessageDialog(frame, Localization.lang("Could not find file '%0'.", entry.link),
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/org/jabref/gui/externalfiles/RenameFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.FieldChange;
import org.jabref.model.entry.ParsedFileField;

public class RenameFileAction extends AbstractAction {
Expand All @@ -48,9 +47,7 @@ public void actionPerformed(ActionEvent e) {
}

FileListEntry entry = editor.getTableModel().getEntry(selected);

ParsedFileField field = entry.toParsedFileField();
System.out.println("Parsed file Field " + field);
// Check if the current file exists:
String ln = entry.link;
boolean httpLink = ln.toLowerCase(Locale.ENGLISH).startsWith("http");
Expand All @@ -63,7 +60,7 @@ public void actionPerformed(ActionEvent e) {
Optional<Path> fileDir = frame.getCurrentBasePanel().getBibDatabaseContext()
.getFirstExistingFileDir(prefs.getFileDirectoryPreferences());
if (!fileDir.isPresent()) {
JOptionPane.showMessageDialog(frame, Localization.lang("File_directory_is_not_set_or_does_not_exist!"),
JOptionPane.showMessageDialog(frame, Localization.lang("File directory is not set or does not exist!"),
Localization.lang("Rename file"), JOptionPane.ERROR_MESSAGE);
return;
}
Expand All @@ -73,25 +70,23 @@ public void actionPerformed(ActionEvent e) {
}

if ((file != null) && Files.exists(file)) {
System.out.println("Cleanup Rename of file " + file);

RenamePdfCleanup pdfCleanup = new RenamePdfCleanup(false,
frame.getCurrentBasePanel().getBibDatabaseContext(), prefs.getFileNamePattern(),
prefs.getLayoutFormatterPreferences(),
prefs.getFileDirectoryPreferences(), field);

String targetFileName = pdfCleanup.getTargetFileName(field, eEditor.getEntry());
System.out.println("TargetFileName " + targetFileName);

String[] options = {Localization.lang("Rename file"), Localization.lang("Cancel")};

int dialogResult = JOptionPane.showOptionDialog(frame, "Rename file to " + targetFileName, "Rename",
int dialogResult = JOptionPane.showOptionDialog(frame,
Localization.lang("Rename file to") + " " + targetFileName,
Localization.lang("Rename file"),
JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[0]);

//indicates Rename pressed
if (dialogResult == JOptionPane.YES_OPTION) {
List<FieldChange> fieldChanges = pdfCleanup.cleanup(eEditor.getEntry());
fieldChanges.stream().findFirst().ifPresent(System.out::println);
pdfCleanup.cleanup(eEditor.getEntry());
}

}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MoveFilesCleanup implements CleanupJob {
private final String fileDirPattern;
private static final Log LOGGER = LogFactory.getLog(MoveFilesCleanup.class);

private ParsedFileField singleFieldCleanup;
private ParsedFileField singleFileFieldCleanup;

public MoveFilesCleanup(BibDatabaseContext databaseContext, String fileDirPattern,
FileDirectoryPreferences fileDirectoryPreferences, LayoutFormatterPreferences layoutPrefs) {
Expand All @@ -50,7 +50,7 @@ public MoveFilesCleanup(BibDatabaseContext databaseContext, String fileDirPatter
ParsedFileField field) {

this(databaseContext, fileDirPattern, fileDirectoryPreferences, prefs);
this.singleFieldCleanup = field;
this.singleFileFieldCleanup = field;
}

@Override
Expand All @@ -73,10 +73,10 @@ public List<FieldChange> cleanup(BibEntry entry) {
List<ParsedFileField> fileList;
List<ParsedFileField> newFileList;

if (singleFieldCleanup != null) {
fileList = Arrays.asList(singleFieldCleanup);

newFileList = typedEntry.getFiles().stream().filter(x -> !x.equals(singleFieldCleanup))
if (singleFileFieldCleanup != null) {
fileList = Arrays.asList(singleFileFieldCleanup);
//Add all other except the current selected file
newFileList = typedEntry.getFiles().stream().filter(name -> !name.equals(singleFileFieldCleanup))
.collect(Collectors.toList());
} else {
newFileList = new ArrayList<>();
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,9 @@ public String getTargetFileName(ParsedFileField flEntry, BibEntry entry) {
StringBuilder targetFileName = new StringBuilder(FileUtil
.createFileNameFromPattern(databaseContext.getDatabase(), entry, fileNamePattern, layoutPrefs)
.trim());

//Add extension to newFilename
targetFileName.append('.').append(FileUtil.getFileExtension(realOldFilename).orElse("pdf"));

return targetFileName.toString();

}

public int getUnsuccessfulRenames() {
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,6 @@ Query_'%0'_with_fetcher_'%1'_did_not_return_any_results.=Forespørgsel_'%0'_med_
Move_file=Flyt_fil
Rename_file=omdøb_fil

File_moved=Fil_flyttet
Move_file_failed=Flytning_af_fil_mislykkedes
Could_not_move_file_'%0'.=Kunne_ikke_flytte_fil_'%0'.
Could_not_find_file_'%0'.=Kunne_ikke_finde_filen_'%0'.
Expand All @@ -1400,7 +1399,6 @@ Show_search_results_in_a_window=Vis_søgeresultater_i_et_vindue
Show_global_search_results_in_a_window=
Search_in_all_open_libraries=
Move_file_to_file_directory?=Flyt_fil_til_filbibliotek?
Rename_to_'%0'=Omdøb_til_'%0'
You_have_changed_the_menu_and_label_font_size.=Du_har_ændret_menu-_og_tekst-skriftstørrelsen.

Library_is_protected._Cannot_save_until_external_changes_have_been_reviewed.=Libraryn_er_beskyttet._Kan_ikke_gemme_før_eksterne_ændringer_er_gennemset.
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,6 @@ Query_'%0'_with_fetcher_'%1'_did_not_return_any_results.=Die_Abfrage_'%0'_mit_de
Move_file=Datei_verschoben
Rename_file=Datei_umbenennen

File_moved=Datei_verschoben
Move_file_failed=Fehler_beim_Verschieben_der_Datei
Could_not_move_file_'%0'.=Datei_'%0'_konnte_nicht_verschoben_werden.
Could_not_find_file_'%0'.=Datei_'%0'_nicht_gefunden.
Expand All @@ -1400,7 +1399,6 @@ Show_search_results_in_a_window=Suchergebnisse_in_einem_Fenster_anzeigen
Show_global_search_results_in_a_window=Globale_Suchergebnisse_in_einem_Fenster_anzeigen
Search_in_all_open_libraries=Suche_in_allen_offenen_Datenbanken
Move_file_to_file_directory?=Datei_in_Dateiverzeichnis_verschieben?
Rename_to_'%0'=Umbenennen_in_'%0'
You_have_changed_the_menu_and_label_font_size.=Sie_haben_die_Schriftgröße_für_Menüs_und_Label_geändert.

Library_is_protected._Cannot_save_until_external_changes_have_been_reviewed.=Die_Datenbank_ist_geschützt._Speichern_nicht_möglich,_bis_externe_Änderungen_geprüft_wurden.
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,6 @@ Query_'%0'_with_fetcher_'%1'_did_not_return_any_results.=Query_'%0'_with_fetcher
Move_file=Move_file
Rename_file=Rename_file

File_moved=File_moved
Move_file_failed=Move_file_failed
Could_not_move_file_'%0'.=Could_not_move_file_'%0'.
Could_not_find_file_'%0'.=Could_not_find_file_'%0'.
Expand All @@ -1400,7 +1399,6 @@ Show_search_results_in_a_window=Show_search_results_in_a_window
Show_global_search_results_in_a_window=Show_global_search_results_in_a_window
Search_in_all_open_libraries=Search_in_all_open_libraries
Move_file_to_file_directory?=Move_file_to_file_directory?
Rename_to_'%0'=Rename_to_'%0'
You_have_changed_the_menu_and_label_font_size.=You_have_changed_the_menu_and_label_font_size.

Library_is_protected._Cannot_save_until_external_changes_have_been_reviewed.=Library_is_protected._Cannot_save_until_external_changes_have_been_reviewed.
Expand Down
Loading

0 comments on commit 76884c2

Please sign in to comment.