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
32 #include "plugindata.h"
34 #include "filetypes.h"
36 #include "pluginmacros.h"
42 extern GeanyData
*geany_data
;
44 struct GeanyProject
*g_current_project
= NULL
;
45 static GPtrArray
*g_projects
= NULL
;
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
);
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 */
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
);
79 if (!g_current_project
)
84 g_hash_table_foreach(g_current_project
->tags
, remove_tag
, NULL
);
85 g_ptr_array_add(g_projects
, g_current_project
);
89 geany_project_free(g_current_project
);
92 g_current_project
= NULL
;
98 xproject_open(const gchar
* path
)
101 struct GeanyProject
*p
= NULL
;
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
);
115 p
= geany_project_new(path
);
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
;
137 xproject_update_tag(const gchar
* filename
)
140 TMWorkObject
*tm_obj
;
142 if (g_current_project
)
144 tm_obj
= g_hash_table_lookup(g_current_project
->tags
, filename
);
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
,
158 p_tm
->source_file_update(tm_obj
, TRUE
, FALSE
, TRUE
);
164 xproject_add_file(const gchar
* path
)
166 TMWorkObject
*tm_obj
;
168 debug("%s path=%s\n", __FUNCTION__
, path
);
170 if (!g_current_project
)
173 if (geany_project_add_file(g_current_project
, path
))
175 tm_obj
= (TMWorkObject
*) g_hash_table_lookup(g_current_project
->tags
, path
);
178 p_tm
->workspace_add_object((TMWorkObject
*) tm_obj
);
187 xproject_remove_file(const gchar
* path
)
189 TMWorkObject
*tm_obj
;
191 debug("%s path=%s\n", __FUNCTION__
, path
);
193 if (!g_current_project
)
196 tm_obj
= (TMWorkObject
*) g_hash_table_lookup(g_current_project
->tags
, path
);
199 p_tm
->workspace_remove_object(tm_obj
, FALSE
, FALSE
);
202 if (geany_project_remove_file(g_current_project
, path
))
213 g_projects
= g_ptr_array_sized_new(10);
214 g_current_project
= NULL
;
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
);