1 package org
.jetbrains
.idea
.svn
.actions
;
3 import com
.intellij
.openapi
.actionSystem
.*;
4 import com
.intellij
.openapi
.project
.Project
;
5 import com
.intellij
.openapi
.vcs
.AbstractVcsHelper
;
6 import com
.intellij
.openapi
.vcs
.ProjectLevelVcsManager
;
7 import com
.intellij
.openapi
.vcs
.VcsDirectoryMapping
;
8 import com
.intellij
.openapi
.vcs
.VcsException
;
9 import com
.intellij
.openapi
.vcs
.changes
.VcsDirtyScopeManager
;
10 import com
.intellij
.openapi
.vfs
.VirtualFile
;
11 import org
.jetbrains
.idea
.svn
.SvnBundle
;
12 import org
.jetbrains
.idea
.svn
.SvnStatusUtil
;
13 import org
.jetbrains
.idea
.svn
.SvnUtil
;
14 import org
.jetbrains
.idea
.svn
.SvnVcs
;
16 import java
.util
.Arrays
;
17 import java
.util
.List
;
19 public class ShareWholeProject
extends AnAction
{
21 public void update(final AnActionEvent e
) {
22 final MyChecker checker
= new MyChecker();
25 final Presentation presentation
= e
.getPresentation();
26 presentation
.setEnabled(checker
.isEnabled());
28 presentation
.setVisible(checker
.isVisible());
29 if (checker
.isEnabled()) {
30 presentation
.setText(SvnBundle
.message("action.share.whole.project.text"));
34 private static class MyChecker
{
35 private boolean myEnabled
;
36 private boolean myVisible
;
37 private Project myProject
;
38 private boolean myHadNoMappings
;
40 public void execute(final AnActionEvent e
) {
41 final DataContext dataContext
= e
.getDataContext();
42 myProject
= PlatformDataKeys
.PROJECT
.getData(dataContext
);
43 if (myProject
== null || myProject
.isDefault()) {
47 final VirtualFile baseDir
= myProject
.getBaseDir();
48 if (baseDir
== null) return;
50 final ProjectLevelVcsManager vcsManager
= ProjectLevelVcsManager
.getInstance(myProject
);
51 final MyCheckResult result
= checkMappings(baseDir
, vcsManager
);
53 if (MyCheckResult
.disable
.equals(result
)) return;
55 myHadNoMappings
= MyCheckResult
.notMapped
.equals(result
);
56 if (MyCheckResult
.notMapped
.equals(result
)) {
57 // no change list manager working
58 if(SvnUtil
.seemsLikeVersionedDir(baseDir
)) return;
59 } else if (SvnStatusUtil
.isUnderControl(myProject
, baseDir
)) {
63 if ((! myHadNoMappings
) && (! SvnVcs
.getInstance(myProject
).getSvnFileUrlMapping().isEmpty())) {
64 // there are some versioned dirs under project dir
68 // visible: already checked above
70 myEnabled
= (! vcsManager
.isBackgroundVcsOperationRunning());
73 private static enum MyCheckResult
{
79 private MyCheckResult
checkMappings(final VirtualFile baseDir
, final ProjectLevelVcsManager vcsManager
) {
80 final List
<VcsDirectoryMapping
> mappings
= vcsManager
.getDirectoryMappings();
82 boolean notMapped
= true;
83 boolean svnMappedToBase
= false;
84 for (VcsDirectoryMapping mapping
: mappings
) {
85 final String vcs
= mapping
.getVcs();
86 if (vcs
!= null && vcs
.length() > 0) {
88 if (SvnVcs
.VCS_NAME
.equals(vcs
)) {
89 if (mapping
.isDefaultMapping() || baseDir
.equals(mapping
.getDirectory())) {
90 svnMappedToBase
= true;
97 return svnMappedToBase ? MyCheckResult
.rootToSvn
:
98 (notMapped ? MyCheckResult
.notMapped
: MyCheckResult
.disable
);
101 public boolean isEnabled() {
105 public boolean isVisible() {
109 public Project
getProject() {
113 public boolean isHadNoMappings() {
114 return myHadNoMappings
;
119 public void actionPerformed(AnActionEvent e
) {
120 final MyChecker checker
= new MyChecker();
122 if (! checker
.isEnabled()) return;
124 final Project project
= checker
.getProject();
125 final VirtualFile baseDir
= project
.getBaseDir();
126 if (baseDir
== null) return;
127 boolean success
= false;
128 boolean excThrown
= false;
130 success
= ShareProjectAction
.share(project
, baseDir
);
131 } catch (VcsException exc
) {
132 AbstractVcsHelper
.getInstance(project
).showError(exc
, "Failed to Share Project");
135 // if success = false -> either action was cancelled or exception was thrown, so also check for exception
136 if (success
|| excThrown
) {
137 baseDir
.refresh(true, true, new Runnable() {
139 VcsDirtyScopeManager
.getInstance(project
).dirDirtyRecursively(project
.getBaseDir());
140 if (checker
.isHadNoMappings() && SvnUtil
.seemsLikeVersionedDir(baseDir
)) {
141 final ProjectLevelVcsManager vcsManager
= ProjectLevelVcsManager
.getInstance(project
);
142 vcsManager
.setDirectoryMappings(Arrays
.asList(new VcsDirectoryMapping("", SvnVcs
.VCS_NAME
)));