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 tagmanager
->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 tagmanager
->workspace_remove_object((TMWorkObject
*) value
, FALSE
, FALSE
);
61 /* This fonction should keep in sync with geany code */
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
);
79 if (!g_current_project
)
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
;
91 xproject_open(const gchar
* path
)
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
);
107 p
= geany_project_new(path
);
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
;
128 xproject_update_tag(const gchar
* filename
)
131 TMWorkObject
*tm_obj
;
133 if (g_current_project
)
135 tm_obj
= g_hash_table_lookup(g_current_project
->tags
, filename
);
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
,
149 tagmanager
->source_file_update(tm_obj
, TRUE
, FALSE
, TRUE
);
155 xproject_add_file(const gchar
* path
)
157 TMWorkObject
*tm_obj
;
159 debug("%s path=%s\n", __FUNCTION__
, path
);
161 if (!g_current_project
)
164 if (geany_project_add_file(g_current_project
, path
))
166 tm_obj
= (TMWorkObject
*) g_hash_table_lookup(g_current_project
->tags
, path
);
169 tagmanager
->workspace_add_object((TMWorkObject
*) tm_obj
);
178 xproject_remove_file(const gchar
* path
)
180 TMWorkObject
*tm_obj
;
182 debug("%s path=%s\n", __FUNCTION__
, path
);
184 if (!g_current_project
)
187 tm_obj
= (TMWorkObject
*) g_hash_table_lookup(g_current_project
->tags
, path
);
190 tagmanager
->workspace_remove_object(tm_obj
, FALSE
, FALSE
);
193 if (geany_project_remove_file(g_current_project
, path
))
204 g_projects
= g_ptr_array_sized_new(10);
205 g_current_project
= NULL
;
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
);