-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Refactor EntryEvents - removal part #5410
Changes from all commits
80e8377
48cb7fd
923b40e
a0ffcb5
b08ae88
3a830a8
4e57a46
b990e0d
3122e67
aac840c
90c27f1
a0cafc4
868deed
2afb868
460f44a
f11389e
f535a0b
77ff450
b0805cc
7ac7a1c
8255ad2
3b8dfea
5f1b811
c41dc17
bb88484
4c97c64
30d8d51
5cf5965
1df2869
0f5d76f
13abf0c
17f04b0
214e958
a90c44e
648c5da
b0f585a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.jabref.gui.undo; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.event.EntriesEventSource; | ||
import org.jabref.model.strings.StringUtil; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class represents the removal of entries. The constructor needs | ||
* references to the database, the entries, and the map of open entry editors. | ||
* TODO is this map still being used? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this TODO be resoled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would appear the map is not being used, as there is no reference to entry editors in the class. Am I mistaken? |
||
* The latter to be able to close the entry's editor if it is opened after | ||
* an undo, and the removal is then undone. | ||
*/ | ||
public class UndoableRemoveEntries extends AbstractUndoableJabRefEdit { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(UndoableRemoveEntries.class); | ||
private final BibDatabase base; | ||
private final List<BibEntry> entries; | ||
private final boolean cut; | ||
|
||
public UndoableRemoveEntries(BibDatabase base, BibEntry entry) { | ||
this(base, Collections.singletonList(entry)); | ||
} | ||
|
||
public UndoableRemoveEntries(BibDatabase base, List<BibEntry> entries) { | ||
this(base, entries, false); | ||
} | ||
|
||
public UndoableRemoveEntries(BibDatabase base, List<BibEntry> entries, boolean cut) { | ||
this.base = base; | ||
this.entries = entries; | ||
this.cut = cut; | ||
} | ||
|
||
@Override | ||
public String getPresentationName() { | ||
if (cut) { | ||
if (entries.size() > 1) { | ||
return Localization.lang("cut entries"); | ||
} else if (entries.size() == 1) { | ||
return Localization.lang("cut entry %0", | ||
StringUtil.boldHTML(entries.get(0).getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
} else { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there something be logged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't thought of that. What do you think? |
||
} | ||
} else { | ||
if (entries.size() > 1) { | ||
return Localization.lang("remove entries"); | ||
} else if (entries.size() == 1) { | ||
return Localization.lang("remove entry %0", | ||
StringUtil.boldHTML(entries.get(0).getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
} else { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there something be logged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't thought of that. What do you think? |
||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void undo() { | ||
super.undo(); | ||
base.insertEntries(entries, EntriesEventSource.UNDO); | ||
} | ||
|
||
@Override | ||
public void redo() { | ||
super.redo(); | ||
|
||
// Redo the change. | ||
try { | ||
base.removeEntries(entries); | ||
} catch (Throwable ex) { | ||
LOGGER.warn("Problem to redo `remove entries`", ex); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lists.of(one, two)
should work, too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I just want to create a
List
of the twoBibEntry
s.