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

When browsing through the MainTable remember which EntryEditor tab was open #3011

Merged
merged 3 commits into from
Jul 14, 2017
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed a bug where new groups information was not stored on save [#2932](https://github.com/JabRef/jabref/issues/2932)
- We fixed a bug where the language files for Brazilian Portugese could not be loaded and the GUI localization remained in English [#1128](https://github.com/JabRef/jabref/issues/1182)
- We fixed a bug where the database was not marked as dirty when entries or groups were changed [#2787](https://github.com/JabRef/jabref/issues/2787)

- We restored the original functionality that when browsing through the MainTable, the Entry Editor remembers which tab was opened before [#2896](https://github.com/JabRef/jabref/issues/2896)
### Removed


Expand Down
96 changes: 43 additions & 53 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe
private StringDialog stringDialog;
private SuggestionProviders suggestionProviders;

/** the query the user searches when this basepanel is active */
// the query the user searches when this BasePanel is active
private Optional<SearchQuery> currentSearchQuery = Optional.empty();

public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) {
Expand Down Expand Up @@ -379,7 +379,6 @@ private void setupActions() {
} else {
preambleEditor.setVisible(true);
}

});

// The action for opening the string editor
Expand All @@ -391,7 +390,6 @@ private void setupActions() {
} else {
stringDialog.setVisible(true);
}

});

actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> {
Expand Down Expand Up @@ -722,6 +720,7 @@ public void update() {

/**
* Generates and copies citations based on the selected entries to the clipboard
*
* @param outputFormat the desired {@link CitationStyleOutputFormat}
*/
private void copyCitationToClipboard(CitationStyleOutputFormat outputFormat) {
Expand Down Expand Up @@ -762,9 +761,9 @@ private void cut() {

/**
* Removes the selected entries from the database
* @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized
* as "deleted".
* If true the action will be localized as "cut"
*
* @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized as
* "deleted". If true the action will be localized as "cut"
*/
private void delete(boolean cut) {
List<BibEntry> entries = mainTable.getSelectedEntries();
Expand Down Expand Up @@ -839,7 +838,6 @@ private void paste() {
bibDatabaseContext.getDatabase().insertEntry(be);

ce.addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this));

}
ce.end();
getUndoManager().addEdit(ce);
Expand Down Expand Up @@ -946,7 +944,7 @@ private void copyKeyAndTitle() {
try {
layout = new LayoutHelper(sr,
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader))
.getLayoutFromText();
.getLayoutFromText();
} catch (IOException e) {
LOGGER.info("Could not get layout", e);
return;
Expand Down Expand Up @@ -1038,7 +1036,7 @@ public void runCommand(final String _command) {
}

private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
SavePreferences.DatabaseSaveType saveType) throws SaveException {
SavePreferences.DatabaseSaveType saveType) throws SaveException {
SaveSession session;
frame.block();
final String SAVE_DATABASE = Localization.lang("Save library");
Expand Down Expand Up @@ -1074,7 +1072,6 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + "\n" + ex.getMessage(),
SAVE_DATABASE, JOptionPane.ERROR_MESSAGE);
throw new SaveException("rt");

} finally {
frame.unblock();
}
Expand All @@ -1092,7 +1089,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
String tryDiff = Localization.lang("Try different encoding");
int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), SAVE_DATABASE,
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
new String[] {Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff);
new String[]{Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff);

if (answer == JOptionPane.NO_OPTION) {
// The user wants to use another encoding.
Expand All @@ -1103,12 +1100,10 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
} else {
Charset newEncoding = Charset.forName((String) choice);
return saveDatabase(file, selectedOnly, newEncoding, saveType);

}
} else if (answer == JOptionPane.CANCEL_OPTION) {
commit = false;
}

}

if (commit) {
Expand Down Expand Up @@ -1258,19 +1253,19 @@ private void createMainTable() {
public void actionPerformed(ActionEvent e) {
// need to close these here, b/c this action overshadows the responsible actions when the main table is selected
switch (mode) {
case SHOWING_NOTHING:
frame.getGlobalSearchBar().endSearch();
break;
case SHOWING_PREVIEW:
getPreviewPanel().close();
break;
case SHOWING_EDITOR:
case WILL_SHOW_EDITOR:
entryEditorClosing(getCurrentEditor());
break;
default:
LOGGER.warn("unknown BasePanelMode: '" + mode + "', doing nothing");
break;
case SHOWING_NOTHING:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Siedlerchr I remember that you (Eclipse?) changed the indention of the switch statement directly in the opposite way. We should fix a style and stick to it. @koppor Any preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the indent, but I don't know what the code quality guys say (@lenhard)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion on the indentation of the cases. Let's just do it consistently.

frame.getGlobalSearchBar().endSearch();
break;
case SHOWING_PREVIEW:
getPreviewPanel().close();
break;
case SHOWING_EDITOR:
case WILL_SHOW_EDITOR:
entryEditorClosing(getCurrentEditor());
break;
default:
LOGGER.warn("unknown BasePanelMode: '" + mode + "', doing nothing");
break;
}
}
});
Expand Down Expand Up @@ -1317,16 +1312,16 @@ public void keyPressed(KeyEvent e) {

if (e.isControlDown()) {
switch (keyCode) {
case KeyEvent.VK_PAGE_DOWN:
frame.nextTab.actionPerformed(null);
e.consume();
break;
case KeyEvent.VK_PAGE_UP:
frame.prevTab.actionPerformed(null);
e.consume();
break;
default:
break;
case KeyEvent.VK_PAGE_DOWN:
frame.nextTab.actionPerformed(null);
e.consume();
break;
case KeyEvent.VK_PAGE_UP:
frame.prevTab.actionPerformed(null);
e.consume();
break;
default:
break;
}
} else if (keyCode == KeyEvent.VK_ENTER) {
e.consume();
Expand Down Expand Up @@ -1443,28 +1438,26 @@ public void adjustSplitter() {
} else {
splitPane.setDividerLocation(
splitPane.getHeight() - Globals.prefs.getInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT));

}
}

private boolean isShowingEditor() {
return (splitPane.getBottomComponent() != null) && (splitPane.getBottomComponent() instanceof EntryEditor);
}

public void showEntry(final BibEntry be) {
public void showEntry(final BibEntry bibEntry) {

if (getShowing() == be) {
if (getShowing() == bibEntry) {
if (splitPane.getBottomComponent() == null) {
// This is the special occasion when showing is set to an
// entry, but no entry editor is in fact shown. This happens
// after Preferences dialog is closed, and it means that we
// must make sure the same entry is shown again. We do this by
// setting showing to null, and recursively calling this method.
newEntryShowing(null);
showEntry(be);
showEntry(bibEntry);
}
return;

}

String visName = null;
Expand All @@ -1473,25 +1466,27 @@ public void showEntry(final BibEntry be) {
}

// We must instantiate a new editor.
EntryEditor entryEditor = new EntryEditor(frame, BasePanel.this, be);
EntryEditor entryEditor = getEntryEditor(bibEntry);
if (visName != null) {
entryEditor.setVisibleTab(visName);
}
showEntryEditor(entryEditor);

newEntryShowing(be);
newEntryShowing(bibEntry);
}

/**
* Get an entry editor ready to edit the given entry. If an appropriate editor is already cached, it will be updated
* and returned.
* Get an entry editor ready to edit the given entry.
*
* @param entry The entry to be edited.
* @return A suitable entry editor.
*/
public EntryEditor getEntryEditor(BibEntry entry) {
// Then start the new one:
return new EntryEditor(frame, BasePanel.this, entry);
String lastTabName = "";
if (currentEditor != null) {
lastTabName = currentEditor.getVisibleTabName();
}
return new EntryEditor(frame, BasePanel.this, entry, lastTabName);
}

public EntryEditor getCurrentEditor() {
Expand Down Expand Up @@ -1621,7 +1616,6 @@ public void markBaseChanged() {
LOGGER.info("Problem marking database as changed", e);
}
}

}

private void markBasedChangedInternal() {
Expand Down Expand Up @@ -1723,7 +1717,6 @@ public boolean showDeleteConfirmationDialog(int numberOfEntries) {
} else {
return true;
}

}

/**
Expand All @@ -1737,7 +1730,7 @@ public void autoGenerateKeysBeforeSaving() {
Optional<String> oldKey = bes.getCiteKeyOptional();
if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) {
BibtexKeyPatternUtil.makeAndSetLabel(bibDatabaseContext.getMetaData()
.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
bibDatabaseContext.getDatabase(),
bes, Globals.prefs.getBibtexKeyPatternPreferences());
bes.getCiteKeyOptional().ifPresent(
Expand All @@ -1756,8 +1749,6 @@ public void autoGenerateKeysBeforeSaving() {
/**
* Activates or deactivates the entry preview, depending on the argument. When deactivating, makes sure that any
* visible preview is hidden.
*
* @param enabled
*/
private void setPreviewActive(boolean enabled) {
selectionListener.setPreviewActive(enabled);
Expand Down Expand Up @@ -1954,7 +1945,6 @@ public void newEntryShowing(BibEntry entry) {
showing = entry;
setBackAndForwardEnabledState();
}

}

/**
Expand Down
Loading