generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): implement LangSketch and add PlantUML support #153
Improve the UI by implementing the LangSketch interface and integrating PlantUML support. This includes: - Enhancing the SingleFileDiffView class to implement LangSketch. - Introducing LanguageSketchProvider for dynamic language sketch provision. - Adding a PlantUmlSketchProvider and PlantUmlSketch class for PlantUML file rendering within the IDE.
- Loading branch information
Showing
6 changed files
with
162 additions
and
25 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
core/src/main/kotlin/com/phodal/shirecore/provider/sketch/LanguageSketchProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.phodal.shirecore.provider.sketch | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName | ||
import com.intellij.openapi.project.Project | ||
import com.phodal.shirecore.ui.viewer.LangSketch | ||
|
||
interface LanguageSketchProvider { | ||
fun isSupported(lang: String): Boolean | ||
|
||
fun createSketch(project: Project, content: String): LangSketch | ||
|
||
companion object { | ||
private val EP_NAME: ExtensionPointName<LanguageSketchProvider> = | ||
ExtensionPointName("com.phodal.shireLangSketchProvider") | ||
|
||
fun provide(language: String): LanguageSketchProvider? { | ||
return EP_NAME.extensionList.firstOrNull { | ||
it.isSupported(language) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
toolsets/plantuml/src/main/kotlin/com/phodal/shire/plantuml/PlantUmlSketchProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.phodal.shire.plantuml | ||
|
||
import com.intellij.lang.Language | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.testFramework.LightVirtualFile | ||
import com.intellij.ui.dsl.builder.panel | ||
import com.phodal.shirecore.provider.sketch.LanguageSketchProvider | ||
import com.phodal.shirecore.ui.viewer.LangSketch | ||
import org.plantuml.idea.preview.editor.PlantUmlPreviewEditor | ||
import org.plantuml.idea.preview.PlantUmlPreviewPanel | ||
import javax.swing.JComponent | ||
|
||
class PlantUmlSketchProvider : LanguageSketchProvider { | ||
override fun isSupported(lang: String): Boolean { | ||
return lang == "plantuml" || lang == "puml" || lang == "uml" | ||
} | ||
|
||
override fun createSketch(project: Project, content: String): LangSketch { | ||
val virtualFile = LightVirtualFile("plantuml.puml", content) | ||
return PlantUmlSketch(project, virtualFile) | ||
} | ||
} | ||
|
||
class PlantUmlSketch(private val project: Project, private val virtualFile: VirtualFile) : LangSketch { | ||
private var mainPanel: JComponent | ||
|
||
init { | ||
val editor = PlantUmlPreviewEditor(virtualFile, project) | ||
val plantUmlPreviewPanel = PlantUmlPreviewPanel(project, editor) | ||
|
||
mainPanel = panel { | ||
row { | ||
plantUmlPreviewPanel.also { | ||
it.isVisible = true | ||
it.setSize(800, 600) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun getViewText(): String { | ||
return virtualFile.inputStream.bufferedReader().use { it.readText() } | ||
} | ||
|
||
override fun updateViewText(text: String) { | ||
virtualFile.setBinaryContent(text.toByteArray()) | ||
} | ||
|
||
override fun getComponent(): JComponent { | ||
return mainPanel!! | ||
} | ||
|
||
override fun updateLanguage(language: Language?) { | ||
} | ||
|
||
override fun dispose() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters