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.
18 * Created by IntelliJ IDEA.
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com
.intellij
.openapi
.editor
.impl
;
27 import com
.intellij
.codeStyle
.CodeStyleFacade
;
28 import com
.intellij
.openapi
.editor
.EditorSettings
;
29 import com
.intellij
.openapi
.editor
.ex
.EditorEx
;
30 import com
.intellij
.openapi
.editor
.ex
.EditorSettingsExternalizable
;
31 import com
.intellij
.openapi
.fileTypes
.FileType
;
32 import com
.intellij
.openapi
.project
.Project
;
33 import com
.intellij
.openapi
.vfs
.VirtualFile
;
34 import org
.jetbrains
.annotations
.Nullable
;
36 public class SettingsImpl
implements EditorSettings
{
37 @Nullable private final EditorEx myEditor
;
38 private Boolean myIsCamelWords
;
40 public SettingsImpl(@Nullable EditorEx editor
) {
44 // This group of settings does not have UI
45 private int myAdditionalLinesCount
= 5;
46 private int myAdditionalColumnsCount
= 3;
47 private int myLineCursorWidth
= 2;
48 private boolean myLineMarkerAreaShown
= true;
50 // These comes from CodeStyleSettings
51 private Integer myTabSize
= null;
52 private Integer myCachedTabSize
;
53 private Boolean myUseTabCharacter
= null;
55 // These comes from EditorSettingsExternalizable defaults.
56 private Boolean myIsVirtualSpace
= null;
57 private Boolean myIsCaretInsideTabs
= null;
58 private Boolean myIsCaretBlinking
= null;
59 private Integer myCaretBlinkingPeriod
= null;
60 private Boolean myIsRightMarginShown
= null;
61 private Integer myRightMargin
= null;
62 private Boolean myAreLineNumbersShown
= null;
63 private Boolean myIsFoldingOutlineShown
= null;
64 private Boolean myIsSmartHome
= null;
65 private Boolean myIsBlockCursor
= null;
66 private Boolean myIsWhitespacesShown
= null;
67 private Boolean myIsAnimatedScrolling
= null;
68 private Boolean myIsAdditionalPageAtBottom
= null;
69 private Boolean myIsDndEnabled
= null;
70 private Boolean myIsWheelFontChangeEnabled
= null;
71 private Boolean myIsMouseClickSelectionHonorsCamelWords
= null;
72 private Boolean myIsRenameVariablesInplace
= null;
73 private Boolean myIsRefrainFromScrolling
= null;
75 public boolean isRightMarginShown() {
76 return myIsRightMarginShown
!= null
77 ? myIsRightMarginShown
.booleanValue()
78 : EditorSettingsExternalizable
.getInstance().isRightMarginShown();
81 public void setRightMarginShown(boolean val
) {
82 myIsRightMarginShown
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
86 public boolean isWhitespacesShown() {
87 return myIsWhitespacesShown
!= null
88 ? myIsWhitespacesShown
.booleanValue()
89 : EditorSettingsExternalizable
.getInstance().isWhitespacesShown();
92 public void setWhitespacesShown(boolean val
) {
93 myIsWhitespacesShown
= Boolean
.valueOf(val
);
96 public boolean isLineNumbersShown() {
97 return myAreLineNumbersShown
!= null
98 ? myAreLineNumbersShown
.booleanValue()
99 : EditorSettingsExternalizable
.getInstance().isLineNumbersShown();
102 public void setLineNumbersShown(boolean val
) {
103 myAreLineNumbersShown
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
107 public int getRightMargin(Project project
) {
108 return myRightMargin
!= null ? myRightMargin
.intValue() :
109 CodeStyleFacade
.getInstance(project
).getRightMargin();
112 public void setRightMargin(int rightMargin
) {
113 myRightMargin
= Integer
.valueOf(rightMargin
);
117 public int getAdditionalLinesCount() {
118 return myAdditionalLinesCount
;
121 public void setAdditionalLinesCount(int additionalLinesCount
) {
122 myAdditionalLinesCount
= additionalLinesCount
;
126 public int getAdditionalColumnsCount() {
127 return myAdditionalColumnsCount
;
130 public void setAdditionalColumnsCount(int additinalColumnsCount
) {
131 myAdditionalColumnsCount
= additinalColumnsCount
;
135 public boolean isLineMarkerAreaShown() {
136 return myLineMarkerAreaShown
;
139 public void setLineMarkerAreaShown(boolean lineMarkerAreaShown
) {
140 myLineMarkerAreaShown
= lineMarkerAreaShown
;
144 public boolean isFoldingOutlineShown() {
145 return myIsFoldingOutlineShown
!= null
146 ? myIsFoldingOutlineShown
.booleanValue()
147 : EditorSettingsExternalizable
.getInstance().isFoldingOutlineShown();
150 public void setFoldingOutlineShown(boolean val
) {
151 myIsFoldingOutlineShown
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
155 public boolean isUseTabCharacter(Project project
) {
156 FileType fileType
= getFileType();
157 return myUseTabCharacter
!= null ? myUseTabCharacter
.booleanValue() : CodeStyleFacade
.getInstance(project
).useTabCharacter(fileType
);
160 public void setUseTabCharacter(boolean val
) {
161 myUseTabCharacter
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
165 public void reinitSettings() {
166 myCachedTabSize
= null;
169 public int getTabSize(Project project
) {
170 if (myTabSize
!= null) return myTabSize
.intValue();
171 if (myCachedTabSize
!= null) return myCachedTabSize
.intValue();
173 FileType fileType
= getFileType();
174 int tabSize
= CodeStyleFacade
.getInstance(project
).getTabSize(fileType
);
175 myCachedTabSize
= Integer
.valueOf(tabSize
);
180 private FileType
getFileType() {
181 VirtualFile file
= myEditor
== null ?
null : myEditor
.getVirtualFile();
182 return file
== null ?
null : file
.getFileType();
185 public void setTabSize(int tabSize
) {
186 myTabSize
= Integer
.valueOf(tabSize
);
190 public boolean isSmartHome() {
191 return myIsSmartHome
!= null
192 ? myIsSmartHome
.booleanValue()
193 : EditorSettingsExternalizable
.getInstance().isSmartHome();
196 public void setSmartHome(boolean val
) {
197 myIsSmartHome
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
201 public boolean isVirtualSpace() {
202 if (myEditor
!= null && myEditor
.isColumnMode()) return true;
203 return myIsVirtualSpace
!= null
204 ? myIsVirtualSpace
.booleanValue()
205 : EditorSettingsExternalizable
.getInstance().isVirtualSpace();
208 public void setVirtualSpace(boolean val
) {
209 myIsVirtualSpace
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
213 public boolean isAdditionalPageAtBottom() {
214 return myIsAdditionalPageAtBottom
!= null
215 ? myIsAdditionalPageAtBottom
.booleanValue()
216 : EditorSettingsExternalizable
.getInstance().isAdditionalPageAtBottom();
219 public void setAdditionalPageAtBottom(boolean val
) {
220 myIsAdditionalPageAtBottom
= Boolean
.valueOf(val
);
223 public boolean isCaretInsideTabs() {
224 if (myEditor
!= null && myEditor
.isColumnMode()) return true;
225 return myIsCaretInsideTabs
!= null
226 ? myIsCaretInsideTabs
.booleanValue()
227 : EditorSettingsExternalizable
.getInstance().isCaretInsideTabs();
230 public void setCaretInsideTabs(boolean val
) {
231 myIsCaretInsideTabs
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
235 public boolean isBlockCursor() {
236 return myIsBlockCursor
!= null
237 ? myIsBlockCursor
.booleanValue()
238 : EditorSettingsExternalizable
.getInstance().isBlockCursor();
241 public void setBlockCursor(boolean val
) {
242 myIsBlockCursor
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
246 public int getLineCursorWidth() {
247 return myLineCursorWidth
;
250 public void setLineCursorWidth(int width
) {
251 myLineCursorWidth
= width
;
254 public boolean isAnimatedScrolling() {
255 return myIsAnimatedScrolling
!= null
256 ? myIsAnimatedScrolling
.booleanValue()
257 : EditorSettingsExternalizable
.getInstance().isSmoothScrolling();
260 public void setAnimatedScrolling(boolean val
) {
261 myIsAnimatedScrolling
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
264 public boolean isCamelWords() {
265 return myIsCamelWords
!= null
266 ? myIsCamelWords
.booleanValue()
267 : EditorSettingsExternalizable
.getInstance().isCamelWords();
270 public void setCamelWords(boolean val
) {
271 myIsCamelWords
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
274 public boolean isBlinkCaret() {
275 return myIsCaretBlinking
!= null
276 ? myIsCaretBlinking
.booleanValue()
277 : EditorSettingsExternalizable
.getInstance().isBlinkCaret();
280 public void setBlinkCaret(boolean val
) {
281 myIsCaretBlinking
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
285 public int getCaretBlinkPeriod() {
286 return myCaretBlinkingPeriod
!= null
287 ? myCaretBlinkingPeriod
.intValue()
288 : EditorSettingsExternalizable
.getInstance().getBlinkPeriod();
291 public void setCaretBlinkPeriod(int blinkPeriod
) {
292 myCaretBlinkingPeriod
= Integer
.valueOf(blinkPeriod
);
296 public boolean isDndEnabled() {
297 return myIsDndEnabled
!= null ? myIsDndEnabled
.booleanValue() : EditorSettingsExternalizable
.getInstance().isDndEnabled();
300 public void setDndEnabled(boolean val
) {
301 myIsDndEnabled
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
304 public boolean isWheelFontChangeEnabled() {
305 return myIsWheelFontChangeEnabled
!= null
306 ? myIsWheelFontChangeEnabled
.booleanValue()
307 : EditorSettingsExternalizable
.getInstance().isWheelFontChangeEnabled();
310 public void setWheelFontChangeEnabled(boolean val
) {
311 myIsWheelFontChangeEnabled
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
314 public boolean isMouseClickSelectionHonorsCamelWords() {
315 return myIsMouseClickSelectionHonorsCamelWords
!= null
316 ? myIsMouseClickSelectionHonorsCamelWords
.booleanValue()
317 : EditorSettingsExternalizable
.getInstance().isMouseClickSelectionHonorsCamelWords();
320 public void setMouseClickSelectionHonorsCamelWords(boolean val
) {
321 myIsMouseClickSelectionHonorsCamelWords
= val ? Boolean
.TRUE
: Boolean
.FALSE
;
324 public boolean isVariableInplaceRenameEnabled() {
325 return myIsRenameVariablesInplace
!= null
326 ? myIsRenameVariablesInplace
.booleanValue()
327 : EditorSettingsExternalizable
.getInstance().isVariableInplaceRenameEnabled();
330 public void setVariableInplaceRenameEnabled(boolean val
) {
331 myIsRenameVariablesInplace
= val? Boolean
.TRUE
: Boolean
.FALSE
;
334 public boolean isRefrainFromScrolling() {
335 if (myIsRefrainFromScrolling
!= null) return myIsRefrainFromScrolling
.booleanValue();
336 return EditorSettingsExternalizable
.getInstance().isRefrainFromScrolling();
340 public void setRefrainFromScrolling(boolean b
) {
341 myIsRefrainFromScrolling
= b ? Boolean
.TRUE
: Boolean
.FALSE
;
344 private void fireEditorRefresh() {
345 if (myEditor
!= null) {
346 myEditor
.reinitSettings();