From a68c2164669c256ebc81ffa320e52324418fecc0 Mon Sep 17 00:00:00 2001 From: Constantine Plotnikov Date: Fri, 5 Jun 2009 18:30:02 +0400 Subject: [PATCH] git4idea: Fixed options on merge and pull dialogs to better reflect git option dependencies --- .../src/git4idea/merge/GitMergeDialog.java | 19 +++--- .../git4idea/src/git4idea/merge/GitMergeUtil.java | 17 +---- .../git4idea/src/git4idea/merge/GitPullDialog.java | 5 +- plugins/git4idea/src/git4idea/ui/GitUIUtil.java | 77 ++++++++++++++++++++++ 4 files changed, 92 insertions(+), 26 deletions(-) diff --git a/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java b/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java index 959f45e976..c722fdfd90 100644 --- a/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java +++ b/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java @@ -101,10 +101,11 @@ public class GitMergeDialog extends DialogWrapper { setTitle(GitBundle.getString("merge.branch.title")); myProject = project; initBranchChooser(); - GitMergeUtil.setupNoCommitCheckbox(myAddLogInformationCheckBox, myCommitMessage, myNoCommitCheckBox); setOKActionEnabled(false); setOKButtonText(GitBundle.getString("merge.branch.button")); GitUIUtil.setupRootChooser(myProject, roots, defaultRoot, myGitRoot, myCurrentBranchText); + GitUIUtil.imply(mySquashCommitCheckBox, true, myNoCommitCheckBox, true); + GitUIUtil.exclusive(mySquashCommitCheckBox, true, myNoFastForwardCheckBox, true); myGitRoot.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { updateBranches(); @@ -128,7 +129,7 @@ public class GitMergeDialog extends DialogWrapper { c.weighty = 1; c.fill = GridBagConstraints.BOTH; myBranchToMergeContainer.add(myBranchChooser, c); - GitMergeUtil.setupStrategies(myBranchChooser, myNoCommitCheckBox, myStrategy); + GitMergeUtil.setupStrategies(myBranchChooser, myStrategy); final ElementsChooser.ElementsMarkListener listener = new ElementsChooser.ElementsMarkListener() { public void elementMarkChanged(final String element, final boolean isMarked) { setOKActionEnabled(myBranchChooser.getMarkedElements().size() != 0); @@ -176,14 +177,12 @@ public class GitMergeDialog extends DialogWrapper { if (myNoCommitCheckBox.isSelected()) { h.addParameters("--no-commit"); } - else { - if (myAddLogInformationCheckBox.isSelected()) { - h.addParameters("--log"); - } - final String msg = myCommitMessage.getText().trim(); - if (msg.length() != 0) { - h.addParameters("-m", msg); - } + if (myAddLogInformationCheckBox.isSelected()) { + h.addParameters("--log"); + } + final String msg = myCommitMessage.getText().trim(); + if (msg.length() != 0) { + h.addParameters("-m", msg); } if (mySquashCommitCheckBox.isSelected()) { h.addParameters("--squash"); diff --git a/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java b/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java index 0498762ca3..dcfecaff16 100644 --- a/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java +++ b/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java @@ -107,13 +107,10 @@ public class GitMergeUtil { /** * Setup strategies combobox. The set of strategies changes according to amount of selected elements in branchChooser. * - * @param branchChooser a branch chooser - * @param noCommitCheckBox no commit checkbox - * @param strategy a strategy selector + * @param branchChooser a branch chooser + * @param strategy a strategy selector */ - public static void setupStrategies(final ElementsChooser branchChooser, - final JCheckBox noCommitCheckBox, - final JComboBox strategy) { + public static void setupStrategies(final ElementsChooser branchChooser, final JComboBox strategy) { final ElementsChooser.ElementsMarkListener listener = new ElementsChooser.ElementsMarkListener() { private void updateStrategies(final List elements) { strategy.removeAllItems(); @@ -129,17 +126,9 @@ public class GitMergeUtil { strategy.setEnabled(false); updateStrategies(elements); } - else if (elements.size() == 1) { - strategy.setEnabled(true); - updateStrategies(elements); - noCommitCheckBox.setEnabled(true); - noCommitCheckBox.setSelected(false); - } else { strategy.setEnabled(true); updateStrategies(elements); - noCommitCheckBox.setEnabled(false); - noCommitCheckBox.setSelected(false); } } }; diff --git a/plugins/git4idea/src/git4idea/merge/GitPullDialog.java b/plugins/git4idea/src/git4idea/merge/GitPullDialog.java index 7b7420ab1f..00a4caf00b 100644 --- a/plugins/git4idea/src/git4idea/merge/GitPullDialog.java +++ b/plugins/git4idea/src/git4idea/merge/GitPullDialog.java @@ -119,8 +119,9 @@ public class GitPullDialog extends DialogWrapper { }; myBranchChooser.addElementsMarkListener(listener); listener.elementMarkChanged(null, true); - GitMergeUtil.setupNoCommitCheckbox(myAddLogInformationCheckBox, null, myNoCommitCheckBox); - GitMergeUtil.setupStrategies(myBranchChooser, myNoCommitCheckBox, myStrategy); + GitUIUtil.imply(mySquashCommitCheckBox, true, myNoCommitCheckBox, true); + GitUIUtil.exclusive(mySquashCommitCheckBox, true, myNoFastForwardCheckBox, true); + GitMergeUtil.setupStrategies(myBranchChooser, myStrategy); init(); } diff --git a/plugins/git4idea/src/git4idea/ui/GitUIUtil.java b/plugins/git4idea/src/git4idea/ui/GitUIUtil.java index d17e421776..3a84c0c02e 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUIUtil.java +++ b/plugins/git4idea/src/git4idea/ui/GitUIUtil.java @@ -248,4 +248,81 @@ public class GitUIUtil { GitVcs.getInstance(project).showErrors(Collections.singletonList(e), GitBundle.getString("pull.retriving.remotes")); } } + + /** + * Checks state of the {@code checked} checkbox and if state is {@code checkedState} than to disable {@code changed} + * checkbox and change its state to {@code impliedState}. When the {@code checked} checkbox changes states to other state, + * than enable {@code changed} and restore its state. Note that the each checkbox should be implied by only one other checkbox. + * + * @param checked the checkbox to monitor + * @param checkedState the state that triggers disabling changed state + * @param changed the checkbox to change + * @param impliedState the implied state of checkbox + */ + public static void imply(final JCheckBox checked, final boolean checkedState, final JCheckBox changed, final boolean impliedState) { + ActionListener l = new ActionListener() { + Boolean previousState; + + public void actionPerformed(ActionEvent e) { + if (checked.isSelected() == checkedState) { + if (previousState == null) { + previousState = changed.isSelected(); + } + changed.setEnabled(false); + changed.setSelected(impliedState); + } + else { + changed.setEnabled(true); + if (previousState != null) { + changed.setSelected(previousState); + previousState = null; + } + } + } + }; + checked.addActionListener(l); + l.actionPerformed(null); + } + + /** + * Declares states for two checkboxes to be mutually exclusive. When one of the checkboxes goes to the specified state, other is + * disabled and forced into reverse of the state (to prevent very fast users from selecting incorrect state or incorrect + * initial configuration). + * + * @param first the first checkbox + * @param firstState the state of the first checkbox + * @param second the second checkbox + * @param secondState the state of the second checkbox + */ + public static void exclusive(final JCheckBox first, final boolean firstState, final JCheckBox second, final boolean secondState) { + ActionListener l = new ActionListener() { + /** + * One way check for the condition + * @param checked the first to check + * @param checkedState the state to match + * @param changed the changed control + * @param impliedState the implied state + */ + private void check(final JCheckBox checked, final boolean checkedState, final JCheckBox changed, final boolean impliedState) { + if (checked.isSelected() == checkedState) { + changed.setSelected(impliedState); + changed.setEnabled(false); + } + else { + changed.setEnabled(true); + } + } + + /** + * {@inheritDoc} + */ + public void actionPerformed(ActionEvent e) { + check(first, firstState, second, !secondState); + check(second, secondState, first, !firstState); + } + }; + first.addActionListener(l); + second.addActionListener(l); + l.actionPerformed(null); + } } -- 2.11.4.GIT