rest of UISetting options as properties

This commit is contained in:
Vladimir Krivosheev
2017-02-16 12:20:35 +01:00
parent 8e6819d877
commit 0bce3fb3b5
10 changed files with 71 additions and 56 deletions
@@ -55,13 +55,15 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
@get:OptionTag("FONT_SIZE")
var fontSize by storedProperty(0)
@Property(filter = FontFilter::class) private var FONT_SCALE: Float = 0.toFloat()
@get:Property(filter = FontFilter::class)
@get:OptionTag("FONT_SCALE")
private var fontScale by storedProperty(0f)
@get:OptionTag("RECENT_FILES_LIMIT") var recentFilesLimit by storedProperty(50)
@get:OptionTag("CONSOLE_COMMAND_HISTORY_LIMIT") var consoleCommandHistoryLimit by storedProperty(300)
@JvmField var OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = false
@JvmField var CONSOLE_CYCLE_BUFFER_SIZE_KB = 1024
@JvmField var EDITOR_TAB_LIMIT = 10
@get:OptionTag("OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE") var overrideConsoleCycleBufferSize by storedProperty(false)
@get:OptionTag("CONSOLE_CYCLE_BUFFER_SIZE_KB") var consoleCycleBufferSizeKb by storedProperty(1024)
@get:OptionTag("EDITOR_TAB_LIMIT") var editorTabLimit by storedProperty(10)
@get:OptionTag("REUSE_NOT_MODIFIED_TABS") var reuseNotModifiedTabs by storedProperty(false)
@get:OptionTag("ANIMATE_WINDOWS") var animateWindows by storedProperty(true)
@@ -113,17 +115,12 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
@get:OptionTag("SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES") var showDirectoryForNonUniqueFilenames by storedProperty(true)
@get:OptionTag("NAVIGATE_TO_PREVIEW") var navigateToPreview by storedProperty(false)
@get:OptionTag("SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY") var sortLookupElementsLexicographically by storedProperty(false)
@get:OptionTag("MERGE_EQUAL_STACKTRACES") var mergeEqualStackTraces by storedProperty(true)
@get:OptionTag("SORT_BOOKMARKS") var sortBookmarks by storedProperty(false)
private val myTreeDispatcher = ComponentTreeEventDispatcher.create(UISettingsListener::class.java)
@get:OptionTag("SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY")
var sortLookupElementsLexicographically by storedProperty(false)
@get:OptionTag("MERGE_EQUAL_STACKTRACES")
var mergeEqualStackTraces by storedProperty(true)
@get:OptionTag("SORT_BOOKMARKS")
var sortBookmarks by storedProperty(false)
init {
tweakPlatformDefaults()
@@ -146,7 +143,6 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
}
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Please use {@link UISettingsListener#TOPIC}")
fun addUISettingsListener(listener: UISettingsListener, parentDisposable: Disposable) {
@@ -184,13 +180,16 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
CONSOLE_COMMAND_HISTORY_LIMIT = consoleCommandHistoryLimit
FONT_SIZE = fontSize
FONT_FACE = fontFace
EDITOR_TAB_LIMIT = editorTabLimit
OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = overrideConsoleCycleBufferSize
CONSOLE_CYCLE_BUFFER_SIZE_KB = consoleCycleBufferSizeKb
}
private fun initDefFont() {
val fontData = systemFontFaceAndSize
if (fontFace == null) fontFace = fontData.first
if (fontSize <= 0) fontSize = fontData.second
if (FONT_SCALE <= 0) FONT_SCALE = JBUI.scale(1f)
if (fontScale <= 0) fontScale = JBUI.scale(1f)
}
class FontFilter : SerializationFilter {
@@ -201,7 +200,7 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
return fontData.first != settings.fontFace
}
// store only in pair
return !(fontData.second == settings.fontSize && 1f == settings.FONT_SCALE)
return !(fontData.second == settings.fontSize && 1f == settings.fontScale)
}
}
@@ -229,14 +228,14 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
alphaModeRatio = 0.5f
}
if (FONT_SCALE <= 0) {
if (fontScale <= 0) {
// Reset font to default on switch from IDEA-managed HiDPI to JDK-managed HiDPI. Doesn't affect OSX.
if (UIUtil.isJDKManagedHiDPI() && !SystemInfo.isMac) fontSize = UIUtil.DEF_SYSTEM_FONT_SIZE.toInt()
}
else {
fontSize = JBUI.scale(fontSize / FONT_SCALE).toInt()
fontSize = JBUI.scale(fontSize / fontScale).toInt()
}
FONT_SCALE = JBUI.scale(1f)
fontScale = JBUI.scale(1f)
initDefFont()
// 1. Sometimes system font cannot display standard ASCII symbols. If so we have
@@ -435,5 +434,23 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
@JvmField
@Transient
var PRESENTATION_MODE_FONT_SIZE = 24
@Suppress("unused")
@Deprecated("Use editorTabLimit", replaceWith = ReplaceWith("editorTabLimit"))
@JvmField
@Transient
var EDITOR_TAB_LIMIT = editorTabLimit
@Suppress("unused")
@Deprecated("Use overrideConsoleCycleBufferSize", replaceWith = ReplaceWith("overrideConsoleCycleBufferSize"))
@JvmField
@Transient
var OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = false
@Suppress("unused")
@Deprecated("Use consoleCycleBufferSizeKb", replaceWith = ReplaceWith("consoleCycleBufferSizeKb"))
@JvmField
@Transient
var CONSOLE_CYCLE_BUFFER_SIZE_KB = consoleCycleBufferSizeKb
//</editor-fold>
}
@@ -125,7 +125,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider {
myEditorTabPlacement.setSelectedItem(uiSettings.getEditorTabPlacement());
myHideKnownExtensions.setSelected(uiSettings.getHdeKnownExtensionInTabs());
myShowDirectoryInTabCheckBox.setSelected(uiSettings.getShowDirectoryForNonUniqueFilenames());
myEditorTabLimitField.setText(Integer.toString(uiSettings.EDITOR_TAB_LIMIT));
myEditorTabLimitField.setText(Integer.toString(uiSettings.getEditorTabLimit()));
myReuseNotModifiedTabsCheckBox.setSelected(uiSettings.getReuseNotModifiedTabs());
myShowCloseButtonOnCheckBox.setSelected(uiSettings.getShowCloseButton());
@@ -184,9 +184,9 @@ public class EditorTabsConfigurable implements EditorOptionsProvider {
if (isModified(myReuseNotModifiedTabsCheckBox, uiSettings.getReuseNotModifiedTabs())) uiSettingsChanged = true;
uiSettings.setReuseNotModifiedTabs(myReuseNotModifiedTabsCheckBox.isSelected());
if (isModified(myEditorTabLimitField, uiSettings.EDITOR_TAB_LIMIT, EDITOR_TABS_RANGE)) uiSettingsChanged = true;
if (isModified(myEditorTabLimitField, uiSettings.getEditorTabLimit(), EDITOR_TABS_RANGE)) uiSettingsChanged = true;
try {
uiSettings.EDITOR_TAB_LIMIT = EDITOR_TABS_RANGE.fit(Integer.parseInt(myEditorTabLimitField.getText().trim()));
uiSettings.setEditorTabLimit(EDITOR_TABS_RANGE.fit(Integer.parseInt(myEditorTabLimitField.getText().trim())));
}
catch (NumberFormatException ignored) {
}
@@ -200,7 +200,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider {
final UISettings uiSettings = UISettings.getInstance();
boolean isModified = isModified(myCbModifiedTabsMarkedWithAsterisk, uiSettings.getMarkModifiedTabsWithAsterisk());
isModified |= isModified(myShowTabsTooltipsCheckBox, uiSettings.getShowTabsTooltips());
isModified |= isModified(myEditorTabLimitField, uiSettings.EDITOR_TAB_LIMIT);
isModified |= isModified(myEditorTabLimitField, uiSettings.getEditorTabLimit());
isModified |= isModified(myReuseNotModifiedTabsCheckBox, uiSettings.getReuseNotModifiedTabs());
int tabPlacement = ((Integer)myEditorTabPlacement.getSelectedItem()).intValue();
isModified |= tabPlacement != uiSettings.getEditorTabPlacement();
@@ -110,10 +110,11 @@ public class ConsoleConfigurable implements SearchableConfigurable, Configurable
boolean isModified = !ContainerUtil.newHashSet(myNegativePanel.getListItems()).equals(ContainerUtil.newHashSet(mySettings.getNegativePatterns()));
isModified |= !ContainerUtil.newHashSet(myPositivePanel.getListItems()).equals(ContainerUtil.newHashSet(mySettings.getPositivePatterns()));
isModified |= isModified(myCbUseSoftWrapsAtConsole, editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.CONSOLE));
isModified |= isModified(myCommandsHistoryLimitField, UISettings.getInstance().getConsoleCommandHistoryLimit());
UISettings uiSettings = UISettings.getInstance();
isModified |= isModified(myCommandsHistoryLimitField, uiSettings.getConsoleCommandHistoryLimit());
if (ConsoleBuffer.useCycleBuffer()) {
isModified |= isModified(myCbOverrideConsoleCycleBufferSize, UISettings.getInstance().OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE);
isModified |= isModified(myConsoleCycleBufferSizeField, UISettings.getInstance().CONSOLE_CYCLE_BUFFER_SIZE_KB);
isModified |= isModified(myCbOverrideConsoleCycleBufferSize, uiSettings.getOverrideConsoleCycleBufferSize());
isModified |= isModified(myConsoleCycleBufferSizeField, uiSettings.getConsoleCycleBufferSizeKb());
}
return isModified;
@@ -141,12 +142,12 @@ public class ConsoleConfigurable implements SearchableConfigurable, Configurable
uiSettingsChanged = true;
}
if (ConsoleBuffer.useCycleBuffer()) {
if (isModified(myCbOverrideConsoleCycleBufferSize, uiSettings.OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE)) {
uiSettings.OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = myCbOverrideConsoleCycleBufferSize.isSelected();
if (isModified(myCbOverrideConsoleCycleBufferSize, uiSettings.getOverrideConsoleCycleBufferSize())) {
uiSettings.setOverrideConsoleCycleBufferSize(myCbOverrideConsoleCycleBufferSize.isSelected());
uiSettingsChanged = true;
}
if (isModified(myConsoleCycleBufferSizeField, uiSettings.CONSOLE_CYCLE_BUFFER_SIZE_KB)) {
uiSettings.CONSOLE_CYCLE_BUFFER_SIZE_KB = Math.max(0, Math.min(1024*100, Integer.parseInt(myConsoleCycleBufferSizeField.getText().trim())));
if (isModified(myConsoleCycleBufferSizeField, uiSettings.getConsoleCycleBufferSizeKb())) {
uiSettings.setConsoleCycleBufferSizeKb(Math.max(0, Math.min(1024*100, Integer.parseInt(myConsoleCycleBufferSizeField.getText().trim()))));
uiSettingsChanged = true;
}
}
@@ -168,9 +169,9 @@ public class ConsoleConfigurable implements SearchableConfigurable, Configurable
myCommandsHistoryLimitField.setText(Integer.toString(uiSettings.getConsoleCommandHistoryLimit()));
myCbOverrideConsoleCycleBufferSize.setEnabled(ConsoleBuffer.useCycleBuffer());
myCbOverrideConsoleCycleBufferSize.setSelected(uiSettings.OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE);
myConsoleCycleBufferSizeField.setEnabled(ConsoleBuffer.useCycleBuffer() && uiSettings.OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE);
myConsoleCycleBufferSizeField.setText(Integer.toString(uiSettings.CONSOLE_CYCLE_BUFFER_SIZE_KB));
myCbOverrideConsoleCycleBufferSize.setSelected(uiSettings.getOverrideConsoleCycleBufferSize());
myConsoleCycleBufferSizeField.setEnabled(ConsoleBuffer.useCycleBuffer() && uiSettings.getOverrideConsoleCycleBufferSize());
myConsoleCycleBufferSizeField.setText(Integer.toString(uiSettings.getConsoleCycleBufferSizeKb()));
myNegativePanel.resetFrom(mySettings.getNegativePatterns());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@ public class ConsoleBuffer {
}
public static int getCycleBufferSize() {
if (UISettings.getInstance().OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE) {
return UISettings.getInstance().CONSOLE_CYCLE_BUFFER_SIZE_KB * 1024;
if (UISettings.getInstance().getOverrideConsoleCycleBufferSize()) {
return UISettings.getInstance().getConsoleCycleBufferSizeKb() * 1024;
}
return getLegacyCycleBufferSize();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,11 +29,9 @@ import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class EditorHelper {
public static <T extends PsiElement> void openFilesInEditor(@NotNull T[] elements) {
final int limit = UISettings.getInstance().EDITOR_TAB_LIMIT;
final int limit = UISettings.getInstance().getEditorTabLimit();
final int max = Math.min(limit, elements.length);
for (int i = 0; i < max; i++) {
openInEditor(elements[i], true);
@@ -106,7 +106,7 @@ public class EditorWindow {
private final Stack<Pair<String, Integer>> myRemovedTabs = new Stack<Pair<String, Integer>>() {
@Override
public void push(Pair<String, Integer> pair) {
if (size() >= UISettings.getInstance().EDITOR_TAB_LIMIT) {
if (size() >= UISettings.getInstance().getEditorTabLimit()) {
remove(0);
}
super.push(pair);
@@ -675,7 +675,7 @@ public class EditorWindow {
final VirtualFile file = editor.getFile();
final Icon template = AllIcons.FileTypes.Text;
myTabbedPane.insertTab(file, EmptyIcon.create(template.getIconWidth(), template.getIconHeight()), new TComp(this, editor), null, indexToInsert);
trimToSize(UISettings.getInstance().EDITOR_TAB_LIMIT, file, false);
trimToSize(UISettings.getInstance().getEditorTabLimit(), file, false);
if (selectEditor) {
setSelectedEditor(editor, focusEditor);
}
@@ -959,7 +959,7 @@ public class EditorWindow {
private void processSiblingEditor(final EditorWithProviderComposite siblingEditor) {
if (myTabbedPane != null &&
getTabCount() < UISettings.getInstance().EDITOR_TAB_LIMIT &&
getTabCount() < UISettings.getInstance().getEditorTabLimit() &&
findFileComposite(siblingEditor.getFile()) == null || myTabbedPane == null && getTabCount() == 0) {
setEditor(siblingEditor, true);
}
@@ -805,7 +805,7 @@ public class EditorsSplitters extends IdePanePanel implements UISettingsListener
final List<Element> children = new ArrayList<>(fileElements.size());
// trim to EDITOR_TAB_LIMIT, ignoring CLOSE_NON_MODIFIED_FILES_FIRST policy
int toRemove = fileElements.size() - UISettings.getInstance().EDITOR_TAB_LIMIT;
int toRemove = fileElements.size() - UISettings.getInstance().getEditorTabLimit();
for (Element fileElement : fileElements) {
if (toRemove <= 0 || Boolean.valueOf(fileElement.getAttributeValue(PINNED)).booleanValue()) {
children.add(fileElement);
@@ -1870,7 +1870,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Persis
for (EditorsSplitters each : getAllSplitters()) {
each.setTabsPlacement(uiSettings.getEditorTabPlacement());
each.trimToSize(uiSettings.EDITOR_TAB_LIMIT);
each.trimToSize(uiSettings.getEditorTabLimit());
// Tab layout policy
if (uiSettings.getScrollTabLayoutInEditor()) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -251,11 +251,11 @@ public class ConsoleViewImplTest extends LightPlatformTestCase {
}
private static void withCycleConsole(int capacityKB, Consumer<ConsoleViewImpl> runnable) {
boolean oldUse = UISettings.getInstance().OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE;
int oldSize = UISettings.getInstance().CONSOLE_CYCLE_BUFFER_SIZE_KB;
boolean oldUse = UISettings.getInstance().getOverrideConsoleCycleBufferSize();
int oldSize = UISettings.getInstance().getConsoleCycleBufferSizeKb();
UISettings.getInstance().OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = true;
UISettings.getInstance().CONSOLE_CYCLE_BUFFER_SIZE_KB = capacityKB;
UISettings.getInstance().setOverrideConsoleCycleBufferSize(true);
UISettings.getInstance().setConsoleCycleBufferSizeKb(capacityKB);
// create new to reflect changed buffer size
ConsoleViewImpl console = createConsole();
try {
@@ -267,8 +267,8 @@ public class ConsoleViewImplTest extends LightPlatformTestCase {
}
finally {
Disposer.dispose(console);
UISettings.getInstance().OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = oldUse;
UISettings.getInstance().CONSOLE_CYCLE_BUFFER_SIZE_KB = oldSize;
UISettings.getInstance().setOverrideConsoleCycleBufferSize(oldUse);
UISettings.getInstance().setConsoleCycleBufferSizeKb(oldSize);
}
}
@@ -52,16 +52,15 @@ public class FileEditorManagerTest extends FileEditorManagerTestCase {
}
public void testTabLimit() throws Exception {
int limit = UISettings.getInstance().EDITOR_TAB_LIMIT;
int limit = UISettings.getInstance().getEditorTabLimit();
try {
UISettings.getInstance().EDITOR_TAB_LIMIT = 2;
UISettings.getInstance().setEditorTabLimit(2);
openFiles(STRING);
// note that foo.xml is pinned
assertOpenFiles("foo.xml", "3.txt");
}
finally {
UISettings.getInstance().EDITOR_TAB_LIMIT = limit;
UISettings.getInstance().setEditorTabLimit(limit);
}
}