diff options
Diffstat (limited to 'platform/dvcs/src/com/intellij')
6 files changed, 211 insertions, 5 deletions
diff --git a/platform/dvcs/src/com/intellij/dvcs/repo/Repository.java b/platform/dvcs/src/com/intellij/dvcs/repo/Repository.java index 3650b99ce200..c12cf4ff0407 100644 --- a/platform/dvcs/src/com/intellij/dvcs/repo/Repository.java +++ b/platform/dvcs/src/com/intellij/dvcs/repo/Repository.java @@ -15,6 +15,7 @@ */ package com.intellij.dvcs.repo; +import com.intellij.openapi.Disposable; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -49,7 +50,7 @@ import org.jetbrains.annotations.Nullable; * * @author Nadya Zabrodina */ -public interface Repository { +public interface Repository extends Disposable { /** diff --git a/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryImpl.java b/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryImpl.java index a7de8f97cb8a..5a605c566710 100644 --- a/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryImpl.java +++ b/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryImpl.java @@ -25,7 +25,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Nadya Zabrodina */ -public abstract class RepositoryImpl implements Repository, Disposable { +public abstract class RepositoryImpl implements Repository { @NotNull private final Project myProject; @NotNull private final VirtualFile myRootDir; @@ -82,7 +82,6 @@ public abstract class RepositoryImpl implements Repository, Disposable { public void dispose() { } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryUtil.java b/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryUtil.java index fa2e9a8bebe8..5a5a555768ba 100644 --- a/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryUtil.java +++ b/platform/dvcs/src/com/intellij/dvcs/repo/RepositoryUtil.java @@ -17,6 +17,7 @@ package com.intellij.dvcs.repo; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; @@ -29,7 +30,10 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.concurrent.Callable; /** @@ -117,7 +121,9 @@ public class RepositoryUtil { @Override public void consume(Object dummy) { - myRepository.update(); + if (!Disposer.isDisposed(myRepository)) { + myRepository.update(); + } } } diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogAction.java b/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogAction.java new file mode 100644 index 000000000000..bb7f64f9b24c --- /dev/null +++ b/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogAction.java @@ -0,0 +1,85 @@ +/* + * 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 com.intellij.dvcs.ui; + +import com.intellij.dvcs.repo.Repository; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.MultiMap; +import com.intellij.vcs.log.VcsFullCommitDetails; +import com.intellij.vcs.log.VcsLog; +import com.intellij.vcs.log.VcsLogDataKeys; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public abstract class VcsLogAction<Repo extends Repository> extends DumbAwareAction { + + @Override + public void actionPerformed(AnActionEvent e) { + Project project = e.getRequiredData(CommonDataKeys.PROJECT); + VcsLog log = e.getRequiredData(VcsLogDataKeys.VSC_LOG); + List<VcsFullCommitDetails> details = log.getSelectedDetails(); + MultiMap<Repo, VcsFullCommitDetails> grouped = groupByRootWithCheck(project, details); + assert grouped != null; + actionPerformed(project, grouped); + } + + @Override + public void update(AnActionEvent e) { + Project project = e.getProject(); + VcsLog log = e.getData(VcsLogDataKeys.VSC_LOG); + if (project == null || log == null) { + e.getPresentation().setEnabledAndVisible(false); + return; + } + + List<VcsFullCommitDetails> details = log.getSelectedDetails(); + MultiMap<Repo, VcsFullCommitDetails> grouped = groupByRootWithCheck(project, details); + if (grouped == null) { + e.getPresentation().setEnabledAndVisible(false); + } + else { + e.getPresentation().setVisible(true); + e.getPresentation().setEnabled(!grouped.isEmpty() && isEnabled(grouped)); + } + } + + protected abstract void actionPerformed(@NotNull Project project, @NotNull MultiMap<Repo, VcsFullCommitDetails> grouped); + + protected abstract boolean isEnabled(@NotNull MultiMap<Repo, VcsFullCommitDetails> grouped); + + @Nullable + protected abstract Repo getRepositoryForRoot(@NotNull Project project, @NotNull VirtualFile root); + + @Nullable + private MultiMap<Repo, VcsFullCommitDetails> groupByRootWithCheck(@NotNull Project project, @NotNull List<VcsFullCommitDetails> commits) { + MultiMap<Repo, VcsFullCommitDetails> map = MultiMap.create(); + for (VcsFullCommitDetails commit : commits) { + Repo root = getRepositoryForRoot(project, commit.getRoot()); + if (root == null) { // commit from some other VCS + return null; + } + map.putValue(root, commit); + } + return map; + } + +} diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogOneCommitPerRepoAction.java b/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogOneCommitPerRepoAction.java new file mode 100644 index 000000000000..1b4be918a3e1 --- /dev/null +++ b/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogOneCommitPerRepoAction.java @@ -0,0 +1,69 @@ +/* + * 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 com.intellij.dvcs.ui; + +import com.intellij.dvcs.repo.Repository; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.MultiMap; +import com.intellij.vcs.log.VcsFullCommitDetails; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Map; + +public abstract class VcsLogOneCommitPerRepoAction<Repo extends Repository> extends VcsLogAction<Repo> { + + @Override + protected void actionPerformed(@NotNull Project project, @NotNull MultiMap<Repo, VcsFullCommitDetails> grouped) { + Map<Repo, VcsFullCommitDetails> singleElementMap = convertToSingleElementMap(grouped); + assert singleElementMap != null; + actionPerformed(project, singleElementMap); + } + + @Override + protected boolean isEnabled(@NotNull MultiMap<Repo, VcsFullCommitDetails> grouped) { + return allValuesAreSingletons(grouped); + } + + protected abstract void actionPerformed(@NotNull Project project, @NotNull Map<Repo, VcsFullCommitDetails> commits); + + private boolean allValuesAreSingletons(@NotNull MultiMap<Repo, VcsFullCommitDetails> grouped) { + return !ContainerUtil.exists(grouped.entrySet(), new Condition<Map.Entry<Repo, Collection<VcsFullCommitDetails>>>() { + @Override + public boolean value(Map.Entry<Repo, Collection<VcsFullCommitDetails>> entry) { + return entry.getValue().size() != 1; + } + }); + } + + @Nullable + private Map<Repo, VcsFullCommitDetails> convertToSingleElementMap(@NotNull MultiMap<Repo, VcsFullCommitDetails> groupedCommits) { + Map<Repo, VcsFullCommitDetails> map = ContainerUtil.newHashMap(); + for (Map.Entry<Repo, Collection<VcsFullCommitDetails>> entry : groupedCommits.entrySet()) { + Collection<VcsFullCommitDetails> commits = entry.getValue(); + if (commits.size() != 1) { + return null; + } + map.put(entry.getKey(), commits.iterator().next()); + } + return map; + } + + +} diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogSingleCommitAction.java b/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogSingleCommitAction.java new file mode 100644 index 000000000000..4b43380ea9eb --- /dev/null +++ b/platform/dvcs/src/com/intellij/dvcs/ui/VcsLogSingleCommitAction.java @@ -0,0 +1,46 @@ +/* + * 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 com.intellij.dvcs.ui; + +import com.intellij.dvcs.repo.Repository; +import com.intellij.openapi.project.Project; +import com.intellij.util.containers.MultiMap; +import com.intellij.vcs.log.VcsFullCommitDetails; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Map; + +public abstract class VcsLogSingleCommitAction<Repo extends Repository> extends VcsLogAction<Repo> { + + @Override + protected boolean isEnabled(@NotNull MultiMap<Repo, VcsFullCommitDetails> grouped) { + return grouped.size() == 1; + } + + @Override + protected void actionPerformed(@NotNull Project project, @NotNull MultiMap<Repo, VcsFullCommitDetails> grouped) { + assert grouped.size() == 1; + Map.Entry<Repo, Collection<VcsFullCommitDetails>> entry = grouped.entrySet().iterator().next(); + Repo repository = entry.getKey(); + Collection<VcsFullCommitDetails> commits = entry.getValue(); + assert commits.size() == 1; + actionPerformed(repository, commits.iterator().next()); + } + + protected abstract void actionPerformed(@NotNull Repo repository, @NotNull VcsFullCommitDetails commit); + +} |