Compilation fix
[geanyprj.git] / src / geanyprj.c
blobe82b788b6136a66e50d6a68e6e6aaefa16224edd
1 /*
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/>.
23 #include <sys/time.h>
25 #include "geany.h"
26 #include "support.h"
27 #include "plugindata.h"
28 #include "document.h"
29 #include "filetypes.h"
30 #include "utils.h"
31 #include "ui_utils.h"
32 #include "pluginmacros.h"
34 #include "project.h"
36 #include "geanyprj.h"
38 PLUGIN_VERSION_CHECK(38);
39 PLUGIN_SET_INFO(_("Project"), _("Alternative project support."), VERSION,
40 _("Yura Siamashka <yurand2@gmail.com>"));
42 PluginFields *plugin_fields;
43 GeanyData *geany_data;
44 GeanyFunctions *geany_functions;
46 static void
47 reload_project()
49 gint idx;
50 gchar *dir;
51 gchar *proj;
53 debug("%s\n", __FUNCTION__);
55 idx = p_document->get_cur_idx();
56 if (!DOC_IDX_VALID(idx) || documents[idx]->file_name == NULL)
57 return;
59 dir = g_path_get_dirname(documents[idx]->file_name);
60 proj = find_file_path(dir, ".geanyprj");
62 // This is not our project, close it as best as we can
63 if (project && project->type != PROJECT_TYPE)
65 debug("%s Closing unknown project type \n", __FUNCTION__);
66 xproject_close(TRUE);
69 if (!proj)
71 if (project)
72 xproject_close(TRUE);
73 return;
76 if (!project)
78 xproject_open(proj);
80 else if (strcmp(proj, g_current_project->path) != 0)
82 xproject_close(TRUE);
83 xproject_open(proj);
85 if (proj)
86 g_free(proj);
89 static void
90 on_doc_save(G_GNUC_UNUSED GObject * obj, gint idx, G_GNUC_UNUSED gpointer user_data)
92 gchar *name;
94 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__, obj, idx, user_data);
95 g_return_if_fail(DOC_IDX_VALID(idx) && documents[idx]->file_name != NULL);
97 name = g_path_get_basename(documents[idx]->file_name);
98 if (g_current_project && strcmp(name, ".geanyprj") == 0)
100 xproject_close(FALSE);
102 reload_project();
103 xproject_update_tag(documents[idx]->file_name);
106 static void
107 on_doc_open(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED gint idx, G_GNUC_UNUSED gpointer user_data)
109 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__, obj, idx, user_data);
110 reload_project();
113 static void
114 on_doc_activate(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED gint idx,
115 G_GNUC_UNUSED gpointer user_data)
117 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__, obj, idx, user_data);
118 reload_project();
121 GeanyCallback geany_callbacks[] = {
122 {"document-open", (GCallback) & on_doc_open, TRUE, NULL},
123 {"document-save", (GCallback) & on_doc_save, TRUE, NULL},
124 {"document-activate", (GCallback) & on_doc_activate, TRUE, NULL},
125 {NULL, NULL, FALSE, NULL}
128 /* Called by Geany to initialize the plugin */
129 void
130 plugin_init(G_GNUC_UNUSED GeanyData * data)
132 GtkWidget *prj =
133 p_support->lookup_widget(GTK_WIDGET(main_widgets->window), "menu_project1");
134 tools_menu_init();
136 gtk_widget_set_child_visible(prj, FALSE);
137 gtk_widget_set_size_request(prj, 0, 0);
139 xproject_init();
140 create_sidebar();
141 reload_project();
144 /* Called by Geany before unloading the plugin. */
145 void
146 plugin_cleanup()
148 GtkWidget *prj =
149 p_support->lookup_widget(GTK_WIDGET(main_widgets->window), "menu_project1");
150 gtk_widget_set_child_visible(prj, TRUE);
151 gtk_widget_set_size_request(prj, -1, -1);
153 tools_menu_uninit();
155 if (project)
157 xproject_close(TRUE);
160 if (g_current_project)
161 geany_project_free(g_current_project);
162 g_current_project = NULL;
164 xproject_cleanup();
165 destroy_sidebar();