compilation fixes for geany svn
[geanyprj.git] / src / xproject.c
blob0307fd406061f56fa0fcb978d002028c6ab273aa
1 /*
2 * geanyprj - Alternative project support for geany light IDE.
4 * Copyright 2007 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
5 * Copyright 2007 Enrico Tröger <enrico.troeger@uvena.de>
6 * Copyright 2007 Nick Treleaven <nick.treleaven@btinternet.com>
7 * Copyright 2007,2008 Yura Siamashka <yurand2@gmail.com>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/time.h>
25 #include "geany.h"
26 #include "support.h"
27 #include "prefs.h"
28 #include "plugindata.h"
29 #include "document.h"
30 #include "filetypes.h"
31 #include "utils.h"
32 #include "pluginmacros.h"
34 #include "project.h"
36 #include "geanyprj.h"
38 extern GeanyData *geany_data;
39 extern GeanyFunctions *geany_functions;
42 struct GeanyProject *g_current_project = NULL;
43 static GPtrArray *g_projects = NULL;
45 static void
46 add_tag(G_GNUC_UNUSED gpointer key, gpointer value, G_GNUC_UNUSED gpointer user_data)
48 debug("%s file=%s\n", __FUNCTION__, (const gchar *) key);
49 p_tm->workspace_add_object((TMWorkObject *) value);
52 static void
53 remove_tag(G_GNUC_UNUSED gpointer key, gpointer value, G_GNUC_UNUSED gpointer user_data)
55 debug("%s file=%s\n", __FUNCTION__, (const gchar *) key);
56 p_tm->workspace_remove_object((TMWorkObject *) value, FALSE, FALSE);
59 /* This fonction should keep in sync with geany code */
60 void
61 xproject_close(gboolean cache)
63 debug("%s\n", __FUNCTION__);
64 g_return_if_fail(project != NULL);
66 p_ui->set_statusbar(TRUE, _("Project \"%s\" closed."), project->name);
68 g_free(project->name);
69 g_free(project->description);
70 g_free(project->file_name);
71 g_free(project->base_path);
72 g_free(project->run_cmd);
74 g_free(project);
75 project = NULL;
77 if (!g_current_project)
78 return;
80 if (cache)
82 g_hash_table_foreach(g_current_project->tags, remove_tag, NULL);
83 g_ptr_array_add(g_projects, g_current_project);
85 else
87 geany_project_free(g_current_project);
90 g_current_project = NULL;
91 sidebar_refresh();
95 void
96 xproject_open(const gchar * path)
98 guint i;
99 struct GeanyProject *p = NULL;
100 debug("%s\n", __FUNCTION__);
102 for (i = 0; i < g_projects->len; i++)
104 if (strcmp(path, ((struct GeanyProject *) g_projects->pdata[i])->path) == 0)
106 p = (struct GeanyProject *) g_projects->pdata[i];
107 g_ptr_array_remove_index(g_projects, i);
108 break;
111 if (!p)
112 p = geany_project_load(path);
114 if (!p)
115 return;
117 p_ui->set_statusbar(TRUE, _("Project \"%s\" opened."), p->name);
119 project = g_new0(struct _GeanyProject, 1);
120 project->type = PROJECT_TYPE;
121 project->name = g_strdup(p->name);
122 project->description = g_strdup(p->description);
123 project->base_path = g_strdup(p->base_path);
124 project->run_cmd = g_strdup(p->run_cmd);
125 project->make_in_base_path = TRUE;
127 g_hash_table_foreach(p->tags, add_tag, NULL);
129 g_current_project = p;
130 sidebar_refresh();
133 void
134 xproject_update_tag(const gchar * filename)
136 guint i;
137 TMWorkObject *tm_obj;
139 if (g_current_project)
141 tm_obj = g_hash_table_lookup(g_current_project->tags, filename);
142 if (tm_obj)
144 p_tm->source_file_update(tm_obj, TRUE, FALSE, TRUE);
148 for (i = 0; i < g_projects->len; i++)
150 tm_obj = (TMWorkObject *)
151 g_hash_table_lookup(((struct GeanyProject *) (g_projects->pdata[i]))->tags,
152 filename);
153 if (tm_obj)
155 p_tm->source_file_update(tm_obj, TRUE, FALSE, TRUE);
160 gboolean
161 xproject_add_file(const gchar * path)
163 TMWorkObject *tm_obj;
165 debug("%s path=%s\n", __FUNCTION__, path);
167 if (!g_current_project)
168 return FALSE;
170 if (geany_project_add_file(g_current_project, path))
172 tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path);
173 if (tm_obj)
175 p_tm->workspace_add_object((TMWorkObject *) tm_obj);
177 sidebar_refresh();
178 return TRUE;
180 return FALSE;
183 gboolean
184 xproject_remove_file(const gchar * path)
186 TMWorkObject *tm_obj;
188 debug("%s path=%s\n", __FUNCTION__, path);
190 if (!g_current_project)
191 return FALSE;
193 tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path);
194 if (tm_obj)
196 p_tm->workspace_remove_object(tm_obj, FALSE, FALSE);
199 if (geany_project_remove_file(g_current_project, path))
201 sidebar_refresh();
202 return TRUE;
204 return FALSE;
207 void
208 xproject_init()
210 g_projects = g_ptr_array_sized_new(10);
211 g_current_project = NULL;
214 void
215 xproject_cleanup()
217 guint i;
218 for (i = 0; i < g_projects->len; i++)
220 geany_project_free(((struct GeanyProject *) (g_projects->pdata[i])));
222 g_ptr_array_free(g_projects, TRUE);
223 g_projects = NULL;