Skip to content

Commit

Permalink
Close entry editor when the shown entry is removed externally (#3156)
Browse files Browse the repository at this point in the history
* Close entry editor when the shown entry is removed externally

* Close entry editor and preview panel separately
  • Loading branch information
lenhard authored Aug 27, 2017
1 parent 2abf651 commit 8abf3ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

- Added 'Filter All' and 'Filter None' buttons with corresponding functionality to Quality Check tool.
- We increased the size of the keywords and file text areas in the entry editor
- When the entry that is currently shown in the entry editor is deleted externally, the editor is now closed automatically [#2946](https://github.com/JabRef/jabref/issues/2946)

### Fixed
- We re-added the "Normalize to BibTeX name format" context menu item [#3136](https://github.com/JabRef/jabref/issues/3136)
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) {
setupActions();

this.getDatabase().registerListener(new SearchListener());
this.getDatabase().registerListener(new EntryRemovedListener());

// ensure that at each addition of a new entry, the entry is added to the groups interface
this.bibDatabaseContext.getDatabase().registerListener(new GroupTreeListener());
Expand Down Expand Up @@ -2097,6 +2098,21 @@ public void listen(EntryAddedEvent addedEntryEvent) {
}
}

private class EntryRemovedListener {

@Subscribe
public void listen(EntryRemovedEvent entryRemovedEvent) {
// if the entry that is displayed in the current entry editor is removed, close the entry editor
if (isShowingEditor() && currentEditor.getEntry().equals(entryRemovedEvent.getBibEntry())) {
currentEditor.close();
}

if (selectionListener.getPreview().getEntry().equals(entryRemovedEvent.getBibEntry())) {
selectionListener.setPreviewActive(false);
}
}
}

/**
* Ensures that the search auto completer is up to date when entries are changed AKA Let the auto completer, if any,
* harvest words from the entry
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private void rebuildOtherFieldsTab() {
boolean isOtherFieldsTabSelected = false;

// find tab index and selection status
for (Tab tab: tabbed.getTabs()) {
for (Tab tab : tabbed.getTabs()) {
if (tab instanceof OtherFieldsTab) {
index = tabbed.getTabs().indexOf(tab);
isOtherFieldsTabSelected = tabbed.getSelectionModel().isSelected(index);
Expand Down Expand Up @@ -313,6 +313,10 @@ private void setupKeyBindings() {
});
}

public void close() {
closeAction.actionPerformed(null);
}

private void addTabs(String lastTabName) {

List<EntryEditorTab> tabs = new ArrayList<>();
Expand Down Expand Up @@ -866,7 +870,7 @@ public void actionPerformed(ActionEvent e) {
}

BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData()
.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
panel.getDatabase(), entry,
Globals.prefs.getBibtexKeyPatternPreferences());

Expand Down

0 comments on commit 8abf3ed

Please sign in to comment.