Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / plugins / project-wizard / action.c
blobc9ea8fd3460dde62e9ba4c736404c581571e13c0
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 action.c
4 Copyright (C) 2004 Sebastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * Actions data read in .wiz file
24 * It's just a list containing all data
25 *---------------------------------------------------------------------------*/
27 #include <config.h>
29 #include "action.h"
31 #include <glib/gdir.h>
33 /*---------------------------------------------------------------------------*/
35 #define STRING_CHUNK_SIZE 256
37 /*---------------------------------------------------------------------------*/
39 /* List containing all actions. It includes chunk for strings and actions
40 * object, so memory allocation is handled by the list itself */
42 struct _NPWActionList
44 GList* list;
45 GStringChunk* string_pool;
46 GMemChunk* data_pool;
49 /* Action object, it includes a pointer on its owner to allocate new data */
51 struct _NPWAction {
52 NPWActionType type;
53 gchar* command;
54 NPWActionList* owner;
55 GList* node;
58 /* Action object
60 *---------------------------------------------------------------------------*/
62 NPWAction*
63 npw_action_new (NPWActionList* owner, NPWActionType type)
65 NPWAction* this;
67 g_return_val_if_fail (owner != NULL, NULL);
69 this = g_chunk_new0(NPWAction, owner->data_pool);
70 this->type = type;
71 this->owner = owner;
72 owner->list = g_list_append (owner->list, this);
73 this->node = g_list_last (owner->list);
75 return this;
78 void
79 npw_action_free (NPWAction* this)
81 /* Memory allocated in string pool and project pool is not free */
84 NPWActionType
85 npw_action_get_type (const NPWAction* this)
87 return this->type;
90 void
91 npw_action_set_command (NPWAction* this, const gchar* command)
93 this->command = g_string_chunk_insert (this->owner->string_pool, command);
96 const gchar*
97 npw_action_get_command (const NPWAction* this)
99 return this->command;
102 void
103 npw_action_set_file (NPWAction* this, const gchar* file)
105 npw_action_set_command (this, file);
108 const gchar*
109 npw_action_get_file (const NPWAction* this)
111 return npw_action_get_command (this);
114 const NPWAction*
115 npw_action_next (const NPWAction* this)
117 GList* node = this->node->next;
119 return node == NULL ? NULL : (NPWAction *)node->data;
123 /* Action list object
124 *---------------------------------------------------------------------------*/
126 NPWActionList*
127 npw_action_list_new (void)
129 NPWActionList* this;
131 this = g_new (NPWActionList, 1);
132 this->string_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
133 this->data_pool = g_mem_chunk_new ("action pool", sizeof (NPWAction), STRING_CHUNK_SIZE * sizeof (NPWAction) / 4, G_ALLOC_ONLY);
134 this->list = NULL;
136 return this;
139 void
140 npw_action_list_free (NPWActionList* this)
142 g_return_if_fail (this != NULL);
144 g_string_chunk_free (this->string_pool);
145 g_mem_chunk_destroy (this->data_pool);
146 g_list_free (this->list);
147 g_free (this);
150 const NPWAction*
151 npw_action_list_first (const NPWActionList* this)
153 GList* node = g_list_first (this->list);
155 return node == NULL ? NULL : (NPWAction *)node->data;