undo.h 2.69 KB
Newer Older
1 2
/*
    This file is part of darktable,
Pascal Obry's avatar
Pascal Obry committed
3
    copyright (c) 2016 pascal obry
4 5 6 7 8 9 10 11 12 13 14 15 16 17

    darktable is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    darktable is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with darktable.  If not, see <http://www.gnu.org/licenses/>.
*/
18 19

#pragma once
20

21 22 23
#include "common/dtpthread.h"  // for dt_pthread_mutex_t
#include <glib.h>              // for gpointer, GList
#include <stdint.h>            // for uint32_t
24 25 26 27

//  types that are known by the undo module
typedef enum dt_undo_type_t
{
28 29
  DT_UNDO_GEOTAG = 1 << 0,
  DT_UNDO_HISTORY = 1 << 1,
30 31 32
  DT_UNDO_MASK = 1 << 2,
  DT_UNDO_DEVELOP = DT_UNDO_HISTORY | DT_UNDO_MASK,
  DT_UNDO_ALL = DT_UNDO_GEOTAG | DT_UNDO_HISTORY | DT_UNDO_MASK
33 34
} dt_undo_type_t;

35
typedef void *dt_undo_data_t;
36

37 38 39
typedef struct dt_undo_t
{
  GList *undo_list, *redo_list;
40
  dt_pthread_mutex_t mutex;
41 42 43 44 45
} dt_undo_t;

dt_undo_t *dt_undo_init(void);
void dt_undo_cleanup(dt_undo_t *self);

46
// record a change that will be insered into the undo list
47 48 49
void dt_undo_record(dt_undo_t *self, gpointer user_data, dt_undo_type_t type, dt_undo_data_t *data,
                    void (*undo)(gpointer user_data, dt_undo_type_t type, dt_undo_data_t *item),
                    void (*free_data)(gpointer data));
50 51 52

//  undo an element which correspond to filter. filter here is expected to be
//  a set of dt_undo_type_t.
53
void dt_undo_do_undo(dt_undo_t *self, uint32_t filter);
54

55
//  redo a previously undone action, does nothing if the redo list is empty
56
void dt_undo_do_redo(dt_undo_t *self, uint32_t filter);
Pascal Obry's avatar
Pascal Obry committed
57

58
//  removes all items which correspond to filter in the undo/redo lists
59
void dt_undo_clear(dt_undo_t *self, uint32_t filter);
60

61 62 63 64
void dt_undo_iterate_internal(dt_undo_t *self, uint32_t filter, gpointer user_data,
                              void (*apply)(gpointer user_data, dt_undo_type_t type, dt_undo_data_t *item));

void dt_undo_iterate(dt_undo_t *self, uint32_t filter, gpointer user_data,
65 66
                     void (*apply)(gpointer user_data, dt_undo_type_t type, dt_undo_data_t *item));

67 68
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
// vim: shiftwidth=2 expandtab tabstop=2 cindent
Tobias Ellinghaus's avatar
Tobias Ellinghaus committed
69
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;