mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-130665 Remember rebase dialog choices
This commit is contained in:
@@ -157,6 +157,7 @@
|
||||
<projectService
|
||||
serviceInterface="git4idea.config.GitVcsSettings"
|
||||
serviceImplementation="git4idea.config.GitVcsSettings"/>
|
||||
<projectService serviceImplementation="git4idea.config.GitRebaseSettings"/>
|
||||
<projectService serviceImplementation="git4idea.config.GitSharedSettings" />
|
||||
<projectService
|
||||
serviceInterface="git4idea.config.GitExecutableValidator"
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.config;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@State(name = "Git.Rebase.Settings", storages = {@Storage(file = StoragePathMacros.WORKSPACE_FILE)})
|
||||
public class GitRebaseSettings implements PersistentStateComponent<GitRebaseSettings.State> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user