Skip to content

Commit

Permalink
feat(preview panel): render updated file
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Aug 28, 2024
1 parent 93a4f65 commit c74dfb4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 208 deletions.
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()

jetbrainsRuntime()
}
}

Expand All @@ -26,8 +28,9 @@ dependencies {
"org.jetbrains.plugins.yaml"
))

instrumentationTools()
pluginVerifier()
jetbrainsRuntime()
instrumentationTools()
testFramework(TestFrameworkType.Platform)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.asyncapi.plugin.idea.extensions.editor.preview

import com.asyncapi.plugin.idea.extensions.editor.ui.AsyncAPIJCEFHtmlPanel
import com.intellij.codeHighlighting.BackgroundEditorHighlighter
import com.intellij.ide.structureView.StructureViewBuilder
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileEditor.FileEditorLocation
import com.intellij.openapi.fileEditor.FileEditorState
import com.intellij.openapi.fileEditor.FileEditorStateLevel
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.UserDataHolderBase
import java.awt.LayoutManager
import java.beans.PropertyChangeListener
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.OverlayLayout

class AsyncAPIPreviewEditor(
private val document: Document?,
Expand All @@ -24,14 +29,35 @@ class AsyncAPIPreviewEditor(

var editor: Editor? = null

override fun getComponent(): JComponent {
private val asyncAPIPreviewEditorComponent: JComponent
private val htmlPanel: AsyncAPIJCEFHtmlPanel = AsyncAPIJCEFHtmlPanel(editor)

init {
asyncAPIPreviewEditorComponent = createComponent()

val documentListenerHandler = object : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
if (asyncAPIPreviewEditorComponent.isVisible && asyncAPIPreviewEditorComponent.isDisplayable) {
htmlPanel.setHtml("${document?.text}")
}
}
}
document?.addDocumentListener(documentListenerHandler, this)
}

private fun createComponent(): JComponent {
val previewEditor = JPanel()
val mockText = JLabel("AsyncAPI Preview Editor")
val overlay: LayoutManager = OverlayLayout(previewEditor)
previewEditor.setLayout(overlay)

htmlPanel.setHtml("${document?.text}")
previewEditor.add(htmlPanel.component)

previewEditor.add(mockText)
return previewEditor
}

override fun getComponent(): JComponent = asyncAPIPreviewEditorComponent

override fun getPreferredFocusedComponent(): JComponent = getComponent()

override fun getName(): String = "Preview"
Expand Down Expand Up @@ -69,9 +95,7 @@ class AsyncAPIPreviewEditor(
override fun getStructureViewBuilder(): StructureViewBuilder? = null

override fun dispose() {
// TODO: dispose component
// Disposer.dispose(previewEditor)
// do nothing
Disposer.dispose(htmlPanel)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.asyncapi.plugin.idea.extensions.editor.ui

import com.intellij.openapi.Disposable
import javax.swing.JComponent

interface AsyncAPIHtmlPanel: Disposable {

fun getComponent(): JComponent

fun setHtml(html: String)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.asyncapi.plugin.idea.extensions.editor.ui

import com.intellij.openapi.editor.Editor
import com.intellij.ui.jcef.JCEFHtmlPanel
import javax.swing.JComponent

class AsyncAPIJCEFHtmlPanel(
var editor: Editor?,
): AsyncAPIHtmlPanel, JCEFHtmlPanel(null) {

override fun getComponent(): JComponent = super.getComponent()

override fun setHtml(html: String) {
loadHTML(html, cefBrowser.url)
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c74dfb4

Please sign in to comment.