2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.jetbrains
.idea
.svn
;
18 import com
.intellij
.openapi
.application
.PathManager
;
19 import com
.intellij
.openapi
.components
.PersistentStateComponent
;
20 import com
.intellij
.openapi
.components
.ServiceManager
;
21 import com
.intellij
.openapi
.components
.State
;
22 import com
.intellij
.openapi
.components
.Storage
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import org
.tmatesoft
.svn
.core
.SVNException
;
25 import org
.tmatesoft
.svn
.core
.SVNURL
;
26 import org
.tmatesoft
.svn
.core
.internal
.io
.svn
.SVNSSHSession
;
29 import java
.util
.ArrayList
;
30 import java
.util
.Collection
;
31 import java
.util
.List
;
35 name
="SvnApplicationSettings",
38 id
="SvnApplicationSettings",
39 file
="$APP_CONFIG$/other.xml"
42 public class SvnApplicationSettings
implements PersistentStateComponent
<SvnApplicationSettings
.ConfigurationBean
> {
43 private SvnFileSystemListenerWrapper myVFSHandler
;
44 private int mySvnProjectCount
;
45 private LimitedStringsList myLimitedStringsList
;
47 public static class ConfigurationBean
{
48 public List
<String
> myCheckoutURLs
= new ArrayList
<String
>();
49 public List
<String
> myTypedURLs
= new ArrayList
<String
>();
52 private ConfigurationBean myConfigurationBean
;
54 public static SvnApplicationSettings
getInstance() {
55 return ServiceManager
.getService(SvnApplicationSettings
.class);
58 public SvnApplicationSettings() {
59 myConfigurationBean
= new ConfigurationBean();
62 public ConfigurationBean
getState() {
63 myConfigurationBean
.myTypedURLs
.clear();
64 myConfigurationBean
.myTypedURLs
.addAll(getTypedList().getList());
65 return myConfigurationBean
;
68 public void loadState(ConfigurationBean object
) {
69 myConfigurationBean
= object
;
73 private LimitedStringsList
getTypedList() {
74 if (myLimitedStringsList
== null) {
75 checkFillTypedFromCheckout();
76 myLimitedStringsList
= new LimitedStringsList(myConfigurationBean
.myTypedURLs
);
78 return myLimitedStringsList
;
81 private void checkFillTypedFromCheckout() {
82 if (myConfigurationBean
.myTypedURLs
.isEmpty() && (! myConfigurationBean
.myCheckoutURLs
.isEmpty())) {
83 myConfigurationBean
.myTypedURLs
.addAll(myConfigurationBean
.myCheckoutURLs
);
87 public void svnActivated() {
88 if (myVFSHandler
== null) {
89 myVFSHandler
= new SvnFileSystemListenerWrapper(new SvnFileSystemListener());
90 myVFSHandler
.registerSelf();
95 public void svnDeactivated() {
97 if (mySvnProjectCount
== 0) {
98 myVFSHandler
.unregisterSelf();
100 SVNSSHSession
.shutdown();
104 private static File
getCommonPath() {
105 File file
= new File(PathManager
.getSystemPath());
106 file
= new File(file
, "plugins");
107 file
= new File(file
, "svn4idea");
112 public static File
getCredentialsFile() {
113 return new File(getCommonPath(), "credentials.xml");
116 private static final String LOADED_REVISIONS_DIR
= "loadedRevisions";
118 public static File
getLoadedRevisionsDir(final Project project
) {
119 File file
= getCommonPath();
120 file
= new File(file
, LOADED_REVISIONS_DIR
);
121 file
= new File(file
, project
.getLocationHash());
126 public Collection
<String
> getCheckoutURLs() {
127 return myConfigurationBean
.myCheckoutURLs
;
130 public void addCheckoutURL(String url
) {
131 if (myConfigurationBean
.myCheckoutURLs
.contains(url
)) {
134 myConfigurationBean
.myCheckoutURLs
.add(0, url
);
137 public void removeCheckoutURL(String url
) {
138 if (myConfigurationBean
.myCheckoutURLs
!= null) {
139 // 'url' is not necessary an exact match for some of the urls in collection - it has been parsed and then converted back to string
140 for(String oldUrl
: myConfigurationBean
.myCheckoutURLs
) {
142 if (url
.equals(oldUrl
) || SVNURL
.parseURIEncoded(url
).equals(SVNURL
.parseURIEncoded(oldUrl
))) {
143 myConfigurationBean
.myCheckoutURLs
.remove(oldUrl
);
147 catch (SVNException e
) {
154 public List
<String
> getTypedUrlsListCopy() {
155 return new ArrayList
<String
>(getTypedList().getList());
158 public void addTypedUrl(final String url
) {
159 getTypedList().add(url
);