1 /*
2  * This is a plug-in for GIMP.
3  *
4  * Generates clickable image maps.
5  *
6  * Copyright (C) 1998-2003 Maurits Rijk  lpeek.mrijk@consunet.nl
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include "config.h"
24 
25 #include <gtk/gtk.h>
26 
27 #include "imap_commands.h"
28 
29 #include "imap_main.h"
30 
31 #include "libgimp/stdplugins-intl.h"
32 
33 static CmdExecuteValue_t create_command_execute(Command_t *parent);
34 static void create_command_destruct(Command_t *parent);
35 static void create_command_undo(Command_t *parent);
36 
37 static CommandClass_t create_command_class = {
38    create_command_destruct,
39    create_command_execute,
40    create_command_undo,
41    NULL                         /* create_command_redo */
42 };
43 
44 typedef struct {
45    Command_t     parent;
46    ObjectList_t *list;
47    Object_t     *obj;
48    gboolean      changed;
49 } CreateCommand_t;
50 
51 Command_t*
create_command_new(ObjectList_t * list,Object_t * obj)52 create_command_new(ObjectList_t *list, Object_t *obj)
53 {
54    CreateCommand_t *command = g_new(CreateCommand_t, 1);
55    command->list = list;
56    command->obj = object_ref(obj);
57    return command_init(&command->parent, _("Create"), &create_command_class);
58 }
59 
60 static void
create_command_destruct(Command_t * parent)61 create_command_destruct(Command_t *parent)
62 {
63    CreateCommand_t *command = (CreateCommand_t*) parent;
64    object_unref(command->obj);
65 }
66 
67 static CmdExecuteValue_t
create_command_execute(Command_t * parent)68 create_command_execute(Command_t *parent)
69 {
70    CreateCommand_t *command = (CreateCommand_t*) parent;
71    command->changed = object_list_get_changed(command->list);
72    object_list_append(command->list, object_ref(command->obj));
73    return CMD_APPEND;
74 }
75 
76 static void
create_command_undo(Command_t * parent)77 create_command_undo(Command_t *parent)
78 {
79    CreateCommand_t *command = (CreateCommand_t*) parent;
80    object_list_remove(command->list, command->obj);
81    object_list_set_changed(command->list, command->changed);
82 }
83