## undo

undo — Undo and redo facility

## Synopsis

    #include <app/gwyapp.h>

    gulong              gwy_app_undo_checkpoint             (GwyContainer *data,
                                                             ...);
    gulong              gwy_app_undo_qcheckpoint            (GwyContainer *data,
                                                             ...);
    gulong              gwy_app_undo_checkpointv            (GwyContainer *data,
                                                             guint n,
                                                             const gchar **keys);
    gulong              gwy_app_undo_qcheckpointv           (GwyContainer *data,
                                                             guint n,
                                                             const GQuark *keys);
    void                gwy_app_undo_undo_container         (GwyContainer *data);
    void                gwy_app_undo_redo_container         (GwyContainer *data);
    gulong              gwy_undo_checkpoint                 (GwyContainer *data,
                                                             ...);
    gulong              gwy_undo_qcheckpoint                (GwyContainer *data,
                                                             ...);
    gulong              gwy_undo_checkpointv                (GwyContainer *data,
                                                             guint n,
                                                             const gchar **keys);
    gulong              gwy_undo_qcheckpointv               (GwyContainer *data,
                                                             guint n,
                                                             const GQuark *keys);
    void                gwy_undo_undo_container             (GwyContainer *data);
    void                gwy_undo_redo_container             (GwyContainer *data);
    gboolean            gwy_undo_container_has_undo         (GwyContainer *data);
    gboolean            gwy_undo_container_has_redo         (GwyContainer *data);
    gint                gwy_undo_container_get_modified     (GwyContainer *data);
    void                gwy_undo_container_set_unmodified   (GwyContainer *data);
    void                gwy_undo_container_remove           (GwyContainer *data,
                                                             const gchar *prefix);

## Description

For a module developer, the only two useful undo/redo functions are probably `gwy_app_undo_checkpoint()` and `gwy_app_undo_checkpointv()` creating a checkpoint in the undo history to which is possible to return to later. You should use these functions before commiting changes to data.

The other functions actually perform undo or redo, and has little use outside main application, unless it wishes to implement its local undo.

There are two types of functions app-level and container-level. App-level functions (have `app' in their names) should be generally used only by the main application as they update menus and toolboxes according to undo and redo state. Container-level functions only perform the actual undo or redo and can be used for local undo implementation.

Undo information for a GwyContainer is automatically destroyed when the container is finalized.

## Details

### gwy_app_undo_checkpoint ()

    gulong              gwy_app_undo_checkpoint             (GwyContainer *data,
                                                             ...);

Create a point in the undo history it is possible to return to.

In addition to what `gwy_undo_checkpoint()` does, this function takes care of updating application controls state.

`data` : | A data container.
`...` : | `NULL`-terminated list of container item names to save.
Returns : | Undo level id. Not useful (yet).

### gwy_app_undo_qcheckpoint ()

    gulong              gwy_app_undo_qcheckpoint            (GwyContainer *data,
                                                             ...);

Create a point in the undo history it is possible to return to.

In addition to what `gwy_undo_checkpoint()` does, this function takes care of updating application controls state.

`data` : | A data container.
`...` : | 0-terminated list of container item quark keys to save.
Returns : | Undo level id. Not useful (yet).

### gwy_app_undo_checkpointv ()

    gulong              gwy_app_undo_checkpointv            (GwyContainer *data,
                                                             guint n,
                                                             const gchar **keys);

Create a point in the undo history it is possible to return to.

In addition to what `gwy_undo_checkpointv()` does, this function takes care of updating application controls state.

`data` : | A data container.
`n` : | The number of strings in `keys`.
`keys` : | An array of container string keys to save data. It can contain holes, that is NUL's, they are ignored. However, it should contain at least one real key.
Returns : | Undo level id. Not useful (yet).

### gwy_app_undo_qcheckpointv ()

    gulong              gwy_app_undo_qcheckpointv           (GwyContainer *data,
                                                             guint n,
                                                             const GQuark *keys);

Create a point in the undo history it is possible to return to.

In addition to what `gwy_undo_checkpointv()` does, this function takes care of updating application controls state.

`data` : | A data container.
`n` : | The number of strings in `keys`.
`keys` : | An array of container quark keys to save data. It can contain holes, that is 0's, they are ignored. However, it should contain at least one real key.
Returns : | Undo level id. Not useful (yet).

### gwy_app_undo_undo_container ()

    void                gwy_app_undo_undo_container         (GwyContainer *data);

Performs undo on a data container.

It must have undo available.

In addition to what `gwy_undo_undo_container()` does, this function takes care of updating application controls state.

`data` : | A data container.

### gwy_app_undo_redo_container ()

    void                gwy_app_undo_redo_container         (GwyContainer *data);

Performs undo on a data container.

It must have redo available.

In addition to what `gwy_undo_redo_container()` does, this function takes care of updating application controls state.

`data` : | A data container.

### gwy_undo_checkpoint ()

    gulong              gwy_undo_checkpoint                 (GwyContainer *data,
                                                             ...);

Create a point in the undo history it is possible to return to.

`data` : | A data container.
`...` : | `NULL`-terminated list of container item names to save.
Returns : | Undo level id. Not useful (yet).

### gwy_undo_qcheckpoint ()

    gulong              gwy_undo_qcheckpoint                (GwyContainer *data,
                                                             ...);

Create a point in the undo history it is possible to return to.

`data` : | A data container.
`...` : | 0-terminated list of container item quark keys to save.
Returns : | Undo level id. Not useful (yet).

### gwy_undo_checkpointv ()

    gulong              gwy_undo_checkpointv                (GwyContainer *data,
                                                             guint n,
                                                             const gchar **keys);

Create a point in the undo history it is possible to return to.

`data` : | A data container.
`n` : | The number of strings in `keys`.
`keys` : | An array of container string keys to save data. It can contain holes, that is NUL's, they are ignored. However, it should contain at least one real key.
Returns : | Undo level id. Not useful (yet).

### gwy_undo_qcheckpointv ()

    gulong              gwy_undo_qcheckpointv               (GwyContainer *data,
                                                             guint n,
                                                             const GQuark *keys);

Create a point in the undo history it is possible to return to.

`data` : | A data container.
`n` : | The number of strings in `keys`.
`keys` : | An array of container quark keys to save data. It can contain holes, that is 0's, they are ignored. However, it should contain at least one real key.
Returns : | Undo level id. Not useful (yet).

### gwy_undo_undo_container ()

    void                gwy_undo_undo_container             (GwyContainer *data);

Performs undo on a data container.

It must have undo available.

`data` : | A data container.

### gwy_undo_redo_container ()

    void                gwy_undo_redo_container             (GwyContainer *data);

Performs undo on a data container.

It must have redo available.

`data` : | A data container.

### gwy_undo_container_has_undo ()

    gboolean            gwy_undo_container_has_undo         (GwyContainer *data);

Returns whether there is any undo available for a container.

`data` : | Data container to get undo infomation of.
Returns : | `TRUE` if there is undo, `FALSE` otherwise.

### gwy_undo_container_has_redo ()

    gboolean            gwy_undo_container_has_redo         (GwyContainer *data);

Returns whether there is any redo available for a container.

`data` : | Data container to get redo infomation of.
Returns : | `TRUE` if there is redo, `FALSE` otherwise.

### gwy_undo_container_get_modified ()

    gint                gwy_undo_container_get_modified     (GwyContainer *data);

Tests whether a container was modified.

FIXME: it may not work.

`data` : | Data container to get modification infomation of.
Returns : | `TRUE` if container was modified, `FALSE` otherwise.

### gwy_undo_container_set_unmodified ()

    void                gwy_undo_container_set_unmodified   (GwyContainer *data);

Marks a data container as umodified (that is, saved).

`data` : | Data container to set modification infomation of.

### gwy_undo_container_remove ()

    void                gwy_undo_container_remove           (GwyContainer *data,
                                                             const gchar *prefix);

Removes undo/redo information for a data container.

`data` : | A data container.
`prefix` : | Prefix to remove undo/redo information under. Pass `NULL` to remove undo/redo information altogether.