Rework the notification for scripts out of project

Add an option to link external gradle project
remove an option to load configuration manually because it cannot be implemented properly: script configurations for those scripts shouldn't be loaded during import for Gradle 6.0

^KT-37178 Fixed
This commit is contained in:
Natalia Selezneva
2020-04-23 14:28:43 +03:00
parent 85141b753b
commit 2fba813a53
2 changed files with 22 additions and 7 deletions
@@ -1,4 +1,4 @@
action.label.text.load.script.configuration=Load script configuration
action.label.text.load.script.configuration=Load related Gradle project
action.text.install=Install
action.text.show.kotlin.gradle.dsl.logs.in=Show Kotlin Gradle DSL Logs in {0}
build.0.project=Build {0}
@@ -42,7 +42,7 @@ text.was.modified={0} was modified
title.configure.kotlin.gradle.plugin=Configure Kotlin-Gradle Plugin
title.kotlin.build.script=Gradle Kotlin DSL Scripts errors
title.update.language.version=Update Language Version
tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed=The external Gradle project needs to be imported to get this script analyzed. <br/>You can import the related Gradle project or click "{0}" to get code insight without importing.
tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed=The external Gradle project needs to be imported to get this script analyzed. <br/>Load related Gradle project to add it to the list of imported Gradle Projects.
display.name.kotlin.multiplatform=Kotlin/Multiplatform
display.name.kotlin.jvm=Kotlin/JVM
display.name.kotlin.js.for.node.js=Kotlin/JS for Node.js
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.idea.scripting.gradle
import com.intellij.icons.AllIcons
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
@@ -14,7 +16,8 @@ import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotifications
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings
import org.jetbrains.plugins.gradle.util.GradleConstants
class GradleScriptOutOfSourceNotificationProvider(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>() {
override fun getKey(): Key<EditorNotificationPanel> = KEY
@@ -26,16 +29,28 @@ class GradleScriptOutOfSourceNotificationProvider(private val project: Project)
if (!isInAffectedGradleProjectFiles(project, file.path)) {
return EditorNotificationPanel().apply {
text(KotlinIdeaGradleBundle.message("text.the.associated.gradle.project.isn.t.imported"))
val loadScriptConfigurationText = KotlinIdeaGradleBundle.message("action.label.text.load.script.configuration")
createActionLabel(loadScriptConfigurationText) {
ScriptConfigurationManager.getInstance(project).forceReloadConfiguration(file, loaderForOutOfProjectScripts)
val linkProjectText = KotlinIdeaGradleBundle.message("action.label.text.load.script.configuration")
createActionLabel(linkProjectText) {
val newProjectSettings = GradleProjectSettings()
newProjectSettings.externalProjectPath = file.parent.path
ExternalSystemUtil.linkExternalProject(
GradleConstants.SYSTEM_ID,
newProjectSettings,
project,
{
},
false,
ProgressExecutionMode.IN_BACKGROUND_ASYNC
)
}
val link = createActionLabel("") {}
link.setIcon(AllIcons.General.ContextHelp)
link.setUseIconAsLink(true)
link.toolTipText = KotlinIdeaGradleBundle.message(
"tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed",
loadScriptConfigurationText
linkProjectText
)
}
}