1 /*
2 * This is a plug-in for GIMP.
3 *
4 * Generates clickable image maps.
5 *
6 * Copyright (C) 1998-1999 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 "libgimp/stdplugins-intl.h"
30
31 static void delete_command_destruct(Command_t *parent);
32 static CmdExecuteValue_t delete_command_execute(Command_t *parent);
33 static void delete_command_undo(Command_t *parent);
34
35 static CommandClass_t delete_command_class = {
36 delete_command_destruct,
37 delete_command_execute,
38 delete_command_undo,
39 NULL /* delete_command_redo */
40 };
41
42 typedef struct {
43 Command_t parent;
44 ObjectList_t *list;
45 Object_t *obj;
46 gint position;
47 gboolean changed;
48 } DeleteCommand_t;
49
50 Command_t*
delete_command_new(ObjectList_t * list,Object_t * obj)51 delete_command_new(ObjectList_t *list, Object_t *obj)
52 {
53 DeleteCommand_t *command = g_new(DeleteCommand_t, 1);
54 command->list = list;
55 command->obj = object_ref(obj);
56 return command_init(&command->parent, _("Delete"),
57 &delete_command_class);
58 }
59
60 static void
delete_command_destruct(Command_t * parent)61 delete_command_destruct(Command_t *parent)
62 {
63 DeleteCommand_t *command = (DeleteCommand_t*) parent;
64 object_unref(command->obj);
65 }
66
67 static CmdExecuteValue_t
delete_command_execute(Command_t * parent)68 delete_command_execute(Command_t *parent)
69 {
70 DeleteCommand_t *command = (DeleteCommand_t*) parent;
71 command->changed = object_list_get_changed(command->list);
72 command->position = object_get_position_in_list(command->obj);
73 object_list_remove(command->list, command->obj);
74 return CMD_APPEND;
75 }
76
77 static void
delete_command_undo(Command_t * parent)78 delete_command_undo(Command_t *parent)
79 {
80 DeleteCommand_t *command = (DeleteCommand_t*) parent;
81 object_list_insert(command->list, command->position, command->obj);
82 object_list_set_changed(command->list, command->changed);
83 }
84