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/>.
28 #include "plugindata.h"
30 #include "filetypes.h"
32 #include "pluginmacros.h"
38 extern GeanyData
*geany_data
;
39 extern GeanyFunctions
*geany_functions
;
42 struct GeanyProject
*g_current_project
= NULL
;
43 static GPtrArray
*g_projects
= NULL
;
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
);
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 */
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
);
77 if (!g_current_project
)
82 g_hash_table_foreach(g_current_project
->tags
, remove_tag
, NULL
);
83 g_ptr_array_add(g_projects
, g_current_project
);
87 geany_project_free(g_current_project
);
90 g_current_project
= NULL
;
96 xproject_open(const gchar
* path
)
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
);
112 p
= geany_project_load(path
);
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
;
134 xproject_update_tag(const gchar
* filename
)
137 TMWorkObject
*tm_obj
;
139 if (g_current_project
)
141 tm_obj
= g_hash_table_lookup(g_current_project
->tags
, filename
);
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
,
155 p_tm
->source_file_update(tm_obj
, TRUE
, FALSE
, TRUE
);
161 xproject_add_file(const gchar
* path
)
163 TMWorkObject
*tm_obj
;
165 debug("%s path=%s\n", __FUNCTION__
, path
);
167 if (!g_current_project
)
170 if (geany_project_add_file(g_current_project
, path
))
172 tm_obj
= (TMWorkObject
*) g_hash_table_lookup(g_current_project
->tags
, path
);
175 p_tm
->workspace_add_object((TMWorkObject
*) tm_obj
);
184 xproject_remove_file(const gchar
* path
)
186 TMWorkObject
*tm_obj
;
188 debug("%s path=%s\n", __FUNCTION__
, path
);
190 if (!g_current_project
)
193 tm_obj
= (TMWorkObject
*) g_hash_table_lookup(g_current_project
->tags
, path
);
196 p_tm
->workspace_remove_object(tm_obj
, FALSE
, FALSE
);
199 if (geany_project_remove_file(g_current_project
, path
))
210 g_projects
= g_ptr_array_sized_new(10);
211 g_current_project
= NULL
;
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
);