Skip to content

Commit

Permalink
Kotlin migration: extract data context into a function, check it on null
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mglukhikh authored and goodwinnk committed Sep 18, 2018
1 parent 4447e4c commit e0723c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions idea/src/org/jetbrains/kotlin/idea/configuration/MigrationUtils.kt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e0723c5

Please sign in to comment.