README update
[geanyprj.git] / geanyprj.c
blob373e8e400609dbb3ce9087243e83bfad7f78a08b
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 "prefs.h"
28 #include "plugindata.h"
29 #include "document.h"
30 #include "filetypes.h"
31 #include "utils.h"
32 #include "pluginmacros.h"
34 #include "project.h"
36 #include "geanyprj.h"
38 VERSION_CHECK(38);
39 PLUGIN_INFO(_("Project"), _("Alternative project support."), VERSION,
40 _("Yura Siamashka <yurand2@gmail.com>"));
42 PluginFields *plugin_fields;
43 GeanyData *geany_data;
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) || doc_list[idx].file_name == NULL)
57 return;
59 dir = g_path_get_dirname(doc_list[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(GObject * obj, gint idx, gpointer user_data)
92 TMWorkObject *tm_obj;
93 gint i;
94 gchar *name;
96 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__, obj, idx, user_data);
97 g_return_if_fail(DOC_IDX_VALID(idx) && doc_list[idx].file_name != NULL);
99 name = g_path_get_basename(doc_list[idx].file_name);
100 if (g_current_project && strcmp(name, ".geanyprj") == 0)
102 xproject_close(FALSE);
104 reload_project();
105 xproject_update_tag(doc_list[idx].file_name);
108 static void
109 on_doc_open(GObject * obj, gint idx, gpointer user_data)
111 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__, obj, idx, user_data);
112 reload_project();
115 static void
116 on_doc_activate(GObject * obj, gint idx, gpointer user_data)
118 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__, obj, idx, user_data);
119 reload_project();
122 GeanyCallback geany_callbacks[] = {
123 {"document-open", (GCallback) & on_doc_open, TRUE, NULL},
124 {"document-save", (GCallback) & on_doc_save, TRUE, NULL},
125 {"document-activate", (GCallback) & on_doc_activate, TRUE, NULL},
126 {NULL, NULL, FALSE, NULL}
129 /* Called by Geany to initialize the plugin */
130 void
131 init(GeanyData * data)
133 GtkWidget *prj = p_support->lookup_widget(GTK_WIDGET(app->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 cleanup()
148 gint i;
150 GtkWidget *prj = p_support->lookup_widget(GTK_WIDGET(app->window), "menu_project1");
151 gtk_widget_set_child_visible(prj, TRUE);
152 gtk_widget_set_size_request(prj, -1, -1);
154 tools_menu_uninit();
156 if (project)
158 xproject_close(TRUE);
161 if (g_current_project)
162 geany_project_free(g_current_project);
163 g_current_project = NULL;
165 xproject_cleanup();
166 destroy_sidebar();