Introduction

Why another editor? Don't we have enough already?

Well, yes, indeed. There are quite a lot of different - and not so different - editors one can download from the Internet. Anyway...

  1. I wanted a simple project to try GUI programming in Unix.
  2. I have an old machine (Pentium 166 MHz, 32 MB RAM) with Slackware Linux 9.0. This machine runs Xfce 3.8, based on GTK+ 1.2.
  3. There's no decent GUI editor for this machine. All are too slow, too bloated or too ugly.

OK, In fact I did found an editor that works fine. It's called gnotepad+, but it too takes too long to load (about 2 seconds) in this old machine. There's plenty of room for improvements here, I thought.

And so gtkedit begun. I only wanted the most basic editing features: cut, copy, paste, basic undo/redo... nothing fancy. The obvious model to copy was, of course, Notepad.

What is it ?

Gtkedit is a simple editor, written using the GTK+ 1.2 toolkit. It aims to be (in that order) light, useful and simple (source code-wise).

Being a simple project, it also can serve as a real world GTK+ tutorial.

Compiling and running

To compile the source, issue the following command from a terminal window:

	gcc $(gtk-config --cflags --libs) -O -o gtkedit gtkedit.c

I assumed you use GNU bash. If you use any other shell, use this instead:

	gcc `gtk-config --cflags --libs` -O -o gtkedit gtkedit.c

(Beware of the back-quotes (`), as they are not the same as single quotes (') if you happen to be a Unix shell).

Once the compilation finishes you can start the program with the command:

	./gtkedit

This opens the editor with a blank unnamed file. You can add the name of a file to have it loaded, if you wish. Alternatively you can use the file manager to drag file over the editor window.

Using the editor

gtkedit is very simple to use. It understands the basic common shortcut keys, like <Ctrl>C for copy. You will find them listed next to each menu item.

Very basic undo/redo capabilities are provided, because the editor can only undo the very last text insertion or removal.

You can find and replace text, and there is a menu option that will allow you to quickly go to any particular line, which is handy if one is writting a program and wants locate an error line.

Finally, you can change the font used for text display, or toggle the wrapping of long lines. These settings are lost when the program closes, though.

Configuring gtkedit

On start-up, gtkedit looks for a file named .gtkeditrc on your home directory. This is a standard GTK+ configuration file, and allows you to configure much of the editor look. I will only show you how to change the default font.

Create the .gtkeditrc file with the following contents:

style "text-widget" {
       font = "-*-*-medium-r-*--*-120-*-*-m-*-iso8859-1"
}
widget "*.gtkedit-text" style "text-widget"
This will instruct GTK+ to use a monospaced (fixed width) font of size 12 for the editor. To try another font open the font selection dialog in the editor, select the font you want, then change to the "Font Information" tab. There you will find the line you have to put in the configuration file to use this font by default.