From a431a59ca60837e6e246749efdad2f28d666d641 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 30 Jan 2017 12:55:03 +0100 Subject: [PATCH] UISettings#SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY isn't saved, part 1 --- .../openapi/roots/LanguageLevelState.kt | 2 +- .../intellij/unscramble/ThreadDumpPanel.java | 8 ++--- .../completion/CompletionSortingTestCase.java | 27 ++++++++++---- .../testSrc/StoredPropertyStateTest.kt | 12 +++++-- platform/editor-ui-api/editor-ui-api.iml | 1 + .../src/com/intellij/ide/ui/UISettings.java | 35 +++++++++++++++---- .../com/intellij/ide/ui/UISettingsState.kt | 27 ++++++++++++++ .../options/CodeCompletionPanel.java | 8 ++--- .../completion/CompletionLookupArranger.java | 4 +-- .../codeInsight/lookup/impl/LookupUi.java | 16 +++++---- .../openapi/components/StoredProperty.kt | 18 ++++++++-- 11 files changed, 121 insertions(+), 37 deletions(-) create mode 100644 platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsState.kt diff --git a/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt b/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt index 37848ae11647..a86dd7a17f4c 100644 --- a/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt +++ b/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt @@ -21,5 +21,5 @@ import com.intellij.util.xmlb.annotations.Attribute class LanguageLevelState : BaseState() { @get:Attribute("LANGUAGE_LEVEL") - var languageLevel: LanguageLevel? by storedProperty() + var languageLevel by storedProperty() } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java index 0a42c7245652..645e353fc613 100644 --- a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java +++ b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 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. @@ -180,7 +180,7 @@ public class ThreadDumpPanel extends JPanel implements DataProvider { model.clear(); int selectedIndex = 0; int index = 0; - List threadStates = UISettings.getInstance().MERGE_EQUAL_STACKTRACES ? myMergedThreadDump : myThreadDump; + List threadStates = UISettings.getInstance().isMergeEqualStackTraces() ? myMergedThreadDump : myThreadDump; for (ThreadState state : threadStates) { if (StringUtil.containsIgnoreCase(state.getStackTrace(), text) || StringUtil.containsIgnoreCase(state.getName(), text)) { //noinspection unchecked @@ -389,12 +389,12 @@ public class ThreadDumpPanel extends JPanel implements DataProvider { @Override public boolean isSelected(AnActionEvent e) { - return UISettings.getInstance().MERGE_EQUAL_STACKTRACES; + return UISettings.getInstance().isMergeEqualStackTraces(); } @Override public void setSelected(AnActionEvent e, boolean state) { - UISettings.getInstance().MERGE_EQUAL_STACKTRACES = state; + UISettings.getInstance().setMergeEqualStackTraces(state); updateThreadList(); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java index e07e1dae0fa2..a43c682f42e1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java @@ -1,6 +1,17 @@ /* - * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved. - * Use is subject to license terms. + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.intellij.codeInsight.completion; @@ -34,10 +45,14 @@ public abstract class CompletionSortingTestCase extends LightFixtureCompletionTe @Override protected void tearDown() throws Exception { - LookupManager.getInstance(getProject()).hideActiveLookup(); - UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false; - CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER; - super.tearDown(); + try { + LookupManager.getInstance(getProject()).hideActiveLookup(); + UISettings.getInstance().setSortLookupElementsLexicographically(false); + CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER; + } + finally { + super.tearDown(); + } } @Override diff --git a/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt b/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt index 5a73f7cca5af..9e8c4e512c00 100644 --- a/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt +++ b/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt @@ -9,15 +9,15 @@ import org.junit.Test private class AState : BaseState() { @get:Attribute("customName") - var languageLevel: String? by storedProperty() + var languageLevel by storedProperty() var property2 by storedProperty(0) - var nestedComplex: NestedState? by storedProperty() + var nestedComplex by storedProperty() } private class NestedState : BaseState() { - var childProperty: String? by storedProperty() + var childProperty by storedProperty() } class StoredPropertyStateTest { @@ -50,5 +50,11 @@ class StoredPropertyStateTest { nestedState.childProperty = "test" assertThat(state.modificationCount).isEqualTo(2) + + state.languageLevel = "11" + assertThat(state.modificationCount).isEqualTo(3) + + state.languageLevel = null + assertThat(state.modificationCount).isEqualTo(4) } } \ No newline at end of file diff --git a/platform/editor-ui-api/editor-ui-api.iml b/platform/editor-ui-api/editor-ui-api.iml index e68f375a0fd6..d73132f4ed76 100644 --- a/platform/editor-ui-api/editor-ui-api.iml +++ b/platform/editor-ui-api/editor-ui-api.iml @@ -12,5 +12,6 @@ + \ No newline at end of file diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java index 0a9344c429ea..4bc1080af643 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java @@ -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. @@ -35,6 +35,7 @@ import com.intellij.util.ui.UIUtil; import com.intellij.util.xmlb.Accessor; import com.intellij.util.xmlb.SerializationFilter; import com.intellij.util.xmlb.XmlSerializerUtil; +import com.intellij.util.xmlb.annotations.OptionTag; import com.intellij.util.xmlb.annotations.Property; import com.intellij.util.xmlb.annotations.Transient; import org.jetbrains.annotations.NonNls; @@ -85,8 +86,6 @@ public class UISettings extends SimpleModificationTracker implements PersistentS public int EDITOR_TAB_LIMIT = 10; public boolean REUSE_NOT_MODIFIED_TABS = false; public boolean ANIMATE_WINDOWS = true; - @Deprecated //todo remove in IDEA 16 - public int ANIMATION_SPEED = 4000; // Pixels per second public int ANIMATION_DURATION = 300; // Milliseconds public boolean SHOW_TOOL_WINDOW_NUMBERS = true; public boolean HIDE_TOOL_STRIPES = true; @@ -113,7 +112,6 @@ public class UISettings extends SimpleModificationTracker implements PersistentS public AntialiasingType IDE_AA_TYPE = AntialiasingType.SUBPIXEL; public AntialiasingType EDITOR_AA_TYPE = AntialiasingType.SUBPIXEL; public ColorBlindness COLOR_BLINDNESS; - public boolean USE_LCD_RENDERING_IN_EDITOR = true; public boolean MOVE_MOUSE_ON_DEFAULT_BUTTON = false; public boolean ENABLE_ALPHA_MODE = false; public int ALPHA_MODE_DELAY = 1500; @@ -124,12 +122,10 @@ public class UISettings extends SimpleModificationTracker implements PersistentS public boolean DISABLE_MNEMONICS = SystemInfo.isMac; // IDEADEV-33409, should be disabled by default on MacOS public boolean DISABLE_MNEMONICS_IN_CONTROLS = false; public boolean USE_SMALL_LABELS_ON_TABS = SystemInfo.isMac; - public boolean SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false; public int MAX_LOOKUP_WIDTH2 = 500; public int MAX_LOOKUP_LIST_HEIGHT = 11; public boolean HIDE_NAVIGATION_ON_FOCUS_LOSS = true; public boolean DND_WITH_PRESSED_ALT_ONLY = false; - public boolean FILE_COLORS_IN_PROJECT_VIEW = false; public boolean DEFAULT_AUTOSCROLL_TO_SOURCE = false; @Transient public boolean PRESENTATION_MODE = false; @@ -139,10 +135,11 @@ public class UISettings extends SimpleModificationTracker implements PersistentS public boolean SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true; public boolean NAVIGATE_TO_PREVIEW = false; public boolean SORT_BOOKMARKS = false; - public boolean MERGE_EQUAL_STACKTRACES = true; private final ComponentTreeEventDispatcher myTreeDispatcher = ComponentTreeEventDispatcher.create(UISettingsListener.class); + private final UISettingsState myState = new UISettingsState(); + public UISettings() { tweakPlatformDefaults(); @@ -152,6 +149,29 @@ public class UISettings extends SimpleModificationTracker implements PersistentS } } + @OptionTag("SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY") + public boolean isSortLookupElementsLexicographically() { + return myState.getSortLookupElementsLexicographically(); + } + + public void setSortLookupElementsLexicographically(boolean value) { + myState.setSortLookupElementsLexicographically(value); + } + + @OptionTag("MERGE_EQUAL_STACKTRACES") + public boolean isMergeEqualStackTraces() { + return myState.getMergeEqualStackTraces(); + } + + public void setMergeEqualStackTraces(boolean value) { + myState.setMergeEqualStackTraces(value); + } + + @Override + public long getModificationCount() { + return super.getModificationCount() + myState.getModificationCount(); + } + private UISettings withDefFont() { initDefFont(); return this; @@ -229,6 +249,7 @@ public class UISettings extends SimpleModificationTracker implements PersistentS @Override public void loadState(UISettings object) { XmlSerializerUtil.copyBean(object, this); + myState.resetModificationCount(); // Check tab placement in editor if (EDITOR_TAB_PLACEMENT != TABS_NONE && diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsState.kt b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsState.kt new file mode 100644 index 000000000000..d2aad3fff658 --- /dev/null +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsState.kt @@ -0,0 +1,27 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.ui + +import com.intellij.openapi.components.BaseState +import com.intellij.util.xmlb.annotations.OptionTag + +class UISettingsState : BaseState() { + @get:OptionTag("SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY") + var sortLookupElementsLexicographically by storedProperty(false) + + @get:OptionTag("MERGE_EQUAL_STACKTRACES") + var mergeEqualStackTraces by storedProperty(true) +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java b/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java index 6c65209d1122..a5a5b71bcc6c 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java @@ -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. @@ -145,7 +145,7 @@ public class CodeCompletionPanel { myCbShowFullParameterSignatures.setSelected(codeInsightSettings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO); myCbAutocompletion.setSelected(codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP); - myCbSorting.setSelected(UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY); + myCbSorting.setSelected(UISettings.getInstance().isSortLookupElementsLexicographically()); myCbAutocompletion.setText("Autopopup code completion" + (PowerSaveMode.isEnabled() ? " (not available in Power Save mode)" : "")); } @@ -168,7 +168,7 @@ public class CodeCompletionPanel { codeInsightSettings.PARAMETER_INFO_DELAY = getIntegerValue(myParameterInfoDelayField.getText(), 0); codeInsightSettings.JAVADOC_INFO_DELAY = getIntegerValue(myAutopopupJavaDocField.getText(), 0); - UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = myCbSorting.isSelected(); + UISettings.getInstance().setSortLookupElementsLexicographically(myCbSorting.isSelected()); final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel)); if (project != null){ @@ -193,7 +193,7 @@ public class CodeCompletionPanel { isModified |= isModified(myCbAutopopupJavaDoc, codeInsightSettings.AUTO_POPUP_JAVADOC_INFO); isModified |= isModified(myParameterInfoDelayField, codeInsightSettings.PARAMETER_INFO_DELAY, 0); isModified |= isModified(myAutopopupJavaDocField, codeInsightSettings.JAVADOC_INFO_DELAY, 0); - isModified |= isModified(myCbSorting, UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY); + isModified |= isModified(myCbSorting, UISettings.getInstance().isSortLookupElementsLexicographically()); return isModified; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java index 4cdb55a1af19..9ab9d98d2c56 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java @@ -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. @@ -238,7 +238,7 @@ public class CompletionLookupArranger extends LookupArranger { } private static boolean isAlphaSorted() { - return ourUISettings.SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY; + return ourUISettings.isSortLookupElementsLexicographically(); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java index 108ed3fb0077..2f88500068ba 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java @@ -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. @@ -46,7 +46,9 @@ import com.intellij.ui.components.JBLayeredPane; import com.intellij.ui.components.JBList; import com.intellij.util.Alarm; import com.intellij.util.PlatformIcons; -import com.intellij.util.ui.*; +import com.intellij.util.ui.AbstractLayoutManager; +import com.intellij.util.ui.AsyncProcessIcon; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -213,7 +215,7 @@ class LookupUi { } private void updateSorting() { - final boolean lexi = UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY; + final boolean lexi = UISettings.getInstance().isSortLookupElementsLexicographically(); mySortingLabel.setIcon(lexi ? AllIcons.Ide.LookupAlphanumeric : AllIcons.Ide.LookupRelevance); mySortingLabel.setToolTipText(lexi ? "Click to sort variants by relevance" : "Click to sort variants alphabetically"); @@ -421,19 +423,19 @@ class LookupUi { DefaultActionGroup group = new DefaultActionGroup(); group.add(createSortingAction(true)); group.add(createSortingAction(false)); - JBPopupFactory.getInstance().createActionGroupPopup("Change sorting", group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false).showInBestPositionFor( + JBPopupFactory.getInstance().createActionGroupPopup("Change Sorting", group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false).showInBestPositionFor( context); return true; } private AnAction createSortingAction(boolean checked) { - boolean currentSetting = UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY; - final boolean newSetting = checked ? currentSetting : !currentSetting; + boolean currentSetting = UISettings.getInstance().isSortLookupElementsLexicographically(); + final boolean newSetting = checked == currentSetting; return new DumbAwareAction(newSetting ? "Sort lexicographically" : "Sort by relevance", null, checked ? PlatformIcons.CHECK_ICON : null) { @Override public void actionPerformed(AnActionEvent e) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CHANGE_SORTING); - UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = newSetting; + UISettings.getInstance().setSortLookupElementsLexicographically(newSetting); updateSorting(); } }; diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt index 0237de225655..1a3a64c4b857 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt @@ -42,7 +42,19 @@ abstract class BaseState : SerializationFilter, ModificationTracker { return false } - fun storedProperty(defaultValue: T? = null): ReadWriteProperty { + fun storedProperty(defaultValue: T? = null): ReadWriteProperty { + val result = StoredProperty(defaultValue) + properties.add(result) + return result + } + + fun storedProperty(defaultValue: Int = 0): ReadWriteProperty { + val result = StoredProperty(defaultValue) + properties.add(result) + return result + } + + fun storedProperty(defaultValue: Boolean = false): ReadWriteProperty { val result = StoredProperty(defaultValue) properties.add(result) return result @@ -77,14 +89,14 @@ abstract class BaseState : SerializationFilter, ModificationTracker { } } -internal class StoredProperty(internal val defaultValue: T?) : ReadWriteProperty { +internal class StoredProperty(internal val defaultValue: T) : ReadWriteProperty { internal var value = defaultValue internal var name: String? = null override operator fun getValue(thisRef: BaseState, property: KProperty<*>) = value @Suppress("UNCHECKED_CAST") - override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") newValue: T?) { + override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") newValue: T) { if (value != newValue) { thisRef.modificationCount++