From 8807c84a84c6cc3a7ddea37b6914be05ab5d8f72 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 14 Apr 2015 18:33:41 +0300 Subject: [PATCH] [git] IDEA-130665 Remember rebase dialog choices --- plugins/git4idea/src/META-INF/plugin.xml | 1 + .../git4idea/config/GitRebaseSettings.java | 89 +++++++++++++++++++ .../src/git4idea/rebase/GitRebaseDialog.java | 64 ++++++++++++- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 plugins/git4idea/src/git4idea/config/GitRebaseSettings.java diff --git a/plugins/git4idea/src/META-INF/plugin.xml b/plugins/git4idea/src/META-INF/plugin.xml index c08dd9e5ddae..cbe70496408e 100644 --- a/plugins/git4idea/src/META-INF/plugin.xml +++ b/plugins/git4idea/src/META-INF/plugin.xml @@ -157,6 +157,7 @@ + { + + private State myState = new State(); + + public static class State { + public boolean INTERACTIVE = true; + public boolean PRESERVE_MERGES = false; + public boolean SHOW_TAGS = false; + public boolean SHOW_REMOTE_BRANCHES = false; + public String ONTO = null; + } + + @Nullable + @Override + public State getState() { + return myState; + } + + @Override + public void loadState(State state) { + myState = state; + } + + public boolean isInteractive() { + return myState.INTERACTIVE; + } + + public void setInteractive(boolean interactive) { + myState.INTERACTIVE = interactive; + } + + public boolean isPreserveMerges() { + return myState.PRESERVE_MERGES; + } + + public void setPreserveMerges(boolean preserveMerges) { + myState.PRESERVE_MERGES = preserveMerges; + } + + public boolean showTags() { + return myState.SHOW_TAGS; + } + + public void setShowTags(boolean showTags) { + myState.SHOW_TAGS = showTags; + } + + public boolean showRemoteBranches() { + return myState.SHOW_REMOTE_BRANCHES; + } + + public void setShowRemoteBranches(boolean showRemoteBranches) { + myState.SHOW_REMOTE_BRANCHES = showRemoteBranches; + } + + @Nullable + public String getOnto() { + return myState.ONTO; + } + + public void setOnto(@Nullable String onto) { + myState.ONTO = onto; + } + +} diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseDialog.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseDialog.java index 51c86a93bdbc..9a3119803309 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseDialog.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseDialog.java @@ -15,10 +15,12 @@ */ package git4idea.rebase; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.DocumentAdapter; @@ -27,12 +29,14 @@ import git4idea.branch.GitBranchUtil; import git4idea.commands.GitCommand; import git4idea.commands.GitLineHandler; import git4idea.config.GitConfigUtil; +import git4idea.config.GitRebaseSettings; import git4idea.i18n.GitBundle; import git4idea.merge.GitMergeUtil; import git4idea.repo.GitRemote; import git4idea.repo.GitRepository; import git4idea.ui.GitReferenceValidator; import git4idea.util.GitUIUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -116,7 +120,7 @@ public class GitRebaseDialog extends DialogWrapper { /** * The current branch */ - protected GitBranch myCurrentBranch; + @Nullable protected GitBranch myCurrentBranch; /** * The tags */ @@ -129,6 +133,9 @@ public class GitRebaseDialog extends DialogWrapper { * The validator for from field */ private final GitReferenceValidator myFromValidator; + @NotNull private final GitRebaseSettings mySettings; + + @Nullable private final String myOriginalOntoBranch; /** * A constructor @@ -143,6 +150,7 @@ public class GitRebaseDialog extends DialogWrapper { setOKButtonText(GitBundle.getString("rebase.button")); init(); myProject = project; + mySettings = ServiceManager.getService(myProject, GitRebaseSettings.class); final Runnable validateRunnable = new Runnable() { public void run() { validateFields(); @@ -158,8 +166,18 @@ public class GitRebaseDialog extends DialogWrapper { validateFields(); } }); + setupBranches(); setupStrategy(); + + myInteractiveCheckBox.setSelected(mySettings.isInteractive()); + myPreserveMergesCheckBox.setSelected(mySettings.isPreserveMerges()); + myShowTagsCheckBox.setSelected(mySettings.showTags()); + myShowRemoteBranchesCheckBox.setSelected(mySettings.showRemoteBranches()); + overwriteOntoForCurrentBranch(mySettings); + + myOriginalOntoBranch = GitUIUtil.getTextField(myOntoComboBox).getText(); + validateFields(); } @@ -169,6 +187,29 @@ public class GitRebaseDialog extends DialogWrapper { return myOntoComboBox; } + private void overwriteOntoForCurrentBranch(@NotNull GitRebaseSettings settings) { + String onto = settings.getOnto(); + if (onto != null && !onto.equals(myBranchComboBox.getSelectedItem())) { + if (!isValidRevision(onto)) { + mySettings.setOnto(null); + } + else { + myOntoComboBox.setSelectedItem(onto); + } + } + } + + private boolean isValidRevision(@NotNull String revisionExpression) { + try { + GitRevisionNumber.resolve(myProject, gitRoot(), revisionExpression); + return true; + } + catch (VcsException e) { + LOG.debug(e); + return false; + } + } + public GitLineHandler handler() { GitLineHandler h = new GitLineHandler(myProject, gitRoot(), GitCommand.REBASE); h.setStdoutSuppressed(false); @@ -202,6 +243,27 @@ public class GitRebaseDialog extends DialogWrapper { return h; } + @Override + protected void doOKAction() { + try { + rememberFields(); + } + finally { + super.doOKAction(); + } + } + + private void rememberFields() { + mySettings.setInteractive(myInteractiveCheckBox.isSelected()); + mySettings.setPreserveMerges(myPreserveMergesCheckBox.isSelected()); + mySettings.setShowTags(myShowTagsCheckBox.isSelected()); + mySettings.setShowRemoteBranches(myShowRemoteBranchesCheckBox.isSelected()); + String onto = StringUtil.nullize(GitUIUtil.getTextField(myOntoComboBox).getText(), true); + if (onto != null && !onto.equals(myOriginalOntoBranch)) { + mySettings.setOnto(onto); + } + } + /** * Setup strategy */