use of org.jabref.gui.undo.UndoableFieldChange in project jabref by JabRef.
the class AttachFileAction method action.
@Override
public void action() {
if (panel.getSelectedEntries().size() != 1) {
panel.output(Localization.lang("This operation requires exactly one item to be selected."));
return;
}
BibEntry entry = panel.getSelectedEntries().get(0);
FileListEntry flEntry = new FileListEntry("", "");
FileListEntryEditor editor = new FileListEntryEditor(panel.frame(), flEntry, false, true, panel.getBibDatabaseContext());
editor.setVisible(true, true);
if (editor.okPressed()) {
FileListTableModel model = new FileListTableModel();
entry.getField(FieldName.FILE).ifPresent(model::setContent);
model.addEntry(model.getRowCount(), flEntry);
String newVal = model.getStringRepresentation();
UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, entry.getField(FieldName.FILE).orElse(null), newVal);
entry.setField(FieldName.FILE, newVal);
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
}
}
use of org.jabref.gui.undo.UndoableFieldChange in project jabref by JabRef.
the class UndoableUnabbreviator method unabbreviate.
/**
* Unabbreviate the journal name of the given entry.
*
* @param entry The entry to be treated.
* @param fieldName The field name (e.g. "journal")
* @param ce If the entry is changed, add an edit to this compound.
* @return true if the entry was changed, false otherwise.
*/
public boolean unabbreviate(BibDatabase database, BibEntry entry, String fieldName, CompoundEdit ce) {
if (!entry.hasField(fieldName)) {
return false;
}
String text = entry.getField(fieldName).get();
String origText = text;
if (database != null) {
text = database.resolveForStrings(text);
}
if (!journalAbbreviationRepository.isKnownName(text)) {
// cannot do anything if it is not known
return false;
}
if (!journalAbbreviationRepository.isAbbreviatedName(text)) {
// cannot unabbreviate unabbreviated name.
return false;
}
// must be here
Abbreviation abbreviation = journalAbbreviationRepository.getAbbreviation(text).get();
String newText = abbreviation.getName();
entry.setField(fieldName, newText);
ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText));
return true;
}
use of org.jabref.gui.undo.UndoableFieldChange in project jabref by JabRef.
the class SpecialFieldDatabaseChangeListener method listen.
@Subscribe
public void listen(EntryAddedEvent event) {
if (!Globals.prefs.isKeywordSyncEnabled()) {
return;
}
final BibEntry entry = event.getBibEntry();
// NamedCompount code similar to SpecialFieldUpdateListener
NamedCompound nc = new NamedCompound(Localization.lang("Synchronized special fields based on keywords"));
List<FieldChange> changes = SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, Globals.prefs.getKeywordDelimiter());
for (FieldChange change : changes) {
nc.addEdit(new UndoableFieldChange(change));
}
// Don't insert the compound into the undoManager,
// it would be added before the component which undoes the insertion of the entry and creates heavy problems
// (which prohibits the undo the deleting multiple entries)
}
Aggregations