GUndoAction

Name

GUndoAction -- Handles info for a single action of type GUndoActionType

Synopsis



struct      GUndoAction;
struct      GUndoActionType;
GUndoAction* g_undo_action_new              (GUndoActionType *type,
                                             gpointer info);

Object Hierarchy


  GObject
   +----GUndoAction

Properties


  "type"                 gpointer             : Read / Write / Construct

Signal Prototypes


"destroyed" void        user_function      (GUndoAction *gundoaction,
                                            gpointer user_data);

Description

When we work with a GUndo list, we use actions which are one or several operations which can be undone or redone at once.

An action is defined by one type (which defines the callbacks to call at different moments of the action's life) and handles some info which is used by the callbacks in several ways.

Details

struct GUndoAction

struct GUndoAction;

The fields should be considered read-only and never modified after construction. The type field is a GUndoActionType pointer and the info field is a generic pointer which should be cast to correct type when accessed.


struct GUndoActionType

struct GUndoActionType{
  gint type;                   /*Type number (should be an enum member)*/
  gchar* name;

  void (*reg)();               /*Type registration callback*/
  void (*unreg)();             /*Type unregistration callback*/
  
  void (*undo)();              /*Action undo callback*/
  void (*redo)();              /*Action redo callback*/
  
  void (*destroy)();            /*Action destruction*/
  void (*create)();             /*Action construction*/

  const gchar* (*toString)();   /*Action string representation*/

  void (*extra_func1)();        /*Free callback*/
  gpointer (*extra_func2)();    /*Free callback*/

  gpointer data;                /*Data which will be passed to all of this type actions callbacks*/
  gint structsize;              /*Used to prealloc the size of the GUndoAction data. */
                                /*If set to 0, the data will not be copyed, */
                                /*but the pointer will be set. (for widget data e.g.)*/

  gint extra_info;              /*Free integer data*/
};

This structure handles the complete definition of an action type. Once bound to a GUndoAction, this structure should never be modified as the results may be unpredicable.

gint typea gint, which should be unique to this GUndoActionType (you'd better use an enum to handle the different types value to ensure unique values)
gchar *namea string to identify the GUndoActionType
void (*reg) ()a callback which is unused by GUndo and GUndoAction but by GtkUndo. This can be used to initialize an object which is bound to a GUndo list (a widget e.g.). The arguments are free. See GtkUndo-example for an example.
void (*unreg) ()See reg, for unregistration.
void (*undo) ()a callback called when an action is undone in a GUndo list. See action concept.
void (*redo) ()a callback called when an action is redone in a GUndo list. See action concept.
void (*destroy) ()a callback called when an action is dropped out of a GUndo list. See GUndo maxlen property for details on action dropping. This callback is called with one argument: the GUndoAction to destroy.
void (*create) ()a callback called just after an action creation. See g_undo_action_new. It is called with the newly created GUndoAction.
const gchar* (*toString) ()a callback used to get a string representation of an action of this type
void (*extra_func1) ()a free defineable callback.
gpointer (*extra_func2) ()a free defineable callback. (Used for widget creation in GtkUndo)
gpointer dataa pointer to some data. In GUndo, this is passed to the undo & redo callbacks as second argument (See action concept.)
gint structsizeSee g-undo-action-new for details
gint extra_infoa gint which may handle some implementation dependant data.


g_undo_action_new ()

GUndoAction* g_undo_action_new              (GUndoActionType *type,
                                             gpointer info);

Instantiates a new GUndoAction. The info can be either an integer by using one of the <link linkend="glib-Type-Conversion-Macros">type conversion macros</link> or a pointer to any data.

The info's type has to be compatible with the type defined by type. If type->structsize==0, info must be either an integer or a data of which address will be stored in the GUndoAction. It cannot be the address of a local structure. If type->structsize >0, the size of the info data must be equal, and the data will be copied. So it may be the address of a local structure (See GUndoActionType, GUndo-using-prog for details, and GtkUndo-example for an example.)

type : a GUndoActionType
info : the information to store in this action
Returns : a new GUndoAction

Properties

"type" (gpointer : Read / Write / Construct)

a GUndoActionType. This should never be modified after construction.

Signals

The "destroyed" signal

void        user_function                  (GUndoAction *gundoaction,
                                            gpointer user_data);

Emitted at the gundoaction end of life.

gundoaction :the GUndoAction which was destroyed.
user_data :user data set when the signal handler was connected.

See Also

GUndo

The undo list object which makes intensive use of GUndoAction.

GtkUndo

The GtkUndo library applies GUndo to the special case of Gtk widgets and defines several GUndoActionInfoType structures for several predefined action types. See GtkUndo examples for an example.