Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sharelatex
Browse files Browse the repository at this point in the history
* upstream/master:
  Initializing EntryEditor Tabs on focus (#3331)
  Fix #3292: annotations are now automatically refreshed (#3325)
  Change integrity message for names depending on database mode (#3330)
  Fix location bundle with fast access (#3327)
  Small code cleanup
  Fix "path not found" exception
  Small fix in drag and drop handler of linked files (#3328)

# Conflicts:
#	src/main/java/org/jabref/gui/DefaultInjector.java
  • Loading branch information
Siedlerchr committed Oct 22, 2017
2 parents 867679d + f71c5a8 commit 418aaad
Show file tree
Hide file tree
Showing 49 changed files with 566 additions and 520 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Updated French translation
- We improved the handling of abstracts in the "Astrophysics Data System" fetcher. [#2471](https://github.com/JabRef/jabref/issues/2471)
- We added support for pasting entries in different formats [#3143](https://github.com/JabRef/jabref/issues/3143)
- In the annotation tab, PDF files are now monitored for new or changed annotation. A manual reload is no longer necessary. [#3292](https://github.com/JabRef/jabref/issues/3292)
- We increased the relative size of the "abstract" field in the entry editor. [Feature request in the forum](http://discourse.jabref.org/t/entry-preview-in-version-4/827)
- Crossreferenced entries are now used when a BibTex key is generated for an entry with empty fields. [#2811](https://github.com/JabRef/jabref/issues/2811)
- We now set the WM_CLASS of the UI to org-jabref-JabRefMain to allow certain Un*x window managers to properly identify its windows
- We changed the default paths for the OpenOffice/LibreOffice binaries to the default path for LibreOffice
- We no longer create a new entry editor when selecting a new entry to increase performance. [#3187](https://github.com/JabRef/jabref/pull/3187)
- We increased performance and decreased the memory footprint of the entry editor drastically. [#3331](https://github.com/JabRef/jabref/pull/3331)


### Fixed
- We fixed the translation of \textendash in the entry preview [#3307](https://github.com/JabRef/jabref/issues/3307)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import java.util.Optional;
import java.util.UUID;

import org.jabref.collab.FileUpdateMonitor;
import org.jabref.gui.GlobalFocusListener;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.journals.JournalAbbreviationLoader;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ private static void start(String[] args) {

Globals.prefs = preferences;
Globals.startBackgroundTasks();
Localization.setLanguage(preferences.get(JabRefPreferences.LANGUAGE));

// Note that the language was already set during the initialization of the preferences and it is safe to
// call the next function.
Globals.prefs.setLanguageDependentDefaultValues();

// Perform Migrations
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/collab/ChangeDisplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ChangeDisplayDialog(JFrame owner, final BasePanel panel,
if (anyDisabled) {
panel.markBaseChanged();
}
panel.setUpdatedExternally(false);
panel.markExternalChangesAsResolved();
dispose();
okPressed = true;
});
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ChangeScanner implements Runnable {

private static final double MATCH_THRESHOLD = 0.4;
private final File file;
private final Path tempFile;
private final BibDatabase databaseInMemory;
private final MetaData metadataInMemory;

Expand All @@ -67,20 +68,20 @@ public class ChangeScanner implements Runnable {

// NamedCompound edit = new NamedCompound("Merged external changes")

public ChangeScanner(JabRefFrame frame, BasePanel bp, File file) {
public ChangeScanner(JabRefFrame frame, BasePanel bp, File file, Path tempFile) {
this.panel = bp;
this.frame = frame;
this.databaseInMemory = bp.getDatabase();
this.metadataInMemory = bp.getBibDatabaseContext().getMetaData();
this.file = file;
this.tempFile = tempFile;
}

@Override
public void run() {
try {

// Parse the temporary file.
Path tempFile = Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle());
ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences();
ParserResult result = OpenDatabase.loadDatabase(tempFile.toFile(), importFormatPreferences);
databaseInTemp = result.getDatabase();
Expand Down Expand Up @@ -153,7 +154,7 @@ private void storeTempDatabase() {
Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
BibDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(databaseInTemp, metadataInTemp, defaults), prefs);
ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle()));
ss.commit(tempFile);
} catch (SaveException ex) {
LOGGER.warn("Problem updating tmp file after accepting external changes", ex);
}
Expand Down
161 changes: 161 additions & 0 deletions src/main/java/org/jabref/collab/DatabaseChangeMonitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package org.jabref.collab;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import javax.swing.SwingUtilities;

import org.jabref.JabRefExecutorService;
import org.jabref.gui.BasePanel;
import org.jabref.gui.SidePaneManager;
import org.jabref.gui.util.FileUpdateListener;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.logic.util.io.FileBasedLock;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;

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

public class DatabaseChangeMonitor implements FileUpdateListener {
private static final Log LOGGER = LogFactory.getLog(DatabaseChangeMonitor.class);

private final BibDatabaseContext database;
private final FileUpdateMonitor fileMonitor;
private final BasePanel panel;
private boolean updatedExternally;
private Path tmpFile;
private long timeStamp;
private long fileSize;

public DatabaseChangeMonitor(BibDatabaseContext database, FileUpdateMonitor fileMonitor, BasePanel panel) {
this.database = database;
this.fileMonitor = fileMonitor;
this.panel = panel;

this.database.getDatabasePath().ifPresent(path -> {
try {
fileMonitor.addListenerForFile(path, this);
timeStamp = Files.getLastModifiedTime(path).toMillis();
fileSize = Files.size(path);
tmpFile = Files.createTempFile("jabref", ".bib");
tmpFile.toFile().deleteOnExit();
copyToTemp(path);
} catch (IOException e) {
LOGGER.error("Error while trying to monitor " + path, e);
}
});
}

@Override
public void fileUpdated() {
if (panel.isSaving()) {
// We are just saving the file, so this message is most likely due to bad timing.
// If not, we'll handle it on the next polling.
return;
}

updatedExternally = true;

final ChangeScanner scanner = new ChangeScanner(panel.frame(), panel, database.getDatabaseFile().orElse(null), tmpFile);

// Test: running scan automatically in background
if (database.getDatabasePath().isPresent() && !FileBasedLock.waitForFileLock(database.getDatabasePath().get())) {
// The file is locked even after the maximum wait. Do nothing.
LOGGER.error("File updated externally, but change scan failed because the file is locked.");

// Wait a bit and then try again
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Nothing to do
}
fileUpdated();
return;
}

JabRefExecutorService.INSTANCE.executeInterruptableTaskAndWait(scanner);

// Adding the sidepane component is Swing work, so we must do this in the Swing
// thread:
Runnable t = () -> {

// Check if there is already a notification about external
// changes:
SidePaneManager sidePaneManager = panel.getSidePaneManager();
boolean hasAlready = sidePaneManager.hasComponent(FileUpdatePanel.class);
if (hasAlready) {
sidePaneManager.hideComponent(FileUpdatePanel.class);
sidePaneManager.unregisterComponent(FileUpdatePanel.class);
}
FileUpdatePanel pan = new FileUpdatePanel(panel, sidePaneManager,
database.getDatabaseFile().orElse(null), scanner);
sidePaneManager.register(pan);
sidePaneManager.show(FileUpdatePanel.class);
};

if (scanner.changesFound()) {
SwingUtilities.invokeLater(t);
} else {
updatedExternally = false;
}
}

/**
* Forces a check on the file, and returns the result. Check if time stamp or the file size has changed.
*
* @return boolean true if the file has changed.
*/
private boolean hasBeenModified() {
Optional<Path> file = database.getDatabasePath();
if (file.isPresent()) {
try {
long modified = Files.getLastModifiedTime(file.get()).toMillis();
if (modified == 0L) {
// File deleted
return false;
}
long fileSizeNow = Files.size(file.get());
return (timeStamp != modified) || (fileSize != fileSizeNow);
} catch (IOException ex) {
return false;
}
}
return false;
}

public void unregister() {
database.getDatabasePath().ifPresent(file -> fileMonitor.removeListener(file, this));
}

public boolean hasBeenModifiedExternally() {
return updatedExternally || hasBeenModified();
}

public void markExternalChangesAsResolved() {
updatedExternally = false;
}

public void markAsSaved() {
database.getDatabasePath().ifPresent(file -> {
try {
timeStamp = Files.getLastModifiedTime(file).toMillis();
fileSize = Files.size(file);

copyToTemp(file);
} catch (IOException ex) {
LOGGER.error("Error while getting file information", ex);
}
});
}

private void copyToTemp(Path file) {
FileUtil.copyFile(file, tmpFile, true);
}

public Path getTempFile() {
return tmpFile;
}
}
Loading

0 comments on commit 418aaad

Please sign in to comment.