Skip to content

Commit

Permalink
feat(editor): add ShirePreviewEditorProvider and enhance editor creat…
Browse files Browse the repository at this point in the history
…ion #157

Introduce `ShirePreviewEditorProvider` for rendering shire file previews. Enhance `ShireFileEditorProvider` with proper editor creation logic and policy. Adjust layout comments for future workflow view implementation.
  • Loading branch information
phodal committed Jan 3, 2025
1 parent a309063 commit 99058b6
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.pom.Navigatable
import com.intellij.testFramework.LightVirtualFile
import com.phodal.shirelang.ShireFileType
import org.jetbrains.annotations.NonNls
import java.awt.BorderLayout
import java.beans.PropertyChangeListener
import javax.swing.JPanel
Expand All @@ -39,6 +38,27 @@ class ShireFileEditorProvider : FileEditorProvider, DumbAware {
override fun getPolicy() = FileEditorPolicy.HIDE_DEFAULT_EDITOR
}

/**
* Display shire file render prompt and have a sample file as view
*/
open class ShirePreviewEditorProvider : FileEditorProvider, DumbAware {
override fun getEditorTypeId() = "shire-preview"

override fun accept(project: Project, file: VirtualFile) =
FileTypeRegistry.getInstance().isFileOfType(file, ShireFileType.INSTANCE)

override fun createEditor(project: Project, file: VirtualFile): FileEditor {
val editor = TextEditorProvider.getInstance().createEditor(project, file) as TextEditorImpl
if (editor.file is LightVirtualFile) {
return editor
}

return ShireFileEditor(project, editor, file)
}

override fun getPolicy() = FileEditorPolicy.HIDE_DEFAULT_EDITOR
}

open class ShireFileEditor(
val project: Project,
val textEditor: TextEditor,
Expand All @@ -49,6 +69,8 @@ open class ShireFileEditor(
init {
val toolbarComponent = createToolbar().component
mainComponent.add(textEditor.component, BorderLayout.CENTER)
// maybe left panel for editor
/// split for workflow view
mainComponent.add(toolbarComponent, BorderLayout.NORTH)
}

Expand Down Expand Up @@ -87,7 +109,7 @@ open class ShireFileEditor(
override fun getBackgroundHighlighter(): BackgroundEditorHighlighter? = textEditor.backgroundHighlighter
override fun getCurrentLocation(): FileEditorLocation? = textEditor.currentLocation
override fun getPreferredFocusedComponent() = textEditor.preferredFocusedComponent
override fun getName(): String = "Shire Editor"
override fun getName(): String = "Shire Preview"

override fun getStructureViewBuilder(): StructureViewBuilder? = textEditor.structureViewBuilder
override fun getEditor(): Editor = textEditor.editor
Expand Down

0 comments on commit 99058b6

Please sign in to comment.