Browse Source

Avoid interfering with Intellij Light Edit mode (#2027)

Resolves #1816
pull/2043/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
362c61a38b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt
  2. 6
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt
  3. 6
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt

8
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt

@ -45,9 +45,11 @@ class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_E
editor: Editor, editor: Editor,
parentDisposable: Disposable parentDisposable: Disposable
) { ) {
val project = editor.project ?: return val project = editor.project
val listener = PreviewEditorToolbarVisibilityUpdater(component, project, editor) if (project != null && isPreviewCompatible(project)) {
editor.caretModel.addCaretListener(listener, parentDisposable) val listener = PreviewEditorToolbarVisibilityUpdater(component, project, editor)
editor.caretModel.addCaretListener(listener, parentDisposable)
}
} }
} }

6
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt

@ -14,10 +14,8 @@ import org.jetbrains.compose.desktop.ide.preview.ui.PreviewPanel
import java.awt.BorderLayout import java.awt.BorderLayout
class PreviewToolWindow : ToolWindowFactory, DumbAware { class PreviewToolWindow : ToolWindowFactory, DumbAware {
override fun isApplicable(project: Project): Boolean { override fun isApplicable(project: Project): Boolean =
// todo: filter only Compose projects isPreviewCompatible(project)
return true
}
override fun init(toolWindow: ToolWindow) { override fun init(toolWindow: ToolWindow) {
toolWindow.setIcon(PreviewIcons.COMPOSE) toolWindow.setIcon(PreviewIcons.COMPOSE)

6
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt

@ -5,10 +5,16 @@
package org.jetbrains.compose.desktop.ide.preview package org.jetbrains.compose.desktop.ide.preview
import com.intellij.ide.lightEdit.LightEdit
import com.intellij.openapi.externalSystem.model.Key import com.intellij.openapi.externalSystem.model.Key
import com.intellij.openapi.externalSystem.model.project.AbstractNamedData import com.intellij.openapi.externalSystem.model.project.AbstractNamedData
import com.intellij.openapi.project.Project
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
// todo: filter only Compose projects
internal fun isPreviewCompatible(project: Project): Boolean =
!LightEdit.owns(project)
internal val kotlinTargetDataKey: Key<out AbstractNamedData> = run { internal val kotlinTargetDataKey: Key<out AbstractNamedData> = run {
val kotlinTargetDataClass = try { val kotlinTargetDataClass = try {
Class.forName("org.jetbrains.kotlin.idea.gradle.configuration.KotlinTargetData") Class.forName("org.jetbrains.kotlin.idea.gradle.configuration.KotlinTargetData")

Loading…
Cancel
Save