From 0c425bed6737ca84b38eae5b8bf8e836497c2b26 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 22 Feb 2012 13:31:58 +0400 Subject: [PATCH] GitCompareBranchesDialog: better keyboard navigation, solved focus problem 1. DialogWrapper needs to have a preferred focus component on Mac, otherwise focus remains in the editor. GitCompareBranchesDialog doesn't have actions => it is necessary to define a preferred focus component. 2. Add default tab movement shortcuts to the tabbed pane. Add mnemonic to the repository selector. Make diff shortcuts work from the commit list. 3. Move DEFAULT_PREV_NEXT_SHORTCUTS and make them public. --- .../src/com/intellij/ui/TabbedPaneImpl.java | 4 ++++ .../src/com/intellij/ui/TabbedPaneWrapper.java | 8 +++----- .../ui/branch/GitCompareBranchesDialog.java | 17 ++++++++++------- .../ui/branch/GitCompareBranchesLogPanel.java | 5 +++++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/TabbedPaneImpl.java b/platform/platform-impl/src/com/intellij/ui/TabbedPaneImpl.java index 367350c4354d..f87145d6f4fe 100644 --- a/platform/platform-impl/src/com/intellij/ui/TabbedPaneImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/TabbedPaneImpl.java @@ -18,6 +18,7 @@ package com.intellij.ui; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.components.JBTabbedPane; @@ -36,6 +37,9 @@ import java.lang.reflect.Method; public class TabbedPaneImpl extends JBTabbedPane implements TabbedPane { + public static final PrevNextActionsDescriptor DEFAULT_PREV_NEXT_SHORTCUTS = new PrevNextActionsDescriptor(IdeActions.ACTION_NEXT_TAB, + IdeActions.ACTION_PREVIOUS_TAB); + private static final Logger LOG = Logger.getInstance("#com.intellij.ui.TabbedPaneImpl"); private ScrollableTabSupport myScrollableTabSupport; diff --git a/platform/platform-impl/src/com/intellij/ui/TabbedPaneWrapper.java b/platform/platform-impl/src/com/intellij/ui/TabbedPaneWrapper.java index fad4918474e4..9def55b7dc9a 100644 --- a/platform/platform-impl/src/com/intellij/ui/TabbedPaneWrapper.java +++ b/platform/platform-impl/src/com/intellij/ui/TabbedPaneWrapper.java @@ -17,7 +17,6 @@ package com.intellij.ui; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.project.Project; @@ -37,7 +36,6 @@ import java.awt.event.MouseListener; * @author Vladimir Kondratyev */ public class TabbedPaneWrapper { - private static final PrevNextActionsDescriptor DEFAULT_SHORTCUTS = new PrevNextActionsDescriptor(IdeActions.ACTION_NEXT_TAB, IdeActions.ACTION_PREVIOUS_TAB); protected TabbedPane myTabbedPane; protected JComponent myTabbedPaneHolder; @@ -45,12 +43,12 @@ public class TabbedPaneWrapper { protected TabbedPaneWrapper(boolean construct) { if (construct) { - init(SwingConstants.TOP, DEFAULT_SHORTCUTS, new JTabbedPaneFactory(this)); + init(SwingConstants.TOP, TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS, new JTabbedPaneFactory(this)); } } public TabbedPaneWrapper(@NotNull Disposable parentDisposable) { - this(SwingConstants.TOP, DEFAULT_SHORTCUTS, parentDisposable); + this(SwingConstants.TOP, TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS, parentDisposable); } /** @@ -533,7 +531,7 @@ public class TabbedPaneWrapper { public static class AsJTabbedPane extends TabbedPaneWrapper { public AsJTabbedPane(int tabPlacement) { super(false); - init(tabPlacement, DEFAULT_SHORTCUTS, new JTabbedPaneFactory(this)); + init(tabPlacement, TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS, new JTabbedPaneFactory(this)); } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java b/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java index 355412335b3e..f607d62654da 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java @@ -18,7 +18,7 @@ package git4idea.ui.branch; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.IconLoader; -import com.intellij.ui.components.JBTabbedPane; +import com.intellij.ui.TabbedPaneImpl; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; import git4idea.util.GitCommitCompareInfo; @@ -26,7 +26,6 @@ import git4idea.util.GitUIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.awt.event.KeyEvent; /** * Dialog for comparing two Git branches. @@ -39,6 +38,7 @@ public class GitCompareBranchesDialog extends DialogWrapper { private final String myCurrentBranchName; private final GitCommitCompareInfo myCompareInfo; private final GitRepository myInitialRepo; + private JPanel myLogPanel; public GitCompareBranchesDialog(@NotNull Project project, @NotNull String branchName, @NotNull String currentBranchName, @NotNull GitCommitCompareInfo compareInfo, @NotNull GitRepository initialRepo) { @@ -62,14 +62,13 @@ public class GitCompareBranchesDialog extends DialogWrapper { @Override protected JComponent createCenterPanel() { - JPanel logPanel = new GitCompareBranchesLogPanel(myProject, myBranchName, myCurrentBranchName, myCompareInfo, myInitialRepo); + myLogPanel = new GitCompareBranchesLogPanel(myProject, myBranchName, myCurrentBranchName, myCompareInfo, myInitialRepo); JPanel diffPanel = new GitCompareBranchesDiffPanel(myProject, myBranchName, myCurrentBranchName, myCompareInfo); - JBTabbedPane tabbedPane = new JBTabbedPane(); - tabbedPane.addTab("Log", IconLoader.getIcon("/icons/branch.png"), logPanel); - tabbedPane.setMnemonicAt(0, KeyEvent.VK_L); + TabbedPaneImpl tabbedPane = new TabbedPaneImpl(SwingConstants.TOP); + tabbedPane.addTab("Log", IconLoader.getIcon("/icons/branch.png"), myLogPanel); tabbedPane.addTab("Diff", IconLoader.getIcon("/actions/diff.png"), diffPanel); - tabbedPane.setMnemonicAt(1, KeyEvent.VK_D); + tabbedPane.setKeyboardNavigation(TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS); return tabbedPane; } @@ -84,4 +83,8 @@ public class GitCompareBranchesDialog extends DialogWrapper { return GitCompareBranchesDialog.class.getName(); } + @Override + public JComponent getPreferredFocusedComponent() { + return myLogPanel; + } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesLogPanel.java b/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesLogPanel.java index 5339c74851e2..120c830e97be 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesLogPanel.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesLogPanel.java @@ -34,6 +34,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Collections; @@ -76,6 +77,9 @@ class GitCompareBranchesLogPanel extends JPanel { addSelectionListener(myHeadToBranchListPanel, myBranchToHeadListPanel, changesBrowser); addSelectionListener(myBranchToHeadListPanel, myHeadToBranchListPanel, changesBrowser); + myHeadToBranchListPanel.registerDiffAction(changesBrowser.getDiffAction()); + myBranchToHeadListPanel.registerDiffAction(changesBrowser.getDiffAction()); + JPanel htb = layoutCommitListPanel(myCurrentBranchName, true); JPanel bth = layoutCommitListPanel(myCurrentBranchName, false); @@ -106,6 +110,7 @@ class GitCompareBranchesLogPanel extends JPanel { JPanel repoSelectorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); JBLabel label = new JBLabel("Repository: "); label.setLabelFor(repoSelectorPanel); + label.setDisplayedMnemonic(KeyEvent.VK_R); repoSelectorPanel.add(label); repoSelectorPanel.add(repoSelector);