mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable: preselect non trivial expr
This commit is contained in:
+10
-1
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.JavaCompletionUtil;
|
||||
import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
import com.intellij.codeInsight.intention.impl.TypeExpression;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.unwrap.ScopeHighlighter;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.featureStatistics.ProductivityFeatureNames;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
@@ -126,13 +127,21 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
|
||||
}
|
||||
else {
|
||||
int selection;
|
||||
PsiExpression expression = expressions.get(0);
|
||||
if (expression instanceof PsiReferenceExpression && ((PsiReferenceExpression)expression).resolve() instanceof PsiLocalVariable) {
|
||||
selection = 1;
|
||||
}
|
||||
else {
|
||||
selection = -1;
|
||||
}
|
||||
IntroduceTargetChooser.showChooser(editor, expressions,
|
||||
new Pass<PsiExpression>(){
|
||||
public void pass(final PsiExpression selectedValue) {
|
||||
invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset());
|
||||
}
|
||||
},
|
||||
new PsiExpressionTrimRenderer.RenderFunction());
|
||||
new PsiExpressionTrimRenderer.RenderFunction(), "Expressions", selection, ScopeHighlighter.NATURAL_RANGER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,12 +57,23 @@ public class IntroduceTargetChooser {
|
||||
final Function<T, String> renderer,
|
||||
String title,
|
||||
NotNullFunction<PsiElement, TextRange> ranger) {
|
||||
showChooser(editor, expressions, callback, renderer, title, -1, ranger);
|
||||
}
|
||||
|
||||
public static <T extends PsiElement> void showChooser(final Editor editor,
|
||||
final List<T> expressions,
|
||||
final Pass<T> callback,
|
||||
final Function<T, String> renderer,
|
||||
String title,
|
||||
int selection,
|
||||
NotNullFunction<PsiElement, TextRange> ranger) {
|
||||
final ScopeHighlighter highlighter = new ScopeHighlighter(editor, ranger);
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
for (T expr : expressions) {
|
||||
model.addElement(expr);
|
||||
}
|
||||
final JList list = new JBList(model);
|
||||
if (selection > -1) list.setSelectedIndex(selection);
|
||||
list.setCellRenderer(new DefaultListCellRenderer() {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user