always store full path in memory. Transform should happend only on project load
[geanyprj.git] / xproject.c
blob6615a75123beafe3039e5216dd31cdbbd9bbfcbe
1 /*
2 * geanyprj.c - 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 2 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, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * Merge geanyprj and geany project codes
27 #include <sys/time.h>
29 #include "geany.h"
30 #include "support.h"
31 #include "prefs.h"
32 #include "plugindata.h"
33 #include "document.h"
34 #include "filetypes.h"
35 #include "utils.h"
36 #include "pluginmacros.h"
38 #include "project.h"
40 #include "geanyprj.h"
42 extern GeanyData *geany_data;
44 struct GeanyProject *g_current_project = NULL;
45 static GPtrArray *g_projects = NULL;
47 static void
48 add_tag(gpointer key, gpointer value, gpointer user_data)
50 debug("%s file=%s\n", __FUNCTION__, (const gchar *) key);
51 p_tm->workspace_add_object((TMWorkObject *) value);
54 static void
55 remove_tag(gpointer key, gpointer value, gpointer user_data)
57 debug("%s file=%s\n", __FUNCTION__, (const gchar *) key);
58 p_tm->workspace_remove_object((TMWorkObject *) value, FALSE, FALSE);
61 /* This fonction should keep in sync with geany code */
62 void
63 xproject_close(gboolean cache)
65 debug("%s\n", __FUNCTION__);
66 g_return_if_fail(project != NULL);
68 p_ui->set_statusbar(TRUE, _("Project \"%s\" closed."), project->name);
70 g_free(project->name);
71 g_free(project->description);
72 g_free(project->file_name);
73 g_free(project->base_path);
74 g_free(project->run_cmd);
76 g_free(project);
77 project = NULL;
79 if (!g_current_project)
80 return;
82 if (cache)
84 g_hash_table_foreach(g_current_project->tags, remove_tag, NULL);
85 g_ptr_array_add(g_projects, g_current_project);
87 else
89 geany_project_free(g_current_project);
92 g_current_project = NULL;
93 sidebar_refresh();
97 void
98 xproject_open(const gchar * path)
100 gint i;
101 struct GeanyProject *p = NULL;
102 gchar *dir;
103 debug("%s\n", __FUNCTION__);
105 for (i = 0; i < g_projects->len; i++)
107 if (strcmp(path, ((struct GeanyProject *) g_projects->pdata[i])->path) == 0)
109 p = (struct GeanyProject *) g_projects->pdata[i];
110 g_ptr_array_remove_index(g_projects, i);
111 break;
114 if (!p)
115 p = geany_project_new(path);
117 if (!p)
118 return;
120 p_ui->set_statusbar(TRUE, _("Project \"%s\" opened."), p->name);
122 project = g_new0(struct _GeanyProject, 1);
123 project->type = PROJECT_TYPE;
124 project->name = g_strdup(p->name);
125 project->description = g_strdup(p->description);
126 project->base_path = g_strdup(p->base_path);
127 project->run_cmd = g_strdup(p->run_cmd);
128 project->make_in_base_path = TRUE;
130 g_hash_table_foreach(p->tags, add_tag, NULL);
132 g_current_project = p;
133 sidebar_refresh();
136 void
137 xproject_update_tag(const gchar * filename)
139 gint i;
140 TMWorkObject *tm_obj;
142 if (g_current_project)
144 tm_obj = g_hash_table_lookup(g_current_project->tags, filename);
145 if (tm_obj)
147 p_tm->source_file_update(tm_obj, TRUE, FALSE, TRUE);
151 for (i = 0; i < g_projects->len; i++)
153 tm_obj = (TMWorkObject *)
154 g_hash_table_lookup(((struct GeanyProject *) (g_projects->pdata[i]))->tags,
155 filename);
156 if (tm_obj)
158 p_tm->source_file_update(tm_obj, TRUE, FALSE, TRUE);
163 gboolean
164 xproject_add_file(const gchar * path)
166 TMWorkObject *tm_obj;
168 debug("%s path=%s\n", __FUNCTION__, path);
170 if (!g_current_project)
171 return FALSE;
173 if (geany_project_add_file(g_current_project, path))
175 tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path);
176 if (tm_obj)
178 p_tm->workspace_add_object((TMWorkObject *) tm_obj);
180 sidebar_refresh();
181 return TRUE;
183 return FALSE;
186 gboolean
187 xproject_remove_file(const gchar * path)
189 TMWorkObject *tm_obj;
191 debug("%s path=%s\n", __FUNCTION__, path);
193 if (!g_current_project)
194 return FALSE;
196 tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path);
197 if (tm_obj)
199 p_tm->workspace_remove_object(tm_obj, FALSE, FALSE);
202 if (geany_project_remove_file(g_current_project, path))
204 sidebar_refresh();
205 return TRUE;
207 return FALSE;
210 void
211 xproject_init()
213 g_projects = g_ptr_array_sized_new(10);
214 g_current_project = NULL;
217 void
218 xproject_cleanup()
220 gint i;
221 for (i = 0; i < g_projects->len; i++)
223 geany_project_free(((struct GeanyProject *) (g_projects->pdata[i])));
225 g_ptr_array_free(g_projects, TRUE);
226 g_projects = NULL;