Skip to content
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

Fix editor freeze #2225

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1614,29 +1614,17 @@ public void showEntry(final BibEntry be) {

}

EntryEditor entryEditor;
int divLoc = -1;
String visName = null;
if ((getShowing() != null) && isShowingEditor()) {
visName = ((EntryEditor) splitPane.getBottomComponent()).getVisiblePanelName();
}
if (getShowing() != null) {
divLoc = splitPane.getDividerLocation();
}

// We must instantiate a new editor.
entryEditor = new EntryEditor(frame, BasePanel.this, be);
EntryEditor entryEditor = new EntryEditor(frame, BasePanel.this, be);
if (visName != null) {
entryEditor.setVisiblePanel(visName);
}
splitPane.setBottomComponent(entryEditor);

if (divLoc > 0) {
splitPane.setDividerLocation(divLoc);
} else {
splitPane.setDividerLocation(
splitPane.getHeight() - Globals.prefs.getInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT));
}
showEntryEditor(entryEditor);

newEntryShowing(be);
setEntryEditorEnabled(true); // Make sure it is enabled.
Expand All @@ -1650,15 +1638,10 @@ public void showEntry(final BibEntry be) {
* @return A suitable entry editor.
*/
public EntryEditor getEntryEditor(BibEntry entry) {
EntryEditor entryEditor;

// We must instantiate a new editor. First make sure the old one
// stores its last edit:
// We must instantiate a new editor. First make sure the old one stores its last edit:
storeCurrentEdit();
// Then start the new one:
entryEditor = new EntryEditor(frame, BasePanel.this, entry);

return entryEditor;
return new EntryEditor(frame, BasePanel.this, entry);
}

public EntryEditor getCurrentEditor() {
Expand All @@ -1677,6 +1660,9 @@ public void showEntryEditor(EntryEditor editor) {
splitPane.getHeight() - splitPane.getDividerLocation());
}
mode = BasePanelMode.SHOWING_EDITOR;
if (currentEditor != null) {
currentEditor.setMovingToDifferentEntry();
}
currentEditor = editor;
splitPane.setBottomComponent(editor);
if (editor.getEntry() != getShowing()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public void updateSource() {

// Set the current Entry to be selected.
// Fixes the bug of losing selection after, e.g. an autogeneration of a BibTeX key.
SwingUtilities.invokeLater(() -> panel.highlightEntry(entry));
panel.highlightEntry(entry);
} catch (IOException ex) {
source.setText(ex.getMessage() + "\n\n" +
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
Expand Down Expand Up @@ -781,7 +781,7 @@ private boolean storeSource() {
// TODO: does updating work properly after source stored?
panel.markBaseChanged();

SwingUtilities.invokeLater(() -> panel.highlightEntry(entry));
panel.highlightEntry(entry);

return true;
} catch (IllegalStateException | IOException ex) {
Expand Down Expand Up @@ -1153,7 +1153,7 @@ public void actionPerformed(ActionEvent event) {
// Make sure we scroll to the entry if it moved in the table.
// Should only be done if this editor is currently showing:
if (!movingAway && isShowing()) {
SwingUtilities.invokeLater(() -> panel.highlightEntry(entry));
panel.highlightEntry(entry);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,9 @@ public void listChanged(ListEvent<BibEntry> e) {
if (oldEditor != null) {
visName = oldEditor.getVisiblePanelName();
}
// Get an old or new editor for the entry to edit:
// Get a new editor for the entry to edit:
EntryEditor newEditor = panel.getEntryEditor(newSelected);

if (oldEditor != null) {
oldEditor.setMovingToDifferentEntry();
}

// Show the new editor unless it was already visible:
if (!Objects.equals(newEditor, oldEditor) || (mode != BasePanelMode.SHOWING_EDITOR)) {

Expand All @@ -132,6 +128,9 @@ public void listChanged(ListEvent<BibEntry> e) {
}
panel.showEntryEditor(newEditor);
SwingUtilities.invokeLater(() -> table.ensureVisible(table.getSelectedRow()));
} else {
// if not used destroy the EntryEditor
newEditor.setMovingToDifferentEntry();
}
} else {
// Either nothing or a preview was shown. Update the preview.
Expand Down