Search in sources :

Example 21 with UndoableFieldChange

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();
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange)

Example 22 with UndoableFieldChange

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;
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange)

Example 23 with UndoableFieldChange

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)
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) FieldChange(org.jabref.model.FieldChange) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)23 BibEntry (org.jabref.model.entry.BibEntry)13 NamedCompound (org.jabref.gui.undo.NamedCompound)11 FieldChange (org.jabref.model.FieldChange)8 FileListTableModel (org.jabref.gui.filelist.FileListTableModel)5 FileListEntry (org.jabref.gui.filelist.FileListEntry)4 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)3 UnknownExternalFileType (org.jabref.gui.externalfiletype.UnknownExternalFileType)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 ExternalFileTypeEntryEditor (org.jabref.gui.externalfiletype.ExternalFileTypeEntryEditor)2 FileListEntryEditor (org.jabref.gui.filelist.FileListEntryEditor)2 Subscribe (com.google.common.eventbus.Subscribe)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 StringReader (java.io.StringReader)1