This example extends the preceding example to give a basic implementation of a “mini blog”; this forms the basis for a series of suggested extensions that will give you a chance to program in wxErlang for yourself.
The mini blog is a list of dated entries, each occupying a single line, much like a Facebook status message or a Twitter Tweet. As well as the About and Exit options, the GUI provides these operations on the blog:
Creates a new, empty mini blog.
Opens the blog saved in the BLOG file.
Saves the current blog in the BLOG file, overwriting its contents if it already exists.
Adds an entry at the end of the blog. The entry is automatically dated.
Undoes the latest “add entry”; this can be done recursively.
Figure 14-4 shows a screenshot of the system.
To describe the Erlang code for
MiniBlog we’ll explain how the
MicroBlog code is modified. The head of the
miniblog.erl module extends
microblog.erl with a number of identifier macro
definitions, to give a unique identifier to each menu command:
-define(APPEND,131). -define(UNDO,132). -define(OPEN,133). -define(SAVE,134). -define(NEW,135).
Figure 14-4. The mini blog application
The main function,
miniblog:start/0, extends the previous function
by adding a text control (
that contains the entries; this
object is then passed to the
start() -> wx:new(), ...