use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.
the class ArgumentProcessor method importPreferences.
private void importPreferences() {
try {
Globals.prefs.importPreferences(cli.getPreferencesImport());
EntryTypes.loadCustomEntryTypes(Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
}
}
use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.
the class DroppedFileHandler method showLinkMoveCopyRenameDialog.
//
// @return true if user pushed "OK", false otherwise
//
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {
String dialogTitle = Localization.lang("Link to file %0", linkFileName);
Optional<Path> dir = panel.getBibDatabaseContext().getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences());
if (!dir.isPresent()) {
destDirLabel.setText(Localization.lang("File directory is not set or does not exist!"));
copyRadioButton.setEnabled(false);
moveRadioButton.setEnabled(false);
renameToTextBox.setEnabled(false);
renameCheckBox.setEnabled(false);
linkInPlace.setSelected(true);
} else {
destDirLabel.setText(Localization.lang("File directory is '%0':", dir.get().toString()));
copyRadioButton.setEnabled(true);
moveRadioButton.setEnabled(true);
renameToTextBox.setEnabled(true);
renameCheckBox.setEnabled(true);
}
ChangeListener cl = arg0 -> {
renameCheckBox.setEnabled(!linkInPlace.isSelected());
renameToTextBox.setEnabled(!linkInPlace.isSelected());
};
linkInPlace.setText(Localization.lang("Leave file in its current directory"));
copyRadioButton.setText(Localization.lang("Copy file to file directory"));
moveRadioButton.setText(Localization.lang("Move file to file directory"));
renameCheckBox.setText(Localization.lang("Rename file to").concat(": "));
LayoutFormatterPreferences layoutPrefs = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
// Determine which name to suggest:
String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN), layoutPrefs);
String fileDirPattern = Globals.prefs.get(JabRefPreferences.IMPORT_FILEDIRPATTERN);
String targetDirName = "";
if (!fileDirPattern.isEmpty()) {
targetDirName = FileUtil.createFileNameFromPattern(database, entry, fileDirPattern, layoutPrefs);
}
if (targetDirName.isEmpty()) {
renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));
} else {
renameToTextBox.setText(targetDirName.concat("/").concat(targetName.concat(".").concat(fileType.getExtension())));
}
linkInPlace.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE));
copyRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY));
moveRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE));
renameCheckBox.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME));
linkInPlace.addChangeListener(cl);
cl.stateChanged(new ChangeEvent(linkInPlace));
try {
Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel };
int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (reply == JOptionPane.OK_OPTION) {
// store user's choice
frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE, linkInPlace.isSelected());
frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY, copyRadioButton.isSelected());
frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE, moveRadioButton.isSelected());
frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME, renameCheckBox.isSelected());
return true;
} else {
return false;
}
} finally {
linkInPlace.removeChangeListener(cl);
}
}
use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.
the class PreferencesDialog method updateAfterPreferenceChanges.
private void updateAfterPreferenceChanges() {
setValues();
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
Globals.prefs.updateEntryEditorTabList();
}
use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.
the class CustomExportList method readPrefs.
private void readPrefs(JabRefPreferences prefs, JournalAbbreviationLoader loader) {
Objects.requireNonNull(prefs);
Objects.requireNonNull(loader);
formats.clear();
list.clear();
int i = 0;
List<String> s;
LayoutFormatterPreferences layoutPreferences = prefs.getLayoutFormatterPreferences(loader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(prefs);
while (!((s = prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) {
Optional<ExportFormat> format = createFormat(s, layoutPreferences, savePreferences);
if (format.isPresent()) {
formats.put(format.get().getConsoleName(), format.get());
list.add(s);
} else {
String customExportFormat = prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i);
LOGGER.error("Error initializing custom export format from string " + customExportFormat);
}
i++;
}
}
use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.
the class RenamePdfCleanupTest method setUp.
@Before
public void setUp() throws Exception {
MetaData metaData = new MetaData();
context = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
context.setDatabaseFile(testFolder.newFile("test.bib"));
fileDirPrefs = mock(FileDirectoryPreferences.class);
//Set Biblocation as Primary Directory, otherwise the tmp folders won't be cleaned up correctly
when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true);
entry = new BibEntry();
entry.setCiteKey("Toot");
layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Aggregations