How do I embed a Smalltalk code editor into my application?

445 Views Asked by At

I'm building a blog entry viewer and editor application in my Pharo image, and the entry content is formatted as Smalltalk code (the Seaside markup API is really nice). I'm pretty new to Smalltalk, so I was using this blog post as an example.

I currently have this for my BlogEditor>>open method:

open
| builder content |

builder := UITheme builder.
content := builder newColumn: {
    builder newRow: {
        builder newListFor: self
        list: #entries 
        selected: #entrySelectedIndex
        changeSelected: #entrySelectedIndex:
        help: 'Blog entries'.
    }.
    builder newRow: {
        editor := builder
            newTextEditorFor: self
            getText: #readSelectedEntry
            setText: #changeSelectedEntry:.
        editor minHeight: 400 } }.

(content openInWindowLabeled: 'Entries') extent: 800@700

I don't know what to put in place of editor := builder newTextEditorFor:. I saw the class SmalltalkEditor, but I don't know how to put one on my UI.

2

There are 2 best solutions below

0
On

Put the line

self halt.

below

builder := UITheme builder.

Run the code. When it halts, debug and select the builder. Browse it to see what else you can add.

You do know a Text in Pharo has formatting? Just browse Text.

0
On

What can be used is a PluggableTextMorph, which refers to a TextMorphForEditView, which in turn gives you a SmalltalkEditor.

PluggableTextMorph is a ScrollPane

You can also look in the TextMorph which could come handy.

The UITheme builder hides all of the nasty details inside but it will bring you back to the classes mentioned above.

Good luck.