From 06e6b70dde7bb8a2ffd2effafa2dd8cb7e4096b4 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 30 Nov 2009 16:28:23 +0300 Subject: [PATCH] "oommit and push" button for git (IDEADEV-41543) --- .../src/com/intellij/openapi/vcs/AbstractVcs.java | 8 ++++++- .../openapi/vcs/changes/CommitExecutor.java | 8 ------- .../openapi/vcs/changes/CommitSession.java | 19 +++++++++++++++ .../openapi/vcs/changes/actions/CommitAction.java | 7 ++++-- .../changes/patch/CreatePatchCommitExecutor.java | 11 --------- .../changes/shelf/ShelveChangesCommitExecutor.java | 11 --------- .../vcs/changes/ui/CommitChangeListDialog.java | 24 +++++++++++++++---- plugins/git4idea/src/git4idea/GitVcs.java | 10 ++++++++ .../git4idea/checkin/GitCheckinEnvironment.java | 20 ++++------------ .../git4idea/checkin/GitCommitAndPushExecutor.java | 28 ++++++++++++---------- 10 files changed, 81 insertions(+), 65 deletions(-) copy platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java => plugins/git4idea/src/git4idea/checkin/GitCommitAndPushExecutor.java (53%) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java index 37507de45b..0349282c2d 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java @@ -17,12 +17,14 @@ package com.intellij.openapi.vcs; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.diff.impl.patch.formove.FilePathComparator; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.UnnamedConfigurable; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.changes.ChangeListEditHandler; import com.intellij.openapi.vcs.changes.ChangeProvider; +import com.intellij.openapi.vcs.changes.CommitExecutor; import com.intellij.openapi.vcs.changes.VcsAppendableDirtyScope; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.diff.DiffProvider; @@ -33,11 +35,11 @@ import com.intellij.openapi.vcs.merge.MergeProvider; import com.intellij.openapi.vcs.rollback.RollbackEnvironment; import com.intellij.openapi.vcs.update.UpdateEnvironment; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.diff.impl.patch.formove.FilePathComparator; import com.intellij.util.containers.Convertor; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; /** @@ -452,5 +454,9 @@ public abstract class AbstractVcs extends StartedActivated { final RemoteDifferenceStrategy strategy = getRemoteDifferenceStrategy(); return RemoteDifferenceStrategy.ASK_LATEST_REVISION.equals(strategy) ? null : getTreeDiffProviderImpl(); } + + public List getCommitExecutors() { + return Collections.emptyList(); + } } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java index cb3d695ed6..3658393a6d 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java @@ -19,21 +19,13 @@ package com.intellij.openapi.vcs.changes; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** * @author max */ public interface CommitExecutor { - @NotNull - Icon getActionIcon(); - @Nls String getActionText(); - @Nls - String getActionDescription(); - @NotNull CommitSession createCommitSession(); } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java index eb92ac6f1b..f294d2b32e 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java @@ -25,6 +25,25 @@ import java.util.Collection; * @author max */ public interface CommitSession { + CommitSession VCS_COMMIT = new CommitSession() { + public JComponent getAdditionalConfigurationUI() { + return null; + } + + public JComponent getAdditionalConfigurationUI(Collection changes, String commitMessage) { + return null; + } + + public boolean canExecute(Collection changes, String commitMessage) { + return true; + } + + public void execute(Collection changes, String commitMessage) { + } + + public void executionCanceled() { + } + }; /** * @deprecated Since version 7.0, {@link #getAdditionalConfigurationUI(java.util.Collection, String)} is called instead diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/CommitAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/CommitAction.java index 0c5239e864..37111b5417 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/CommitAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/CommitAction.java @@ -35,6 +35,7 @@ import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog; import java.util.Arrays; +import java.util.List; public class CommitAction extends AnAction implements DumbAware { public void update(AnActionEvent e) { @@ -73,8 +74,10 @@ public class CommitAction extends AnAction implements DumbAware { ChangeListManager.getInstance(project).invokeAfterUpdate(new Runnable() { public void run() { - CommitChangeListDialog.commitChanges(project, Arrays.asList(changes), (LocalChangeList) list, - ChangeListManager.getInstance(project).getRegisteredExecutors(), true, null); + final List changesList = Arrays.asList(changes); + final List executors = CommitChangeListDialog.collectExecutors(project, changesList); + CommitChangeListDialog.commitChanges(project, changesList, (LocalChangeList) list, + executors, true, null); } }, InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE, VcsBundle.message("waiting.changelists.update.for.show.commit.dialog.message"), null); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java index 8deae85ecf..71d2d53128 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java @@ -33,7 +33,6 @@ import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; -import com.intellij.util.Icons; import org.jdom.Element; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; @@ -69,21 +68,11 @@ public class CreatePatchCommitExecutor implements CommitExecutor, ProjectCompone myChangeListManager = changeListManager; } - @NotNull - public Icon getActionIcon() { - return Icons.TASK_ICON; - } - @Nls public String getActionText() { return VcsBundle.message("create.patch.commit.action.text"); } - @Nls - public String getActionDescription() { - return VcsBundle.message("create.patch.commit.action.description"); - } - @NotNull public CommitSession createCommitSession() { return new CreatePatchCommitSession(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesCommitExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesCommitExecutor.java index e4c698cc10..069a3fe512 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesCommitExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesCommitExecutor.java @@ -30,7 +30,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.*; -import com.intellij.util.Icons; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,21 +46,11 @@ public class ShelveChangesCommitExecutor implements CommitExecutor { myProject = project; } - @NotNull - public Icon getActionIcon() { - return Icons.TASK_ICON; - } - @Nls public String getActionText() { return VcsBundle.message("shelve.changes.action"); } - @Nls - public String getActionDescription() { - return VcsBundle.message("shelve.changes.action"); - } - @NotNull public CommitSession createCommitSession() { return new ShelveChangesCommitSession(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index d44d123f24..2164d5b938 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -141,15 +141,25 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj public static boolean commitChanges(final Project project, final Collection changes, final LocalChangeList initialSelection, final CommitExecutor executor, final String comment) { - final ChangeListManager manager = ChangeListManager.getInstance(project); if (executor == null) { - return commitChanges(project, changes, initialSelection, manager.getRegisteredExecutors(), true, comment); + return commitChanges(project, changes, initialSelection, collectExecutors(project, changes), true, comment); } else { return commitChanges(project, changes, initialSelection, Collections.singletonList(executor), false, comment); } } + public static List collectExecutors(Project project, Collection changes) { + List result = new ArrayList(); + final ChangeListManager manager = ChangeListManager.getInstance(project); + final List vcses = getAffectedVcses(project, changes); + for (AbstractVcs vcs : vcses) { + result.addAll(vcs.getCommitExecutors()); + } + result.addAll(manager.getRegisteredExecutors()); + return result; + } + public static boolean commitChanges(final Project project, final Collection changes, final LocalChangeList initialSelection, final List executors, final boolean showVcsCommit, final String comment) { if (changes.isEmpty()) { @@ -389,7 +399,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj } private void updateVcsOptionsVisibility() { - final List affectedVcses = getAffectedVcses(myBrowser.getSelectedChangeList().getChanges()); + final List affectedVcses = getAffectedVcses(myProject, myBrowser.getSelectedChangeList().getChanges()); for(Map.Entry entry: myPerVcsOptionsPanels.entrySet()) { entry.getValue().setVisible(affectedVcses.contains(entry.getKey())); } @@ -420,6 +430,10 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj if (!saveDialogState()) return; saveComments(true); final CommitSession session = commitExecutor.createCommitSession(); + if (session == CommitSession.VCS_COMMIT) { + doOKAction(); + return; + } boolean isOK = true; if (SessionDialog.createConfigurationUI(session, getIncludedChanges(), getCommitMessage())!= null) { DialogWrapper sessionDialog = new SessionDialog(commitExecutor.getActionText(), @@ -778,10 +792,10 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj return myBrowserExtender.getAffectedVcses(); } - private List getAffectedVcses(final Collection changes) { + private static List getAffectedVcses(Project project, final Collection changes) { Set result = new HashSet(); for (Change change : changes) { - final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, myProject); + final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project); if (vcs != null) { result.add(vcs); } diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 321932153d..d383c086de 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -25,6 +25,7 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.ChangeProvider; +import com.intellij.openapi.vcs.changes.CommitExecutor; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.diff.DiffProvider; import com.intellij.openapi.vcs.diff.RevisionSelector; @@ -43,6 +44,7 @@ import git4idea.changes.GitChangeProvider; import git4idea.changes.GitCommittedChangeListProvider; import git4idea.changes.GitOutgoingChangesProvider; import git4idea.checkin.GitCheckinEnvironment; +import git4idea.checkin.GitCommitAndPushExecutor; import git4idea.commands.GitHandler; import git4idea.commands.GitSimpleHandler; import git4idea.config.GitVcsConfigurable; @@ -170,6 +172,8 @@ public class GitVcs extends AbstractVcs { private final TreeDiffProvider myTreeDiffProvider; + private GitCommitAndPushExecutor myCommitAndPushExecutor; + public static GitVcs getInstance(@NotNull Project project) { return (GitVcs)ProjectLevelVcsManager.getInstance(project).findVcsByName(NAME); } @@ -199,6 +203,7 @@ public class GitVcs extends AbstractVcs { myCommittedChangeListProvider = new GitCommittedChangeListProvider(myProject); myOutgoingChangesProvider = new GitOutgoingChangesProvider(myProject); myTreeDiffProvider = new GitTreeDiffProvider(myProject); + myCommitAndPushExecutor = new GitCommitAndPushExecutor(gitCheckinEnvironment); } /** @@ -647,4 +652,9 @@ public class GitVcs extends AbstractVcs { protected TreeDiffProvider getTreeDiffProviderImpl() { return myTreeDiffProvider; } + + @Override + public List getCommitExecutors() { + return Collections.singletonList(myCommitAndPushExecutor); + } } diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index 1bdb3a82e7..0a1d7817b8 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -588,10 +588,6 @@ public class GitCheckinEnvironment implements CheckinEnvironment { */ private final JPanel myPanel; /** - * If checked, the changes are pushed to the server as well as connected. - */ - private final JCheckBox myPushChanges; - /** * The author ComboBox, the combobox contains previously selected authors. */ private final JComboBox myAuthor; @@ -607,21 +603,13 @@ public class GitCheckinEnvironment implements CheckinEnvironment { c.gridy = 0; c.anchor = GridBagConstraints.WEST; c.insets = insets; - myPushChanges = new JCheckBox(GitBundle.message("commit.push.changes")); - myPushChanges.setToolTipText(GitBundle.getString("commit.push.changes.tooltip")); - myPanel.add(myPushChanges, c); - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.WEST; - c.insets = insets; - c.gridx = 0; - c.gridy = 1; final JLabel authorLabel = new JLabel(GitBundle.message("commit.author")); myPanel.add(authorLabel, c); c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.insets = insets; c.gridx = 0; - c.gridy = 2; + c.gridy = 1; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; myAuthor = new JComboBox(mySettings.PREVIOUS_COMMIT_AUTHORS); @@ -645,7 +633,6 @@ public class GitCheckinEnvironment implements CheckinEnvironment { */ public void refresh() { myAuthor.setSelectedItem(""); - myPushChanges.setSelected(false); myNextCommitAuthor = null; myNextCommitIsPushed = null; } @@ -663,7 +650,6 @@ public class GitCheckinEnvironment implements CheckinEnvironment { myNextCommitAuthor = author; mySettings.saveCommitAuthor(author); } - myNextCommitIsPushed = myPushChanges.isSelected(); } /** @@ -673,4 +659,8 @@ public class GitCheckinEnvironment implements CheckinEnvironment { refresh(); } } + + public void setNextCommitIsPushed(Boolean nextCommitIsPushed) { + myNextCommitIsPushed = nextCommitIsPushed; + } } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java b/plugins/git4idea/src/git4idea/checkin/GitCommitAndPushExecutor.java similarity index 53% copy from platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java copy to plugins/git4idea/src/git4idea/checkin/GitCommitAndPushExecutor.java index cb3d695ed6..67b83ec2fc 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitExecutor.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCommitAndPushExecutor.java @@ -13,27 +13,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package git4idea.checkin; -package com.intellij.openapi.vcs.changes; - +import com.intellij.openapi.vcs.changes.CommitExecutor; +import com.intellij.openapi.vcs.changes.CommitSession; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** - * @author max + * @author yole */ -public interface CommitExecutor { - @NotNull - Icon getActionIcon(); +public class GitCommitAndPushExecutor implements CommitExecutor { + private final GitCheckinEnvironment myCheckinEnvironment; - @Nls - String getActionText(); + public GitCommitAndPushExecutor(GitCheckinEnvironment checkinEnvironment) { + myCheckinEnvironment = checkinEnvironment; + } @Nls - String getActionDescription(); + public String getActionText() { + return "Commit and &Push"; + } @NotNull - CommitSession createCommitSession(); + public CommitSession createCommitSession() { + myCheckinEnvironment.setNextCommitIsPushed(true); + return CommitSession.VCS_COMMIT; + } } -- 2.11.4.GIT