Skip to content

Commit

Permalink
Merge branch 'master' into arxivNoCookie
Browse files Browse the repository at this point in the history
* master:
  Fix NPE when closing the last tab (#1783)
  Updated java-string-similarity to 0.16 (#1784)
  Fix Imports
  Move logic to ImportFileFilter
  Some OS didn't show directories when a file type was selected in the import dialog
  GvkFetcher (#1656)
  Add some more Objects.requireNonNull checks
  Fixed startup problem
  Add isPresentLocalBibEntry (#1777)
  Injected LayoutFormatterPreferences in ExportFormat (#1695)
  Added UpdateFieldPreferences (#1773)
  Fix typo
  Optimize imports
  Fix #1771 Show all supported import types as default
  • Loading branch information
Siedlerchr committed Aug 19, 2016
2 parents f691139 + 8b20e69 commit 8428847
Show file tree
Hide file tree
Showing 50 changed files with 625 additions and 450 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1751](https://github.com/JabRef/jabref/issues/1751) Added tooltip to web search button
- [#1758](https://github.com/JabRef/jabref/issues/1758) Added a button to open Database Properties dialog help
- Improve focus of the maintable after a sidepane gets closed (Before it would focus the toolbar or it would focus the wrong entry)
- File open dialogs now use default extensions as primary file filter

### Fixed
- Fixed [#1632](https://github.com/JabRef/jabref/issues/1632): User comments (@Comment) with or without brackets are now kept
Expand Down Expand Up @@ -72,6 +73,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#1716](https://github.com/JabRef/jabref/issues/1716): `@`-Symbols stored in BibTeX fields no longer break the database
- Fixed [#1499](https://github.com/JabRef/jabref/issues/1499): {} braces are now treated correctly in in author/editor
- Fixed [#1531](https://github.com/JabRef/jabref/issues/1531): `\relax` can be used for abbreviation of author names
- Fixed [#1771](https://github.com/JabRef/jabref/issues/1771): Show all supported import types as default


### Removed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependencies {

compile 'org.jsoup:jsoup:1.9.2'
compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'info.debatty:java-string-similarity:0.14'
compile 'info.debatty:java-string-similarity:0.16'

compile 'org.apache.logging.log4j:log4j-jcl:2.6.2'
compile 'org.apache.logging.log4j:log4j-api:2.6.2'
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/net/sf/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
package net.sf.jabref;

import java.net.Authenticator;
import java.util.Map;

import javax.swing.SwingUtilities;

import net.sf.jabref.cli.ArgumentProcessor;
import net.sf.jabref.gui.remote.JabRefMessageHandler;
import net.sf.jabref.logic.CustomEntryTypesManager;
import net.sf.jabref.logic.exporter.ExportFormat;
import net.sf.jabref.logic.exporter.ExportFormats;
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.net.ProxyAuthenticator;
import net.sf.jabref.logic.net.ProxyPreferences;
import net.sf.jabref.logic.net.ProxyRegisterer;
Expand Down Expand Up @@ -74,14 +78,19 @@ private static void start(String[] args) {
// Update which fields should be treated as numeric, based on preferences:
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));

// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();

/* Build list of Import and Export formats */
Globals.IMPORT_FORMAT_READER.resetImportFormats(ImportFormatPreferences.fromPreferences(Globals.prefs),
XMPPreferences.fromPreferences(Globals.prefs));
CustomEntryTypesManager.loadCustomEntryTypes(preferences);
ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));

// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = LayoutFormatterPreferences.fromPreferences(Globals.prefs,
Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);

// Initialize protected terms loader
Globals.protectedTermsLoader = new ProtectedTermsLoader(
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.prefs.BackingStoreException;

Expand All @@ -25,6 +26,7 @@
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.exporter.BibDatabaseWriter;
import net.sf.jabref.logic.exporter.BibtexDatabaseWriter;
import net.sf.jabref.logic.exporter.ExportFormat;
import net.sf.jabref.logic.exporter.ExportFormats;
import net.sf.jabref.logic.exporter.FileSaveSession;
import net.sf.jabref.logic.exporter.IExportFormat;
Expand All @@ -37,6 +39,7 @@
import net.sf.jabref.logic.importer.OutputPrinter;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.logging.JabRefLogger;
import net.sf.jabref.logic.search.DatabaseSearcher;
import net.sf.jabref.logic.search.SearchQuery;
Expand Down Expand Up @@ -390,7 +393,12 @@ private void importPreferences() {
try {
Globals.prefs.importPreferences(cli.getPreferencesImport());
CustomEntryTypesManager.loadCustomEntryTypes(Globals.prefs);
ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = LayoutFormatterPreferences.fromPreferences(Globals.prefs,
Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ExternalFileTypeEntryEditor {
appDir = Globals.prefs.get(JabRefPreferences.FILE_WORKING_DIRECTORY);
}

Optional<Path> path = new FileDialog(fParent, appDir).openDialogAndGetSelectedFile();
Optional<Path> path = new FileDialog(fParent, appDir).showDialogAndGetSelectedFile();
path.ifPresent(applicationDir -> {
if (applicationDir.getParent() != null) {
Globals.prefs.put(JabRefPreferences.FILE_WORKING_DIRECTORY, applicationDir.getParent().toString());
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ public void update() {
tidialog.setVisible(true);

if (tidialog.okPressed()) {
UpdateField.setAutomaticFields(Collections.singletonList(bibEntry), false, false, Globals.prefs);
UpdateField.setAutomaticFields(Collections.singletonList(bibEntry), false, false,
Globals.prefs.getUpdateFieldPreferences());
insertEntry(bibEntry);
}
});
Expand Down Expand Up @@ -832,8 +833,7 @@ private void paste() {
if (firstBE == null) {
firstBE = be;
}
UpdateField.setAutomaticFields(be, Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_OWNER),
Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_TIME_STAMP), Globals.prefs);
UpdateField.setAutomaticFields(be, Globals.prefs.getUpdateFieldPreferences());

// We have to clone the
// entries, since the pasted
Expand Down Expand Up @@ -1155,7 +1155,7 @@ public BibEntry newEntry(EntryType type) {
// Set owner/timestamp if options are enabled:
List<BibEntry> list = new ArrayList<>();
list.add(be);
UpdateField.setAutomaticFields(list, true, true, Globals.prefs);
UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());

// Create an UndoableInsertEntry object.
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this));
Expand Down Expand Up @@ -1308,7 +1308,7 @@ public void insertEntry(final BibEntry bibEntry) {
bibDatabaseContext.getDatabase().insertEntry(bibEntry);
if (Globals.prefs.getBoolean(JabRefPreferences.USE_OWNER)) {
// Set owner field to default value
UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs);
UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs.getUpdateFieldPreferences());
}
// Create an UndoableInsertEntry object.
getUndoManager()
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/net/sf/jabref/gui/FileDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -16,6 +15,7 @@
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import net.sf.jabref.Globals;
Expand Down Expand Up @@ -57,7 +57,6 @@ public void approveSelection() {

private final JFrame parent;
private final String directory;
private List<FileNameExtensionFilter> fileFilters = new ArrayList<>();
private Collection<FileExtensions> extensions = EnumSet.noneOf(FileExtensions.class);

/**
Expand Down Expand Up @@ -111,7 +110,6 @@ public FileDialog withExtensions(Collection<FileExtensions> fileExtensions) {
for (FileExtensions ext : fileExtensions) {
FileNameExtensionFilter extFilter = new FileNameExtensionFilter(ext.getDescription(), ext.getExtensions());
fileChooser.addChoosableFileFilter(extFilter);
fileFilters.add(extFilter);
}

return this;
Expand All @@ -130,6 +128,25 @@ public void setDefaultExtension(FileExtensions extension) {
.ifPresent(fileChooser::setFileFilter);
}

/**
* Returns the currently selected file filter.
*
* @return FileFilter
*/
public FileFilter getFileFilter() {
return fileChooser.getFileFilter();
}

/**
* Sets a custom file filter.
* Only use when withExtension() does not suffice.
*
* @param filter the custom file filter
*/
public void setFileFilter(FileFilter filter) {
fileChooser.setFileFilter(filter);
}

/**
* Updates the working directory preference
* @return FileDialog
Expand Down Expand Up @@ -161,7 +178,7 @@ public List<String> showDialogAndGetMultipleFiles() {
* Shows an {@link JFileChooser#OPEN_DIALOG} and allows to select a single file/folder
* @return The path of the selected file/folder or {@link Optional#empty()} if dialog is aborted
*/
public Optional<Path> openDialogAndGetSelectedFile() {
public Optional<Path> showDialogAndGetSelectedFile() {
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

if (showDialogAndIsAccepted()) {
Expand Down Expand Up @@ -198,5 +215,4 @@ private boolean showDialogAndIsAccepted() {
private static String getWorkingDir() {
return Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY);
}

}
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/FileListEntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public boolean okPressed() {
workingDir = Globals.prefs.get(JabRefPreferences.FILE_WORKING_DIRECTORY);
}

Optional<Path> path = new FileDialog(this.frame, workingDir).openDialogAndGetSelectedFile();
Optional<Path> path = new FileDialog(this.frame, workingDir).showDialogAndGetSelectedFile();

path.ifPresent(selection -> {

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/net/sf/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ public synchronized void show(String name) {

public synchronized void hide(String name) {
SidePaneComponent sidePaneComponent = components.get(name);
MainTable mainTable = frame.getCurrentBasePanel().getMainTable();
if (sidePaneComponent == null) {
LOGGER.warn("Side pane component '" + name + "' unknown.");
} else {
hideComponent(sidePaneComponent);
mainTable.setSelected(mainTable.getSelectedRow());
mainTable.requestFocus();
if (frame.getCurrentBasePanel() != null) {
MainTable mainTable = frame.getCurrentBasePanel().getMainTable();
mainTable.setSelected(mainTable.getSelectedRow());
mainTable.requestFocus();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/actions/BrowseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public void actionPerformed(ActionEvent e) {
private String askUser() {
if (dirsOnly) {
Path path = new FileDialog(frame, comp.getText()).dirsOnly().withExtensions(extensions)
.openDialogAndGetSelectedFile().orElse(Paths.get(""));
.showDialogAndGetSelectedFile().orElse(Paths.get(""));
String file = path.toString();

return file;
} else {
Path path = new FileDialog(frame, comp.getText()).withExtensions(extensions)
.openDialogAndGetSelectedFile().orElse(Paths.get(""));
.showDialogAndGetSelectedFile().orElse(Paths.get(""));
String file = path.toString();

return file;
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/net/sf/jabref/gui/exporter/ExportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.MnemonicAwareAction;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.exporter.ExportFormat;
import net.sf.jabref.logic.exporter.ExportFormats;
import net.sf.jabref.logic.exporter.IExportFormat;
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -59,7 +62,11 @@ public InternalExportAction(JabRefFrame frame, boolean selectedOnly) {

@Override
public void actionPerformed(ActionEvent e) {
ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
JFileChooser fc = ExportAction
.createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY));
fc.showSaveDialog(frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.gui.util.FocusRequester;
import net.sf.jabref.gui.util.GUIUtil;
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;

import ca.odell.glazedlists.gui.TableFormat;
import ca.odell.glazedlists.swing.DefaultEventTableModel;
Expand Down Expand Up @@ -92,7 +94,9 @@ public ExportCustomizationDialog(final JabRefFrame frame) {
ecd.setVisible(true);
if (ecd.okPressed()) {
List<String> newFormat = Arrays.asList(ecd.name(), ecd.layoutFile(), ecd.extension());
Globals.prefs.customExports.addFormat(newFormat);
Globals.prefs.customExports.addFormat(newFormat,
LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader),
SavePreferences.loadForExportFromPreferences(Globals.prefs));
Globals.prefs.customExports.store(Globals.prefs);
}
});
Expand Down Expand Up @@ -126,8 +130,10 @@ public ExportCustomizationDialog(final JabRefFrame frame) {
for (int i = 0; i < rows.length; i++) {
entries.add(Globals.prefs.customExports.getSortedList().get(rows[i]));
}
LayoutFormatterPreferences layoutPreferences = LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
for (List<String> list : entries) {
Globals.prefs.customExports.remove(list);
Globals.prefs.customExports.remove(list, layoutPreferences, savePreferences);
}
Globals.prefs.customExports.store(Globals.prefs);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ImportCustomizationDialog(final JabRefFrame frame) {
CustomImporter importer = new CustomImporter();

Optional<Path> selectedFile = new FileDialog(frame).withExtension(FileExtensions.CLASS)
.openDialogAndGetSelectedFile();
.showDialogAndGetSelectedFile();

if (selectedFile.isPresent() && (selectedFile.get().getParent() != null)) {
importer.setBasePath(selectedFile.get().getParent().toString());
Expand Down Expand Up @@ -137,7 +137,7 @@ public ImportCustomizationDialog(final JabRefFrame frame) {
JButton addFromJarButton = new JButton(Localization.lang("Add from JAR"));
addFromJarButton.addActionListener(e -> {
Optional<Path> jarZipFile = new FileDialog(frame)
.withExtensions(EnumSet.of(FileExtensions.ZIP, FileExtensions.JAR)).openDialogAndGetSelectedFile();
.withExtensions(EnumSet.of(FileExtensions.ZIP, FileExtensions.JAR)).showDialogAndGetSelectedFile();

if (jarZipFile.isPresent()) {
try (ZipFile zipFile = new ZipFile(jarZipFile.get().toFile(), ZipFile.OPEN_READ)) {
Expand Down
Loading

0 comments on commit 8428847

Please sign in to comment.