Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in the entry editor mark the database as dirty #2997

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* A single tab displayed in the EntryEditor holding several FieldEditors.
*/
class FieldsEditorTab extends EntryEditorTab {
public class FieldsEditorTab extends EntryEditorTab {

private final Region panel;
private final List<String> fields;
Expand Down Expand Up @@ -67,6 +67,10 @@ public FieldsEditorTab(JabRefFrame frame, BasePanel basePanel, List<String> fiel
//panel.setFocusCycleRoot(true);
}

public void markAsDirty() {
basePanel.markBaseChanged();
}

private static void addColumn(GridPane gridPane, int columnIndex, List<Label> nodes) {
gridPane.addColumn(columnIndex, nodes.toArray(new Node[nodes.size()]));
}
Expand Down Expand Up @@ -121,7 +125,7 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse
fieldEditor.setAutoCompleteListener(autoCompleteListener);
*/

FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.TASK_EXECUTOR, new FXDialogService(),
FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.TASK_EXECUTOR, this, new FXDialogService(),
Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs,
bPanel.getBibDatabaseContext(), entry.getType());
fieldEditor.bindToEntry(entry);
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationPreferences;
Expand All @@ -15,7 +16,7 @@

public class FieldEditors {

public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType) {
public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, FieldsEditorTab editorTab, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType) {
final Set<FieldProperty> fieldExtras = InternalBibtexFields.getFieldProperties(fieldName);

if (Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD).equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) {
Expand All @@ -25,36 +26,36 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu
return new DateEditor(fieldName, DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)));
}
} else if (fieldExtras.contains(FieldProperty.EXTERNAL)) {
return new UrlEditor(fieldName, dialogService);
return new UrlEditor(fieldName, dialogService, editorTab);
} else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) {
return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences);
return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences, editorTab);
} else if (fieldExtras.contains(FieldProperty.DOI) || fieldExtras.contains(FieldProperty.EPRINT) || fieldExtras.contains(FieldProperty.ISBN)) {
return new IdentifierEditor(fieldName, taskExecutor, dialogService);
return new IdentifierEditor(fieldName, taskExecutor, dialogService, editorTab);
} else if (fieldExtras.contains(FieldProperty.OWNER)) {
return new OwnerEditor(fieldName, preferences);
return new OwnerEditor(fieldName, preferences, editorTab);
} else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) {
return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor);
return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, editorTab);
} else if (fieldExtras.contains(FieldProperty.YES_NO)) {
return new OptionEditor<>(fieldName, new YesNoEditorViewModel());
return new OptionEditor<>(fieldName, new YesNoEditorViewModel(), editorTab);
} else if (fieldExtras.contains(FieldProperty.MONTH)) {
return new OptionEditor<>(fieldName, new MonthEditorViewModel(databaseContext.getMode()));
return new OptionEditor<>(fieldName, new MonthEditorViewModel(databaseContext.getMode()), editorTab);
} else if (fieldExtras.contains(FieldProperty.GENDER)) {
return new OptionEditor<>(fieldName, new GenderEditorViewModel());
return new OptionEditor<>(fieldName, new GenderEditorViewModel(), editorTab);
} else if (fieldExtras.contains(FieldProperty.EDITOR_TYPE)) {
return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel());
return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel(), editorTab);
} else if (fieldExtras.contains(FieldProperty.PAGINATION)) {
return new OptionEditor<>(fieldName, new PaginationEditorViewModel());
return new OptionEditor<>(fieldName, new PaginationEditorViewModel(), editorTab);
} else if (fieldExtras.contains(FieldProperty.TYPE)) {
if ("patent".equalsIgnoreCase(entryType)) {
return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel());
return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel(), editorTab);
} else {
return new OptionEditor<>(fieldName, new TypeEditorViewModel());
return new OptionEditor<>(fieldName, new TypeEditorViewModel(), editorTab);
}
} else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
return new LinkedEntriesEditor(fieldName, databaseContext);
return new LinkedEntriesEditor(fieldName, databaseContext, editorTab);
}

// default
return new SimpleEditor(fieldName);
return new SimpleEditor(fieldName, editorTab);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javafx.scene.layout.HBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.fieldeditors.contextmenu.EditorMenus;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.TaskExecutor;
Expand All @@ -29,13 +30,14 @@ public class IdentifierEditor extends HBox implements FieldEditorFX {
@FXML private Button lookupIdentifierButton;
private Optional<BibEntry> entry;

public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService) {
public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new IdentifierEditorViewModel(fieldName, taskExecutor, dialogService);

ControlHelper.loadFXMLForControl(this);

textArea.textProperty().bindBidirectional(viewModel.textProperty());
textArea.textProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());

fetchInformationByIdentifierButton.setTooltip(
new Tooltip(Localization.lang("Get BibTeX data from %0", FieldName.getDisplayName(fieldName))));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.Parent;
import javafx.scene.layout.HBox;

import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.fieldeditors.contextmenu.EditorMenus;
import org.jabref.gui.util.ControlHelper;
import org.jabref.logic.journals.JournalAbbreviationLoader;
Expand All @@ -20,13 +21,14 @@ public class JournalEditor extends HBox implements FieldEditorFX {
@FXML private EditorTextArea textArea;
private Optional<BibEntry> entry;

public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) {
public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new JournalEditorViewModel(journalAbbreviationLoader, journalAbbreviationPreferences);

ControlHelper.loadFXMLForControl(this);

textArea.textProperty().bindBidirectional(viewModel.textProperty());
textArea.textProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());

textArea.addToContextMenu(EditorMenus.getDefaultMenu(textArea));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.Parent;
import javafx.scene.layout.HBox;

import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.component.TagBar;
import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -17,7 +18,7 @@ public class LinkedEntriesEditor extends HBox implements FieldEditorFX {
@FXML private LinkedEntriesEditorViewModel viewModel;
@FXML private TagBar<ParsedEntryLink> linkedEntriesBar;

public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext) {
public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new LinkedEntriesEditorViewModel(databaseContext);

Expand All @@ -26,6 +27,7 @@ public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext)
linkedEntriesBar.setStringConverter(viewModel.getStringConverter());
linkedEntriesBar.setOnTagClicked((parsedEntryLink, mouseEvent) -> viewModel.jumpToEntry(parsedEntryLink));
Bindings.bindContentBidirectional(linkedEntriesBar.tagsProperty(), viewModel.linkedEntriesProperty());
linkedEntriesBar.tagsProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());
}

public LinkedEntriesEditorViewModel getViewModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.TaskExecutor;
Expand All @@ -39,7 +40,7 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX {
@FXML private final LinkedFilesEditorViewModel viewModel;
@FXML private ListView<LinkedFileViewModel> listView;

public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) {
public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new LinkedFilesEditorViewModel(dialogService, databaseContext, taskExecutor);

Expand All @@ -52,6 +53,7 @@ public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatab
.withOnMouseClickedEvent(this::handleItemMouseClick);
listView.setCellFactory(cellFactory);
Bindings.bindContent(listView.itemsProperty().get(), viewModel.filesProperty());
listView.itemsProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());
setUpKeyBindings();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;

import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.model.entry.BibEntry;
Expand All @@ -18,7 +19,7 @@ public class OptionEditor<T> extends HBox implements FieldEditorFX {
@FXML private OptionEditorViewModel<T> viewModel;
@FXML private ComboBox<T> comboBox;

public OptionEditor(String fieldName, OptionEditorViewModel<T> viewModel) {
public OptionEditor(String fieldName, OptionEditorViewModel<T> viewModel, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = viewModel;

Expand All @@ -28,6 +29,7 @@ public OptionEditor(String fieldName, OptionEditorViewModel<T> viewModel) {
comboBox.setCellFactory(new ViewModelListCellFactory<T>().withText(viewModel::convertToDisplayText));
comboBox.getItems().setAll(viewModel.getItems());
comboBox.getEditor().textProperty().bindBidirectional(viewModel.textProperty());
comboBox.getEditor().textProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());
}

public OptionEditorViewModel<T> getViewModel() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.Parent;
import javafx.scene.layout.HBox;

import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.util.ControlHelper;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;
Expand All @@ -18,13 +19,14 @@ public class OwnerEditor extends HBox implements FieldEditorFX {
@FXML private EditorTextArea textArea;
private Optional<BibEntry> entry;

public OwnerEditor(String fieldName, JabRefPreferences preferences) {
public OwnerEditor(String fieldName, JabRefPreferences preferences, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new OwnerEditorViewModel(preferences);

ControlHelper.loadFXMLForControl(this);

textArea.textProperty().bindBidirectional(viewModel.textProperty());
textArea.textProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());
}

public OwnerEditorViewModel getViewModel() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;

import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.fieldeditors.contextmenu.EditorMenus;
import org.jabref.model.entry.BibEntry;

Expand All @@ -13,14 +14,15 @@ public class SimpleEditor extends HBox implements FieldEditorFX {
protected final String fieldName;
@FXML private final SimpleEditorViewModel viewModel;

public SimpleEditor(String fieldName) {
public SimpleEditor(String fieldName, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new SimpleEditorViewModel();

EditorTextArea textArea = new EditorTextArea();
HBox.setHgrow(textArea, Priority.ALWAYS);
textArea.textProperty().bindBidirectional(viewModel.textProperty());
textArea.addToContextMenu(EditorMenus.getDefaultMenu(textArea));
textArea.textProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());
this.getChildren().add(textArea);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.scene.layout.HBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.entryeditor.FieldsEditorTab;
import org.jabref.gui.util.ControlHelper;
import org.jabref.model.entry.BibEntry;

Expand All @@ -18,13 +19,14 @@ public class UrlEditor extends HBox implements FieldEditorFX {
@FXML private EditorTextArea textArea;
private Optional<BibEntry> entry;

public UrlEditor(String fieldName, DialogService dialogService) {
public UrlEditor(String fieldName, DialogService dialogService, FieldsEditorTab editorTab) {
this.fieldName = fieldName;
this.viewModel = new UrlEditorViewModel(dialogService);

ControlHelper.loadFXMLForControl(this);

textArea.textProperty().bindBidirectional(viewModel.textProperty());
textArea.textProperty().addListener((observable, oldValue, newValue) -> editorTab.markAsDirty());
}

public UrlEditorViewModel getViewModel() {
Expand Down