Defining the class TextEditor
Next, create a subclass of Object:
1. From the Classes menu, select Add > Subclass.
2. When a prompter opens, enter the name of your new class, for example, TextEditor.
3. In the next prompter, select subclass; then select OK.
4. In the description pane, which now displays the description for TextEditor, do the following:
a. Add the instance variables mainWindow menuBar workRegion shell text fileName modified popup.
b. Add the pool dictionaries CfsConstants CldtConstants CgConstants CwConstants.
5. Save the class.
Implementing the public instance methods
TextEditor has six public instance methods: cr (carriage return), display, nextPutAll:, open, openOn:, and show:. You can implement them in any order.
Public methods for the category Initialization & Startup
Method open
open
"Public - Creates and realizes the receiver."
self
createShell;
createWindow.
mainWindow
setAreas: menuBar
horizontalScrollbar: nil
verticalScrollbar: nil
workRegion: workRegion;
manageChild.
self realizeWindow.
Method openOn:
openOn: pathName
"Public - Opens the receiver on the text file specified by pathName."
self open.
self
fileName: pathName;
undo: nil clientData: nil callData: nil.
Public methods for category File Operations
Method cr
cr
"Public - Inserts a carriage return."
self nextPutAll: (String with: Lf)
Method display
display
"Public - Displays the shell."
^self shell display.
Method nextPutAll:
nextPutAll: aString
"Public - Appends the contents of aString to the receiver."
| pos |
text insert: (pos := text getLastPosition) value: aString;
showPosition: pos + aString size.
text updateWidget.
Method show:
show: aString
"Public - Appends the contents of aString to the receiver."
self nextPutAll: aString.
Last modified date: 04/26/2019