Skip to content

Commit

Permalink
Mark Database as changed after the LoadDatabaseMigration
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDietz committed Feb 16, 2018
1 parent 38e6139 commit b246cfe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
47 changes: 23 additions & 24 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ public void windowClosing(WindowEvent e) {
}

initShowTrackingNotification();

}

private void initShowTrackingNotification() {
Expand Down Expand Up @@ -715,7 +714,7 @@ public void setWindowTitle() {
String changeFlag = panel.isModified() && !isAutosaveEnabled ? "*" : "";
String databaseFile = panel.getBibDatabaseContext().getDatabaseFile().map(File::getPath)
.orElse(GUIGlobals.UNTITLED_TITLE);
setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
} else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) {
setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
+ Localization.lang("shared") + "]" + modeInfo);
Expand Down Expand Up @@ -800,7 +799,6 @@ private void tearDownJabRef(List<String> filenames) {
File focusedDatabase = getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null);
new LastFocusedTabPreferences(prefs).setLastFocusedTab(focusedDatabase);
}

}

fileHistory.storeHistory();
Expand Down Expand Up @@ -963,7 +961,6 @@ public BasePanel getBasePanelAt(int i) {

/**
* Returns a list of BasePanel.
*
*/
public List<BasePanel> getBasePanelList() {
List<BasePanel> returnList = new ArrayList<>();
Expand Down Expand Up @@ -1282,26 +1279,32 @@ private void fillMenu() {
createDisabledIconsForMenuEntries(mb);
}

public void addParserResult(ParserResult pr, boolean focusPanel) {
if (pr.toOpenTab()) {
public void addParserResult(ParserResult parserResult, boolean focusPanel) {
if (parserResult.toOpenTab()) {
// Add the entries to the open tab.
BasePanel panel = getCurrentBasePanel();
if (panel == null) {
// There is no open tab to add to, so we create a new tab:
addTab(pr.getDatabaseContext(), focusPanel);
panel = addTab(parserResult.getDatabaseContext(), focusPanel);
if (parserResult.wasChangedOnMigration) {
panel.markBaseChanged();
}
} else {
List<BibEntry> entries = new ArrayList<>(pr.getDatabase().getEntries());
List<BibEntry> entries = new ArrayList<>(parserResult.getDatabase().getEntries());
addImportedEntries(panel, entries, false);
}
} else {
// only add tab if DB is not already open
Optional<BasePanel> panel = getBasePanelList().stream()
.filter(p -> p.getBibDatabaseContext().getDatabaseFile().equals(pr.getFile())).findFirst();
.filter(p -> p.getBibDatabaseContext().getDatabaseFile().equals(parserResult.getFile())).findFirst();

if (panel.isPresent()) {
tabbedPane.setSelectedComponent(panel.get());
} else {
addTab(pr.getDatabaseContext(), focusPanel);
BasePanel basePanel = addTab(parserResult.getDatabaseContext(), focusPanel);
if (parserResult.wasChangedOnMigration) {
basePanel.markBaseChanged();
}
}
}
}
Expand Down Expand Up @@ -1447,7 +1450,6 @@ dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImpo
atLeastOneEntryActions.addAll(Arrays.asList(downloadFullText, lookupIdentifiers, exportLinkedFiles));

tabbedPane.addChangeListener(event -> updateEnabledState());

}

/**
Expand Down Expand Up @@ -1510,7 +1512,6 @@ public void setupAllTables() {
// Update tables:
if (bf.getDatabase() != null) {
bf.setupMainPanel();

}
}
}
Expand Down Expand Up @@ -1561,7 +1562,7 @@ public void updateAllTabTitles() {
}
}

public void addTab(BasePanel basePanel, boolean raisePanel) {
public BasePanel addTab(BasePanel basePanel, boolean raisePanel) {
// add tab
tabbedPane.add(basePanel.getTabTitle(), basePanel);

Expand All @@ -1586,22 +1587,23 @@ public void addTab(BasePanel basePanel, boolean raisePanel) {

// Track opening
trackOpenNewDatabase(basePanel);
return basePanel;
}

private void trackOpenNewDatabase(BasePanel basePanel) {

Map<String, String> properties = new HashMap<>();
Map<String, Double> measurements = new HashMap<>();
measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount());
measurements.put("NumberOfEntries", (double) basePanel.getDatabaseContext().getDatabase().getEntryCount());

Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements));
}

public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) {
Objects.requireNonNull(databaseContext);
BasePanel bp = new BasePanel(JabRefFrame.this, databaseContext);
addTab(bp, raisePanel);
return bp;
BasePanel basePanel = new BasePanel(JabRefFrame.this, databaseContext);
addTab(basePanel, raisePanel);
return basePanel;
}

private boolean readyForAutosave(BibDatabaseContext context) {
Expand Down Expand Up @@ -1727,7 +1729,6 @@ public void setProgressBarValue(final int value) {
} else {
SwingUtilities.invokeLater(() -> progressBar.setValue(value));
}

}

/**
Expand All @@ -1742,7 +1743,6 @@ public void setProgressBarIndeterminate(final boolean value) {
} else {
SwingUtilities.invokeLater(() -> progressBar.setIndeterminate(value));
}

}

/**
Expand All @@ -1759,11 +1759,11 @@ public void setProgressBarMaximum(final int value) {
} else {
SwingUtilities.invokeLater(() -> progressBar.setMaximum(value));
}

}

/**
* Return a boolean, if the selected entry have file
*
* @param selectEntryList A selected entries list of the current base pane
* @return true, if the selected entry contains file.
* false, if multiple entries are selected or the selected entry doesn't contains file
Expand All @@ -1778,6 +1778,7 @@ private boolean isExistFile(List<BibEntry> selectEntryList) {

/**
* Return a boolean, if the selected entry have url or doi
*
* @param selectEntryList A selected entries list of the current base pane
* @return true, if the selected entry contains url or doi.
* false, if multiple entries are selected or the selected entry doesn't contains url or doi
Expand Down Expand Up @@ -2135,7 +2136,8 @@ public EditAction(String command, String menuTitle, String description, KeyStrok
putValue(Action.SHORT_DESCRIPTION, description);
}

@Override public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {

LOGGER.debug(Globals.getFocusListener().getFocused().toString());
JComponent source = Globals.getFocusListener().getFocused();
Expand Down Expand Up @@ -2197,7 +2199,6 @@ public void actionPerformed(ActionEvent e) {
GenFieldsCustomizer gf = new GenFieldsCustomizer(JabRefFrame.this);
gf.setLocationRelativeTo(JabRefFrame.this);
gf.setVisible(true);

}
}

Expand Down Expand Up @@ -2232,7 +2233,6 @@ public void actionPerformed(ActionEvent e) {
propertiesDialog.setLocationRelativeTo(JabRefFrame.this);
propertiesDialog.setVisible(true);
}

}

private class BibtexKeyPatternAction extends MnemonicAwareAction {
Expand All @@ -2256,7 +2256,6 @@ public void actionPerformed(ActionEvent e) {
bibtexKeyPatternDialog.setLocationRelativeTo(JabRefFrame.this);
bibtexKeyPatternDialog.setVisible(true);
}

}

private class DefaultTableFontSizeAction extends MnemonicAwareAction {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/logic/importer/ParserResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jabref.model.metadata.MetaData;

public class ParserResult {
public boolean wasChangedOnMigration = false;

private final Map<String, EntryType> entryTypes;
private final List<String> warnings = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void performMigration(ParserResult parserResult) {
entries.stream()
.filter(this::hasReviewField)
.filter(entry -> !this.hasCommentField(entry))
.forEach(this::migrate);
.forEach(entry -> migrate(entry, parserResult));

// determine conflicts
List<BibEntry> conflicts = entries.stream()
Expand All @@ -38,7 +38,7 @@ public void performMigration(ParserResult parserResult) {
if (!conflicts.isEmpty() && new MergeReviewIntoCommentUIManager().askUserForMerge(conflicts)) {
conflicts.stream()
.filter(this::hasReviewField)
.forEach(this::migrate);
.forEach(entry -> migrate(entry, parserResult));
}
}

Expand All @@ -58,8 +58,9 @@ private boolean hasReviewField(BibEntry entry) {
return entry.getField(FieldName.REVIEW).isPresent();
}

private void migrate(BibEntry entry) {
private void migrate(BibEntry entry, ParserResult parserResult) {
updateFields(entry, mergeCommentFieldIfPresent(entry, entry.getField(FieldName.REVIEW).get()));
parserResult.wasChangedOnMigration = true;
}

private void updateFields(BibEntry entry, String review) {
Expand Down

0 comments on commit b246cfe

Please sign in to comment.