Logo

18.5.5 Smalltalk code presentation

The SmalltalkCode presentation is a specialization of the TextPresentation that provides handy features for handling Smalltalk code: syntax highlighting and code completion.

There are two modes in which this presentation can be used:

  1. by default, the presentation behaves like a Smalltalk Workspace, and it highlights the code as if it were written in the Smalltalk Workspace.
  2. by specifying a smalltalkClass: you can specialize it and make it behave as a method code editor. This property takes as parameters the entity objects and its evaluation is expected to produce a Smalltalk class. As a result the code will be highlighted as if it were a method definition inside the specified class.

When in the Workspace mode, you can also specify variable bindings that can be passed to the overall context. This is achieved by getting the variableBindings: return a collection of associations in which each key is the name of the variable, and each value is the value of the corresponding variable.

An example of a simple Smalltalk code can be seen below:

| browser |
browser := GLMTabulator new.
browser row: #code span: 2; row: #preview.
browser transmit to: #code; andShow: [ :a |
a smalltalkCode
title: 'Smalltalk Code';
populate: #acceptedCode
icon: GLMUIThemeExtraIcons glamorousAccept
on: $s
entitled: 'Accept'
with: [:text | text text ] ].
browser transmit from: #code port: #acceptedCode; to: #preview; andShow: [ :a |
a text
title: 'Evaluated result';
display: [:code | [Compiler evaluate: code ] on: Error do: ['Error']] ].
browser openOn: '1+2'

Add a Note