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

This commit is contained in:
Alexey Tsvetkov
2021-08-02 12:11:51 +03:00
committed by GitHub
parent 227834f963
commit 5d4a26b076
2 changed files with 9 additions and 3 deletions

View File

@@ -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

View File

@@ -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,