2 * Copyright 2000-2014 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 com.intellij.ide;
18 import com.intellij.ide.util.PropertiesComponent;
19 import com.intellij.openapi.components.*;
20 import com.intellij.openapi.util.text.StringUtil;
21 import com.intellij.util.xmlb.XmlSerializerUtil;
22 import com.intellij.util.xmlb.annotations.OptionTag;
23 import com.intellij.util.xmlb.annotations.Transient;
24 import org.intellij.lang.annotations.MagicConstant;
25 import org.jetbrains.annotations.NonNls;
26 import org.jetbrains.annotations.Nullable;
28 import java.beans.PropertyChangeListener;
29 import java.beans.PropertyChangeSupport;
32 name = "GeneralSettings",
33 storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/ide.general.xml")
35 public class GeneralSettings implements PersistentStateComponent<GeneralSettings> {
36 public static final int OPEN_PROJECT_ASK = -1;
37 public static final int OPEN_PROJECT_NEW_WINDOW = 0;
38 public static final int OPEN_PROJECT_SAME_WINDOW = 1;
40 @NonNls public static final String PROP_INACTIVE_TIMEOUT = "inactiveTimeout";
42 private String myBrowserPath = BrowserUtil.getDefaultAlternativeBrowserPath();
43 private boolean myShowTipsOnStartup = true;
44 private boolean myReopenLastProject = true;
45 private boolean mySyncOnFrameActivation = true;
46 private boolean mySaveOnFrameDeactivation = true;
47 private boolean myAutoSaveIfInactive = false; // If true the IDEA automatically saves files if it is inactive for some seconds
48 private int myInactiveTimeout; // Number of seconds of inactivity after which IDEA automatically saves all files
49 private boolean myUseSafeWrite = true;
50 private final PropertyChangeSupport myPropertyChangeSupport;
51 private boolean myUseDefaultBrowser = true;
52 private boolean mySearchInBackground;
53 private boolean myConfirmExit = true;
54 private int myConfirmOpenNewProject = OPEN_PROJECT_ASK;
56 public static GeneralSettings getInstance(){
57 return ServiceManager.getService(GeneralSettings.class);
60 public GeneralSettings() {
61 myInactiveTimeout = 15;
62 myPropertyChangeSupport = new PropertyChangeSupport(this);
65 public void addPropertyChangeListener(PropertyChangeListener listener){
66 myPropertyChangeSupport.addPropertyChangeListener(listener);
69 public void removePropertyChangeListener(PropertyChangeListener listener){
70 myPropertyChangeSupport.removePropertyChangeListener(listener);
73 public String getBrowserPath() {
77 @SuppressWarnings("unused")
80 * Use RecentProjectsManagerBase
82 public String getLastProjectCreationLocation() {
86 @SuppressWarnings("unused")
89 * Use RecentProjectsManagerBase
91 public void setLastProjectCreationLocation(String lastProjectLocation) {
94 public void setBrowserPath(String browserPath) {
95 myBrowserPath = browserPath;
98 @SuppressWarnings("unused")
100 public boolean showTipsOnStartup() {
101 return isShowTipsOnStartup();
104 public boolean isShowTipsOnStartup() {
105 return myShowTipsOnStartup;
108 public void setShowTipsOnStartup(boolean b) {
109 myShowTipsOnStartup = b;
113 public int getLastTip() {
114 return StringUtil.parseInt(PropertiesComponent.getInstance().getValue("lastTip"), 0);
117 public void setLastTip(int i) {
118 PropertiesComponent.getInstance().setValue("lastTip", Integer.toString(i), "0");
121 public boolean isReopenLastProject() {
122 return myReopenLastProject;
125 public void setReopenLastProject(boolean reopenLastProject) {
126 myReopenLastProject = reopenLastProject;
129 @OptionTag("autoSyncFiles")
130 public boolean isSyncOnFrameActivation() {
131 return mySyncOnFrameActivation;
134 public void setSyncOnFrameActivation(boolean syncOnFrameActivation) {
135 mySyncOnFrameActivation = syncOnFrameActivation;
138 @OptionTag("autoSaveFiles")
139 public boolean isSaveOnFrameDeactivation() {
140 return mySaveOnFrameDeactivation;
143 public void setSaveOnFrameDeactivation(boolean saveOnFrameDeactivation) {
144 mySaveOnFrameDeactivation = saveOnFrameDeactivation;
148 * @return <code>true</code> if IDEA saves all files after "idle" timeout.
150 public boolean isAutoSaveIfInactive(){
151 return myAutoSaveIfInactive;
154 public void setAutoSaveIfInactive(boolean autoSaveIfInactive) {
155 myAutoSaveIfInactive = autoSaveIfInactive;
159 * @return timeout in seconds after which IDEA saves all files if there was no user activity.
160 * The method always return non positive (more then zero) value.
162 public int getInactiveTimeout(){
163 return myInactiveTimeout;
166 public void setInactiveTimeout(int inactiveTimeout) {
167 int oldInactiveTimeout = myInactiveTimeout;
169 myInactiveTimeout = inactiveTimeout;
170 myPropertyChangeSupport.firePropertyChange(
171 PROP_INACTIVE_TIMEOUT, Integer.valueOf(oldInactiveTimeout), Integer.valueOf(inactiveTimeout)
175 public boolean isUseSafeWrite() {
176 return myUseSafeWrite;
179 public void setUseSafeWrite(final boolean useSafeWrite) {
180 myUseSafeWrite = useSafeWrite;
185 public GeneralSettings getState() {
190 public void loadState(GeneralSettings state) {
191 XmlSerializerUtil.copyBean(state, this);
194 public boolean isUseDefaultBrowser() {
195 return myUseDefaultBrowser;
198 public void setUseDefaultBrowser(boolean value) {
199 myUseDefaultBrowser = value;
202 @SuppressWarnings("unused")
205 public boolean isConfirmExtractFiles() {
209 @SuppressWarnings("unused")
211 public void setConfirmExtractFiles(boolean value) {
214 public boolean isConfirmExit() {
215 return myConfirmExit;
218 public void setConfirmExit(boolean confirmExit) {
219 myConfirmExit = confirmExit;
222 @MagicConstant(intValues = {OPEN_PROJECT_ASK, OPEN_PROJECT_NEW_WINDOW, OPEN_PROJECT_SAME_WINDOW})
223 @interface OpenNewProjectOption {}
227 * <li>{@link GeneralSettings#OPEN_PROJECT_NEW_WINDOW} if new project should be opened in new window
228 * <li>{@link GeneralSettings#OPEN_PROJECT_SAME_WINDOW} if new project should be opened in same window
229 * <li>{@link GeneralSettings#OPEN_PROJECT_ASK} if a confirmation dialog should be shown
232 @OpenNewProjectOption
233 @OptionTag("confirmOpenNewProject2")
234 public int getConfirmOpenNewProject() {
235 return myConfirmOpenNewProject;
238 public void setConfirmOpenNewProject(@OpenNewProjectOption int confirmOpenNewProject) {
239 myConfirmOpenNewProject = confirmOpenNewProject;
242 public boolean isSearchInBackground() {
243 return mySearchInBackground;
246 public void setSearchInBackground(final boolean searchInBackground) {
247 mySearchInBackground = searchInBackground;