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);
}
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);
}
}
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.");
}
}
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)
}
Aggregations