[r=dmitry.avdeev] a setting to select the first element in autopopup (IDEA-59718)

This commit is contained in:
peter.gromov
2010-11-29 20:57:43 +03:00
parent 96b88b21aa
commit c70dd2bc4a
5 changed files with 55 additions and 7 deletions
@@ -22,6 +22,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.ui.UIUtil
import com.intellij.codeInsight.CodeInsightSettings
/**
* @author peter
@@ -36,6 +37,7 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa
})
CompletionAutoPopupHandler.ourTestingAutopopup = true
CodeInsightSettings.instance.FOCUS_AUTOPOPUP = CodeInsightSettings.SMART
}
void superSetUp() {
super.setUp()
@@ -45,6 +47,7 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa
}
@Override protected void tearDown() {
CodeInsightSettings.instance.FOCUS_AUTOPOPUP = CodeInsightSettings.NEVER
CompletionAutoPopupHandler.ourTestingAutopopup = false
UIUtil.invokeAndWaitIfNeeded(new Runnable(){
@Override
@@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="7f988" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="1">
<grid id="7f988" layout-manager="GridLayoutManager" row-count="10" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="1">
<margin top="7" left="7" bottom="7" right="7"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
@@ -108,7 +108,7 @@
</component>
<component id="749a1" class="javax.swing.JCheckBox" binding="myCbAutopopupJavaDoc">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="2" left="2" bottom="12" right="2"/>
@@ -117,7 +117,7 @@
</component>
<component id="a1f3b" class="javax.swing.JTextField" binding="myAutopopupJavaDocField">
<constraints>
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="9" fill="0" indent="0" use-parent-layout="false">
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="9" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="-1"/>
<maximum-size width="50" height="-1"/>
</grid>
@@ -127,6 +127,32 @@
<text value="1000"/>
</properties>
</component>
<grid id="42a0" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="15" bottom="3" right="0"/>
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ae843" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<iconTextGap value="4"/>
<inheritsPopupMenu value="false"/>
<text value="Preselect the first suggestion:"/>
</properties>
</component>
</children>
</grid>
<component id="6cbc" class="javax.swing.JComboBox" binding="myFocusLookup">
<constraints>
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="b9e15" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="1" vgap="-1">
@@ -45,12 +45,16 @@ public class CodeCompletionPanel {
private JCheckBox myCbShowFullParameterSignatures;
private JComboBox myCaseSensitiveCombo;
private JComboBox myFocusLookup;
private static final String CASE_SENSITIVE_ALL = ApplicationBundle.message("combobox.autocomplete.casesensitive.all");
private static final String CASE_SENSITIVE_NONE = ApplicationBundle.message("combobox.autocomplete.casesensitive.none");
private static final String CASE_SENSITIVE_FIRST_LETTER = ApplicationBundle.message("combobox.autocomplete.casesensitive.first.letter");
private static final String[] CASE_VARIANTS = {CASE_SENSITIVE_ALL, CASE_SENSITIVE_NONE, CASE_SENSITIVE_FIRST_LETTER};
private static final String[] FOCUS_VARIANTS = {"Never", "Smart", "Always"};
public CodeCompletionPanel(){
myCaseSensitiveCombo.setModel(new DefaultComboBoxModel(new String[]{CASE_SENSITIVE_ALL, CASE_SENSITIVE_NONE, CASE_SENSITIVE_FIRST_LETTER}));
myCaseSensitiveCombo.setModel(new DefaultComboBoxModel(CASE_VARIANTS));
myFocusLookup.setModel(new DefaultComboBoxModel(FOCUS_VARIANTS));
myCbAutocompletion.addActionListener(
@@ -88,9 +92,6 @@ public class CodeCompletionPanel {
component.setVisible(OptionsApplicabilityFilter.isApplicable(id));
}
/*
*/
public void reset() {
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
@@ -110,6 +111,8 @@ public class CodeCompletionPanel {
}
myCaseSensitiveCombo.setSelectedItem(value);
myFocusLookup.setSelectedIndex(Math.min(Math.max(codeInsightSettings.FOCUS_AUTOPOPUP - 1, 0), FOCUS_VARIANTS.length - 1));
myCbOnCodeCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION);
myCbOnSmartTypeCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION);
myCbOnClassNameCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_CLASS_NAME_COMPLETION);
@@ -137,6 +140,7 @@ public class CodeCompletionPanel {
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
codeInsightSettings.COMPLETION_CASE_SENSITIVE = getCaseSensitiveValue();
codeInsightSettings.FOCUS_AUTOPOPUP = getFocusLookupValue();
codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION = myCbOnCodeCompletion.isSelected();
codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = myCbOnSmartTypeCompletion.isSelected();
@@ -164,6 +168,7 @@ public class CodeCompletionPanel {
boolean isModified = false;
isModified |= (getCaseSensitiveValue() != codeInsightSettings.COMPLETION_CASE_SENSITIVE);
isModified |= (getFocusLookupValue() != codeInsightSettings.FOCUS_AUTOPOPUP);
isModified |= isModified(myCbOnCodeCompletion, codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION);
isModified |= isModified(myCbOnSmartTypeCompletion, codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION);
@@ -215,4 +220,8 @@ public class CodeCompletionPanel {
return CodeInsightSettings.FIRST_LETTER;
}
}
private int getFocusLookupValue() {
return myFocusLookup.getSelectedIndex() + 1;
}
}
@@ -85,6 +85,11 @@ public class CodeInsightSettings implements PersistentStateComponent<Element>, C
public static final int NONE = 2;
public static final int FIRST_LETTER = 3;
public int FOCUS_AUTOPOPUP = NEVER; // NEVER, SMART or ALWAYS
public static final int NEVER = 1;
public static final int SMART = 2;
public static final int ALWAYS = 3;
public boolean AUTOCOMPLETE_ON_CODE_COMPLETION = true;
public boolean AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = true;
public boolean AUTOCOMPLETE_ON_CLASS_NAME_COMPLETION = false;
@@ -220,6 +220,11 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
return true;
}
switch (CodeInsightSettings.getInstance().FOCUS_AUTOPOPUP) {
case CodeInsightSettings.ALWAYS: return true;
case CodeInsightSettings.NEVER: return false;
}
final Language language = PsiUtilBase.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset());
for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
final ThreeState result = confidence.shouldFocusLookup(parameters);