Kotlin migration: extract data context into a function, check it on null

The extraction itself is needed due to different behaviour of related
IDEA functions in different platforms.
Check on null is needed because `createFromAnAction` last argument
cannot be null, otherwise we will get an exception.

Partial fix of KT-26399
This commit is contained in:
Mikhail Glukhikh
2018-08-27 17:21:13 +03:00
committed by Ilya Gorbunov
parent 319c16c885
commit 2e4f46045e
2 changed files with 18 additions and 4 deletions
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.idea.configuration
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -94,10 +93,12 @@ class KotlinMigrationProjectComponent(val project: Project) {
if (migrationNotificationDialog.isOK) {
val action = ActionManager.getInstance().getAction(CodeMigrationAction.ACTION_ID)
val dataContext = DataManager.getInstance().dataContextFromFocus.result
val actionEvent = AnActionEvent.createFromAnAction(action, null, ActionPlaces.ACTION_SEARCH, dataContext)
val dataContext = getDataContextFromDialog(migrationNotificationDialog)
if (dataContext != null) {
val actionEvent = AnActionEvent.createFromAnAction(action, null, ActionPlaces.ACTION_SEARCH, dataContext)
action.actionPerformed(actionEvent)
action.actionPerformed(actionEvent)
}
}
}
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.configuration
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.ui.DialogWrapper
@Suppress("UNUSED_PARAMETER")
internal fun getDataContextFromDialog(wrapper: DialogWrapper): DataContext? = DataManager.getInstance().dataContextFromFocus.result