UISettings#SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY isn't saved, part 1

This commit is contained in:
Vladimir Krivosheev
2017-01-30 15:51:21 +01:00
parent ac447039b4
commit a431a59ca6
11 changed files with 121 additions and 37 deletions
@@ -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<LanguageLevel?>()
}
@@ -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<ThreadState> threadStates = UISettings.getInstance().MERGE_EQUAL_STACKTRACES ? myMergedThreadDump : myThreadDump;
List<ThreadState> 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();
}
}
@@ -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
@@ -9,15 +9,15 @@ import org.junit.Test
private class AState : BaseState() {
@get:Attribute("customName")
var languageLevel: String? by storedProperty()
var languageLevel by storedProperty<String?>()
var property2 by storedProperty(0)
var nestedComplex: NestedState? by storedProperty()
var nestedComplex by storedProperty<NestedState?>()
}
private class NestedState : BaseState() {
var childProperty: String? by storedProperty()
var childProperty by storedProperty<String?>()
}
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)
}
}
+1
View File
@@ -12,5 +12,6 @@
<orderEntry type="module" module-name="annotations" />
<orderEntry type="module" module-name="projectModel-api" />
<orderEntry type="module" module-name="indexing-api" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
@@ -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<UISettingsListener> 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 &&
@@ -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)
}
@@ -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;
}
@@ -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
@@ -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();
}
};
@@ -42,7 +42,19 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
return false
}
fun <T : Any> storedProperty(defaultValue: T? = null): ReadWriteProperty<BaseState, T?> {
fun <T> storedProperty(defaultValue: T? = null): ReadWriteProperty<BaseState, T?> {
val result = StoredProperty(defaultValue)
properties.add(result)
return result
}
fun storedProperty(defaultValue: Int = 0): ReadWriteProperty<BaseState, Int> {
val result = StoredProperty(defaultValue)
properties.add(result)
return result
}
fun storedProperty(defaultValue: Boolean = false): ReadWriteProperty<BaseState, Boolean> {
val result = StoredProperty(defaultValue)
properties.add(result)
return result
@@ -77,14 +89,14 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
}
}
internal class StoredProperty<T>(internal val defaultValue: T?) : ReadWriteProperty<BaseState, T?> {
internal class StoredProperty<T>(internal val defaultValue: T) : ReadWriteProperty<BaseState, T> {
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++