Skip to content

Commit

Permalink
enhance toggle behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
chriba committed Sep 27, 2016
1 parent b8d1c2e commit 482db82
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private void setupActions() {
// The action for toggling the groups interface
actions.put(Actions.TOGGLE_GROUPS, (BaseAction) () -> {
sidePaneManager.toggle("groups");
frame.groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
frame.getGroupToggle().setSelected(sidePaneManager.isComponentVisible("groups"));
});

actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> {
Expand Down Expand Up @@ -1217,7 +1217,7 @@ public void listen(EntryAddedEvent addedEntryEvent) {
}

// Automatically add new entry to the selected group (or set of groups)
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP) && frame.groupToggle.isSelected()) {
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP) && frame.getGroupToggle().isSelected()) {
final List<BibEntry> entries = Collections.singletonList(addedEntryEvent.getBibEntry());
final TreePath[] selection = frame.getGroupSelector().getGroupsTree().getSelectionPaths();
if (selection != null) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter {

/* References to the toggle buttons in the toolbar */
// the groups interface
public JToggleButton groupToggle;
private JToggleButton groupToggle;
private JToggleButton previewToggle;
private JToggleButton fetcherToggle;

Expand Down Expand Up @@ -2378,8 +2378,12 @@ public GroupSelector getGroupSelector() {
return groupSelector;
}

public void setFetcherToggle(boolean enabled) {
fetcherToggle.setSelected(enabled);
public JToggleButton getFetcherToggle() {
return fetcherToggle;
}

public JToggleButton getGroupToggle() {
return groupToggle;
}

public void setPreviewToggle(boolean enabled) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/sf/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public synchronized boolean isComponentVisible(String name) {
}

public synchronized void toggle(String name) {
if (isComponentVisible(name)) {
if (isComponentVisible(name) && Globals.getFocusListener().getFocused() == components.get(name)) {
hide(name);
} else {
show(name);
Expand Down Expand Up @@ -114,6 +114,8 @@ private synchronized void show(SidePaneComponent component) {
updateView();
component.componentOpening();
}
Globals.getFocusListener().setFocused(component);
component.grabFocus();
}

public synchronized SidePaneComponent getComponent(String name) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class Actions {
public static final String TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_DISABLE = "toggleHighlightGroupsMatchingDisable";
public static final String TOGGLE_GROUPS = "toggleGroups";
public static final String TOGGLE_PREVIEW = "togglePreview";
public static final String TOGGLE_TOOLBAR = "toggleToolbar";
public static final String UNABBREVIATE = "unabbreviate";
public static final String UNDO = "undo";
public static final String UNMARK_ALL = "unmarkAll";
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/sf/jabref/gui/groups/GroupSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ public void componentClosing() {
if (panel != null) {// panel may be null if no file is open any more
panel.getMainTable().getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.DISABLED);
}
frame.groupToggle.setSelected(false);
frame.getGroupToggle().setSelected(false);
}

private void setGroups(GroupTreeNode groupsRoot) {
Expand Down Expand Up @@ -1269,4 +1269,10 @@ public GroupsTree getGroupsTree() {
public void listen(GroupUpdatedEvent updateEvent) {
setGroups(updateEvent.getMetaData().getGroups().orElse(null));
}

@Override
public void grabFocus() {
groupsTree.grabFocus();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,20 @@ public void actionPerformed(ActionEvent e) {

if (frame.getTabbedPane().getTabCount() > 0) {
sidePaneManager.toggle(GeneralFetcher.this.getTitle());
if (sidePaneManager.isComponentVisible(GeneralFetcher.this.getTitle())) {
getTextField().requestFocus();
}
frame.getFetcherToggle().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.this.getTitle()));
}
}
}

@Override
public void grabFocus() {
getTextField().grabFocus();
}

@Override
public void componentClosing() {
super.componentClosing();
frame.setFetcherToggle(false);
frame.getFetcherToggle().setSelected(false);
Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ public static OpenOfficePanel getInstance() {
return OpenOfficePanel.instance;
}

public SidePaneComponent getSidePaneComponent() {
return comp;
}

public void init(JabRefFrame jabRefFrame, SidePaneManager spManager) {
this.frame = jabRefFrame;
this.manager = spManager;
Expand All @@ -161,7 +157,7 @@ public JMenuItem getMenuItem() {
}
JMenuItem item = new JMenuItem(Localization.lang("OpenOffice/LibreOffice connection"),
IconTheme.getImage("openoffice"));
item.addActionListener(event -> manager.show(getName()));
item.addActionListener(event -> manager.toggle(getName()));
item.setAccelerator(Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION));
return item;
}
Expand Down Expand Up @@ -817,6 +813,7 @@ private class OOPanel extends SidePaneComponent {
public OOPanel(SidePaneManager sidePaneManager, Icon url, String s, OpenOfficePanel panel) {
super(sidePaneManager, url, s);
openOfficePanel = panel;
sidePaneManager.register(getName(), this);
}

@Override
Expand Down

0 comments on commit 482db82

Please sign in to comment.