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 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.
26 #include "plugindata.h"
28 #include "filetypes.h"
31 #include "pluginmacros.h"
34 PLUGIN_INFO(_("Project"), _("Alternative project support."), VERSION
,
35 _("Yura Siamashka <yurand2@gmail.com>"));
45 PluginFields
*plugin_fields
;
46 GeanyData
*geany_data
;
50 find_file_path(const gchar
* dir
, const gchar
* filename
)
55 gchar
*base_prev
= g_strdup(":");
59 while (strcmp(base
, base_prev
) != 0)
61 gitdir
= g_build_path("/", base
, filename
, NULL
);
62 ret
= g_file_test(gitdir
, G_FILE_TEST_IS_REGULAR
);
72 base
= g_path_get_dirname(base
);
80 /* Reads the given filename and creates a new project with the data found in the file.
81 * At this point there should not be an already opened project in Geany otherwise it will just
83 * The filename is expected in the locale encoding. */
85 xload_config(const gchar
* filename
)
90 // there should not be an open project
91 g_return_val_if_fail(project
== NULL
&& filename
!= NULL
, FALSE
);
93 config
= g_key_file_new();
94 if (!g_key_file_load_from_file(config
, filename
, G_KEY_FILE_NONE
, NULL
))
96 g_key_file_free(config
);
100 p
= project
= g_new0(GeanyProject
, 1);
102 p
->name
= utils
->get_setting_string(config
, "project", "name", GEANY_STRING_UNTITLED
);
103 p
->description
= utils
->get_setting_string(config
, "project", "description", "");
104 p
->file_name
= utils
->get_utf8_from_locale(filename
);
105 p
->base_path
= utils
->get_setting_string(config
, "project", "base_path", "");
106 p
->run_cmd
= utils
->get_setting_string(config
, "project", "run_cmd", "");
108 g_key_file_get_string_list(config
, "project", "file_patterns", NULL
, NULL
);
110 g_key_file_free(config
);
117 xproject_load_file(const gchar
* locale_file_name
)
119 g_return_val_if_fail(locale_file_name
!= NULL
, FALSE
);
121 if (xload_config(locale_file_name
))
123 ui
->set_statusbar(TRUE
, _("Project \"%s\" opened."), project
->name
);
128 gchar
*utf8_filename
= utils
->get_utf8_from_locale(locale_file_name
);
129 ui
->set_statusbar(TRUE
, _("Project file \"%s\" could not be loaded."),
131 g_free(utf8_filename
);
137 /* This fonction should keep in sync with geany code */
141 g_return_if_fail(project
!= NULL
);
143 ui
->set_statusbar(TRUE
, _("Project \"%s\" closed."), project
->name
);
145 g_free(project
->name
);
146 g_free(project
->description
);
147 g_free(project
->file_name
);
148 g_free(project
->base_path
);
149 g_free(project
->run_cmd
);
162 idx
= documents
->get_cur_idx();
163 g_return_if_fail(DOC_IDX_VALID(idx
) && doc_list
[idx
].file_name
!= NULL
);
165 dir
= g_path_get_dirname(doc_list
[idx
].file_name
);
166 proj
= find_file_path(dir
, ".geanyprj");
178 xproject_load_file(proj
);
180 else if (strcmp(proj
, project
->file_name
) != 0)
183 xproject_load_file(proj
);
190 on_doc_save(GObject
* obj
, gint idx
, gpointer user_data
)
192 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__
, obj
, idx
, user_data
);
197 on_doc_open(GObject
* obj
, gint idx
, gpointer user_data
)
199 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__
, obj
, idx
, user_data
);
204 on_doc_activate(GObject
* obj
, gint idx
, gpointer user_data
)
206 debug("%s obj=%p, idx = %d, user_data = %p\n", __FUNCTION__
, obj
, idx
, user_data
);
210 GeanyCallback geany_callbacks
[] = {
211 {"document-open", (GCallback
) & on_doc_open
, TRUE
, NULL
},
212 {"document-save", (GCallback
) & on_doc_save
, TRUE
, NULL
},
213 {"document-activate", (GCallback
) & on_doc_activate
, TRUE
, NULL
},
214 {NULL
, NULL
, FALSE
, NULL
}
217 /* Called by Geany to initialize the plugin */
219 init(GeanyData
* data
)
224 /* Called by Geany before unloading the plugin. */