views:

953

answers:

3

I'm trying to keep dependencies to a minimum for a program I contribute to, it's a small text editor.

GTK Textview doesn't seem to come with a built-in undo function. Is there any reference implementation I've been missing on so far? Is everyone writing their own undo function for their TextView widgets?

I'll be happy about any sample code - most happy about python sample code, as our project is in python.

+2  A: 

As far as I know, GTK TextView doesn't include an undo function. So while I am not familiar with Python's GTK library, I would think it doesn't have one.

The Ruby-GNOME2 project has a sample text editor that has undo/redo functionality. Basically they are connecting to the insert_text and delete_range signals of the TextView widget and recording the events and associated data in a list.

mcl
+2  A: 

Depending on just how dependency-averse you are, and what kind of text editor you're building, GtkSourceView adds undo/redo among many other things. Very worth looking at if you want some of the other features it offers.

Kai
+3  A: 

as a follwow-up: I ported gtksourceview's undo mechanism to python: http://bitbucket.org/tiax/gtk-textbuffer-with-undo/

serves as a drop-in replacement for gtksourceview's undo

(OP here, but launchpad open-id doesn't work anymore)

tiax