GwyResourceEditor: Gwyddion Application Library Reference Manual

## GwyResourceEditor GwyResourceEditor — Base/helper class for resource editors |

## Functions

GwyResource * | gwy_resource_editor_get_edited ()
void | gwy_resource_editor_queue_commit ()
gboolean | gwy_resource_editor_commit ()
void | gwy_resource_editor_setup ()
void | gwy_resource_editor_class_setup ()

## Types and Values

struct | GwyResourceEditor
struct | GwyResourceEditorClass

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkObject
                ╰── GtkWidget
                    ╰── GtkContainer
                        ╰── GtkBin
                            ╰── GtkWindow
                                ╰── GwyResourceEditor

## Implemented Interfaces

GwyResourceEditor implements AtkImplementorIface and GtkBuildable.

## Includes

    #include <app/gwyapp.h>

## Description

The base class contains all the methods that handle the resource list, set defaults, or sync resource list with disk. Particular editors (subclasses) have to override (in fact, to fill, because GwyResourceEditor does not define them) the methods and class data in their class init methods. Then they generally only need to care about widgets inside their edit windows.

## Functions

### gwy_resource_editor_get_edited ()

    GwyResource *
    gwy_resource_editor_get_edited (GwyResourceEditor *editor);

Gets the currently edited resource.

It is an error to call this method when no resource is being edited.

#### Parameters

editor | A resource editor. |

#### Returns

The currently edited resource.

### gwy_resource_editor_queue_commit ()

    void
    gwy_resource_editor_queue_commit (GwyResourceEditor *editor);

Queues commit of resource changes, marking the currently edited resource `dirty'.

Call this method in particular resource editor subclass whenever user changes some editor property.

To flush pending commit, call `gwy_resource_editor_commit()`. To immediately commit a change, call this method and then `gwy_resource_editor_commit()`.

#### Parameters

editor | A resource editor. |

### gwy_resource_editor_commit ()

    gboolean
    gwy_resource_editor_commit (GwyResourceEditor *editor);

Commits pending resource changes, if there are any.

It calls `apply_changes` method first (if it exists), then saves resource to disk.

Changes are always immediately committed (if there are any pending): before the editor is destroyed, when a resource stops being edited, before a resource is deleted, before a resource is renamed. When a resource is newly created, it is immediately created on disk too.

#### Parameters

editor | A resource editor. |

#### Returns

Always `FALSE` (to be usable as GSourceFunc).

### gwy_resource_editor_setup ()

    void
    gwy_resource_editor_setup (GwyResourceEditor *editor);

Sets up particular resource editor.

Helper method only intended for resource editor implementation. To be called in particular resource initialization methods.

#### Parameters

editor | A resource editor. |

### gwy_resource_editor_class_setup ()

    void
    gwy_resource_editor_class_setup (GwyResourceEditorClass *klass);

Sets up particular resource editor class.

Helper class method only intended for resource editor implementation. To be called in particular class initialization methods.

#### Parameters

klass | A resource editor class. |

## Types and Values

### struct GwyResourceEditor

    struct GwyResourceEditor;

### struct GwyResourceEditorClass

    struct GwyResourceEditorClass {
        GtkWindowClass parent_class;

        GType resource_type;
        const gchar *base_resource;
        const gchar *window_title;
        const gchar *editor_title;

        gchar *settings_prefix;

        GtkWidget* (*construct_treeview)(GCallback callback,
                                         gpointer cbdata,
                                         const gchar *active);
        void (*construct_editor)(GwyResourceEditor *editor);
        void (*apply_changes)(GwyResourceEditor *editor);
        void (*switch_resource)(GwyResourceEditor *editor);

        void (*reserved1)(void);
        void (*reserved2)(void);

        GwyResourceEditor *instance;
    };

The resource editor class.

#### Members

GType `resource_type`; | The GType of edited resources. It must be a type derived from GwyResource. |
const gchar *`base_resource`; | The name of vanilla, default resource. The `New' button creates a new resource as a copy of this one. |
const gchar *`window_title`; | Resource list window title. It should be already translated. |
const gchar *`editor_title`; | Editor window title template. It must contain one ``s`` that will be replaced with edited resource name. It should be already translated. |
gchar *`settings_prefix`; | Settings prefix for saved state, filled by `gwy_resource_editor_class_setup()`. |
`construct_treeview` () | Method to create the resource list widget, it is of the `gwy_gradient_tree_view_new()` signature. There are currently some hardcoded assumptions about the tree view columns, so it cannot be completely arbitrary. |
`construct_editor` () | Method to construct editor window contents (the window itself is managed by GwyResourceEditor, its contents by a particular editor). |
`apply_changes` () | Method called on commit (before resource is written to disk). It should obtain values from the editor widgets and actually update the resource. |
`switch_resource` () | Method to update editor window widgets to display another resource. |
`reserved1` () |  |
`reserved2` () |  |
GwyResourceEditor *`instance`; | Editor instance. Resource editors are singletons so if an instance exists, pointer to it is kept here. |