Search in sources :

Example 31 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class DroppedFileHandler method handleDroppedfile.

/**
     * @param fileName  The name of the dragged file.
     * @param fileType  The FileType associated with the file.
     * @param entry     The target entry for the drop.
     */
public void handleDroppedfile(String fileName, ExternalFileType fileType, BibEntry entry) {
    NamedCompound edits = new NamedCompound(Localization.lang("Drop %0", fileType.getExtension()));
    if (tryXmpImport(fileName, fileType, edits)) {
        edits.end();
        panel.getUndoManager().addEdit(edits);
        return;
    }
    // Show dialog
    if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.getDatabase())) {
        return;
    }
    /*
         * Ok, we're ready to go. See first if we need to do a file copy before
         * linking:
         */
    boolean success = true;
    String destFilename;
    if (linkInPlace.isSelected()) {
        destFilename = FileUtil.shortenFileName(Paths.get(fileName), panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())).toString();
    } else {
        destFilename = renameCheckBox.isSelected() ? renameToTextBox.getText() : Paths.get(fileName).toString();
        if (copyRadioButton.isSelected()) {
            success = doCopy(fileName, destFilename, edits);
        } else if (moveRadioButton.isSelected()) {
            success = doMove(fileName, destFilename, edits);
        }
    }
    if (success) {
        doLink(entry, fileType, destFilename, false, edits);
        panel.markBaseChanged();
        panel.updateEntryEditorIfShowing();
    }
    edits.end();
    panel.getUndoManager().addEdit(edits);
}
Also used : NamedCompound(org.jabref.gui.undo.NamedCompound)

Example 32 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class ImportMenuItem method mergeImportResults.

private ParserResult mergeImportResults(List<ImportFormatReader.UnknownFormatImport> imports) {
    BibDatabase database = new BibDatabase();
    ParserResult directParserResult = null;
    boolean anythingUseful = false;
    for (ImportFormatReader.UnknownFormatImport importResult : imports) {
        if (importResult == null) {
            continue;
        }
        if (ImportFormatReader.BIBTEX_FORMAT.equals(importResult.format)) {
            // Bibtex result. We must merge it into our main base.
            ParserResult pr = importResult.parserResult;
            anythingUseful = anythingUseful || pr.getDatabase().hasEntries() || (!pr.getDatabase().hasNoStrings());
            // Record the parserResult, as long as this is the first bibtex result:
            if (directParserResult == null) {
                directParserResult = pr;
            }
            // Merge entries:
            for (BibEntry entry : pr.getDatabase().getEntries()) {
                database.insertEntry(entry);
            }
            // Merge strings:
            for (BibtexString bs : pr.getDatabase().getStringValues()) {
                try {
                    database.addString((BibtexString) bs.clone());
                } catch (KeyCollisionException e) {
                // TODO: This means a duplicate string name exists, so it's not
                // a very exceptional situation. We should maybe give a warning...?
                }
            }
        } else {
            ParserResult pr = importResult.parserResult;
            Collection<BibEntry> entries = pr.getDatabase().getEntries();
            anythingUseful = anythingUseful | !entries.isEmpty();
            // set timestamp and owner
            // set timestamp and owner
            UpdateField.setAutomaticFields(entries, Globals.prefs.getUpdateFieldPreferences());
            boolean markEntries = !openInNew && EntryMarker.shouldMarkEntries();
            for (BibEntry entry : entries) {
                if (markEntries) {
                    EntryMarker.markEntry(entry, EntryMarker.IMPORT_MARK_LEVEL, false, new NamedCompound(""));
                }
                database.insertEntry(entry);
            }
        }
    }
    if (!anythingUseful) {
        return null;
    }
    if ((imports.size() == 1) && (directParserResult != null)) {
        return directParserResult;
    } else {
        return new ParserResult(database);
    }
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) ImportFormatReader(org.jabref.logic.importer.ImportFormatReader) BibtexString(org.jabref.model.entry.BibtexString) BibDatabase(org.jabref.model.database.BibDatabase)

Example 33 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class UnabbreviateAction method run.

@Override
public void run() {
    List<BibEntry> entries = panel.getSelectedEntries();
    if (entries == null) {
        return;
    }
    UndoableUnabbreviator undoableAbbreviator = new UndoableUnabbreviator(Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
    NamedCompound ce = new NamedCompound(Localization.lang("Unabbreviate journal names"));
    int count = 0;
    for (BibEntry entry : entries) {
        for (String journalField : InternalBibtexFields.getJournalNameFields()) {
            if (undoableAbbreviator.unabbreviate(panel.getDatabase(), entry, journalField, ce)) {
                count++;
            }
        }
    }
    if (count > 0) {
        ce.end();
        panel.getUndoManager().addEdit(ce);
        panel.markBaseChanged();
        message = Localization.lang("Unabbreviated %0 journal names.", String.valueOf(count));
    } else {
        message = Localization.lang("No journal names could be unabbreviated.");
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound)

Example 34 with NamedCompound

use of org.jabref.gui.undo.NamedCompound 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

NamedCompound (org.jabref.gui.undo.NamedCompound)34 BibEntry (org.jabref.model.entry.BibEntry)27 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)11 FieldChange (org.jabref.model.FieldChange)7 ArrayList (java.util.ArrayList)5 BasePanel (org.jabref.gui.BasePanel)5 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)4 UndoableKeyChange (org.jabref.gui.undo.UndoableKeyChange)4 UndoableRemoveEntry (org.jabref.gui.undo.UndoableRemoveEntry)3 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2 IOException (java.io.IOException)2 List (java.util.List)2 JButton (javax.swing.JButton)2 JSeparator (javax.swing.JSeparator)2 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)2 UndoableChangeType (org.jabref.gui.undo.UndoableChangeType)2 WindowLocation (org.jabref.gui.util.WindowLocation)2 CheckBoxMessage (org.jabref.gui.util.component.CheckBoxMessage)2 ParserResult (org.jabref.logic.importer.ParserResult)2