From 9819a31c979d4527471596a62dc71e8fd7fd9029 Mon Sep 17 00:00:00 2001 From: Irina Chernushina Date: Wed, 29 Jul 2009 17:22:33 +0400 Subject: [PATCH] VCS: common checkin action update --- .../intellij/openapi/vcs/ProjectLevelVcsManager.java | 2 ++ .../vcs/actions/AbstractCommonCheckinAction.java | 10 +++------- .../openapi/vcs/actions/CommonCheckinFilesAction.java | 5 +++++ .../vcs/actions/CommonCheckinProjectAction.java | 7 +++++++ .../changes/actions/AbstractCommitChangesAction.java | 19 ++++++++++++++----- .../openapi/vcs/impl/ProjectLevelVcsManagerImpl.java | 4 ++++ .../openapi/vcs/impl/projectlevelman/NewMappings.java | 6 ++++++ 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java b/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java index 63a90e1bbd..58938305f3 100644 --- a/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java +++ b/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java @@ -148,6 +148,8 @@ public abstract class ProjectLevelVcsManager { */ public abstract AbstractVcs[] getAllActiveVcss(); + public abstract boolean hasAnyMappings(); + public abstract void addMessageToConsoleWindow(String message, TextAttributes attributes); @NotNull diff --git a/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.java b/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.java index 48430b2157..0e91f344fb 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.java @@ -130,6 +130,8 @@ public abstract class AbstractCommonCheckinAction extends AbstractVcsAction { protected abstract FilePath[] getRoots(VcsContext dataContext); + protected abstract boolean approximatelyHasRoots(final VcsContext dataContext); + protected void update(VcsContext vcsContext, Presentation presentation) { Project project = vcsContext.getProject(); if (project == null) { @@ -144,13 +146,7 @@ public abstract class AbstractCommonCheckinAction extends AbstractVcsAction { return; } - FilePath[] roots = filterRoots(getRoots(vcsContext), project); - if (roots == null || roots.length == 0) { - presentation.setEnabled(false); - return; - } - - if (roots.length == 0) { + if (! approximatelyHasRoots(vcsContext)) { presentation.setEnabled(false); return; } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.java b/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.java index c7bbb897a5..35533e3f3c 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinFilesAction.java @@ -124,6 +124,11 @@ public class CommonCheckinFilesAction extends AbstractCommonCheckinAction { } } + @Override + protected boolean approximatelyHasRoots(VcsContext dataContext) { + return dataContext.getSelectedFilePaths().length > 0; + } + protected FilePath[] getRoots(VcsContext context) { return context.getSelectedFilePaths(); } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.java b/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.java index 475e63461d..7578647bc2 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.java @@ -25,6 +25,13 @@ public class CommonCheckinProjectAction extends AbstractCommonCheckinAction { return virtualFiles.toArray(new FilePath[virtualFiles.size()]); } + @Override + protected boolean approximatelyHasRoots(VcsContext dataContext) { + Project project = dataContext.getProject(); + final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); + return vcsManager.hasAnyMappings(); + } + protected void update(VcsContext vcsContext, Presentation presentation) { Project project = vcsContext.getProject(); if (project == null) { diff --git a/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/AbstractCommitChangesAction.java b/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/AbstractCommitChangesAction.java index 77db0884eb..463300d6db 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/AbstractCommitChangesAction.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/AbstractCommitChangesAction.java @@ -4,15 +4,17 @@ package com.intellij.openapi.vcs.changes.actions; +import com.intellij.openapi.actionSystem.ActionPlaces; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FileStatus; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.actions.AbstractCommonCheckinAction; import com.intellij.openapi.vcs.actions.VcsContext; -import com.intellij.openapi.vcs.changes.ChangeList; import com.intellij.openapi.vcs.changes.Change; +import com.intellij.openapi.vcs.changes.ChangeList; import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.FileStatus; -import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.actionSystem.ActionPlaces; /** * @author yole @@ -22,6 +24,13 @@ public abstract class AbstractCommitChangesAction extends AbstractCommonCheckinA return getAllContentRoots(context); } + @Override + protected boolean approximatelyHasRoots(VcsContext dataContext) { + final Project project = dataContext.getProject(); + final ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project); + return manager.hasAnyMappings(); + } + protected boolean filterRootsBeforeAction() { return false; } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index 5773b80d00..03b1e549cf 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -293,6 +293,10 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme return myMappings.getActiveVcses(); } + public boolean hasAnyMappings() { + return ! myMappings.isEmpty(); + } + public void addMessageToConsoleWindow(final String message, final TextAttributes attributes) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { diff --git a/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java b/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java index de9de8872f..9efe0391ee 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java @@ -275,6 +275,12 @@ public class NewMappings { } } + public boolean isEmpty() { + synchronized (myLock) { + return mySortedMappings.length == 0; + } + } + @Modification public void removeDirectoryMapping(final VcsDirectoryMapping mapping) { LOG.debug("remove mapping: " + mapping.getDirectory()); -- 2.11.4.GIT