From b51333a2f35f94246de8c9be0cf57217e4d24aea Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Wed, 26 Feb 2014 20:19:22 +0400 Subject: [PATCH] IDEA-75033 Implemented feature to automatically switch directory on new branch creation --- .../jetbrains/idea/svn/SvnBundle.properties | 2 + .../svn/actions/CreateBranchOrTagAction.java | 10 +++++ .../svn/dialogs/CreateBranchOrTagDialog.form | 25 +++++++---- .../svn/dialogs/CreateBranchOrTagDialog.java | 7 ++++ .../idea/svn/update/AutoSvnUpdater.java | 9 ++-- .../idea/svn/update/SingleRootSwitcher.java | 41 +++++++++++++++++++ 6 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 plugins/svn4idea/src/org/jetbrains/idea/svn/update/SingleRootSwitcher.java diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties index f9da72589390..a81cc3129c8f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties @@ -458,6 +458,8 @@ compare.with.branch.list.error=Error Loading Branches create.branch.invalid.revision.error=Invalid revision ''{0}'' create.branch.no.working.copy.error=No working copy found at {0} create.branch.no.base.location.error=No branch base location selected +create.branch.switch.on.create.title=Switch after create +action.name.switch=Switch import.dialog.title=Import into Subversion import.dialog.button=Import repository.browser.add.location.action=Add Repository Location diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/CreateBranchOrTagAction.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/CreateBranchOrTagAction.java index d263f1e325b6..43b0a479d089 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/CreateBranchOrTagAction.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/CreateBranchOrTagAction.java @@ -30,6 +30,7 @@ import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.WindowManager; +import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.svn.SvnBundle; import org.jetbrains.idea.svn.SvnStatusUtil; @@ -37,6 +38,8 @@ import org.jetbrains.idea.svn.SvnVcs; import org.jetbrains.idea.svn.checkin.IdeaCommitHandler; import org.jetbrains.idea.svn.commandLine.CommitEventHandler; import org.jetbrains.idea.svn.dialogs.CreateBranchOrTagDialog; +import org.jetbrains.idea.svn.update.AutoSvnUpdater; +import org.jetbrains.idea.svn.update.SingleRootSwitcher; import org.tmatesoft.svn.core.SVNErrorCode; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNURL; @@ -125,6 +128,13 @@ public class CreateBranchOrTagAction extends BasicAction { if (!exception.isNull()) { throw new VcsException(exception.get()); } + + if (dialog.isCopyFromWorkingCopy() && dialog.isSwitchOnCreate()) { + SingleRootSwitcher switcher = + new SingleRootSwitcher(project, VcsUtil.getFilePath(srcFile, srcFile.isDirectory()), dstSvnUrl.toDecodedString()); + + AutoSvnUpdater.run(switcher, SvnBundle.message("action.name.switch")); + } } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.form b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.form index 1b8924b12e77..6dfcae6c9f6f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.form +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.form @@ -2,7 +2,7 @@
- + @@ -26,7 +26,7 @@ - + @@ -55,7 +55,7 @@ - + @@ -63,13 +63,13 @@ - + - + @@ -77,17 +77,17 @@ - + - + - + @@ -103,6 +103,15 @@ + + + + + + + + + diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.java index 05ed4b0689bb..9c5d19420399 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CreateBranchOrTagDialog.java @@ -27,6 +27,7 @@ import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ComboboxWithBrowseButton; import com.intellij.ui.DocumentAdapter; +import com.intellij.ui.components.JBCheckBox; import com.intellij.util.ArrayUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -81,6 +82,7 @@ public class CreateBranchOrTagDialog extends DialogWrapper { private JButton myProjectButton; private JLabel myErrorLabel; private JLabel myUseThisVariantToLabel; + private JBCheckBox mySwitchOnCreate; @NonNls private static final String HELP_ID = "vcs.subversion.branch"; private SvnBranchConfigurationNew myBranchConfiguration; @@ -236,6 +238,7 @@ public class CreateBranchOrTagDialog extends DialogWrapper { private void updateControls() { myWorkingCopyField.setEnabled(myWorkingCopyRadioButton.isSelected()); + mySwitchOnCreate.setEnabled(myWorkingCopyRadioButton.isSelected()); myRepositoryField.setEnabled(myRepositoryRadioButton.isSelected()); myRevisionPanel.setEnabled(myRepositoryRadioButton.isSelected()); myProjectButton.setEnabled(myRepositoryRadioButton.isSelected()); @@ -369,4 +372,8 @@ public class CreateBranchOrTagDialog extends DialogWrapper { public String getCopyFromUrl() { return myRepositoryField.getText(); } + + public boolean isSwitchOnCreate() { + return mySwitchOnCreate.isSelected(); + } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/update/AutoSvnUpdater.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/update/AutoSvnUpdater.java index e349a39ca2f3..925d13c7242f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/update/AutoSvnUpdater.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/update/AutoSvnUpdater.java @@ -69,13 +69,16 @@ public class AutoSvnUpdater extends AbstractCommonUpdateAction { configuration17.setUpdateDepth(SVNDepth.INFINITY); final SvnVcs vcs = SvnVcs.getInstance(myProject); for (FilePath root : myRoots) { - final UpdateRootInfo info = configuration17.getUpdateRootInfo(root.getIOFile(), vcs); - info.setRevision(SVNRevision.HEAD); - info.setUpdateToRevision(false); + configureUpdateRootInfo(root, configuration17.getUpdateRootInfo(root.getIOFile(), vcs)); } super.actionPerformed(context); } + protected void configureUpdateRootInfo(@NotNull FilePath root, @NotNull UpdateRootInfo info) { + info.setRevision(SVNRevision.HEAD); + info.setUpdateToRevision(false); + } + @Override protected boolean filterRootsBeforeAction() { return false; diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SingleRootSwitcher.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SingleRootSwitcher.java new file mode 100644 index 000000000000..2a8423caae1d --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/update/SingleRootSwitcher.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2014 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 org.jetbrains.idea.svn.update; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.FilePath; +import org.jetbrains.annotations.NotNull; + +/** + * @author Konstantin Kolosovsky. + */ +public class SingleRootSwitcher extends AutoSvnUpdater { + + @NotNull private String myUrl; + + public SingleRootSwitcher(Project project, @NotNull FilePath root, @NotNull String url) { + super(project, new FilePath[]{root}); + + myUrl = url; + } + + @Override + protected void configureUpdateRootInfo(@NotNull FilePath root, @NotNull UpdateRootInfo info) { + super.configureUpdateRootInfo(root, info); + + info.setUrl(myUrl); + } +}