geany_project_save implementation
[geanyprj.git] / xproject.c
blobea409a44df8b63bbad7775c9a78113ae8340466d
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 tagmanager->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 tagmanager->workspace_remove_object((TMWorkObject *) value, FALSE, FALSE);
61 /* This fonction should keep in sync with geany code */
62 void
63 xproject_close()
65 debug("%s\n", __FUNCTION__);
66 g_return_if_fail(project != NULL);
68 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 g_ptr_array_add(g_projects, g_current_project);
83 g_hash_table_foreach(g_current_project->tags, remove_tag, NULL);
85 g_current_project = NULL;
86 sidebar_refresh();
90 void
91 xproject_open(const gchar * path)
93 gint i;
94 struct GeanyProject *p = NULL;
95 debug("%s\n", __FUNCTION__);
97 for (i = 0; i < g_projects->len; i++)
99 if (strcmp(path, ((struct GeanyProject *) g_projects->pdata[i])->path) == 0)
101 p = (struct GeanyProject *) g_projects->pdata[i];
102 g_ptr_array_remove_index(g_projects, i);
103 break;
106 if (!p)
107 p = geany_project_new(path);
109 if (!p)
110 return;
112 ui->set_statusbar(TRUE, _("Project \"%s\" opened."), p->name);
114 project = g_new0(struct _GeanyProject, 1);
115 project->type = PROJECT_TYPE;
116 project->name = g_strdup(p->name);
117 project->description = g_strdup(p->description);
118 project->base_path = g_strdup(p->base_path);
119 project->run_cmd = g_strdup(p->run_cmd);
121 g_hash_table_foreach(p->tags, add_tag, NULL);
123 g_current_project = p;
124 sidebar_refresh();
127 void
128 xproject_update_tag(const gchar * filename)
130 gint i;
131 TMWorkObject *tm_obj;
133 if (g_current_project)
135 tm_obj = g_hash_table_lookup(g_current_project->tags, filename);
136 if (tm_obj)
138 tagmanager->source_file_update(tm_obj, TRUE, FALSE, TRUE);
142 for (i = 0; i < g_projects->len; i++)
144 tm_obj = (TMWorkObject *)
145 g_hash_table_lookup(((struct GeanyProject *) (g_projects->pdata[i]))->tags,
146 filename);
147 if (tm_obj)
149 tagmanager->source_file_update(tm_obj, TRUE, FALSE, TRUE);
154 gboolean
155 xproject_add_file(const gchar * path)
157 TMWorkObject *tm_obj;
159 debug("%s path=%s\n", __FUNCTION__, path);
161 if (!g_current_project)
162 return FALSE;
164 if (geany_project_add_file(g_current_project, path))
166 tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path);
167 if (tm_obj)
169 tagmanager->workspace_add_object((TMWorkObject *) tm_obj);
171 sidebar_refresh();
172 return TRUE;
174 return FALSE;
177 gboolean
178 xproject_remove_file(const gchar * path)
180 TMWorkObject *tm_obj;
182 debug("%s path=%s\n", __FUNCTION__, path);
184 if (!g_current_project)
185 return FALSE;
187 tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path);
188 if (tm_obj)
190 tagmanager->workspace_remove_object(tm_obj, FALSE, FALSE);
193 if (geany_project_remove_file(g_current_project, path))
195 sidebar_refresh();
196 return TRUE;
198 return FALSE;
201 void
202 xproject_init()
204 g_projects = g_ptr_array_sized_new(10);
205 g_current_project = NULL;
208 void
209 xproject_cleanup()
211 gint i;
212 for (i = 0; i < g_projects->len; i++)
214 geany_project_free(((struct GeanyProject *) (g_projects->pdata[i])));
216 g_ptr_array_free(g_projects, TRUE);
217 g_projects = NULL;