vcs: Disallow "Browse Changes" action if corresponding repository location is not found

Previously tab with empty title with "Repository" tab functionality was opened (e.g. there was no "Filter" action like in tabs with correct repository location). Looks like such behavior was not intended.

GitOrigin-RevId: 0f9737d8326f85b65166b44632655cab142cc835
This commit is contained in:
Konstantin Kolosovsky
2019-12-09 12:31:29 +00:00
committed by intellij-monorepo-bot
parent 10142ee9cc
commit 02dc4db01a
6 changed files with 40 additions and 44 deletions
@@ -69,17 +69,11 @@ public abstract class AbstractVcsHelper {
public abstract void showWhatDiffersBrowser(@Nullable Component parent, Collection<Change> changes, @Nls String title);
public abstract void openCommittedChangesTab(AbstractVcs vcs,
VirtualFile root,
public abstract void openCommittedChangesTab(@NotNull CommittedChangesProvider provider,
@NotNull RepositoryLocation location,
ChangeBrowserSettings settings,
int maxCount,
final String title);
public abstract void openCommittedChangesTab(CommittedChangesProvider provider,
RepositoryLocation location,
ChangeBrowserSettings settings,
int maxCount,
final String title);
String title);
/**
* Shows the multiple file merge dialog for resolving conflicts in the specified set of virtual files.
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.changes.actions;
import com.intellij.openapi.actionSystem.AnAction;
@@ -8,13 +8,18 @@ import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.components.ServiceKt;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.AbstractVcsHelper;
import com.intellij.openapi.vcs.CommittedChangesProvider;
import com.intellij.openapi.vcs.RepositoryLocation;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesFilterDialog;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesVisibilityPredicate;
import com.intellij.openapi.vcs.changes.committed.RepositoryLocationCache;
import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
import static com.intellij.CommonBundle.getCancelButtonText;
@@ -22,6 +27,7 @@ import static com.intellij.openapi.ui.Messages.*;
import static com.intellij.openapi.vcs.AbstractVcs.fileInVcsByFileStatus;
import static com.intellij.openapi.vcs.VcsBundle.message;
import static com.intellij.openapi.vcs.changes.ChangesUtil.getVcsForFile;
import static com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier.showOverVersionControlView;
import static com.intellij.util.ObjectUtils.notNull;
public class BrowseChangesAction extends AnAction implements DumbAware {
@@ -35,7 +41,7 @@ public class BrowseChangesAction extends AnAction implements DumbAware {
CommittedChangesFilterDialog dialog = new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
if (dialog.showAndGet()) {
showChanges(vcs, file, settings);
showChanges(vcs, provider, file, settings);
}
}
@@ -69,12 +75,21 @@ public class BrowseChangesAction extends AnAction implements DumbAware {
return vcs.allowsRemoteCalls(file) && fileInVcsByFileStatus(project, file);
}
private static void showChanges(@NotNull AbstractVcs vcs, @NotNull VirtualFile file, @NotNull ChangeBrowserSettings settings) {
private static void showChanges(@NotNull AbstractVcs vcs,
@NotNull CommittedChangesProvider<?, ?> provider,
@NotNull VirtualFile file,
@NotNull ChangeBrowserSettings settings) {
int maxCount = !settings.isAnyFilterSpecified() ? askMaxCount(vcs.getProject()) : 0;
if (maxCount < 0) return;
if (maxCount >= 0) {
AbstractVcsHelper.getInstance(vcs.getProject()).openCommittedChangesTab(vcs, file, settings, maxCount, null);
RepositoryLocationCache cache = CommittedChangesCache.getInstance(vcs.getProject()).getLocationCache();
RepositoryLocation location = cache.getLocation(vcs, VcsUtil.getFilePath(file), false);
if (location == null) {
showOverVersionControlView(vcs.getProject(), "Repository location not found for " + file.getPresentableUrl(), MessageType.ERROR);
return;
}
AbstractVcsHelper.getInstance(vcs.getProject()).openCommittedChangesTab(provider, location, settings, maxCount, null);
}
private static int askMaxCount(@NotNull Project project) {
@@ -48,8 +48,11 @@ public class CommittedChangesPanel extends JPanel implements DataProvider, Dispo
private volatile boolean myInLoad;
private final Consumer<String> myIfNotCachedReloader;
public CommittedChangesPanel(Project project, final CommittedChangesProvider provider, final ChangeBrowserSettings settings,
@Nullable final RepositoryLocation location, @Nullable ActionGroup extraActions) {
public CommittedChangesPanel(@NotNull Project project,
@NotNull CommittedChangesProvider provider,
ChangeBrowserSettings settings,
@Nullable RepositoryLocation location,
@Nullable ActionGroup extraActions) {
super(new BorderLayout());
mySettings = settings;
myProject = project;
@@ -35,7 +35,10 @@ import com.intellij.openapi.vcs.annotate.FileAnnotation;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.CommitResultHandler;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.committed.*;
import com.intellij.openapi.vcs.changes.committed.ChangesBrowserDialog;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesFilterDialog;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesPanel;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesTableModel;
import com.intellij.openapi.vcs.changes.ui.*;
import com.intellij.openapi.vcs.history.FileHistoryRefresher;
import com.intellij.openapi.vcs.history.FileHistoryRefresherI;
@@ -472,28 +475,17 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper {
}
@Override
public void openCommittedChangesTab(final AbstractVcs vcs,
final VirtualFile root,
final ChangeBrowserSettings settings,
final int maxCount,
String title) {
RepositoryLocationCache cache = CommittedChangesCache.getInstance(myProject).getLocationCache();
RepositoryLocation location = cache.getLocation(vcs, VcsUtil.getFilePath(root), false);
openCommittedChangesTab(vcs.getCommittedChangesProvider(), location, settings, maxCount, title);
}
@Override
public void openCommittedChangesTab(final CommittedChangesProvider provider,
final RepositoryLocation location,
final ChangeBrowserSettings settings,
final int maxCount,
public void openCommittedChangesTab(@NotNull CommittedChangesProvider provider,
@NotNull RepositoryLocation location,
ChangeBrowserSettings settings,
int maxCount,
String title) {
DefaultActionGroup extraActions = new DefaultActionGroup();
CommittedChangesPanel panel = new CommittedChangesPanel(myProject, provider, settings, location, extraActions);
panel.setMaxCount(maxCount);
panel.refreshChanges(false);
final ContentFactory factory = ContentFactory.SERVICE.getInstance();
if (title == null && location != null) {
if (title == null) {
title = VcsBundle.message("browse.changes.content.title", location.toPresentableString());
}
final Content content = factory.createContent(panel, title, false);
@@ -40,11 +40,7 @@ class MockVcsHelper(project: Project) : AbstractVcsHelper(project) {
throw UnsupportedOperationException()
}
override fun openCommittedChangesTab(vcs: AbstractVcs?, root: VirtualFile?, settings: ChangeBrowserSettings?, maxCount: Int, title: String?) {
throw UnsupportedOperationException()
}
override fun openCommittedChangesTab(provider: CommittedChangesProvider<*, *>?, location: RepositoryLocation?, settings: ChangeBrowserSettings?, maxCount: Int, title: String?) {
override fun openCommittedChangesTab(provider: CommittedChangesProvider<*, *>, location: RepositoryLocation, settings: ChangeBrowserSettings?, maxCount: Int, title: String?) {
throw UnsupportedOperationException()
}
@@ -78,12 +78,8 @@ public class HgMockVcsHelper extends AbstractVcsHelper {
}
@Override
public void openCommittedChangesTab(AbstractVcs vcs, VirtualFile root, ChangeBrowserSettings settings, int maxCount, String title) {
}
@Override
public void openCommittedChangesTab(CommittedChangesProvider provider,
RepositoryLocation location,
public void openCommittedChangesTab(@NotNull CommittedChangesProvider provider,
@NotNull RepositoryLocation location,
ChangeBrowserSettings settings,
int maxCount,
String title) {