mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user