summaryrefslogtreecommitdiff
path: root/plugins/hg4idea/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/hg4idea/src/org')
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java85
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAbstractGlobalAction.java15
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAction.java61
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchAbstractAction.java36
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java145
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchesAction.java20
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommonBranchActions.java129
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java15
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagFromLogAction.java7
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java96
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java7
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPushAction.java14
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java36
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java36
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCommand.java65
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCreateCommand.java45
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchesCommand.java (renamed from plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java)45
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java17
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java23
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranch.java52
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java19
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgHeadMerger.java7
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java8
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java6
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.form (renamed from plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.form)14
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java148
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.form139
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java176
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java18
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form97
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java76
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.java45
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRunConflictResolverDialog.java17
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgTagDialog.java11
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java129
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/util/HgBranchesAndTags.java62
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java89
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java22
38 files changed, 735 insertions, 1297 deletions
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java
index 9c10a51a7145..17d4f364a154 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java
@@ -23,27 +23,21 @@ import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
import org.zmlx.hg4idea.command.HgPushCommand;
-import org.zmlx.hg4idea.command.HgTagBranch;
-import org.zmlx.hg4idea.command.HgTagBranchCommand;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgPushDialog;
-import org.zmlx.hg4idea.util.HgUtil;
-import java.util.Collections;
+import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-/**
- * @author Kirill Likhodedov
- */
public class HgPusher {
private static final Logger LOG = Logger.getInstance(HgPusher.class);
@@ -59,52 +53,27 @@ public class HgPusher {
myProject = project;
}
- public void showDialogAndPush(@Nullable final VirtualFile selectedRepo) {
- HgUtil.executeOnPooledThreadIfNeeded(new Runnable() {
- public void run() {
- final List<VirtualFile> repositories = HgUtil.getHgRepositories(myProject);
- if (repositories.isEmpty()) {
- VcsBalloonProblemNotifier.showOverChangesView(myProject, "No Mercurial repositories in the project", MessageType.ERROR);
- return;
- }
- VirtualFile firstRepo = repositories.get(0);
- final List<HgTagBranch> branches = getBranches(myProject, firstRepo);
- if (branches.isEmpty()) {
- return;
- }
- final AtomicReference<HgPushCommand> pushCommand = new AtomicReference<HgPushCommand>();
- UIUtil.invokeAndWaitIfNeeded(new Runnable() {
- @Override
- public void run() {
- final HgPushDialog dialog = new HgPushDialog(myProject, repositories, branches, selectedRepo);
- dialog.show();
- if (dialog.isOK()) {
- dialog.rememberSettings();
- pushCommand.set(preparePushCommand(myProject, dialog));
- new Task.Backgroundable(myProject, "Pushing...", false) {
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- if (pushCommand.get() != null) {
- push(myProject, pushCommand.get());
- }
- }
- }.queue();
- }
- }
- });
- }
- });
- }
+ public void showDialogAndPush (@NotNull Collection<HgRepository> repositories,@Nullable final HgRepository selectedRepo) {
- @NotNull
- public static List<HgTagBranch> getBranches(@NotNull Project project, @NotNull VirtualFile root) {
- HgCommandResult branchesResult = new HgTagBranchCommand(project, root).collectBranches();
- if (branchesResult == null) {
- new HgCommandResultNotifier(project)
- .notifyError(branchesResult, "Mercurial command failed", HgVcsMessages.message("hg4idea.branches.error.description"));
- return Collections.emptyList();
+ if (repositories.isEmpty()) {
+ VcsBalloonProblemNotifier.showOverChangesView(myProject, "No Mercurial repositories in the project", MessageType.ERROR);
+ return;
+ }
+ final AtomicReference<HgPushCommand> pushCommand = new AtomicReference<HgPushCommand>();
+ final HgPushDialog dialog = new HgPushDialog(myProject, repositories, selectedRepo);
+ dialog.show();
+ if (dialog.isOK()) {
+ dialog.rememberSettings();
+ pushCommand.set(preparePushCommand(myProject, dialog));
+ new Task.Backgroundable(myProject, "Pushing...", false) {
+ @Override
+ public void run(@NotNull ProgressIndicator indicator) {
+ if (pushCommand.get() != null) {
+ push(myProject, pushCommand.get());
+ }
+ }
+ }.queue();
}
- return HgTagBranchCommand.parseResult(branchesResult);
}
private static void push(final Project project, HgPushCommand command) {
@@ -122,9 +91,11 @@ public class HgPusher {
String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum),
repo.getPresentableName());
new HgCommandResultNotifier(project).notifySuccess(successTitle, successDescription);
- } else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) {
+ }
+ else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) {
new HgCommandResultNotifier(project).notifySuccess("", "Nothing to push");
- } else {
+ }
+ else {
new HgCommandResultNotifier(project).notifyError(result, "Push failed",
"Failed to push to [" + repo.getPresentableName() + "]");
}
@@ -133,10 +104,11 @@ public class HgPusher {
}
private static HgPushCommand preparePushCommand(Project project, HgPushDialog dialog) {
- final HgPushCommand command = new HgPushCommand(project, dialog.getRepository(), dialog.getTarget());
+ final HgPushCommand command = new HgPushCommand(project, dialog.getRepository().getRoot(), dialog.getTarget());
command.setRevision(dialog.getRevision());
command.setForce(dialog.isForce());
- command.setBranch(dialog.getBranch());
+ command.setBranchName(dialog.getBranch());
+ command.setBookmarkName(dialog.getBookmarkName());
command.setIsNewBranch(dialog.isNewBranch());
return command;
}
@@ -159,5 +131,4 @@ public class HgPusher {
}
return numberOfCommitsInAllSubrepos;
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAbstractGlobalAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAbstractGlobalAction.java
index 3db5f19df3d9..9984facc8037 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAbstractGlobalAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAbstractGlobalAction.java
@@ -23,6 +23,8 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcs;
+import org.zmlx.hg4idea.repo.HgRepository;
+import org.zmlx.hg4idea.repo.HgRepositoryManager;
import org.zmlx.hg4idea.util.HgUtil;
import javax.swing.*;
@@ -47,10 +49,11 @@ abstract class HgAbstractGlobalAction extends AnAction {
return;
}
VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
- VirtualFile repo = file != null ? HgUtil.getHgRootOrNull(project, file) : null;
- List<VirtualFile> repos = HgUtil.getHgRepositories(project);
- if (!repos.isEmpty()) {
- execute(project, repos, repo);
+ HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(project);
+ HgRepository repo = file != null ? repositoryManager.getRepositoryForFile(file): HgUtil.getCurrentRepository(project);
+ List<HgRepository> repositories = repositoryManager.getRepositories();
+ if (!repositories.isEmpty()) {
+ execute(project, repositories, repo);
}
}
@@ -62,8 +65,8 @@ abstract class HgAbstractGlobalAction extends AnAction {
}
protected abstract void execute(@NotNull Project project,
- @NotNull Collection<VirtualFile> repositories,
- @Nullable VirtualFile selectedRepo);
+ @NotNull Collection<HgRepository> repositories,
+ @Nullable HgRepository selectedRepo);
public static void handleException(@Nullable Project project, @NotNull Exception e) {
handleException(project, "Error", e);
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAction.java
deleted file mode 100644
index 6660d104f49e..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgAction.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2000-2011 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.zmlx.hg4idea.action;
-
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.CommonDataKeys;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.util.HgUtil;
-
-import javax.swing.*;
-
-/**
- * @author Kirill Likhodedov
- */
-public abstract class HgAction extends AnAction {
- protected HgAction() {
- }
-
- protected HgAction(Icon icon) {
- super(icon);
- }
-
- @Override
- public void actionPerformed(AnActionEvent event) {
- final DataContext dataContext = event.getDataContext();
- final Project project = CommonDataKeys.PROJECT.getData(dataContext);
- if (project == null) {
- return;
- }
- VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
- VirtualFile repo = file != null ? HgUtil.getHgRootOrNull(project, file) : null;
- execute(project, repo);
- }
-
- @Override
- public void update(AnActionEvent e) {
- boolean enabled = HgAbstractGlobalAction.isEnabled(e);
- e.getPresentation().setEnabled(enabled);
- }
-
- public abstract void execute(Project project, @Nullable VirtualFile selectedRepo);
-
-}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchAbstractAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchAbstractAction.java
new file mode 100644
index 000000000000..78b67013ed54
--- /dev/null
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchAbstractAction.java
@@ -0,0 +1,36 @@
+/*
+ * 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.zmlx.hg4idea.action;
+
+import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+import org.zmlx.hg4idea.repo.HgRepository;
+
+public abstract class HgBranchAbstractAction extends DumbAwareAction {
+ @NotNull protected final Project myProject;
+ @NotNull protected final HgRepository mySelectedRepository;
+ @NotNull protected final String myBranchName;
+
+ public HgBranchAbstractAction(@NotNull Project project, @NotNull String title,
+ @NotNull HgRepository selectedRepository,
+ @NotNull String branchName) {
+ super(title);
+ myProject = project;
+ mySelectedRepository = selectedRepository;
+ myBranchName = branchName;
+ }
+} \ No newline at end of file
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java
index b2b4f99fd946..01627240d8e4 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java
@@ -23,13 +23,10 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vcs.VcsException;
-import com.intellij.openapi.vcs.update.UpdatedFiles;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.PlatformIcons;
import com.intellij.util.containers.ContainerUtil;
@@ -39,14 +36,12 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgNameWithHashInfo;
import org.zmlx.hg4idea.HgRevisionNumber;
-import org.zmlx.hg4idea.HgVcs;
-import org.zmlx.hg4idea.HgVcsMessages;
-import org.zmlx.hg4idea.command.*;
+import org.zmlx.hg4idea.command.HgBookmarkCommand;
+import org.zmlx.hg4idea.command.HgBranchCreateCommand;
+import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
import org.zmlx.hg4idea.execution.HgCommandException;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
-import org.zmlx.hg4idea.provider.update.HgConflictResolver;
-import org.zmlx.hg4idea.provider.update.HgHeadMerger;
import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgBookmarkDialog;
import org.zmlx.hg4idea.util.HgErrorUtil;
@@ -55,9 +50,6 @@ import java.util.*;
import static org.zmlx.hg4idea.util.HgUtil.*;
-/**
- * @author Nadya Zabrodina
- */
public class HgBranchPopupActions {
private final Project myProject;
@@ -80,9 +72,8 @@ public class HgBranchPopupActions {
popupGroup.addSeparator("Bookmarks");
List<String> bookmarkNames = getNamesWithoutHashes(myRepository.getBookmarks());
String currentBookmark = myRepository.getCurrentBookmark();
- Collections.sort(bookmarkNames);
for (String bookmark : bookmarkNames) {
- AnAction bookmarkAction = new BranchActions(myProject, bookmark, myRepository);
+ AnAction bookmarkAction = new BookmarkActions(myProject, myRepository, bookmark);
if (bookmark.equals(currentBookmark)) {
bookmarkAction.getTemplatePresentation().setIcon(PlatformIcons.CHECK_ICON);
}
@@ -94,7 +85,7 @@ public class HgBranchPopupActions {
Collections.sort(branchNamesList);
for (String branch : branchNamesList) {
if (!branch.equals(myRepository.getCurrentBranch())) { // don't show current branch in the list
- popupGroup.add(new BranchActions(myProject, branch, myRepository));
+ popupGroup.add(new HgCommonBranchActions(myProject, myRepository, branch));
}
}
return popupGroup;
@@ -160,17 +151,7 @@ public class HgBranchPopupActions {
if (bookmarkDialog.isOK()) {
try {
final String name = bookmarkDialog.getName();
- new HgBookmarkCreateCommand(myProject, myPreselectedRepo, name,
- bookmarkDialog.isActive()).execute(new HgCommandResultHandler() {
- @Override
- public void process(@Nullable HgCommandResult result) {
- getRepositoryManager(myProject).updateRepository(myPreselectedRepo);
- if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
- new HgCommandResultNotifier(myProject)
- .notifyError(result, "Creation failed", "Bookmark creation [" + name + "] failed");
- }
- }
- });
+ new HgBookmarkCommand(myProject, myPreselectedRepo, name).createBookmark(bookmarkDialog.isActive());
}
catch (HgCommandException exception) {
HgAbstractGlobalAction.handleException(myProject, exception);
@@ -229,7 +210,7 @@ public class HgBranchPopupActions {
public AnAction[] getChildren(@Nullable AnActionEvent e) {
List<AnAction> branchHeadActions = new ArrayList<AnAction>();
for (Hash hash : myHeads) {
- branchHeadActions.add(new BranchActions(myProject, hash.toShortString(), myRepository));
+ branchHeadActions.add(new HgCommonBranchActions(myProject, myRepository, hash.toShortString()));
}
return ContainerUtil.toArray(branchHeadActions, new AnAction[branchHeadActions.size()]);
}
@@ -246,117 +227,35 @@ public class HgBranchPopupActions {
}
}
-
/**
- * Actions available for branches.
+ * Actions available for bookmarks.
*/
- static class BranchActions extends ActionGroup {
-
- private final Project myProject;
- private String myBranchName;
- @NotNull private final HgRepository mySelectedRepository;
-
- BranchActions(@NotNull Project project, @NotNull String branchName,
- @NotNull HgRepository selectedRepository) {
- super("", true);
- myProject = project;
- myBranchName = branchName;
- mySelectedRepository = selectedRepository;
- getTemplatePresentation().setText(calcBranchText(), false); // no mnemonics
- }
+ static class BookmarkActions extends HgCommonBranchActions {
- @NotNull
- private String calcBranchText() {
- return myBranchName;
+ BookmarkActions(@NotNull Project project, @NotNull HgRepository selectedRepository, @NotNull String branchName) {
+ super(project, selectedRepository, branchName);
}
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
- return new AnAction[]{
- new UpdateToAction(myProject, mySelectedRepository, myBranchName),
- new MergeAction(myProject, mySelectedRepository, myBranchName)
- };
+ return ArrayUtil.append(super.getChildren(e), new DeleteBookmarkAction(myProject, mySelectedRepository, myBranchName));
}
- private static class MergeAction extends DumbAwareAction {
-
- private final Project myProject;
- private final HgRepository mySelectedRepository;
- private final String myBranchName;
+ private static class DeleteBookmarkAction extends HgBranchAbstractAction {
- public MergeAction(@NotNull Project project,
- @NotNull HgRepository selectedRepository,
- @NotNull String branchName) {
- super("Merge");
- myProject = project;
- mySelectedRepository = selectedRepository;
- myBranchName = branchName;
+ DeleteBookmarkAction(@NotNull Project project, @NotNull HgRepository selectedRepository, @NotNull String branchName) {
+ super(project, "Delete", selectedRepository, branchName);
}
@Override
public void actionPerformed(AnActionEvent e) {
- final UpdatedFiles updatedFiles = UpdatedFiles.create();
- final HgMergeCommand hgMergeCommand = new HgMergeCommand(myProject, mySelectedRepository.getRoot());
- hgMergeCommand.setBranch(myBranchName);
- final HgCommandResultNotifier notifier = new HgCommandResultNotifier(myProject);
- new Task.Backgroundable(myProject, "Merging changes...") {
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- try {
- new HgHeadMerger(myProject, hgMergeCommand)
- .merge(mySelectedRepository.getRoot(), updatedFiles, HgRevisionNumber.NULL_REVISION_NUMBER);
- new HgConflictResolver(myProject, updatedFiles).resolve(mySelectedRepository.getRoot());
- }
-
- catch (VcsException exception) {
- if (exception.isWarning()) {
- notifier.notifyWarning("Warning during merge", exception.getMessage());
- }
- else {
- notifier.notifyError(null, "Exception during merge", exception.getMessage());
- }
- }
- catch (Exception e1) {
- HgAbstractGlobalAction.handleException(myProject, e1);
- }
- }
- }.queue();
- }
- }
-
- private static class UpdateToAction extends DumbAwareAction {
-
- @NotNull private final Project myProject;
- @NotNull private final HgRepository mySelectedRepository;
- @NotNull private final String myBranch;
-
- public UpdateToAction(@NotNull Project project,
- @NotNull HgRepository selectedRepository,
- @NotNull String branch) {
- super("Update To");
- myProject = project;
- mySelectedRepository = selectedRepository;
- myBranch = branch;
- }
-
- @Override
- public void actionPerformed(AnActionEvent e) {
- final VirtualFile repository = mySelectedRepository.getRoot();
- final HgUpdateCommand hgUpdateCommand = new HgUpdateCommand(myProject, repository);
- hgUpdateCommand.setBranch(myBranch);
- new Task.Backgroundable(myProject, HgVcsMessages.message("action.hg4idea.updateTo.description", myBranch)) {
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- HgCommandResult result = hgUpdateCommand.execute();
- assert myProject != null; // myProject couldn't be null, see annotation for updateTo action
- if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
- new HgCommandResultNotifier(myProject).notifyError(result, "", "Update failed");
- new HgConflictResolver(myProject).resolve(repository);
- }
- myProject.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(myProject, null);
- }
- }.queue();
+ try {
+ new HgBookmarkCommand(myProject, mySelectedRepository.getRoot(), myBranchName).deleteBookmark();
+ }
+ catch (HgCommandException exception) {
+ HgAbstractGlobalAction.handleException(myProject, exception);
+ }
}
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchesAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchesAction.java
index 61cf991c20a5..b8a10ed92116 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchesAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchesAction.java
@@ -16,34 +16,18 @@
package org.zmlx.hg4idea.action;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.repo.HgRepository;
-import org.zmlx.hg4idea.util.HgUtil;
import java.util.Collection;
-/**
- * @author Nadya Zabrodina
- */
-
public class HgBranchesAction extends HgAbstractGlobalAction {
@Override
- protected void execute(@NotNull Project project, @NotNull Collection<VirtualFile> repositories, @Nullable VirtualFile selectedRepo) {
- HgRepository repository = null;
+ protected void execute(@NotNull Project project, @NotNull Collection<HgRepository> repositories, @Nullable HgRepository selectedRepo) {
if (selectedRepo != null) {
- repository = HgUtil.getRepositoryManager(project).getRepositoryForRoot(selectedRepo);
- }
- else {
- VirtualFile selectedRoot = HgUtil.getRootForSelectedFile(project);
- if (selectedRoot != null) {
- repository = HgUtil.getRepositoryManager(project).getRepositoryForRoot(selectedRoot);
- }
- }
- if (repository != null) {
- HgBranchPopup.getInstance(project, repository).asListPopup().showInFocusCenter();
+ HgBranchPopup.getInstance(project, selectedRepo).asListPopup().showInFocusCenter();
}
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommonBranchActions.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommonBranchActions.java
new file mode 100644
index 000000000000..992a26c6ab5e
--- /dev/null
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCommonBranchActions.java
@@ -0,0 +1,129 @@
+/*
+ * 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.zmlx.hg4idea.action;
+
+import com.intellij.openapi.actionSystem.ActionGroup;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.progress.ProgressIndicator;
+import com.intellij.openapi.progress.Task;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.VcsException;
+import com.intellij.openapi.vcs.update.UpdatedFiles;
+import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.zmlx.hg4idea.HgVcs;
+import org.zmlx.hg4idea.HgVcsMessages;
+import org.zmlx.hg4idea.command.HgMergeCommand;
+import org.zmlx.hg4idea.command.HgUpdateCommand;
+import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.provider.update.HgConflictResolver;
+import org.zmlx.hg4idea.provider.update.HgHeadMerger;
+import org.zmlx.hg4idea.repo.HgRepository;
+import org.zmlx.hg4idea.util.HgErrorUtil;
+
+public class HgCommonBranchActions extends ActionGroup {
+
+ @NotNull protected final Project myProject;
+ @NotNull protected String myBranchName;
+ @NotNull protected final HgRepository mySelectedRepository;
+
+ HgCommonBranchActions(@NotNull Project project, @NotNull HgRepository selectedRepository, @NotNull String branchName) {
+ super("", true);
+ myProject = project;
+ myBranchName = branchName;
+ mySelectedRepository = selectedRepository;
+ getTemplatePresentation().setText(myBranchName, false); // no mnemonics
+ }
+
+ @NotNull
+ @Override
+ public AnAction[] getChildren(@Nullable AnActionEvent e) {
+ return new AnAction[]{
+ new UpdateAction(myProject, mySelectedRepository, myBranchName),
+ new MergeAction(myProject, mySelectedRepository, myBranchName)
+ };
+ }
+
+ private static class MergeAction extends HgBranchAbstractAction {
+
+ public MergeAction(@NotNull Project project,
+ @NotNull HgRepository selectedRepository,
+ @NotNull String branchName) {
+ super(project, "Merge", selectedRepository, branchName);
+ }
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ final UpdatedFiles updatedFiles = UpdatedFiles.create();
+ final HgMergeCommand hgMergeCommand = new HgMergeCommand(myProject, mySelectedRepository.getRoot());
+ hgMergeCommand.setRevision(myBranchName);//there is no difference between branch or revision or bookmark as parameter to merge,
+ // we need just a string
+ final HgCommandResultNotifier notifier = new HgCommandResultNotifier(myProject);
+ new Task.Backgroundable(myProject, "Merging changes...") {
+ @Override
+ public void run(@NotNull ProgressIndicator indicator) {
+ try {
+ new HgHeadMerger(myProject, hgMergeCommand)
+ .merge(mySelectedRepository.getRoot());
+ new HgConflictResolver(myProject, updatedFiles).resolve(mySelectedRepository.getRoot());
+ }
+
+ catch (VcsException exception) {
+ if (exception.isWarning()) {
+ notifier.notifyWarning("Warning during merge", exception.getMessage());
+ }
+ else {
+ notifier.notifyError(null, "Exception during merge", exception.getMessage());
+ }
+ }
+ catch (Exception e1) {
+ HgAbstractGlobalAction.handleException(myProject, e1);
+ }
+ }
+ }.queue();
+ }
+ }
+
+ private static class UpdateAction extends HgBranchAbstractAction {
+
+ public UpdateAction(@NotNull Project project,
+ @NotNull HgRepository selectedRepository,
+ @NotNull String branchName) {
+ super(project, "Update", selectedRepository, branchName);
+ }
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ final VirtualFile repository = mySelectedRepository.getRoot();
+ final HgUpdateCommand hgUpdateCommand = new HgUpdateCommand(myProject, repository);
+ hgUpdateCommand.setBranch(myBranchName);
+ new Task.Backgroundable(myProject, HgVcsMessages.message("action.hg4idea.updateTo.description", myBranchName)) {
+ @Override
+ public void run(@NotNull ProgressIndicator indicator) {
+ HgCommandResult result = hgUpdateCommand.execute();
+ assert myProject != null; // myProject couldn't be null, see annotation for updateTo action
+ if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
+ new HgCommandResultNotifier(myProject).notifyError(result, "", "Update failed");
+ new HgConflictResolver(myProject).resolve(repository);
+ }
+ myProject.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(myProject, null);
+ }
+ }.queue();
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java
index 1aec1a0e56e4..5c97e3ca9f39 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java
@@ -13,13 +13,13 @@
package org.zmlx.hg4idea.action;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.command.HgTagCreateCommand;
import org.zmlx.hg4idea.execution.HgCommandException;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgTagDialog;
import org.zmlx.hg4idea.util.HgErrorUtil;
@@ -28,11 +28,10 @@ import java.util.Collection;
public class HgCreateTagAction extends HgAbstractGlobalAction {
public void execute(@NotNull final Project project,
- @NotNull Collection<VirtualFile> repos,
- @Nullable VirtualFile selectedRepo,
+ @NotNull Collection<HgRepository> repositories,
+ @Nullable HgRepository selectedRepo,
@Nullable final String reference) {
- final HgTagDialog dialog = new HgTagDialog(project);
- dialog.setRoots(repos, selectedRepo);
+ final HgTagDialog dialog = new HgTagDialog(project, repositories, selectedRepo);
dialog.show();
if (dialog.isOK()) {
try {
@@ -52,7 +51,9 @@ public class HgCreateTagAction extends HgAbstractGlobalAction {
}
}
- protected void execute(@NotNull final Project project, @NotNull Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo) {
- execute(project, repos, selectedRepo, null);
+ protected void execute(@NotNull final Project project,
+ @NotNull Collection<HgRepository> repositories,
+ @Nullable HgRepository selectedRepo) {
+ execute(project, repositories, selectedRepo, null);
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagFromLogAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagFromLogAction.java
index 18a42d735046..03f6f951cea7 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagFromLogAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagFromLogAction.java
@@ -19,15 +19,12 @@ import com.intellij.vcs.log.VcsFullCommitDetails;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.repo.HgRepository;
-import java.util.Arrays;
+import java.util.Collections;
-/**
- * @author Nadya Zabrodina
- */
public class HgCreateTagFromLogAction extends HgLogSingleCommitAction {
@Override
protected void actionPerformed(@NotNull HgRepository repository, @NotNull VcsFullCommitDetails commit) {
String revisionHash = commit.getHash().asString();
- new HgCreateTagAction().execute(repository.getProject(), Arrays.asList(repository.getRoot()), repository.getRoot(), revisionHash);
+ new HgCreateTagAction().execute(repository.getProject(), Collections.singleton(repository), repository, revisionHash);
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java
index fe022bcfb775..87c907d76d59 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMerge.java
@@ -18,56 +18,37 @@ package org.zmlx.hg4idea.action;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.update.UpdatedFiles;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.HgRevisionNumber;
-import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.command.HgMergeCommand;
-import org.zmlx.hg4idea.command.HgTagBranch;
import org.zmlx.hg4idea.execution.HgCommandException;
import org.zmlx.hg4idea.provider.update.HgConflictResolver;
import org.zmlx.hg4idea.provider.update.HgHeadMerger;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgMergeDialog;
-import org.zmlx.hg4idea.util.HgBranchesAndTags;
-import org.zmlx.hg4idea.util.HgUiUtil;
import java.util.Collection;
-/**
- * @author Nadya Zabrodina
- */
public class HgMerge extends HgAbstractGlobalAction {
@Override
public void execute(@NotNull final Project project,
- @NotNull final Collection<VirtualFile> repos,
- @Nullable final VirtualFile selectedRepo) {
- HgUiUtil.loadBranchesInBackgroundableAndExecuteAction(project, repos, new Consumer<HgBranchesAndTags>() {
-
- @Override
- public void consume(HgBranchesAndTags info) {
- showMergeDialogAndExecute(project, repos, selectedRepo, info);
- }
- });
- }
-
- private void showMergeDialogAndExecute(final Project project,
- Collection<VirtualFile> repos,
- @Nullable VirtualFile selectedRepo, HgBranchesAndTags branchesAndTags) {
- final HgMergeDialog mergeDialog = new HgMergeDialog(project, repos, selectedRepo, branchesAndTags);
+ @NotNull final Collection<HgRepository> repos,
+ @Nullable final HgRepository selectedRepo) {
+ final HgMergeDialog mergeDialog = new HgMergeDialog(project, repos, selectedRepo);
mergeDialog.show();
if (mergeDialog.isOK()) {
+ final String targetValue = mergeDialog.getTargetValue();
+ final VirtualFile repoRoot = mergeDialog.getRepository().getRoot();
new Task.Backgroundable(project, "Merging changes...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
- executeMerge(mergeDialog, project);
- markDirtyAndHandleErrors(project, mergeDialog.getRepository());
+ executeMerge(project, repoRoot, targetValue);
+ markDirtyAndHandleErrors(project, repoRoot);
}
catch (HgCommandException e) {
handleException(project, e);
@@ -77,63 +58,26 @@ public class HgMerge extends HgAbstractGlobalAction {
}
}
- private static void executeMerge(final HgMergeDialog dialog, final Project project) throws HgCommandException {
+
+ private static void executeMerge(@NotNull final Project project, @NotNull VirtualFile repo, @NotNull String targetValue)
+ throws HgCommandException {
UpdatedFiles updatedFiles = UpdatedFiles.create();
HgCommandResultNotifier notifier = new HgCommandResultNotifier(project);
- final VirtualFile repo = dialog.getRepository();
HgMergeCommand hgMergeCommand = new HgMergeCommand(project, repo);
+ hgMergeCommand.setRevision(targetValue);
- HgRevisionNumber incomingRevision = null;
- HgTagBranch branch = dialog.getBranch();
- if (branch != null) {
- hgMergeCommand.setBranch(branch.getName());
- incomingRevision = branch.getHead();
- }
-
- HgTagBranch tag = dialog.getTag();
- if (tag != null) {
- hgMergeCommand.setRevision(tag.getName());
- incomingRevision = tag.getHead();
- }
-
- HgTagBranch bookmark = dialog.getBookmark();
- if (bookmark != null) {
- hgMergeCommand.setRevision(bookmark.getName());
- incomingRevision = bookmark.getHead();
- }
-
- String revision = dialog.getRevision();
- if (revision != null) {
- hgMergeCommand.setRevision(revision);
- incomingRevision = HgRevisionNumber.getLocalInstance(revision);
- }
-
- HgRevisionNumber otherHead = dialog.getOtherHead();
- if (otherHead != null) {
- String changeset = otherHead.getChangeset();
- hgMergeCommand.setRevision(StringUtil.isEmptyOrSpaces(changeset) ? otherHead.getRevision() : changeset);
- incomingRevision = otherHead;
+ try {
+ new HgHeadMerger(project, hgMergeCommand).merge(repo);
+ new HgConflictResolver(project, updatedFiles).resolve(repo);
}
-
- if (incomingRevision != null) {
- try {
- new HgHeadMerger(project, hgMergeCommand)
- .merge(repo, updatedFiles, incomingRevision);
- new HgConflictResolver(project, updatedFiles).resolve(repo);
+ catch (VcsException e) {
+ if (e.isWarning()) {
+ notifier.notifyWarning("Warning during merge", e.getMessage());
}
- catch (VcsException e) {
- if (e.isWarning()) {
- notifier.notifyWarning("Warning during merge", e.getMessage());
- }
- else {
- notifier.notifyError(null, "Exception during merge", e.getMessage());
- }
+ else {
+ notifier.notifyError(null, "Exception during merge", e.getMessage());
}
}
- else {
- //noinspection ThrowableInstanceNeverThrown
- notifier.notifyError(null, "Merge error", HgVcsMessages.message("hg4idea.error.invalidTarget"));
- }
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java
index 136a50e69809..557d3cfab286 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java
@@ -16,10 +16,10 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.command.HgPullCommand;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgPullDialog;
import java.util.Collection;
@@ -30,9 +30,8 @@ public class HgPullAction extends HgAbstractGlobalAction {
}
@Override
- protected void execute(@NotNull final Project project, @NotNull Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo) {
- final HgPullDialog dialog = new HgPullDialog(project);
- dialog.setRoots(repos, selectedRepo);
+ protected void execute(@NotNull final Project project, @NotNull Collection<HgRepository> repos, @Nullable HgRepository selectedRepo) {
+ final HgPullDialog dialog = new HgPullDialog(project, repos, selectedRepo);
dialog.show();
if (dialog.isOK()) {
dialog.rememberSettings();
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPushAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPushAction.java
index ae6206c7a253..1b5704f1d0f4 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPushAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPushAction.java
@@ -14,18 +14,22 @@ package org.zmlx.hg4idea.action;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgPusher;
+import org.zmlx.hg4idea.repo.HgRepository;
-public class HgPushAction extends HgAction {
+import java.util.Collection;
+
+public class HgPushAction extends HgAbstractGlobalAction {
public HgPushAction() {
super(AllIcons.Actions.Commit);
}
@Override
- public void execute(final Project project, @Nullable final VirtualFile selectedRepo) {
- new HgPusher(project).showDialogAndPush(selectedRepo);
+ public void execute(@NotNull final Project project,
+ @NotNull Collection<HgRepository> repositories,
+ @Nullable final HgRepository selectedRepo) {
+ new HgPusher(project).showDialogAndPush(repositories, selectedRepo);
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java
index 3be82ada2a8d..938413e95356 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java
@@ -15,11 +15,12 @@ package org.zmlx.hg4idea.action;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.provider.update.HgConflictResolver;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgRunConflictResolverDialog;
import java.util.Collection;
@@ -27,39 +28,26 @@ import java.util.Collection;
public class HgRunConflictResolverAction extends HgAbstractGlobalAction {
@Override
- public void execute(@NotNull final Project project, @NotNull Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo) {
- final VirtualFile repository;
- if (repos.size() > 1) {
- repository = letUserSelectRepository(repos, project, selectedRepo);
- }
- else if (repos.size() == 1) {
- repository = repos.iterator().next();
- }
- else {
- repository = null;
- }
+ public void execute(@NotNull final Project project, @NotNull Collection<HgRepository> repositories, @Nullable HgRepository selectedRepo) {
+ final HgRepository repository = repositories.size() > 1 ? letUserSelectRepository(project, repositories, selectedRepo) :
+ ContainerUtil.getFirstItem(repositories);
if (repository != null) {
new Task.Backgroundable(project, HgVcsMessages.message("action.hg4idea.run.conflict.resolver.description")) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
- new HgConflictResolver(project).resolve(repository);
- markDirtyAndHandleErrors(project, repository);
+ new HgConflictResolver(project).resolve(repository.getRoot());
+ markDirtyAndHandleErrors(project, repository.getRoot());
}
}.queue();
}
}
-
- private static VirtualFile letUserSelectRepository(Collection<VirtualFile> repos, Project project, @Nullable VirtualFile selectedRepo) {
- HgRunConflictResolverDialog dialog = new HgRunConflictResolverDialog(project);
- dialog.setRoots(repos, selectedRepo);
+ @Nullable
+ private static HgRepository letUserSelectRepository(@NotNull Project project, @NotNull Collection<HgRepository> repositories,
+ @Nullable HgRepository selectedRepo) {
+ HgRunConflictResolverDialog dialog = new HgRunConflictResolverDialog(project, repositories, selectedRepo);
dialog.show();
- if (dialog.isOK()) {
- return dialog.getRepository();
- }
- else {
- return null;
- }
+ return dialog.isOK() ? dialog.getRepository() : null;
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java
index 1a2cdeae8b55..7e1025921234 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java
@@ -17,61 +17,43 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcsMessages;
import org.zmlx.hg4idea.command.HgUpdateCommand;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.provider.update.HgConflictResolver;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.ui.HgUpdateToDialog;
-import org.zmlx.hg4idea.util.HgBranchesAndTags;
import org.zmlx.hg4idea.util.HgErrorUtil;
-import org.zmlx.hg4idea.util.HgUiUtil;
import java.util.Collection;
public class HgUpdateToAction extends HgAbstractGlobalAction {
- protected void execute(@NotNull final Project project,
- @NotNull final Collection<VirtualFile> repos,
- @Nullable final VirtualFile selectedRepo) {
- HgUiUtil.loadBranchesInBackgroundableAndExecuteAction(project, repos, new Consumer<HgBranchesAndTags>() {
- @Override
- public void consume(HgBranchesAndTags info) {
- showUpdateDialogAndExecute(project, repos, selectedRepo, info);
- }
- });
- }
-
- private static void showUpdateDialogAndExecute(@NotNull final Project project,
- @NotNull Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo,
- @NotNull HgBranchesAndTags branchesAndTags) {
- final HgUpdateToDialog dialog = new HgUpdateToDialog(project);
- dialog.setRoots(repos, selectedRepo, branchesAndTags);
+ @Override
+ protected void execute(@NotNull Project project, @NotNull Collection<HgRepository> repositories, @Nullable HgRepository selectedRepo) {
+ final HgUpdateToDialog dialog = new HgUpdateToDialog(project, repositories, selectedRepo);
dialog.show();
if (dialog.isOK()) {
FileDocumentManager.getInstance().saveAllDocuments();
- final String updateToValue = dialog.isBranchSelected()
- ? dialog.getBranch().getName()
- : dialog.isBookmarkSelected()
- ? dialog.getBookmark().getName()
- : dialog.isTagSelected() ? dialog.getTag().getName() : dialog.getRevision();
+ final String updateToValue = dialog.getTargetValue();
+ boolean clean = dialog.isRemoveLocalChanges();
String title = HgVcsMessages.message("hg4idea.progress.updatingTo", updateToValue);
- runUpdateToInBackground(project, title, dialog.getRepository(), updateToValue, dialog.isRemoveLocalChanges());
+ runUpdateToInBackground(project, title, dialog.getRepository().getRoot(), updateToValue, clean);
}
}
public static void runUpdateToInBackground(@NotNull final Project project,
@NotNull String title,
@NotNull final VirtualFile root,
- @NotNull final String updateToNameOrRevision,
+ @NotNull final String updateToValue,
final boolean clean) {
new Task.Backgroundable(project, title) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final HgUpdateCommand command = new HgUpdateCommand(project, root);
- command.setRevision(updateToNameOrRevision);
+ command.setRevision(updateToValue);
command.setClean(clean);
HgCommandResult result = command.execute();
new HgConflictResolver(project).resolve(root);
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCommand.java
new file mode 100644
index 000000000000..21b4edd2d7cb
--- /dev/null
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCommand.java
@@ -0,0 +1,65 @@
+package org.zmlx.hg4idea.command;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.zmlx.hg4idea.action.HgCommandResultNotifier;
+import org.zmlx.hg4idea.execution.HgCommandException;
+import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
+import org.zmlx.hg4idea.util.HgErrorUtil;
+
+import java.util.List;
+
+import static org.zmlx.hg4idea.util.HgUtil.getRepositoryManager;
+
+public class HgBookmarkCommand {
+ @NotNull private final Project myProject;
+ @NotNull private final VirtualFile myRepo;
+ @Nullable private final String myBookmarkName;
+ @NotNull private final HgCommandResultHandler myBookmarkResultHandler;
+
+ public HgBookmarkCommand(@NotNull Project project,
+ @NotNull VirtualFile repo,
+ @Nullable String bookmarkName) {
+ myProject = project;
+ myRepo = repo;
+ myBookmarkName = bookmarkName;
+ myBookmarkResultHandler = new HgCommandResultHandler() {
+ @Override
+ public void process(@Nullable HgCommandResult result) {
+ getRepositoryManager(myProject).updateRepository(myRepo);
+ if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
+ new HgCommandResultNotifier(myProject)
+ .notifyError(result, "Hg Error", "Hg bookmark command failed for " + myBookmarkName);
+ }
+ }
+ };
+ }
+
+ public void createBookmark(boolean isActive) throws HgCommandException {
+ if (isActive) {
+ executeBookmarkCommand();
+ }
+ else {
+ executeBookmarkCommand("--inactive");
+ }
+ }
+
+ public void deleteBookmark() throws HgCommandException {
+ executeBookmarkCommand("-d"); //delete
+ }
+
+ private void executeBookmarkCommand(@NotNull String... args) throws HgCommandException {
+ if (StringUtil.isEmptyOrSpaces(myBookmarkName)) {
+ throw new HgCommandException("bookmark name is empty");
+ }
+ List<String> arguments = ContainerUtil.newArrayList(args);
+ arguments.add(myBookmarkName);
+ new HgCommandExecutor(myProject).execute(myRepo, "bookmark", arguments, myBookmarkResultHandler);
+ }
+}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCreateCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCreateCommand.java
deleted file mode 100644
index 89442efbc35e..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBookmarkCreateCommand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.zmlx.hg4idea.command;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.execution.HgCommandException;
-import org.zmlx.hg4idea.execution.HgCommandExecutor;
-import org.zmlx.hg4idea.execution.HgCommandResultHandler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Nadya Zabrodina
- */
-public class HgBookmarkCreateCommand {
- @NotNull private final Project myProject;
- @NotNull private final VirtualFile myRepo;
- @Nullable private final String myBookmarkName;
- private final boolean isActive;
-
- public HgBookmarkCreateCommand(@NotNull Project project,
- @NotNull VirtualFile repo,
- @Nullable String bookmarkName,
- boolean active) {
- myProject = project;
- myRepo = repo;
- myBookmarkName = bookmarkName;
- isActive = active;
- }
-
- public void execute(@Nullable HgCommandResultHandler resultHandler) throws HgCommandException {
- if (StringUtil.isEmptyOrSpaces(myBookmarkName)) {
- throw new HgCommandException("bookmark name is empty");
- }
- List<String> arguments = new ArrayList<String>();
- arguments.add(myBookmarkName);
- if (!isActive) {
- arguments.add("--inactive");
- }
- new HgCommandExecutor(myProject).execute(myRepo, "bookmark", arguments, resultHandler);
- }
-}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchesCommand.java
index 7c1aa067b20d..430e7e10b58d 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgBranchesCommand.java
@@ -17,72 +17,31 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.HgRevisionNumber;
import org.zmlx.hg4idea.execution.HgCommandExecutor;
import org.zmlx.hg4idea.execution.HgCommandResult;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class HgTagBranchCommand {
+public class HgBranchesCommand {
private static final Pattern BRANCH_LINE = Pattern.compile("(.+)\\s([0-9]+):([0-9a-f]+).*");
private static final int NAME_INDEX = 1;
- private static final int REVISION_INDEX = 2;
- private static final int CHANGESET_INDEX = 3;
private final Project project;
private final VirtualFile repo;
- public HgTagBranchCommand(Project project, @NotNull VirtualFile repo) {
+ public HgBranchesCommand(Project project, @NotNull VirtualFile repo) {
this.project = project;
this.repo = repo;
}
@Nullable
- public String getCurrentBranch() {
- final HgCommandExecutor executor = new HgCommandExecutor(project);
- executor.setSilent(true);
- HgCommandResult result = executor.executeInCurrentThread(repo, "branch", null);
- if (result == null) {
- return null;
- }
- List<String> output = result.getOutputLines();
- if (output == null || output.isEmpty()) {
- return null;
- }
- return output.get(0).trim();
- }
-
public HgCommandResult collectBranches() {
return new HgCommandExecutor(project).executeInCurrentThread(repo, "branches", null);
}
- public HgCommandResult collectTags() {
- return new HgCommandExecutor(project).executeInCurrentThread(repo, "tags", null);
- }
-
- public HgCommandResult collectBookmarks() {
- return new HgCommandExecutor(project).executeInCurrentThread(repo, "bookmarks", null);
- }
-
- public static List<HgTagBranch> parseResult(@NotNull HgCommandResult result) {
- List<HgTagBranch> branches = new LinkedList<HgTagBranch>();
- for (final String line : result.getOutputLines()) {
- Matcher matcher = BRANCH_LINE.matcher(line);
- if (matcher.matches()) {
- HgRevisionNumber hgRevisionNumber = HgRevisionNumber.getInstance(
- matcher.group(REVISION_INDEX), matcher.group(CHANGESET_INDEX)
- );
- branches.add(new HgTagBranch(matcher.group(NAME_INDEX).trim(), line.trim(), hgRevisionNumber));
- }
- }
- return branches;
- }
-
@NotNull
public static Set<String> collectNames(@NotNull HgCommandResult result) {
Set<String> branches = new HashSet<String>();
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java
index d8d70f0c5cc8..ad10a373de4e 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java
@@ -15,6 +15,7 @@ package org.zmlx.hg4idea.command;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcs;
import org.zmlx.hg4idea.execution.HgCommandExecutor;
@@ -26,22 +27,17 @@ import java.util.List;
public class HgMergeCommand {
- private final Project project;
- private final VirtualFile repo;
+ @NotNull private final Project project;
+ @NotNull private final VirtualFile repo;
- private String branch;
private String revision;
- public HgMergeCommand(Project project, VirtualFile repo) {
+ public HgMergeCommand(@NotNull Project project, @NotNull VirtualFile repo) {
this.project = project;
this.repo = repo;
}
- public void setBranch(String branch) {
- this.branch = branch;
- }
-
- public void setRevision(String revision) {
+ public void setRevision(@NotNull String revision) {
this.revision = revision;
}
@@ -53,13 +49,10 @@ public class HgMergeCommand {
if (!StringUtil.isEmptyOrSpaces(revision)) {
arguments.add("--rev");
arguments.add(revision);
- } else if (!StringUtil.isEmptyOrSpaces(branch)) {
- arguments.add(branch);
}
final HgCommandResult result =
commandExecutor.executeInCurrentThread(repo, "merge", arguments, new HgDeleteModifyPromptHandler());
project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project, null);
return result;
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java
index 357fa891201a..16748462a45f 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java
@@ -33,7 +33,8 @@ public class HgPushCommand {
private String myRevision;
private boolean myForce;
- private HgTagBranch myBranch;
+ private String myBranchName;
+ private String myBookmarkName;
private boolean myIsNewBranch;
public HgPushCommand(Project project, @NotNull VirtualFile repo, String destination) {
@@ -50,13 +51,17 @@ public class HgPushCommand {
myForce = force;
}
- public void setBranch(HgTagBranch branch) {
- myBranch = branch;
+ public void setBranchName(String branchName) {
+ myBranchName = branchName;
}
public void setIsNewBranch(boolean isNewBranch) {
- myIsNewBranch = isNewBranch;
- }
+ myIsNewBranch = isNewBranch;
+ }
+
+ public void setBookmarkName(String bookmark) {
+ myBookmarkName = bookmark;
+ }
public void execute(final HgCommandResultHandler resultHandler) {
final List<String> arguments = new LinkedList<String>();
@@ -64,15 +69,19 @@ public class HgPushCommand {
arguments.add("-r");
arguments.add(myRevision);
}
- if (myBranch != null) {
+ if (myBranchName != null) {
if (myIsNewBranch) {
arguments.add("--new-branch");
}
else {
arguments.add("-b");
- arguments.add(myBranch.getName());
+ arguments.add(myBranchName);
}
}
+ if (!StringUtil.isEmptyOrSpaces(myBookmarkName)) {
+ arguments.add("-B");
+ arguments.add(myBookmarkName);
+ }
if (myForce) {
arguments.add("-f");
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranch.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranch.java
deleted file mode 100644
index cf4325afdcb4..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranch.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2008-2010 Victor Iacoban
-//
-// 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.zmlx.hg4idea.command;
-
-import com.intellij.openapi.util.text.StringUtil;
-import org.zmlx.hg4idea.HgRevisionNumber;
-
-public final class HgTagBranch {
-
- private static final int SPACINGAFTERFIRSTLETTER = 20;
-
- private final String name;
- private final String description;
- private final HgRevisionNumber head;
- private final String presentation;
-
- public HgTagBranch(String name, String description, HgRevisionNumber head) {
- this.name = name;
- this.description = description;
- this.head = head;
- int whitespaceNum = SPACINGAFTERFIRSTLETTER - name.length();
- String presentationName = whitespaceNum <= 0 ? name.substring(0, SPACINGAFTERFIRSTLETTER - 4).concat("...") : name;
- presentation = String.format("%s%s%s", presentationName, whitespaceNum > 0 ? StringUtil.repeatSymbol(' ', whitespaceNum) : " ", head);
- }
-
- public String getName() {
- return name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public HgRevisionNumber getHead() {
- return head;
- }
-
- @Override
- public String toString() {
- return presentation;
- }
-}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java
index aaf9e9dd1c8b..dec0e720fcdb 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java
@@ -40,6 +40,8 @@ import org.zmlx.hg4idea.command.*;
import org.zmlx.hg4idea.execution.HgCommandException;
import org.zmlx.hg4idea.execution.HgCommandExecutor;
import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.repo.HgRepository;
+import org.zmlx.hg4idea.repo.HgRepositoryManager;
import org.zmlx.hg4idea.util.HgUtil;
import java.util.*;
@@ -125,9 +127,12 @@ public class HgCheckinEnvironment implements CheckinEnvironment {
// push if needed
if (myNextCommitIsPushed && exceptions.isEmpty()) {
final VirtualFile preselectedRepo = repositoriesMap.size() == 1 ? repositoriesMap.keySet().iterator().next() : null;
+ HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(myProject);
+ final HgRepository repo = preselectedRepo != null ? repositoryManager.getRepositoryForFile(preselectedRepo) : null;
+ final Collection<HgRepository> repositories = repositoryManager.getRepositories();
UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() {
- new HgPusher(myProject).showDialogAndPush(preselectedRepo);
+ new HgPusher(myProject).showDialogAndPush(repositories, repo);
}
});
}
@@ -264,31 +269,33 @@ public class HgCheckinEnvironment implements CheckinEnvironment {
public HgCommitAdditionalComponent(@NotNull Project project, @NotNull CheckinProjectPanel panel) {
super(project, panel);
HgVcs myVcs = HgVcs.getInstance(myProject);
- if (myVcs != null && !myVcs.getVersion().isAmendSupported()) {
- myAmend.setEnabled(false);
- }
+ myAmend.setEnabled(myVcs != null && myVcs.getVersion().isAmendSupported());
}
+ @Override
public void refresh() {
super.refresh();
myNextCommitAmend = false;
}
+ @Override
public void saveState() {
myNextCommitAmend = myAmend.isSelected();
}
+ @Override
public void restoreState() {
myNextCommitAmend = false;
}
@NotNull
@Override
- protected Collection<VirtualFile> getRoots() {
- return HgUtil.getHgRepositories(myProject);
+ protected Set<VirtualFile> getVcsRoots(@NotNull Collection<FilePath> filePaths) {
+ return HgUtil.hgRoots(myProject, filePaths);
}
@Nullable
+ @Override
protected String getLastCommitMessage(@NotNull VirtualFile repo) throws VcsException {
HgCommandExecutor commandExecutor = new HgCommandExecutor(myProject);
List<String> args = new ArrayList<String>();
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgHeadMerger.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgHeadMerger.java
index 15ab366f1001..a9df96b07ca3 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgHeadMerger.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgHeadMerger.java
@@ -15,8 +15,6 @@ package org.zmlx.hg4idea.provider.update;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsException;
-import com.intellij.openapi.vcs.history.VcsRevisionNumber;
-import com.intellij.openapi.vcs.update.UpdatedFiles;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.command.HgMergeCommand;
@@ -38,11 +36,9 @@ public final class HgHeadMerger {
this.hgMergeCommand = hgMergeCommand;
}
- public HgCommandResult merge(VirtualFile repo, UpdatedFiles updatedFiles,
- VcsRevisionNumber revisionNumber) throws VcsException {
+ public HgCommandResult merge(VirtualFile repo) throws VcsException {
HgCommandResult commandResult = ensureSuccess(hgMergeCommand.execute());
-
try {
HgUtil.markDirectoryDirty(project, repo);
}
@@ -61,5 +57,4 @@ public final class HgHeadMerger {
LOG.info(msg, e);
throw new VcsException(msg);
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java
index b0b4c7a0ab56..355405f33e7f 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java
@@ -113,7 +113,7 @@ public class HgRegularUpdater implements HgUpdater {
abortOnMultiplePulledHeads(pulledBranchHeads);
abortOnMultipleLocalHeads(remainingOriginalBranchHeads);
- HgCommandResult mergeResult = doMerge(updatedFiles, indicator, pulledBranchHeads.get(0));
+ HgCommandResult mergeResult = doMerge(indicator);
if (shouldCommitAfterMerge()) {
commitOrWarnAboutConflicts(warnings, mergeResult);
@@ -198,15 +198,13 @@ public class HgRegularUpdater implements HgUpdater {
}
}
- private HgCommandResult doMerge(UpdatedFiles updatedFiles,
- ProgressIndicator indicator,
- HgRevisionNumber headToMerge) throws VcsException {
+ private HgCommandResult doMerge(ProgressIndicator indicator) throws VcsException {
indicator.setText2(HgVcsMessages.message("hg4idea.update.progress.merging"));
HgMergeCommand mergeCommand = new HgMergeCommand(project, repoRoot);
//do not explicitly set the revision, that way mercurial itself checks that there are exactly
//two heads in this branch
// mergeCommand.setRevision(headToMerge.getRevision());
- return new HgHeadMerger(project, mergeCommand).merge(repoRoot, updatedFiles, headToMerge);
+ return new HgHeadMerger(project, mergeCommand).merge(repoRoot);
}
private void abortOnLocalChanges() throws VcsException {
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java
index bef1b6854d1b..fb0036185ebf 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgNameWithHashInfo;
import org.zmlx.hg4idea.HgVcs;
-import org.zmlx.hg4idea.command.HgTagBranchCommand;
+import org.zmlx.hg4idea.command.HgBranchesCommand;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.util.HgUtil;
@@ -162,13 +162,13 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository {
// Then blinking and do not work properly;
if (!Disposer.isDisposed(getProject()) && !currentInfo.equals(myInfo)) {
myInfo = currentInfo;
- HgCommandResult branchCommandResult = new HgTagBranchCommand(getProject(), getRoot()).collectBranches();
+ HgCommandResult branchCommandResult = new HgBranchesCommand(getProject(), getRoot()).collectBranches();
if (branchCommandResult == null || branchCommandResult.getExitValue() != 0) {
LOG.warn("Could not collect hg opened branches."); // hg executable is not valid
myOpenedBranches = myInfo.getBranches().keySet();
}
else {
- myOpenedBranches = HgTagBranchCommand.collectNames(branchCommandResult);
+ myOpenedBranches = HgBranchesCommand.collectNames(branchCommandResult);
}
getProject().getMessageBus().syncPublisher(HgVcs.STATUS_TOPIC).update(getProject(), getRoot());
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.form
index 0fe5286fdb5a..1e932fe8a2ba 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.form
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.form
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.zmlx.hg4idea.ui.HgUpdateToDialog">
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.zmlx.hg4idea.ui.HgCommonDialogWithChoices">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
- <xy x="20" y="20" width="500" height="400"/>
+ <xy x="22" y="20" width="498" height="291"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="84392">
<constraints>
- <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+ <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="2" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="af9e5">
@@ -23,10 +23,14 @@
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
+ <enabled value="false"/>
<text value="&amp;Overwrite locally modified files (no backup)"/>
</properties>
+ <clientProperties>
+ <html.disable class="java.lang.Boolean" value="false"/>
+ </clientProperties>
</component>
- <grid id="814c5" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <grid id="814c5" binding="myBranchesBorderPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -35,7 +39,7 @@
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
</clientProperties>
- <border type="none" title="Switch to"/>
+ <border type="none"/>
<children>
<component id="674b0" class="javax.swing.JRadioButton" binding="branchOption">
<constraints>
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java
new file mode 100644
index 000000000000..4c7ff6214e94
--- /dev/null
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCommonDialogWithChoices.java
@@ -0,0 +1,148 @@
+/*
+ * 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.zmlx.hg4idea.ui;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.ui.ValidationInfo;
+import com.intellij.openapi.util.text.StringUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.zmlx.hg4idea.repo.HgRepository;
+import org.zmlx.hg4idea.util.HgUtil;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Collection;
+
+public class HgCommonDialogWithChoices extends DialogWrapper {
+
+
+ private JPanel contentPanel;
+ private JRadioButton branchOption;
+ private JRadioButton revisionOption;
+ private JRadioButton tagOption;
+ private JRadioButton bookmarkOption;
+ private JTextField revisionTxt;
+ protected JCheckBox cleanCbx;
+ private JComboBox branchSelector;
+ private JComboBox tagSelector;
+ private JComboBox bookmarkSelector;
+ protected HgRepositorySelectorComponent hgRepositorySelectorComponent;
+ protected JPanel myBranchesBorderPanel;
+
+ public HgCommonDialogWithChoices(@NotNull Project project, @NotNull Collection<HgRepository> repositories, @Nullable HgRepository selectedRepo) {
+ super(project, false);
+ hgRepositorySelectorComponent.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ updateRepository();
+ }
+ });
+
+ ChangeListener changeListener = new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ update();
+ }
+ };
+ branchOption.addChangeListener(changeListener);
+ tagOption.addChangeListener(changeListener);
+ bookmarkOption.addChangeListener(changeListener);
+ revisionOption.addChangeListener(changeListener);
+ cleanCbx.setVisible(false);
+ setRoots(repositories, selectedRepo);
+ init();
+ }
+
+ public void setRoots(Collection<HgRepository> repos,
+ @Nullable HgRepository selectedRepo) {
+ hgRepositorySelectorComponent.setRoots(repos);
+ hgRepositorySelectorComponent.setSelectedRoot(selectedRepo);
+ updateRepository();
+ }
+
+ public HgRepository getRepository() {
+ return hgRepositorySelectorComponent.getRepository();
+ }
+
+ public String getTag() {
+ return (String)tagSelector.getSelectedItem();
+ }
+
+ public boolean isTagSelected() {
+ return tagOption.isSelected();
+ }
+
+ public String getBranch() {
+ return (String)branchSelector.getSelectedItem();
+ }
+
+ public boolean isBranchSelected() {
+ return branchOption.isSelected();
+ }
+
+ public String getBookmark() {
+ return (String)bookmarkSelector.getSelectedItem();
+ }
+
+ public boolean isBookmarkSelected() {
+ return bookmarkOption.isSelected();
+ }
+
+ public String getRevision() {
+ return revisionTxt.getText();
+ }
+
+ private void update() {
+ revisionTxt.setEnabled(revisionOption.isSelected());
+ branchSelector.setEnabled(branchOption.isSelected());
+ tagSelector.setEnabled(tagOption.isSelected());
+ bookmarkSelector.setEnabled(bookmarkOption.isSelected());
+ }
+
+ private void updateRepository() {
+ HgRepository repo = hgRepositorySelectorComponent.getRepository();
+ branchSelector.setModel(new DefaultComboBoxModel(repo.getOpenedBranches().toArray()));
+ DefaultComboBoxModel tagComboBoxModel = new DefaultComboBoxModel(HgUtil.getNamesWithoutHashes(repo.getTags()).toArray());
+ tagComboBoxModel.addElement("tip"); //HgRepository does not store 'tip' tag because it is internal and not included in tags file
+ tagSelector.setModel(tagComboBoxModel);
+ bookmarkSelector.setModel(new DefaultComboBoxModel(HgUtil.getNamesWithoutHashes(repo.getBookmarks()).toArray()));
+ update();
+ }
+
+ protected JComponent createCenterPanel() {
+ return contentPanel;
+ }
+
+ @Override
+ protected String getDimensionServiceKey() {
+ return getClass().getName();
+ }
+
+ protected void createUIComponents() {
+ }
+
+ public String getTargetValue() {
+ return isBranchSelected() ? getBranch() : isBookmarkSelected() ? getBookmark() : isTagSelected() ? getTag() : getRevision();
+ }
+
+ protected ValidationInfo doValidate() {
+ String message = "You have to specify appropriate name or revision.";
+ return StringUtil.isEmptyOrSpaces(getTargetValue()) ? new ValidationInfo(message, myBranchesBorderPanel) : null;
+ }
+}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.form
deleted file mode 100644
index 5a9411c4b563..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.form
+++ /dev/null
@@ -1,139 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.zmlx.hg4idea.ui.HgMergeDialog">
- <grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <xy x="20" y="20" width="500" height="400"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <grid id="a0d6" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <clientProperties>
- <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
- </clientProperties>
- <border type="none" title="Merge with"/>
- <children>
- <component id="99075" class="javax.swing.JRadioButton" binding="branchOption">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <selected value="true"/>
- <text value="&amp;Branch"/>
- </properties>
- </component>
- <component id="653f0" class="javax.swing.JRadioButton" binding="tagOption">
- <constraints>
- <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="&amp;Tag"/>
- </properties>
- </component>
- <component id="cefd6" class="javax.swing.JComboBox" binding="branchSelector">
- <constraints>
- <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <enabled value="true"/>
- <font name="Monospaced"/>
- </properties>
- </component>
- <component id="e6ad1" class="javax.swing.JComboBox" binding="tagSelector">
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <enabled value="false"/>
- <font name="Monospaced"/>
- </properties>
- </component>
- <hspacer id="2892f">
- <constraints>
- <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- </hspacer>
- <component id="f1e00" class="javax.swing.JTextField" binding="revisionTxt">
- <constraints>
- <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties>
- <enabled value="false"/>
- </properties>
- </component>
- <component id="f198c" class="javax.swing.JRadioButton" binding="revisionOption">
- <constraints>
- <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <selected value="false"/>
- <text value="&amp;Revision"/>
- </properties>
- </component>
- <component id="8ad2b" class="javax.swing.JRadioButton" binding="otherHeadRadioButton" default-binding="true">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <selected value="false"/>
- <text value="&amp;Other head:"/>
- <toolTipText value="There is exactly one other head on this branch"/>
- </properties>
- </component>
- <component id="10618" class="javax.swing.JLabel" binding="otherHeadLabel">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value=""/>
- </properties>
- </component>
- <component id="dc07f" class="javax.swing.JRadioButton" binding="bookmarkOption">
- <constraints>
- <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Book&amp;mark"/>
- </properties>
- </component>
- <component id="14e6b" class="javax.swing.JComboBox" binding="bookmarkSelector">
- <constraints>
- <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <enabled value="false"/>
- <font name="Monospaced"/>
- </properties>
- </component>
- </children>
- </grid>
- <vspacer id="fe9e6">
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
- </constraints>
- </vspacer>
- <nested-form id="8b57e" form-file="org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.form" binding="hgRepositorySelectorComponent">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- </nested-form>
- </children>
- </grid>
- <buttonGroups>
- <group name="mergeTarget">
- <member id="f198c"/>
- <member id="99075"/>
- <member id="653f0"/>
- <member id="8ad2b"/>
- <member id="dc07f"/>
- </group>
- </buttonGroups>
-</form>
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java
index f41972a47cea..259fe1192c3b 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java
@@ -12,181 +12,27 @@
// limitations under the License.
package org.zmlx.hg4idea.ui;
-import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.ui.UIUtil;
+import com.intellij.ui.IdeBorderFactory;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.HgRevisionNumber;
-import org.zmlx.hg4idea.command.HgHeadsCommand;
-import org.zmlx.hg4idea.command.HgTagBranch;
-import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
-import org.zmlx.hg4idea.util.HgBranchesAndTags;
-import org.zmlx.hg4idea.util.HgUiUtil;
+import org.zmlx.hg4idea.repo.HgRepository;
-import javax.swing.*;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-public class HgMergeDialog extends DialogWrapper {
+public class HgMergeDialog extends HgCommonDialogWithChoices {
- private final Project project;
-
- private JRadioButton revisionOption;
- private JTextField revisionTxt;
- private JRadioButton branchOption;
- private JRadioButton tagOption;
- private JRadioButton bookmarkOption;
- private JComboBox branchSelector;
- private JComboBox tagSelector;
- private JComboBox bookmarkSelector;
- private JPanel contentPanel;
- private HgRepositorySelectorComponent hgRepositorySelectorComponent;
- private JRadioButton otherHeadRadioButton;
- private JLabel otherHeadLabel;
-
- private HgRevisionNumber otherHead;
- private Map<VirtualFile, Collection<HgTagBranch>> branchesForRepos;
- private Map<VirtualFile, Collection<HgTagBranch>> tagsForRepos;
- private Map<VirtualFile, Collection<HgTagBranch>> bookmarksForRepos;
-
- public HgMergeDialog(Project project,
- Collection<VirtualFile> roots,
- @Nullable VirtualFile selectedRepo, HgBranchesAndTags branchesAndTags) {
- super(project, false);
- this.project = project;
- branchesForRepos = branchesAndTags.getBranchesForRepos();
- tagsForRepos = branchesAndTags.getTagsForRepos();
- bookmarksForRepos = branchesAndTags.getBookmarksForRepos();
- setRoots(roots, selectedRepo);
+ public HgMergeDialog(@NotNull Project project,
+ @NotNull Collection<HgRepository> repositories,
+ @Nullable HgRepository selectedRepo) {
+ super(project, repositories, selectedRepo);
hgRepositorySelectorComponent.setTitle("Select repository to merge");
- hgRepositorySelectorComponent.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- updateRepository();
- }
- });
-
- ChangeListener changeListener = new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- updateOptions();
- }
- };
- branchOption.addChangeListener(changeListener);
- tagOption.addChangeListener(changeListener);
- bookmarkOption.addChangeListener(changeListener);
- revisionOption.addChangeListener(changeListener);
- otherHeadRadioButton.addChangeListener(changeListener);
+ myBranchesBorderPanel.setBorder(IdeBorderFactory.createTitledBorder("Merge with", true));
setTitle("Merge");
- init();
- }
-
- public void setRoots(Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo) {
- hgRepositorySelectorComponent.setRoots(repos);
- hgRepositorySelectorComponent.setSelectedRoot(selectedRepo);
- updateRepository();
- }
-
- public VirtualFile getRepository() {
- return hgRepositorySelectorComponent.getRepository();
- }
-
- public HgTagBranch getBranch() {
- return branchOption.isSelected() ? (HgTagBranch) branchSelector.getSelectedItem() : null;
- }
-
- public HgTagBranch getTag() {
- return tagOption.isSelected() ? (HgTagBranch) tagSelector.getSelectedItem() : null;
- }
-
- public HgTagBranch getBookmark() {
- return bookmarkOption.isSelected() ? (HgTagBranch)bookmarkSelector.getSelectedItem() : null;
- }
-
- public String getRevision() {
- return revisionOption.isSelected() ? revisionTxt.getText() : null;
- }
-
- public HgRevisionNumber getOtherHead() {
- return otherHeadRadioButton.isSelected() ? otherHead : null;
- }
-
- private void updateRepository() {
- VirtualFile repo = getRepository();
- HgUiUtil.loadContentToDialog(repo, branchesForRepos, branchSelector);
- HgUiUtil.loadContentToDialog(repo, tagsForRepos, tagSelector);
- HgUiUtil.loadContentToDialog(repo, bookmarksForRepos, bookmarkSelector);
- loadHeads(repo);
- }
-
- private void updateOptions() {
- revisionTxt.setEnabled(revisionOption.isSelected());
- branchSelector.setEnabled(branchOption.isSelected());
- tagSelector.setEnabled(tagOption.isSelected());
- bookmarkSelector.setEnabled(bookmarkOption.isSelected());
- }
-
- private void loadHeads(final VirtualFile root) {
- ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
- @Override
- public void run() {
- final List<HgRevisionNumber> heads = new HgHeadsCommand(project, root).execute();
- if (heads.size() != 2) {
- disableOtherHeadsChoice();
- return;
- }
-
- HgRevisionNumber currentParent = new HgWorkingCopyRevisionsCommand(project).identify(root).getFirst();
- for (Iterator<HgRevisionNumber> it = heads.iterator(); it.hasNext(); ) {
- final HgRevisionNumber rev = it.next();
- if (rev.getRevisionNumber().equals(currentParent.getRevisionNumber())) {
- it.remove();
- }
- }
-
- if (heads.size() == 1) {
- UIUtil.invokeLaterIfNeeded(new Runnable() {
- @Override
- public void run() {
- otherHeadRadioButton.setVisible(true);
- otherHeadLabel.setVisible(true);
- otherHead = heads.get(0);
- otherHeadLabel.setText(" " + otherHead.asString());
- }
- });
- }
- else {
- //apparently we are not at one of the heads
- disableOtherHeadsChoice();
- }
- }
- });
- }
-
- private void disableOtherHeadsChoice() {
- UIUtil.invokeLaterIfNeeded(new Runnable() {
- @Override
- public void run() {
- otherHeadLabel.setVisible(false);
- otherHeadRadioButton.setVisible(false);
- }
- });
- }
-
- @Nullable
- @Override
- protected JComponent createCenterPanel() {
- return contentPanel;
}
@Override
- protected String getDimensionServiceKey() {
- return getClass().getName();
+ protected String getHelpId() {
+ return "reference.mercurial.merge.dialog";
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java
index 5b4af4a5ba96..2729817a404e 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java
@@ -23,8 +23,10 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorComboBox;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.UIUtil;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgRememberedInputs;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.util.HgUtil;
import javax.swing.*;
@@ -40,7 +42,7 @@ public class HgPullDialog extends DialogWrapper {
private EditorComboBox myRepositoryURL;
private String myCurrentRepositoryUrl;
- public HgPullDialog(Project project) {
+ public HgPullDialog(@NotNull Project project, @NotNull Collection<HgRepository> repositories, @Nullable final HgRepository selectedRepo) {
super(project, false);
this.project = project;
hgRepositorySelector.setTitle("Select repository to pull changesets for");
@@ -53,6 +55,7 @@ public class HgPullDialog extends DialogWrapper {
setTitle("Pull");
setOKButtonText("Pull");
init();
+ setRoots(repositories, selectedRepo);
}
public void createUIComponents() {
@@ -67,7 +70,7 @@ public class HgPullDialog extends DialogWrapper {
});
}
- private void addPathsFromHgrc(VirtualFile repo) {
+ private void addPathsFromHgrc(@NotNull VirtualFile repo) {
Collection<String> paths = HgUtil.getRepositoryPaths(project, repo);
for (String path : paths) {
myRepositoryURL.prependItem(path);
@@ -80,15 +83,15 @@ public class HgPullDialog extends DialogWrapper {
}
public VirtualFile getRepository() {
- return hgRepositorySelector.getRepository();
+ return hgRepositorySelector.getRepository().getRoot();
}
public String getSource() {
return myCurrentRepositoryUrl;
}
- public void setRoots(Collection<VirtualFile> repos, @Nullable final VirtualFile selectedRepo) {
- hgRepositorySelector.setRoots(repos);
+ private void setRoots(@NotNull Collection<HgRepository> repositories, @Nullable final HgRepository selectedRepo) {
+ hgRepositorySelector.setRoots(repositories);
hgRepositorySelector.setSelectedRoot(selectedRepo);
onChangeRepository();
}
@@ -106,8 +109,8 @@ public class HgPullDialog extends DialogWrapper {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
- final VirtualFile repo = hgRepositorySelector.getRepository();
- final String defaultPath = HgUtil.getRepositoryDefaultPath(project,repo);
+ final VirtualFile repo = hgRepositorySelector.getRepository().getRoot();
+ final String defaultPath = HgUtil.getRepositoryDefaultPath(project, repo);
if (!StringUtil.isEmptyOrSpaces(defaultPath)) {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
@@ -133,5 +136,4 @@ public class HgPullDialog extends DialogWrapper {
protected String getDimensionServiceKey() {
return HgPullDialog.class.getName();
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form
index a11d251812ad..ab1fd73801f5 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.form
@@ -3,7 +3,7 @@
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
- <xy x="20" y="20" width="529" height="307"/>
+ <xy x="3" y="20" width="546" height="397"/>
</constraints>
<properties/>
<border type="none"/>
@@ -18,13 +18,13 @@
<children>
<vspacer id="f51de">
<constraints>
- <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+ <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="2" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
- <grid id="3b42" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <grid id="3b42" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
- <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
+ <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="100"/>
</grid>
</constraints>
@@ -34,17 +34,9 @@
</clientProperties>
<border type="etched" title="Options"/>
<children>
- <component id="e40ef" class="javax.swing.JCheckBox" binding="revisionCbx">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="&amp;Revision:"/>
- </properties>
- </component>
<component id="8b024" class="javax.swing.JTextField" binding="revisionTxt">
<constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
+ <grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@@ -55,45 +47,76 @@
</component>
<hspacer id="27a66">
<constraints>
- <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ <grid row="2" column="1" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
- <component id="5fcc4" class="javax.swing.JCheckBox" binding="forceCheckBox" default-binding="true">
+ <grid id="3c96d" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
<constraints>
- <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
- <properties>
- <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.force"/>
- </properties>
- </component>
- <component id="e6341" class="javax.swing.JCheckBox" binding="branchCheckBox" default-binding="true">
+ <properties/>
+ <border type="etched" title="Branch Options"/>
+ <children>
+ <component id="1adc4" class="javax.swing.JComboBox" binding="branchComboBox">
+ <constraints>
+ <grid row="0" column="1" row-span="1" col-span="2" vsize-policy="4" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ </component>
+ <component id="e6341" class="javax.swing.JCheckBox" binding="branchCheckBox" default-binding="true">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.branch"/>
+ </properties>
+ </component>
+ <component id="e76b" class="javax.swing.JCheckBox" binding="newBranchCheckBox">
+ <constraints>
+ <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <enabled value="false"/>
+ <horizontalAlignment value="0"/>
+ <horizontalTextPosition value="11"/>
+ <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.asNewBranch"/>
+ </properties>
+ </component>
+ <component id="131ed" class="javax.swing.JComboBox" binding="myBookmarkComboBox">
+ <constraints>
+ <grid row="2" column="1" row-span="1" col-span="2" vsize-policy="4" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <editable value="true"/>
+ </properties>
+ </component>
+ <component id="a621e" class="javax.swing.JCheckBox" binding="myBookmarkCheckBox">
+ <constraints>
+ <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.bookmark"/>
+ </properties>
+ </component>
+ </children>
+ </grid>
+ <component id="e40ef" class="javax.swing.JCheckBox" binding="revisionCbx">
<constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
- <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.branch"/>
+ <text value="&amp;Revision:"/>
</properties>
</component>
- <component id="1adc4" class="javax.swing.JComboBox" binding="branchComboBox">
- <constraints>
- <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- </component>
- <component id="e76b" class="javax.swing.JCheckBox" binding="newBranchCheckBox">
+ <component id="5fcc4" class="javax.swing.JCheckBox" binding="forceCheckBox" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
- <enabled value="false"/>
- <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.asNewBranch"/>
+ <text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.push.force"/>
</properties>
</component>
- <hspacer id="af930">
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- </hspacer>
</children>
</grid>
<nested-form id="9e17d" form-file="org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.form" binding="hgRepositorySelectorComponent">
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java
index 7660494463ec..892bbb933a06 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java
@@ -13,8 +13,6 @@
package org.zmlx.hg4idea.ui;
import com.intellij.dvcs.DvcsRememberedInputs;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.editor.event.DocumentAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -24,10 +22,9 @@ import com.intellij.ui.EditorComboBox;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.HgPusher;
import org.zmlx.hg4idea.HgRememberedInputs;
import org.zmlx.hg4idea.HgVcsMessages;
-import org.zmlx.hg4idea.command.HgTagBranch;
+import org.zmlx.hg4idea.repo.HgRepository;
import org.zmlx.hg4idea.util.HgUtil;
import javax.swing.*;
@@ -38,7 +35,6 @@ import javax.swing.event.DocumentListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
-import java.util.List;
public class HgPushDialog extends DialogWrapper {
@@ -53,9 +49,11 @@ public class HgPushDialog extends DialogWrapper {
private JComboBox branchComboBox;
private EditorComboBox myRepositoryURL;
private JCheckBox newBranchCheckBox;
+ private JComboBox myBookmarkComboBox;
+ private JCheckBox myBookmarkCheckBox;
private String myCurrentRepositoryUrl;
- public HgPushDialog(Project project, Collection<VirtualFile> repos, List<HgTagBranch> branches, @Nullable VirtualFile selectedRepo) {
+ public HgPushDialog(Project project, Collection<HgRepository> repos, @Nullable HgRepository selectedRepo) {
super(project, false);
myProject = project;
@@ -69,15 +67,22 @@ public class HgPushDialog extends DialogWrapper {
final UpdatingListener updatingListener = new UpdatingListener();
revisionCbx.addChangeListener(updatingListener);
branchCheckBox.addChangeListener(updatingListener);
+ myBookmarkCheckBox.addChangeListener(updatingListener);
revisionTxt.getDocument().addDocumentListener(updatingListener);
setTitle(HgVcsMessages.message("hg4idea.push.dialog.title"));
setOKButtonText("Push");
init();
+ setRoots(repos, selectedRepo);
+ }
+
+ private void setRoots(@NotNull Collection<HgRepository> repos,
+ @Nullable HgRepository selectedRepo) {
hgRepositorySelectorComponent.setRoots(repos);
hgRepositorySelectorComponent.setSelectedRoot(selectedRepo);
- updateBranchComboBox(branches);
+ HgRepository repo = hgRepositorySelectorComponent.getRepository();
+ updateComboBoxes(repo);
updateRepository();
}
@@ -101,10 +106,12 @@ public class HgPushDialog extends DialogWrapper {
}
}
- public VirtualFile getRepository() {
+ @NotNull
+ public HgRepository getRepository() {
return hgRepositorySelectorComponent.getRepository();
}
+ @NotNull
public String getTarget() {
return myCurrentRepositoryUrl;
}
@@ -115,8 +122,13 @@ public class HgPushDialog extends DialogWrapper {
}
@Nullable
- public HgTagBranch getBranch() {
- return branchCheckBox.isSelected() ? (HgTagBranch) branchComboBox.getSelectedItem() : null;
+ public String getBranch() {
+ return branchCheckBox.isSelected() ? (String)branchComboBox.getSelectedItem() : null;
+ }
+
+ @Nullable
+ public String getBookmarkName() {
+ return myBookmarkCheckBox.isSelected() ? (String)myBookmarkComboBox.getSelectedItem() : null;
}
public boolean isForce() {
@@ -124,8 +136,8 @@ public class HgPushDialog extends DialogWrapper {
}
public boolean isNewBranch() {
- return newBranchCheckBox.isSelected();
- }
+ return newBranchCheckBox.isSelected();
+ }
protected JComponent createCenterPanel() {
return contentPanel;
@@ -137,25 +149,21 @@ public class HgPushDialog extends DialogWrapper {
}
public void updateRepository() {
- ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
- @Override
- public void run() {
- final VirtualFile repo = hgRepositorySelectorComponent.getRepository();
- final String defaultPath = HgUtil.getRepositoryDefaultPushPath(myProject, repo);
- final List<HgTagBranch> branches = HgPusher.getBranches(myProject, repo);
- ApplicationManager.getApplication().invokeLater(new Runnable() {
- @Override
- public void run() {
- addPathsFromHgrc(repo);
- if (defaultPath != null) {
- updateRepositoryUrlText(HgUtil.removePasswordIfNeeded(defaultPath));
- myCurrentRepositoryUrl = defaultPath;
- }
- updateBranchComboBox(branches);
- }
- }, ModalityState.stateForComponent(getRootPane()));
- }
- });
+ HgRepository repo = hgRepositorySelectorComponent.getRepository();
+ String defaultPath = HgUtil.getRepositoryDefaultPushPath(repo);
+ addPathsFromHgrc(repo.getRoot());
+ if (defaultPath != null) {
+ updateRepositoryUrlText(HgUtil.removePasswordIfNeeded(defaultPath));
+ myCurrentRepositoryUrl = defaultPath;
+ }
+ updateComboBoxes(repo);
+ }
+
+ private void updateComboBoxes(HgRepository repo) {
+ final Collection<String> branches = repo.getOpenedBranches();
+ final Collection<String> bookmarkNames = HgUtil.getNamesWithoutHashes(repo.getBookmarks());
+ branchComboBox.setModel(new DefaultComboBoxModel(branches.toArray()));
+ myBookmarkComboBox.setModel(new DefaultComboBoxModel(bookmarkNames.toArray()));
}
private void updateRepositoryUrlText(String defaultPath) {
@@ -165,15 +173,12 @@ public class HgPushDialog extends DialogWrapper {
}
}
- private void updateBranchComboBox(@NotNull List<HgTagBranch> branches) {
- branchComboBox.setModel(new DefaultComboBoxModel(branches.toArray()));
- }
-
private void update() {
setOKActionEnabled(validateOptions());
revisionTxt.setEnabled(revisionCbx.isSelected());
branchComboBox.setEnabled(branchCheckBox.isSelected());
newBranchCheckBox.setEnabled(branchCheckBox.isSelected());
+ myBookmarkComboBox.setEnabled(myBookmarkCheckBox.isSelected());
}
private boolean validateOptions() {
@@ -213,5 +218,4 @@ public class HgPushDialog extends DialogWrapper {
update();
}
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.java
index 89fc834de60b..edc2fb0c1dec 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRepositorySelectorComponent.java
@@ -12,10 +12,10 @@
// limitations under the License.
package org.zmlx.hg4idea.ui;
-import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.IdeBorderFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.zmlx.hg4idea.repo.HgRepository;
import javax.swing.*;
import java.awt.event.ActionListener;
@@ -25,54 +25,31 @@ public class HgRepositorySelectorComponent {
private JComboBox repositorySelector;
private JPanel mainPanel;
- public void setRoots(Collection<VirtualFile> roots) {
+ public void setRoots(Collection<HgRepository> roots) {
DefaultComboBoxModel model = new DefaultComboBoxModel();
- for (VirtualFile repo : roots) {
- model.addElement(new RepositoryDisplay(repo));
+ for (HgRepository repo : roots) {
+ model.addElement(repo);
}
repositorySelector.setModel(model);
mainPanel.setVisible(roots.size() > 1);
}
- public void setSelectedRoot(@Nullable VirtualFile repository) {
+ public void setSelectedRoot(@Nullable HgRepository repository) {
if (repository != null) {
- repositorySelector.setSelectedItem(new RepositoryDisplay(repository));
+ repositorySelector.setSelectedItem(repository);
}
}
- public void addActionListener(ActionListener actionListener) {
+ public void addActionListener(@NotNull ActionListener actionListener) {
repositorySelector.addActionListener(actionListener);
}
- public void setTitle(String title) {
+ public void setTitle(@NotNull String title) {
mainPanel.setBorder(IdeBorderFactory.createTitledBorder(title, true));
}
- public VirtualFile getRepository() {
- return ((RepositoryDisplay) repositorySelector.getSelectedItem()).repo;
+ @NotNull
+ public HgRepository getRepository() {
+ return (HgRepository)repositorySelector.getSelectedItem();
}
-
- private class RepositoryDisplay {
- @NotNull private final VirtualFile repo;
-
- public RepositoryDisplay(@NotNull VirtualFile repo) {
- this.repo = repo;
- }
-
- @Override
- public String toString() {
- return repo.getPresentableUrl();
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj instanceof RepositoryDisplay && this.repo.equals(((RepositoryDisplay)obj).repo);
- }
-
- @Override
- public int hashCode() {
- return repo.hashCode();
- }
- }
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRunConflictResolverDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRunConflictResolverDialog.java
index ca4ab00462f6..0196bd4a16cc 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRunConflictResolverDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRunConflictResolverDialog.java
@@ -18,10 +18,12 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgFile;
import org.zmlx.hg4idea.command.HgResolveCommand;
import org.zmlx.hg4idea.command.HgResolveStatusEnum;
+import org.zmlx.hg4idea.repo.HgRepository;
import javax.swing.*;
import java.awt.event.ActionEvent;
@@ -37,7 +39,9 @@ public class HgRunConflictResolverDialog extends DialogWrapper {
private final Project project;
- public HgRunConflictResolverDialog(Project project) {
+ public HgRunConflictResolverDialog(@NotNull Project project,
+ @NotNull Collection<HgRepository> repositories,
+ @Nullable HgRepository selectedRepo) {
super(project, false);
this.project = project;
repositorySelector.addActionListener(new ActionListener() {
@@ -47,14 +51,16 @@ public class HgRunConflictResolverDialog extends DialogWrapper {
});
setTitle("Resolve Conflicts");
init();
+ setRoots(repositories, selectedRepo);
}
- public VirtualFile getRepository() {
+ @NotNull
+ public HgRepository getRepository() {
return repositorySelector.getRepository();
}
- public void setRoots(Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo) {
- repositorySelector.setRoots(repos);
+ private void setRoots(@NotNull Collection<HgRepository> repositories, @Nullable HgRepository selectedRepo) {
+ repositorySelector.setRoots(repositories);
repositorySelector.setSelectedRoot(selectedRepo);
onChangeRepository();
}
@@ -64,7 +70,7 @@ public class HgRunConflictResolverDialog extends DialogWrapper {
}
private void onChangeRepository() {
- VirtualFile repo = repositorySelector.getRepository();
+ VirtualFile repo = repositorySelector.getRepository().getRoot();
HgResolveCommand command = new HgResolveCommand(project);
final ModalityState modalityState = ApplicationManager.getApplication().getModalityStateForComponent(getRootPane());
command.list(repo, new Consumer<Map<HgFile, HgResolveStatusEnum>>() {
@@ -90,5 +96,4 @@ public class HgRunConflictResolverDialog extends DialogWrapper {
}
});
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgTagDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgTagDialog.java
index 02e3e8d7a245..ba900078600a 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgTagDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgTagDialog.java
@@ -16,7 +16,9 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.zmlx.hg4idea.repo.HgRepository;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
@@ -29,7 +31,7 @@ public class HgTagDialog extends DialogWrapper {
private JTextField tagTxt;
private HgRepositorySelectorComponent hgRepositorySelectorComponent;
- public HgTagDialog(Project project) {
+ public HgTagDialog(@NotNull Project project, @NotNull Collection<HgRepository> repos, @Nullable HgRepository selectedRepo) {
super(project, false);
hgRepositorySelectorComponent.setTitle("Select repository to tag");
DocumentListener documentListener = new DocumentListener() {
@@ -50,6 +52,8 @@ public class HgTagDialog extends DialogWrapper {
setTitle("Tag");
init();
+
+ setRoots(repos, selectedRepo);
}
public String getTagName() {
@@ -57,10 +61,10 @@ public class HgTagDialog extends DialogWrapper {
}
public VirtualFile getRepository() {
- return hgRepositorySelectorComponent.getRepository();
+ return hgRepositorySelectorComponent.getRepository().getRoot();
}
- public void setRoots(Collection<VirtualFile> repos, @Nullable VirtualFile selectedRepo) {
+ private void setRoots(@NotNull Collection<HgRepository> repos, @Nullable HgRepository selectedRepo) {
hgRepositorySelectorComponent.setRoots(repos);
hgRepositorySelectorComponent.setSelectedRoot(selectedRepo);
update();
@@ -77,5 +81,4 @@ public class HgTagDialog extends DialogWrapper {
private boolean validateOptions() {
return !StringUtil.isEmptyOrSpaces(tagTxt.getText());
}
-
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java
index d6638dde80b4..c0b66075841b 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java
@@ -13,141 +13,30 @@
package org.zmlx.hg4idea.ui;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.ui.IdeBorderFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.command.HgTagBranch;
-import org.zmlx.hg4idea.util.HgBranchesAndTags;
-import org.zmlx.hg4idea.util.HgUiUtil;
+import org.zmlx.hg4idea.repo.HgRepository;
-import javax.swing.*;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.util.Collection;
-import java.util.Map;
-public class HgUpdateToDialog extends DialogWrapper {
+public class HgUpdateToDialog extends HgCommonDialogWithChoices {
- private final Project project;
-
- private JPanel contentPanel;
- private JRadioButton branchOption;
- private JRadioButton revisionOption;
- private JRadioButton tagOption;
- private JRadioButton bookmarkOption;
- private JTextField revisionTxt;
- private JCheckBox cleanCbx;
- private JComboBox branchSelector;
- private JComboBox tagSelector;
- private JComboBox bookmarkSelector;
- private HgRepositorySelectorComponent hgRepositorySelectorComponent;
- @NotNull private Map<VirtualFile, Collection<HgTagBranch>> branchesForRepos;
- @NotNull private Map<VirtualFile, Collection<HgTagBranch>> tagsForRepos;
- @NotNull private Map<VirtualFile, Collection<HgTagBranch>> bookmarksForRepos;
-
- public HgUpdateToDialog(Project project) {
- super(project, false);
- this.project = project;
+ public HgUpdateToDialog(Project project, @NotNull Collection<HgRepository> repos, @Nullable HgRepository selectedRepo) {
+ super(project, repos, selectedRepo);
+ myBranchesBorderPanel.setBorder(IdeBorderFactory.createTitledBorder("Switch to", true));
hgRepositorySelectorComponent.setTitle("Select repository to switch");
- hgRepositorySelectorComponent.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- updateRepository();
- }
- });
-
- ChangeListener changeListener = new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- update();
- }
- };
- branchOption.addChangeListener(changeListener);
- tagOption.addChangeListener(changeListener);
- bookmarkOption.addChangeListener(changeListener);
- revisionOption.addChangeListener(changeListener);
-
- setTitle("Switch working directory");
- init();
- }
-
- public void setRoots(Collection<VirtualFile> repos,
- @Nullable VirtualFile selectedRepo, HgBranchesAndTags branchesAndTags) {
- hgRepositorySelectorComponent.setRoots(repos);
- branchesForRepos = branchesAndTags.getBranchesForRepos();
- tagsForRepos = branchesAndTags.getTagsForRepos();
- bookmarksForRepos = branchesAndTags.getBookmarksForRepos();
- hgRepositorySelectorComponent.setSelectedRoot(selectedRepo);
- updateRepository();
- }
-
- public VirtualFile getRepository() {
- return hgRepositorySelectorComponent.getRepository();
- }
-
- public HgTagBranch getTag() {
- return (HgTagBranch) tagSelector.getSelectedItem();
- }
-
- public boolean isTagSelected() {
- return tagOption.isSelected();
- }
-
- public HgTagBranch getBranch() {
- return (HgTagBranch) branchSelector.getSelectedItem();
- }
-
- public boolean isBranchSelected() {
- return branchOption.isSelected();
- }
-
- public HgTagBranch getBookmark() {
- return (HgTagBranch)bookmarkSelector.getSelectedItem();
- }
-
- public boolean isBookmarkSelected() {
- return bookmarkOption.isSelected();
- }
-
- public String getRevision() {
- return revisionTxt.getText();
- }
-
- public boolean isRevisionSelected() {
- return revisionOption.isSelected();
+ setTitle("Switch Working Directory");
+ cleanCbx.setVisible(true);
+ cleanCbx.setEnabled(true);
}
public boolean isRemoveLocalChanges() {
return cleanCbx.isSelected();
}
- private void update() {
- revisionTxt.setEnabled(revisionOption.isSelected());
- branchSelector.setEnabled(branchOption.isSelected());
- tagSelector.setEnabled(tagOption.isSelected());
- bookmarkSelector.setEnabled(bookmarkOption.isSelected());
- }
-
- private void updateRepository() {
- VirtualFile repo = hgRepositorySelectorComponent.getRepository();
- HgUiUtil.loadContentToDialog(repo, branchesForRepos, branchSelector);
- HgUiUtil.loadContentToDialog(repo, tagsForRepos, tagSelector);
- HgUiUtil.loadContentToDialog(repo, bookmarksForRepos, bookmarkSelector);
- update();
- }
-
- protected JComponent createCenterPanel() {
- return contentPanel;
- }
-
@Override
protected String getHelpId() {
return "reference.mercurial.switch.working.directory";
}
-
- @Override
- protected String getDimensionServiceKey() {
- return getClass().getName();
- }
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgBranchesAndTags.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgBranchesAndTags.java
deleted file mode 100644
index 08d71414594b..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgBranchesAndTags.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2000-2013 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.zmlx.hg4idea.util;
-
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.NotNull;
-import org.zmlx.hg4idea.command.HgTagBranch;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * @author Nadya Zabrodina
- */
-
-public class HgBranchesAndTags {
-
- @NotNull private final Map<VirtualFile, Collection<HgTagBranch>> branchesForRepos = ContainerUtil.newHashMap();
- @NotNull private final Map<VirtualFile, Collection<HgTagBranch>> tagsForRepos = ContainerUtil.newHashMap();
- @NotNull private final Map<VirtualFile, Collection<HgTagBranch>> bookmarks = ContainerUtil.newHashMap();
-
- @NotNull
- public Map<VirtualFile, Collection<HgTagBranch>> getBranchesForRepos() {
- return branchesForRepos;
- }
-
- public void addBranches(@NotNull VirtualFile repo, @NotNull Collection<HgTagBranch> branches) {
- branchesForRepos.put(repo, branches);
- }
-
- @NotNull
- public Map<VirtualFile, Collection<HgTagBranch>> getTagsForRepos() {
- return tagsForRepos;
- }
-
- public void addTags(@NotNull VirtualFile repo, @NotNull Collection<HgTagBranch> tags) {
- tagsForRepos.put(repo, tags);
- }
-
- @NotNull
- public Map<VirtualFile, Collection<HgTagBranch>> getBookmarksForRepos() {
- return bookmarks;
- }
-
- public void addBookmarks(@NotNull VirtualFile repo, @NotNull Collection<HgTagBranch> tags) {
- bookmarks.put(repo, tags);
- }
-} \ No newline at end of file
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java
deleted file mode 100644
index 6d806b309ed0..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2000-2013 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.zmlx.hg4idea.util;
-
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.Task;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.Consumer;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.zmlx.hg4idea.HgVcsMessages;
-import org.zmlx.hg4idea.action.HgCommandResultNotifier;
-import org.zmlx.hg4idea.command.HgTagBranch;
-import org.zmlx.hg4idea.command.HgTagBranchCommand;
-import org.zmlx.hg4idea.execution.HgCommandResult;
-
-import javax.swing.*;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * @author Nadya Zabrodina
- */
-public class HgUiUtil {
-
- public static void loadBranchesInBackgroundableAndExecuteAction(@NotNull final Project project,
- @NotNull final Collection<VirtualFile> repos,
- @NotNull final Consumer<HgBranchesAndTags> successHandler) {
- final HgBranchesAndTags branchTagInfo = new HgBranchesAndTags();
- new Task.Backgroundable(project, "Collecting information...") {
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- for (final VirtualFile repo : repos) {
- HgTagBranchCommand tagBranchCommand = new HgTagBranchCommand(project, repo);
- HgCommandResult result = tagBranchCommand.collectBranches();
- if (result == null) {
- indicator.cancel();
- return;
- }
- branchTagInfo.addBranches(repo, HgTagBranchCommand.parseResult(result));
- result = tagBranchCommand.collectTags();
- if (result == null) {
- indicator.cancel();
- return;
- }
- branchTagInfo.addTags(repo, HgTagBranchCommand.parseResult(result));
-
- result = tagBranchCommand.collectBookmarks();
- if (result == null) {
- indicator.cancel();
- return;
- }
- branchTagInfo.addBookmarks(repo, HgTagBranchCommand.parseResult(result));
- }
- }
-
- @Override
- public void onCancel() {
- new HgCommandResultNotifier(project)
- .notifyError(null, "Mercurial command failed", HgVcsMessages.message("hg4idea.branches.error.description"));
- }
-
- @Override
- public void onSuccess() {
- successHandler.consume(branchTagInfo);
- }
- }.queue();
- }
-
- public static void loadContentToDialog(@Nullable VirtualFile root, @NotNull Map<VirtualFile, Collection<HgTagBranch>> contentMap,
- @NotNull JComboBox selector) {
- assert contentMap.get(root) != null : "No information about root " + root;
- selector.setModel(new DefaultComboBoxModel(contentMap.get(root).toArray()));
- }
-}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java
index fd0fc503df7d..ee7f1b4f5ce4 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java
@@ -40,6 +40,7 @@ import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.impl.status.StatusBarUtil;
import com.intellij.ui.GuiUtils;
+import com.intellij.util.containers.ContainerUtil;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -241,6 +242,21 @@ public abstract class HgUtil {
}
/**
+ * Get hg roots for paths
+ *
+ * @param filePaths the context paths
+ * @return a set of hg roots
+ */
+ @NotNull
+ public static Set<VirtualFile> hgRoots(@NotNull Project project, @NotNull Collection<FilePath> filePaths) {
+ HashSet<VirtualFile> roots = new HashSet<VirtualFile>();
+ for (FilePath path : filePaths) {
+ ContainerUtil.addIfNotNull(roots, getHgRootOrNull(project, path));
+ }
+ return roots;
+ }
+
+ /**
* Gets the Mercurial root for the given file path or null if non exists:
* the root should not only be in directory mappings, but also the .hg repository folder should exist.
* @see #getHgRootOrThrow(com.intellij.openapi.project.Project, com.intellij.openapi.vcs.FilePath)
@@ -596,6 +612,11 @@ public abstract class HgUtil {
}
@Nullable
+ public static String getRepositoryDefaultPushPath(@NotNull HgRepository repository) {
+ return repository.getRepositoryConfig().getDefaultPushPath();
+ }
+
+ @Nullable
public static String getConfig(@NotNull Project project,
@NotNull VirtualFile root,
@NotNull String section,
@@ -646,6 +667,7 @@ public abstract class HgUtil {
names.add(hash.getName());
}
}
+ Collections.sort(names);
return names;
}