Browse Source

Fix preview floating panel compatibility with both 2020.3 and 2021.1 (#973)

update-web-docs
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
5d4a26b076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      idea-plugin/gradle.properties
  2. 10
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt

2
idea-plugin/gradle.properties

@ -11,5 +11,5 @@ plugin.until.build=212.*
plugin.verifier.ide.versions=2020.3.2, 2021.1
platform.type=IC
platform.version=2020.3.2
platform.version=2021.1
platform.download.sources=true

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

@ -26,14 +26,20 @@ class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_E
override fun register(toolbar: FloatingToolbarComponent, parentDisposable: Disposable) {
try {
// todo: use provided data context once 2020.3 is no longer supported
val toolbarImpl = toolbar as? FloatingToolbarComponentImpl ?: return
val editor = toolbarImpl.getData(CommonDataKeys.EDITOR.name) as? Editor ?: return
val toolbarClass = FloatingToolbarComponentImpl::class.java
val getDataMethod = toolbarClass.getMethod("getData", String::class.java)
val editor = getDataMethod.invoke(toolbar, CommonDataKeys.EDITOR.name) as? Editor ?: return
registerComponent(toolbar, editor, parentDisposable)
} catch (e: Exception) {
LOG.error(e)
}
}
override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) {
val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return
registerComponent(component, editor, parentDisposable)
}
private fun registerComponent(
component: FloatingToolbarComponent,
editor: Editor,

Loading…
Cancel
Save