Largest Provider of Commercial Smalltalk
Cincom is one of the largest commercial providers of Smalltalk, with twice as many customers and partners as other commercial providers.

Tom Nies

Get Started

The Cincom® ObjectStudio® GUI Files: LogFileViewer

Posted on in Categories ObjectStudio, Windows-Centric

We always try to come up with something useful. Some tools we use on a daily basis and write them ourselves using the new GUI. This allows us to find inconsistencies in the code pretty quickly.

This month we’re going to have a look at a LogFileViewer (not unlike the UNIX tool “tail”) using a RichEdit control and what we can do with it.

LogFileViewer

RichEdit Controls are more than just the “big brother” of multiline Edit Controls. In addition to almost all of the messages and notification codes, they enable the user to assign character and paragraph formatting. Text, even very large documents, can be streamed in and out of a RichEdit Control. It even supports Undo and Redo operations.

Opening the UI

When we open the UI, we first create the main window and the RichEdit Control.

We create a Timer that runs every second, to update the read stream from the file and highlight the items on the control.

Updating the Content

There are many algorithms dealing with documents and streaming files in and out of the system. For this purpose, we just keep the whole file in memory.

First we read the whole file into the memory using a simple FileStream and display the text in the RichEdit Control. To scroll down to the end, we just need to select the last position.

This code is called every second. If the file size has not changed, we don’t update the control, avoiding unnecessary repaints.

Text Highlighting

It’s very simple to apply formatting to parts of the text inside of a RichEdit Control. With methods like #setColor:from:to: or #setFormat:from:to:, you can change the background color, text color, font and other text styles (e.g., bold, italic, etc.).

e.g.

(…)
richEditCtrl setColor: RGBColor blue from: start to: start +
string size
(…)

Or

(…)
fmt := (UICharFormat new)
                         bold;
                         underline;
                         backColor: (RGBColor blue);
                         textColor: (RGBColor red);
                         fontFaceName: ‘Webdings’;
                         height: 300;
                         yourself.
richEditCtrl setFormat: fmt from: start to: start + string size.
(…)

Of course, we don’t want to format the whole log file. We ask the RichEdit Control for the start and end of the visible text and only format that part.

Closing the Window

When the window is closed, all that’s left to do is stop the timer and close the file stream.