GUndo

Name

GUndo -- GUndo handles a list of actions and has functions to undo or redo this actions, with signal emission.

Synopsis



struct      GUndo;
#define     G_UNDO_DEFAULT_MAXLEN
GUndo*      g_undo_new                      (const GUndoActionType *types);
GUndo*      g_undo_new_with_maxlen          (const GUndoActionType *types,
                                             guint maxlen);
GUndoAction* g_undo_add_action              (GUndo *undo,
                                             guint type,
                                             gpointer data);
void        g_undo_undo                     (GUndo *undo);
void        g_undo_redo                     (GUndo *undo);
void        g_undo_undo_downto              (GUndo *undo,
                                             GUndoAction *action);
void        g_undo_redo_upto                (GUndo *undo,
                                             GUndoAction *action);
gchar*      g_undo_to_string                (GUndo *undo);

Object Hierarchy


  GObject
   +----GUndo

Properties


  "maxlen"               guint                : Read / Write / Construct

Signal Prototypes


"action-added"
            void        user_function      (GUndo *gundo,
                                            GObject *arg1,
                                            gpointer user_data);
"action-dropped"
            void        user_function      (GUndo *gundo,
                                            GObject *arg1,
                                            gpointer user_data);
"redo"      void        user_function      (GUndo *gundo,
                                            GObject *arg1,
                                            gboolean arg2,
                                            gpointer user_data);
"undo"      void        user_function      (GUndo *gundo,
                                            GObject *arg1,
                                            gboolean arg2,
                                            gpointer user_data);

Description

GUndo handles a list of GUndoAction which are of predefined GUndoActionType. This actions can be undone or redone, and signals are emitted when data is added, destroyed, undone or redone.

Details

struct GUndo

struct GUndo;


G_UNDO_DEFAULT_MAXLEN

#define G_UNDO_DEFAULT_MAXLEN 10


g_undo_new ()

GUndo*      g_undo_new                      (const GUndoActionType *types);

Creates a new undo list with the length set to G_UNDO_DEFAULT_MAXLEN.

You may read the documentation about GUndoActionType to learn about the types parameter.

types : an array of GUndoActionType to define the actions for each type of action.
Returns : a new GUndo.


g_undo_new_with_maxlen ()

GUndo*      g_undo_new_with_maxlen          (const GUndoActionType *types,
                                             guint maxlen);

Creates a new undo list with the specified maximum length and registered types.

You may read the documentation about GUndoActionType to learn about the types parameter.

types : an array of GUndoActionType to define the actions for each type of action.
maxlen : The maximum length of the action list to store (if this max length is reached, the older actions are deleted.)
Returns : a new GUndo.


g_undo_add_action ()

GUndoAction* g_undo_add_action              (GUndo *undo,
                                             guint type,
                                             gpointer data);

Adds an action on top of undo's list. The Gundo-action-added signal is emitted.

undo : a GUndo
type : a guint to specify the action's type. This should be an enum value, which corresponds to a registered GUndoActionType.
data : a pointer to any data or an integer by using one of the glib-Type-Conversion-Macros.
Returns :


g_undo_undo ()

void        g_undo_undo                     (GUndo *undo);

Undoes the current action, calls the undo function of the GUndoActionType of the current GUndoAction, and goes forward in the list.

The GUndo-undo signal will be emitted.

undo : a GUndo


g_undo_redo ()

void        g_undo_redo                     (GUndo *undo);

Goes forward in the list , redoes the next action, and calls the undo function of the GUndoActionType of the next GUndoAction.

The GUndo-redo signal will be emitted.

undo : a GUndo


g_undo_undo_downto ()

void        g_undo_undo_downto              (GUndo *undo,
                                             GUndoAction *action);

Undoes the actions in undo until action is reached.

undo : a GUndo
action : a GUndoAction


g_undo_redo_upto ()

void        g_undo_redo_upto                (GUndo *undo,
                                             GUndoAction *action);

Redoes the actions in undo until action is reached.

undo :
action :


g_undo_to_string ()

gchar*      g_undo_to_string                (GUndo *undo);

Creates a string representation of undo, which may be usefull for debugging purposes. This function concatenates the result of the call of GUndoActionType ->toString for each GUndoAction of the list.

undo : a GUndo
Returns : A string which has to be g_free'd when not used anymore.

Properties

"maxlen" (guint : Read / Write / Construct)

The maxlen, if != 0, sets the number of GUndoAction the list can handle. When this capacity is reached, every new GUndoAction added will cause the oldest GUndoAction to be flushed (with emission of a GUndo::action-dropped signal).

See GFifo's concepts to learn more about the amximum length feature.

Signals

The "action-added" signal

void        user_function                  (GUndo *gundo,
                                            GObject *arg1,
                                            gpointer user_data);

Emitted when a new action is added on top of a GUndo.

gundo :the object which received the signal.
arg1 :The GUndoAction which was just added.
user_data :user data set when the signal handler was connected.


The "action-dropped" signal

void        user_function                  (GUndo *gundo,
                                            GObject *arg1,
                                            gpointer user_data);

Emitted when an action is deleted from a GUndo (see the GUndo-maxlen explanations)

gundo :the object which received the signal.
arg1 :the GUndoAction which was just dropped.
user_data :user data set when the signal handler was connected.


The "redo" signal

void        user_function                  (GUndo *gundo,
                                            GObject *arg1,
                                            gboolean arg2,
                                            gpointer user_data);

Emitted when a GUndo has just been redone.

gundo :the object which received the signal.
arg1 :the GUndoAction which was redone
arg2 :a gboolean which indicates whether the end of the list was reached (TRUE) or not.
user_data :user data set when the signal handler was connected.


The "undo" signal

void        user_function                  (GUndo *gundo,
                                            GObject *arg1,
                                            gboolean arg2,
                                            gpointer user_data);

Emitted when a GUndo has been undone.

gundo :the object which received the signal.
arg1 :the GUndoAction which was undone
arg2 :a gboolean which indicates whether the beginning of the list was reached (TRUE) or not.
user_data :user data set when the signal handler was connected.

See Also

GFifo

The object which really handles the data and provides a simple signal scheme.

GtkUndo

It is a higher level library which deals with widgets modification and provides several predefined GUndoActionType for elementary actions on widgets.

GtkUndo is able to manage a whole interface and to add undo/redo abilities for number of standard widgets, provides an history popup feature, and undo/redo management with only a few lines of code.