Introduce Parameter: Implement dialog advertisement and switch
This commit is contained in:
+13
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinI
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.idea.util.supertypes
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
@@ -172,6 +173,8 @@ public class KotlinInplaceParameterIntroducer(
|
||||
revalidate()
|
||||
}
|
||||
|
||||
override fun getAdvertisementActionId() = "IntroduceParameter"
|
||||
|
||||
override fun initPanelControls() {
|
||||
addPanelControl {
|
||||
val previewer = EditorFactory.getInstance().createEditor(EditorFactory.getInstance().createDocument(""),
|
||||
@@ -292,4 +295,14 @@ public class KotlinInplaceParameterIntroducer(
|
||||
previewer = null
|
||||
}
|
||||
}
|
||||
|
||||
fun switchToDialogUI() {
|
||||
stopIntroduce()
|
||||
with (originalDescriptor) {
|
||||
KotlinIntroduceParameterDialog(myProject,
|
||||
this,
|
||||
myNameSuggestions.copyToArray(),
|
||||
listOf(parameterType) + parameterType.supertypes()).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.KotlinIntroduceHandlerBase
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinInplaceVariableIntroducer
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.selectElementsWithTargetParent
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHint
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHintByKey
|
||||
@@ -276,6 +277,11 @@ public open class KotlinIntroduceParameterHandler: KotlinIntroduceHandlerBase()
|
||||
}
|
||||
|
||||
override fun invoke(project: Project, editor: Editor, file: PsiFile, dataContext: DataContext?) {
|
||||
(KotlinInplaceVariableIntroducer.getActiveInstance(editor) as? KotlinInplaceParameterIntroducer)?.let {
|
||||
it.switchToDialogUI()
|
||||
return
|
||||
}
|
||||
|
||||
if (file !is JetFile) return
|
||||
selectElementsWithTargetParent(
|
||||
operationName = INTRODUCE_PARAMETER,
|
||||
|
||||
+24
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
@@ -136,6 +137,16 @@ public class KotlinInplaceVariableIntroducer<D extends JetCallableDeclaration> e
|
||||
myDoNotChangeVar = doNotChangeVar;
|
||||
myExprType = exprType;
|
||||
this.noTypeInference = noTypeInference;
|
||||
|
||||
String advertisementActionId = getAdvertisementActionId();
|
||||
if (advertisementActionId != null) {
|
||||
showDialogAdvertisement(advertisementActionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getAdvertisementActionId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -422,6 +433,19 @@ public class KotlinInplaceVariableIntroducer<D extends JetCallableDeclaration> e
|
||||
}
|
||||
}
|
||||
|
||||
public void stopIntroduce() {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
templateState.gotoEnd(true);
|
||||
}
|
||||
};
|
||||
CommandProcessor.getInstance().executeCommand(myProject, runnable, getCommandName(), getCommandName());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static KotlinInplaceVariableIntroducer getActiveInstance(@NotNull Editor editor) {
|
||||
return editor.getUserData(ACTIVE_INTRODUCER);
|
||||
|
||||
Reference in New Issue
Block a user