Always emit the project-save signal when writing project file
[geany-mirror.git] / src / project.c
blob07b3c995d76d69cd481defbd054383201e4643ce
1 /*
2 * project.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2007-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /** @file project.h
23 * Project Management.
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include "project.h"
32 #include "app.h"
33 #include "build.h"
34 #include "dialogs.h"
35 #include "document.h"
36 #include "editor.h"
37 #include "filetypesprivate.h"
38 #include "geanyobject.h"
39 #include "keyfile.h"
40 #include "main.h"
41 #include "projectprivate.h"
42 #include "sidebar.h"
43 #include "stash.h"
44 #include "support.h"
45 #include "ui_utils.h"
46 #include "utils.h"
47 #include "win32.h"
49 #include <string.h>
50 #include <unistd.h>
51 #include <errno.h>
54 ProjectPrefs project_prefs = { NULL, FALSE, FALSE };
57 static GeanyProjectPrivate priv;
58 static GeanyIndentPrefs indentation;
60 static GSList *stash_groups = NULL;
62 static struct
64 gchar *project_file_path; /* in UTF-8 */
65 } local_prefs = { NULL };
67 /* simple struct to keep references to the elements of the properties dialog */
68 typedef struct _PropertyDialogElements
70 GtkWidget *dialog;
71 GtkWidget *notebook;
72 GtkWidget *name;
73 GtkWidget *description;
74 GtkWidget *file_name;
75 GtkWidget *base_path;
76 GtkWidget *patterns;
77 BuildTableData build_properties;
78 gint build_page_num;
79 gboolean entries_modified;
80 } PropertyDialogElements;
83 static gboolean update_config(const PropertyDialogElements *e, gboolean new_project);
84 static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e);
85 static gboolean load_config(const gchar *filename);
86 static gboolean write_config(void);
87 static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e);
88 static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e);
89 static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line);
90 static void apply_editor_prefs(void);
91 static void init_stash_prefs(void);
92 static void destroy_project(gboolean open_default);
95 #define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args)
96 #define SHOW_ERR1(args, more) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args, more)
97 #define MAX_NAME_LEN 50
98 /* "projects" is part of the default project base path so be careful when translating
99 * please avoid special characters and spaces, look at the source for details or ask Frank */
100 #define PROJECT_DIR _("projects")
103 // returns whether we have working documents open
104 static gboolean have_session_docs(void)
106 gint npages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
107 GeanyDocument *doc = document_get_current();
109 return npages > 1 || (npages == 1 && (doc->file_name || doc->changed));
113 /* TODO: this should be ported to Glade like the project preferences dialog,
114 * then we can get rid of the PropertyDialogElements struct altogether as
115 * widgets pointers can be accessed through ui_lookup_widget(). */
116 void project_new(void)
118 GtkWidget *vbox;
119 GtkWidget *table;
120 GtkWidget *image;
121 GtkWidget *button;
122 GtkWidget *bbox;
123 GtkWidget *label;
124 gchar *tooltip;
125 PropertyDialogElements e = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, FALSE };
127 if (!app->project && project_prefs.project_session)
129 /* save session in case the dialog is cancelled */
130 configuration_save_default_session();
131 /* don't ask if the only doc is an unmodified new doc */
132 if (have_session_docs())
134 if (dialogs_show_question(
135 _("Move the current documents into the new project's session?")))
137 // don't reload session on closing project
138 configuration_clear_default_session();
140 else
142 if (!document_close_all())
143 return;
148 if (! project_ask_close())
149 return;
151 g_return_if_fail(app->project == NULL);
153 e.dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(main_widgets.window),
154 GTK_DIALOG_DESTROY_WITH_PARENT,
155 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
157 gtk_widget_set_name(e.dialog, "GeanyDialogProject");
158 button = ui_button_new_with_image(GTK_STOCK_NEW, _("C_reate"));
159 gtk_widget_set_can_default(button, TRUE);
160 gtk_window_set_default(GTK_WINDOW(e.dialog), button);
161 gtk_dialog_add_action_widget(GTK_DIALOG(e.dialog), button, GTK_RESPONSE_OK);
163 vbox = ui_dialog_vbox_new(GTK_DIALOG(e.dialog));
165 table = gtk_table_new(3, 2, FALSE);
166 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
167 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
169 label = gtk_label_new(_("Name:"));
170 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
172 e.name = gtk_entry_new();
173 gtk_entry_set_activates_default(GTK_ENTRY(e.name), TRUE);
174 ui_entry_add_clear_icon(GTK_ENTRY(e.name));
175 gtk_entry_set_max_length(GTK_ENTRY(e.name), MAX_NAME_LEN);
176 gtk_widget_set_tooltip_text(e.name, _("Project name"));
178 ui_table_add_row(GTK_TABLE(table), 0, label, e.name, NULL);
180 label = gtk_label_new(_("Filename:"));
181 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
183 e.file_name = gtk_entry_new();
184 gtk_entry_set_activates_default(GTK_ENTRY(e.file_name), TRUE);
185 ui_entry_add_clear_icon(GTK_ENTRY(e.file_name));
186 gtk_entry_set_width_chars(GTK_ENTRY(e.file_name), 30);
187 tooltip = g_strdup_printf(
188 _("Path of the file representing the project and storing its settings. "
189 "It should normally have the \"%s\" extension."), "."GEANY_PROJECT_EXT);
190 gtk_widget_set_tooltip_text(e.file_name, tooltip);
191 g_free(tooltip);
192 button = gtk_button_new();
193 g_signal_connect(button, "clicked", G_CALLBACK(on_file_save_button_clicked), &e);
194 image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
195 gtk_container_add(GTK_CONTAINER(button), image);
196 bbox = gtk_hbox_new(FALSE, 6);
197 gtk_box_pack_start(GTK_BOX(bbox), e.file_name, TRUE, TRUE, 0);
198 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
200 ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);
202 label = gtk_label_new(_("Base path:"));
203 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
205 e.base_path = gtk_entry_new();
206 gtk_entry_set_activates_default(GTK_ENTRY(e.base_path), TRUE);
207 ui_entry_add_clear_icon(GTK_ENTRY(e.base_path));
208 gtk_widget_set_tooltip_text(e.base_path,
209 _("Base directory of all files that make up the project. "
210 "This can be a new path, or an existing directory tree. "
211 "You can use paths relative to the project filename."));
212 bbox = ui_path_box_new(_("Choose Project Base Path"),
213 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e.base_path));
215 ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);
217 gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
219 /* signals */
220 g_signal_connect(e.name, "changed", G_CALLBACK(on_name_entry_changed), &e);
221 /* run the callback manually to initialise the base_path and file_name fields */
222 on_name_entry_changed(GTK_EDITABLE(e.name), &e);
224 g_signal_connect(e.file_name, "changed", G_CALLBACK(on_entries_changed), &e);
225 g_signal_connect(e.base_path, "changed", G_CALLBACK(on_entries_changed), &e);
227 gtk_widget_show_all(e.dialog);
229 while (1)
231 if (gtk_dialog_run(GTK_DIALOG(e.dialog)) != GTK_RESPONSE_OK)
233 // any open docs were meant to be moved into the project
234 // rewrite default session because it was cleared
235 if (have_session_docs())
236 configuration_save_default_session();
237 else
239 // reload any documents that were closed
240 configuration_reload_default_session();
241 configuration_open_files();
243 break;
245 // dialog confirmed
246 if (update_config(&e, TRUE))
248 // app->project is now set
249 if (!write_config())
251 SHOW_ERR(_("Project file could not be written"));
252 destroy_project(FALSE);
254 else
256 ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name);
257 ui_add_recent_project_file(app->project->file_name);
258 break;
262 gtk_widget_destroy(e.dialog);
263 document_new_file_if_non_open();
264 ui_focus_current_document();
268 gboolean project_load_file_with_session(const gchar *locale_file_name)
270 if (project_load_file(locale_file_name))
272 if (project_prefs.project_session)
274 configuration_open_files();
275 document_new_file_if_non_open();
276 ui_focus_current_document();
278 return TRUE;
280 return FALSE;
284 static void run_open_dialog(GtkDialog *dialog)
286 while (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT)
288 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
290 /* try to load the config */
291 if (! project_load_file_with_session(filename))
293 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
295 SHOW_ERR1(_("Project file \"%s\" could not be loaded."), utf8_filename);
296 gtk_widget_grab_focus(GTK_WIDGET(dialog));
297 g_free(utf8_filename);
298 g_free(filename);
299 continue;
301 g_free(filename);
302 break;
307 void project_open(void)
309 const gchar *dir = local_prefs.project_file_path;
311 if (! project_ask_close()) return;
313 #ifdef G_OS_WIN32
314 if (interface_prefs.use_native_windows_dialogs)
316 gchar *file = win32_show_project_open_dialog(main_widgets.window, _("Open Project"), dir, FALSE, TRUE);
317 if (file != NULL)
319 /* try to load the config */
320 if (! project_load_file_with_session(file))
322 SHOW_ERR1(_("Project file \"%s\" could not be loaded."), file);
324 g_free(file);
327 else
328 #endif
330 GtkWidget *dialog;
331 GtkFileFilter *filter;
332 gchar *locale_path;
334 dialog = gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(main_widgets.window),
335 GTK_FILE_CHOOSER_ACTION_OPEN,
336 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
337 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
338 gtk_widget_set_name(dialog, "GeanyDialogProject");
340 /* set default Open, so pressing enter can open multiple files */
341 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
342 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
343 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
344 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
345 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window));
346 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
348 /* add FileFilters */
349 filter = gtk_file_filter_new();
350 gtk_file_filter_set_name(filter, _("All files"));
351 gtk_file_filter_add_pattern(filter, "*");
352 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
353 filter = gtk_file_filter_new();
354 gtk_file_filter_set_name(filter, _("Project files"));
355 gtk_file_filter_add_pattern(filter, "*." GEANY_PROJECT_EXT);
356 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
357 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
359 locale_path = utils_get_locale_from_utf8(dir);
360 if (g_file_test(locale_path, G_FILE_TEST_EXISTS) &&
361 g_file_test(locale_path, G_FILE_TEST_IS_DIR))
363 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
365 g_free(locale_path);
367 gtk_widget_show_all(dialog);
368 run_open_dialog(GTK_DIALOG(dialog));
369 gtk_widget_destroy(GTK_WIDGET(dialog));
374 /* Called when creating, opening, closing and updating projects. */
375 static void update_ui(void)
377 if (main_status.quitting)
378 return;
380 ui_set_window_title(NULL);
381 build_menu_update(NULL);
382 // update project name
383 sidebar_openfiles_update_all();
384 ui_update_recent_project_menu();
388 static void remove_foreach_project_filetype(gpointer data, gpointer user_data)
390 GeanyFiletype *ft = data;
391 if (ft != NULL)
393 SETPTR(ft->priv->projfilecmds, NULL);
394 SETPTR(ft->priv->projexeccmds, NULL);
395 SETPTR(ft->priv->projerror_regex_string, NULL);
396 ft->priv->project_list_entry = -1;
401 /* open_default will make function reload default session files on close */
402 gboolean project_close(gboolean open_default)
404 g_return_val_if_fail(app->project != NULL, FALSE);
406 /* save project session files, etc */
407 if (!write_config())
408 g_warning("Project file \"%s\" could not be written", app->project->file_name);
410 if (project_prefs.project_session)
412 /* close all existing tabs first */
413 if (!document_close_all())
414 return FALSE;
416 ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
417 destroy_project(open_default);
418 return TRUE;
422 static void destroy_project(gboolean open_default)
424 GSList *node;
426 g_return_if_fail(app->project != NULL);
428 g_signal_emit_by_name(geany_object, "project-before-close");
430 /* remove project filetypes build entries */
431 if (app->project->priv->build_filetypes_list != NULL)
433 g_ptr_array_foreach(app->project->priv->build_filetypes_list, remove_foreach_project_filetype, NULL);
434 g_ptr_array_free(app->project->priv->build_filetypes_list, FALSE);
437 /* remove project non filetype build menu items */
438 build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_NON_FT, -1);
439 build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_EXEC, -1);
441 g_free(app->project->name);
442 g_free(app->project->description);
443 g_free(app->project->file_name);
444 g_free(app->project->base_path);
445 g_strfreev(app->project->file_patterns);
447 g_free(app->project);
448 app->project = NULL;
450 foreach_slist(node, stash_groups)
451 stash_group_free(node->data);
453 g_slist_free(stash_groups);
454 stash_groups = NULL;
456 apply_editor_prefs(); /* ensure that global settings are restored */
458 if (project_prefs.project_session)
460 /* after closing all tabs let's open the tabs found in the default config */
461 if (open_default && cl_options.load_session)
463 configuration_reload_default_session();
464 configuration_open_files();
465 document_new_file_if_non_open();
466 ui_focus_current_document();
469 g_signal_emit_by_name(geany_object, "project-close");
471 update_ui();
475 /* Shows the file chooser dialog when base path button is clicked
476 * FIXME: this should be connected in Glade but 3.8.1 has a bug
477 * where it won't pass any objects as user data (#588824). */
478 static void on_project_properties_base_path_button_clicked(GtkWidget *button,
479 GtkWidget *base_path_entry)
481 GtkWidget *dialog;
483 g_return_if_fail(base_path_entry != NULL);
484 g_return_if_fail(GTK_IS_WIDGET(base_path_entry));
486 dialog = gtk_file_chooser_dialog_new(_("Choose Project Base Path"),
487 NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
488 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
489 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
490 NULL);
492 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
494 gtk_entry_set_text(GTK_ENTRY(base_path_entry),
495 gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
498 gtk_widget_destroy(dialog);
502 static void insert_build_page(PropertyDialogElements *e)
504 GtkWidget *build_table, *label;
505 GeanyDocument *doc = document_get_current();
506 GeanyFiletype *ft = NULL;
508 if (doc != NULL)
509 ft = doc->file_type;
511 build_table = build_commands_table(doc, GEANY_BCS_PROJ, &(e->build_properties), ft);
512 gtk_container_set_border_width(GTK_CONTAINER(build_table), 6);
513 label = gtk_label_new(_("Build"));
514 e->build_page_num = gtk_notebook_append_page(GTK_NOTEBOOK(e->notebook),
515 build_table, label);
519 static void create_properties_dialog(PropertyDialogElements *e)
521 GtkWidget *wid;
522 static guint base_path_button_handler_id = 0;
523 static guint radio_long_line_handler_id = 0;
525 e->dialog = create_project_dialog();
526 e->notebook = ui_lookup_widget(e->dialog, "project_notebook");
527 e->file_name = ui_lookup_widget(e->dialog, "label_project_dialog_filename");
528 e->name = ui_lookup_widget(e->dialog, "entry_project_dialog_name");
529 e->description = ui_lookup_widget(e->dialog, "textview_project_dialog_description");
530 e->base_path = ui_lookup_widget(e->dialog, "entry_project_dialog_base_path");
531 e->patterns = ui_lookup_widget(e->dialog, "entry_project_dialog_file_patterns");
533 gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
535 ui_entry_add_clear_icon(GTK_ENTRY(e->name));
536 ui_entry_add_clear_icon(GTK_ENTRY(e->base_path));
537 ui_entry_add_clear_icon(GTK_ENTRY(e->patterns));
539 /* Workaround for bug in Glade 3.8.1, see comment above signal handler */
540 if (base_path_button_handler_id == 0)
542 wid = ui_lookup_widget(e->dialog, "button_project_dialog_base_path");
543 base_path_button_handler_id =
544 g_signal_connect(wid, "clicked",
545 G_CALLBACK(on_project_properties_base_path_button_clicked),
546 e->base_path);
549 /* Same as above, should be in Glade but can't due to bug in 3.8.1 */
550 if (radio_long_line_handler_id == 0)
552 wid = ui_lookup_widget(e->dialog, "radio_long_line_custom_project");
553 radio_long_line_handler_id =
554 g_signal_connect(wid, "toggled",
555 G_CALLBACK(on_radio_long_line_custom_toggled),
556 ui_lookup_widget(e->dialog, "spin_long_line_project"));
561 static void show_project_properties(gboolean show_build)
563 GeanyProject *p = app->project;
564 GtkWidget *widget = NULL;
565 GtkWidget *radio_long_line_custom;
566 static PropertyDialogElements e;
567 GSList *node;
568 gchar *entry_text;
569 GtkTextBuffer *buffer;
571 g_return_if_fail(app->project != NULL);
573 if (e.dialog == NULL)
574 create_properties_dialog(&e);
576 insert_build_page(&e);
578 foreach_slist(node, stash_groups)
579 stash_group_display(node->data, e.dialog);
581 /* fill the elements with the appropriate data */
582 gtk_entry_set_text(GTK_ENTRY(e.name), p->name);
583 gtk_label_set_text(GTK_LABEL(e.file_name), p->file_name);
584 gtk_entry_set_text(GTK_ENTRY(e.base_path), p->base_path);
586 radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project");
587 switch (p->priv->long_line_behaviour)
589 case 0: widget = ui_lookup_widget(e.dialog, "radio_long_line_disabled_project"); break;
590 case 1: widget = ui_lookup_widget(e.dialog, "radio_long_line_default_project"); break;
591 case 2: widget = radio_long_line_custom; break;
593 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
595 widget = ui_lookup_widget(e.dialog, "spin_long_line_project");
596 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->priv->long_line_column);
597 on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget);
599 /* set text */
600 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e.description));
601 gtk_text_buffer_set_text(buffer, p->description ? p->description : "", -1);
603 /* set the file patterns */
604 entry_text = p->file_patterns ? g_strjoinv(" ", p->file_patterns) : g_strdup("");
605 gtk_entry_set_text(GTK_ENTRY(e.patterns), entry_text);
606 g_free(entry_text);
608 g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook);
609 gtk_widget_show_all(e.dialog);
611 /* note: notebook page must be shown before setting current page */
612 if (show_build)
613 gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
614 else
615 gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), 0);
617 while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK)
619 if (update_config(&e, FALSE))
621 g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook);
622 if (!write_config())
623 SHOW_ERR(_("Project file could not be written"));
624 else
626 ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name);
627 break;
632 build_free_fields(e.build_properties);
633 g_signal_emit_by_name(geany_object, "project-dialog-close", e.notebook);
634 gtk_notebook_remove_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
635 gtk_widget_hide(e.dialog);
639 void project_properties(void)
641 show_project_properties(FALSE);
645 void project_build_properties(void)
647 show_project_properties(TRUE);
651 /* checks whether there is an already open project and asks the user if he wants to close it or
652 * abort the current action. Returns FALSE when the current action(the caller) should be cancelled
653 * and TRUE if we can go ahead */
654 gboolean project_ask_close(void)
656 if (app->project != NULL)
658 if (dialogs_show_question_full(NULL, GTK_STOCK_CLOSE, GTK_STOCK_CANCEL,
659 _("Do you want to close it before proceeding?"),
660 _("The '%s' project is open."), app->project->name))
662 return project_close(FALSE);
664 else
665 return FALSE;
667 else
668 return TRUE;
672 static GeanyProject *create_project(void)
674 GeanyProject *project = g_new0(GeanyProject, 1);
676 memset(&priv, 0, sizeof priv);
677 priv.indentation = &indentation;
678 project->priv = &priv;
680 init_stash_prefs();
682 project->file_patterns = NULL;
684 project->priv->long_line_behaviour = 1 /* use global settings */;
685 project->priv->long_line_column = editor_prefs.long_line_column;
687 app->project = project;
688 return project;
692 /* Verifies data for New & Properties dialogs.
693 * Creates app->project if NULL.
694 * Returns: FALSE if the user needs to change any data. */
695 static gboolean update_config(const PropertyDialogElements *e, gboolean new_project)
697 const gchar *name, *file_name, *base_path;
698 gchar *locale_filename;
699 gsize name_len;
700 gint err_code = 0;
701 GeanyProject *p;
703 g_return_val_if_fail(e != NULL, TRUE);
705 name = gtk_entry_get_text(GTK_ENTRY(e->name));
706 name_len = strlen(name);
707 if (name_len == 0)
709 SHOW_ERR(_("The specified project name is too short."));
710 gtk_widget_grab_focus(e->name);
711 return FALSE;
713 else if (name_len > MAX_NAME_LEN)
715 SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
716 gtk_widget_grab_focus(e->name);
717 return FALSE;
720 if (new_project)
721 file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
722 else
723 file_name = gtk_label_get_text(GTK_LABEL(e->file_name));
725 if (G_UNLIKELY(EMPTY(file_name)))
727 SHOW_ERR(_("You have specified an invalid project filename."));
728 gtk_widget_grab_focus(e->file_name);
729 return FALSE;
732 locale_filename = utils_get_locale_from_utf8(file_name);
733 base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
734 if (!EMPTY(base_path))
735 { /* check whether the given directory actually exists */
736 gchar *locale_path = utils_get_locale_from_utf8(base_path);
738 if (! g_path_is_absolute(locale_path))
739 { /* relative base path, so add base dir of project file name */
740 gchar *dir = g_path_get_dirname(locale_filename);
741 SETPTR(locale_path, g_build_filename(dir, locale_path, NULL));
742 g_free(dir);
745 if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
747 gboolean create_dir;
749 create_dir = dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
750 _("Create the project's base path directory?"),
751 _("The path \"%s\" does not exist."),
752 base_path);
754 if (create_dir)
755 err_code = utils_mkdir(locale_path, TRUE);
757 if (! create_dir || err_code != 0)
759 if (err_code != 0)
760 SHOW_ERR1(_("Project base directory could not be created (%s)."),
761 g_strerror(err_code));
762 gtk_widget_grab_focus(e->base_path);
763 utils_free_pointers(2, locale_path, locale_filename, NULL);
764 return FALSE;
767 g_free(locale_path);
769 /* finally test whether the given project file can be written */
770 if ((err_code = utils_is_file_writable(locale_filename)) != 0 ||
771 (err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0)
773 SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code));
774 gtk_widget_grab_focus(e->file_name);
775 g_free(locale_filename);
776 return FALSE;
778 else if (new_project && g_file_test(locale_filename, G_FILE_TEST_EXISTS) &&
779 ! dialogs_show_question_full(NULL, _("_Replace"), GTK_STOCK_CANCEL,
780 NULL,
781 _("The file '%s' already exists. Do you want to overwrite it?"),
782 file_name))
784 gtk_widget_grab_focus(e->file_name);
785 g_free(locale_filename);
786 return FALSE;
788 g_free(locale_filename);
790 if (app->project == NULL)
792 create_project();
793 new_project = TRUE;
795 p = app->project;
797 SETPTR(p->name, g_strdup(name));
798 SETPTR(p->file_name, g_strdup(file_name));
799 /* use "." if base_path is empty */
800 SETPTR(p->base_path, g_strdup(!EMPTY(base_path) ? base_path : "./"));
802 if (! new_project) /* save properties specific fields */
804 GtkTextIter start, end;
805 GtkTextBuffer *buffer;
806 GeanyDocument *doc = document_get_current();
807 GeanyBuildCommand *oldvalue;
808 GeanyFiletype *ft = doc ? doc->file_type : NULL;
809 GtkWidget *widget;
810 gchar *tmp;
811 GString *str;
812 GSList *node;
814 /* get and set the project description */
815 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
816 gtk_text_buffer_get_start_iter(buffer, &start);
817 gtk_text_buffer_get_end_iter(buffer, &end);
818 SETPTR(p->description, gtk_text_buffer_get_text(buffer, &start, &end, FALSE));
820 foreach_slist(node, stash_groups)
821 stash_group_update(node->data, e->dialog);
823 /* read the project build menu */
824 oldvalue = ft ? ft->priv->projfilecmds : NULL;
825 build_read_project(ft, e->build_properties);
827 if (ft != NULL && ft->priv->projfilecmds != oldvalue && ft->priv->project_list_entry < 0)
829 if (p->priv->build_filetypes_list == NULL)
830 p->priv->build_filetypes_list = g_ptr_array_new();
831 ft->priv->project_list_entry = p->priv->build_filetypes_list->len;
832 g_ptr_array_add(p->priv->build_filetypes_list, ft);
834 build_menu_update(doc);
836 widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project");
837 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
838 p->priv->long_line_behaviour = 0;
839 else
841 widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project");
842 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
843 p->priv->long_line_behaviour = 1;
844 else
845 /* "Custom" radio button must be checked */
846 p->priv->long_line_behaviour = 2;
849 widget = ui_lookup_widget(e->dialog, "spin_long_line_project");
850 p->priv->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
851 apply_editor_prefs();
853 /* get and set the project file patterns */
854 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns)));
855 g_strfreev(p->file_patterns);
856 g_strstrip(tmp);
857 str = g_string_new(tmp);
858 do {} while (utils_string_replace_all(str, " ", " "));
859 p->file_patterns = g_strsplit(str->str, " ", -1);
860 g_string_free(str, TRUE);
861 g_free(tmp);
864 update_ui();
866 return TRUE;
870 #ifndef G_OS_WIN32
871 static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
873 /* set filename in the file chooser dialog */
874 const gchar *utf8_filename = gtk_entry_get_text(GTK_ENTRY(entry));
875 gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
877 if (g_path_is_absolute(locale_filename))
879 if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
881 /* if the current filename is a directory, we must use
882 * gtk_file_chooser_set_current_folder(which expects a locale filename) otherwise
883 * we end up in the parent directory */
884 if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR))
885 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_filename);
886 else
887 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
889 else /* if the file doesn't yet exist, use at least the current directory */
891 gchar *locale_dir = g_path_get_dirname(locale_filename);
892 gchar *name = g_path_get_basename(utf8_filename);
894 if (g_file_test(locale_dir, G_FILE_TEST_EXISTS))
895 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dir);
896 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), name);
898 g_free(name);
899 g_free(locale_dir);
902 else if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
904 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), utf8_filename);
906 g_free(locale_filename);
908 /* run it */
909 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
911 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
912 gchar *tmp_utf8_filename = utils_get_utf8_from_locale(filename);
914 gtk_entry_set_text(GTK_ENTRY(entry), tmp_utf8_filename);
916 g_free(tmp_utf8_filename);
917 g_free(filename);
919 gtk_widget_destroy(dialog);
921 #endif
924 static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e)
926 #ifdef G_OS_WIN32
927 gchar *path = win32_show_project_open_dialog(e->dialog, _("Choose Project Filename"),
928 gtk_entry_get_text(GTK_ENTRY(e->file_name)), TRUE, TRUE);
929 if (path != NULL)
931 gtk_entry_set_text(GTK_ENTRY(e->file_name), path);
932 g_free(path);
934 #else
935 GtkWidget *dialog;
937 /* initialise the dialog */
938 dialog = gtk_file_chooser_dialog_new(_("Choose Project Filename"), NULL,
939 GTK_FILE_CHOOSER_ACTION_SAVE,
940 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
941 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
942 gtk_widget_set_name(dialog, "GeanyDialogProject");
943 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
944 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
945 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
946 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
948 run_dialog(dialog, e->file_name);
949 #endif
953 /* sets the project base path and the project file name according to the project name */
954 static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
956 gchar *base_path;
957 gchar *file_name;
958 gchar *name;
959 const gchar *project_dir = local_prefs.project_file_path;
961 if (e->entries_modified)
962 return;
964 name = gtk_editable_get_chars(editable, 0, -1);
965 if (!EMPTY(name))
967 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
968 name, G_DIR_SEPARATOR_S, NULL);
969 if (project_prefs.project_file_in_basedir)
970 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, name, G_DIR_SEPARATOR_S,
971 name, "." GEANY_PROJECT_EXT, NULL);
972 else
973 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
974 name, "." GEANY_PROJECT_EXT, NULL);
976 else
978 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
979 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
981 g_free(name);
983 gtk_entry_set_text(GTK_ENTRY(e->base_path), base_path);
984 gtk_entry_set_text(GTK_ENTRY(e->file_name), file_name);
986 e->entries_modified = FALSE;
988 g_free(base_path);
989 g_free(file_name);
993 static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
995 e->entries_modified = TRUE;
999 static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line)
1001 gtk_widget_set_sensitive(spin_long_line, gtk_toggle_button_get_active(radio));
1005 gboolean project_load_file(const gchar *locale_file_name)
1007 g_return_val_if_fail(locale_file_name != NULL, FALSE);
1009 if (load_config(locale_file_name))
1011 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1013 ui_set_statusbar(TRUE, _("Project \"%s\" opened."), app->project->name);
1015 ui_add_recent_project_file(utf8_filename);
1016 g_free(utf8_filename);
1017 return TRUE;
1019 else
1021 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1023 ui_set_statusbar(TRUE, _("Project file \"%s\" could not be loaded."), utf8_filename);
1024 g_free(utf8_filename);
1026 return FALSE;
1030 /* Reads the given filename and creates a new project with the data found in the file.
1031 * At this point there should not be an already opened project in Geany otherwise it will just
1032 * return.
1033 * The filename is expected in the locale encoding. */
1034 static gboolean load_config(const gchar *filename)
1036 GKeyFile *config;
1037 GeanyProject *p;
1038 GSList *node;
1040 /* there should not be an open project */
1041 g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
1043 config = g_key_file_new();
1044 if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL))
1046 g_key_file_free(config);
1047 return FALSE;
1050 p = create_project();
1052 foreach_slist(node, stash_groups)
1053 stash_group_load_from_key_file(node->data, config);
1055 p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED);
1056 p->description = utils_get_setting_string(config, "project", "description", "");
1057 p->file_name = utils_get_utf8_from_locale(filename);
1058 p->base_path = utils_get_setting_string(config, "project", "base_path", "");
1059 p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
1061 p->priv->long_line_behaviour = utils_get_setting_integer(config, "long line marker",
1062 "long_line_behaviour", 1 /* follow global */);
1063 p->priv->long_line_column = utils_get_setting_integer(config, "long line marker",
1064 "long_line_column", editor_prefs.long_line_column);
1065 apply_editor_prefs();
1067 build_load_menu(config, GEANY_BCS_PROJ, (gpointer)p);
1068 if (project_prefs.project_session)
1070 /* save current (non-project) session (it could have been changed since program startup) */
1071 configuration_save_default_session();
1072 /* now close all open files */
1073 document_close_all();
1074 /* read session files so they can be opened with configuration_open_files() */
1075 configuration_load_session_files(config, FALSE);
1077 g_signal_emit_by_name(geany_object, "project-open", config);
1078 g_key_file_free(config);
1080 update_ui();
1081 return TRUE;
1085 static void apply_editor_prefs(void)
1087 guint i;
1089 foreach_document(i)
1090 editor_apply_update_prefs(documents[i]->editor);
1094 /* Write the project settings as well as the project session files into its configuration files.
1095 * Returns: TRUE if project file was written successfully. */
1096 static gboolean write_config(void)
1098 GeanyProject *p;
1099 GKeyFile *config;
1100 gchar *filename;
1101 gchar *data;
1102 gboolean ret = FALSE;
1103 GSList *node;
1105 g_return_val_if_fail(app->project != NULL, FALSE);
1107 p = app->project;
1109 config = g_key_file_new();
1110 /* try to load an existing config to keep manually added comments */
1111 filename = utils_get_locale_from_utf8(p->file_name);
1112 g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
1114 foreach_slist(node, stash_groups)
1115 stash_group_save_to_key_file(node->data, config);
1117 g_key_file_set_string(config, "project", "name", p->name);
1118 g_key_file_set_string(config, "project", "base_path", p->base_path);
1120 if (p->description)
1121 g_key_file_set_string(config, "project", "description", p->description);
1122 if (p->file_patterns)
1123 g_key_file_set_string_list(config, "project", "file_patterns",
1124 (const gchar**) p->file_patterns, g_strv_length(p->file_patterns));
1126 // editor settings
1127 g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->priv->long_line_behaviour);
1128 g_key_file_set_integer(config, "long line marker", "long_line_column", p->priv->long_line_column);
1130 /* store the session files into the project too */
1131 if (project_prefs.project_session)
1132 configuration_save_session_files(config);
1133 build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ);
1134 g_signal_emit_by_name(geany_object, "project-save", config);
1135 /* write the file */
1136 data = g_key_file_to_data(config, NULL, NULL);
1137 ret = (utils_write_file(filename, data) == 0);
1139 g_free(data);
1140 g_free(filename);
1141 g_key_file_free(config);
1143 return ret;
1147 /** Forces the project file rewrite and emission of the project-save signal. Plugins
1148 * can use this function to save additional project data outside the project dialog.
1150 * @since 1.25
1152 GEANY_API_SYMBOL
1153 void project_write_config(void)
1155 if (!write_config())
1156 SHOW_ERR(_("Project file could not be written"));
1160 /* Constructs the project's base path which is used for "Make all" and "Execute".
1161 * The result is an absolute string in UTF-8 encoding which is either the same as
1162 * base path if it is absolute or it is built out of project file name's dir and base_path.
1163 * If there is no project or project's base_path is invalid, NULL will be returned.
1164 * The returned string should be freed when no longer needed. */
1165 gchar *project_get_base_path(void)
1167 GeanyProject *project = app->project;
1169 if (project && !EMPTY(project->base_path))
1171 if (g_path_is_absolute(project->base_path))
1172 return g_strdup(project->base_path);
1173 else
1174 { /* build base_path out of project file name's dir and base_path */
1175 gchar *path;
1176 gchar *dir = g_path_get_dirname(project->file_name);
1178 if (utils_str_equal(project->base_path, "./"))
1179 return dir;
1181 path = g_build_filename(dir, project->base_path, NULL);
1182 g_free(dir);
1183 return path;
1186 return NULL;
1190 /* This is to save project-related global settings, NOT project file settings. */
1191 void project_save_prefs(GKeyFile *config)
1193 GeanyProject *project = app->project;
1195 if (cl_options.load_session)
1197 const gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
1199 g_key_file_set_string(config, "project", "session_file", utf8_filename);
1201 g_key_file_set_string(config, "project", "project_file_path",
1202 FALLBACK(local_prefs.project_file_path, ""));
1206 void project_load_prefs(GKeyFile *config)
1208 if (cl_options.load_session)
1210 g_return_if_fail(project_prefs.session_file == NULL);
1211 project_prefs.session_file = utils_get_setting_string(config, "project",
1212 "session_file", "");
1214 local_prefs.project_file_path = utils_get_setting_string(config, "project",
1215 "project_file_path", NULL);
1216 if (local_prefs.project_file_path == NULL)
1218 local_prefs.project_file_path = g_build_filename(g_get_home_dir(), PROJECT_DIR, NULL);
1223 /* Initialize project-related preferences in the Preferences dialog. */
1224 void project_setup_prefs(void)
1226 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1227 GtkWidget *path_btn = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_button");
1228 static gboolean callback_setup = FALSE;
1230 g_return_if_fail(local_prefs.project_file_path != NULL);
1232 gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
1233 if (! callback_setup)
1234 { /* connect the callback only once */
1235 callback_setup = TRUE;
1236 ui_setup_open_button_callback(path_btn, NULL,
1237 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(path_entry));
1242 /* Update project-related preferences after using the Preferences dialog. */
1243 void project_apply_prefs(void)
1245 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1246 const gchar *str;
1248 str = gtk_entry_get_text(GTK_ENTRY(path_entry));
1249 SETPTR(local_prefs.project_file_path, g_strdup(str));
1253 static void add_stash_group(StashGroup *group, gboolean apply_defaults)
1255 GKeyFile *kf;
1257 stash_groups = g_slist_prepend(stash_groups, group);
1258 if (!apply_defaults)
1259 return;
1261 kf = g_key_file_new();
1262 stash_group_load_from_key_file(group, kf);
1263 g_key_file_free(kf);
1267 static void init_stash_prefs(void)
1269 StashGroup *group;
1271 group = stash_group_new("indentation");
1272 /* copy global defaults */
1273 indentation = *editor_get_indent_prefs(NULL);
1274 stash_group_set_use_defaults(group, FALSE);
1275 add_stash_group(group, FALSE);
1277 stash_group_add_spin_button_integer(group, &indentation.width,
1278 "indent_width", 4, "spin_indent_width_project");
1279 stash_group_add_radio_buttons(group, (gint*)(gpointer)&indentation.type,
1280 "indent_type", GEANY_INDENT_TYPE_TABS,
1281 "radio_indent_spaces_project", GEANY_INDENT_TYPE_SPACES,
1282 "radio_indent_tabs_project", GEANY_INDENT_TYPE_TABS,
1283 "radio_indent_both_project", GEANY_INDENT_TYPE_BOTH,
1284 NULL);
1285 /* This is a 'hidden' pref for backwards-compatibility */
1286 stash_group_add_integer(group, &indentation.hard_tab_width,
1287 "indent_hard_tab_width", 8);
1288 stash_group_add_toggle_button(group, &indentation.detect_type,
1289 "detect_indent", FALSE, "check_detect_indent_type_project");
1290 stash_group_add_toggle_button(group, &indentation.detect_width,
1291 "detect_indent_width", FALSE, "check_detect_indent_width_project");
1292 stash_group_add_combo_box(group, (gint*)(gpointer)&indentation.auto_indent_mode,
1293 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project");
1295 group = stash_group_new("file_prefs");
1296 stash_group_add_toggle_button(group, &priv.final_new_line,
1297 "final_new_line", file_prefs.final_new_line, "check_new_line1");
1298 stash_group_add_toggle_button(group, &priv.ensure_convert_new_lines,
1299 "ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1");
1300 stash_group_add_toggle_button(group, &priv.strip_trailing_spaces,
1301 "strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
1302 stash_group_add_toggle_button(group, &priv.replace_tabs,
1303 "replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
1304 add_stash_group(group, TRUE);
1306 group = stash_group_new("editor");
1307 stash_group_add_toggle_button(group, &priv.line_wrapping,
1308 "line_wrapping", editor_prefs.line_wrapping, "check_line_wrapping1");
1309 stash_group_add_spin_button_integer(group, &priv.line_break_column,
1310 "line_break_column", editor_prefs.line_break_column, "spin_line_break1");
1311 stash_group_add_toggle_button(group, &priv.auto_continue_multiline,
1312 "auto_continue_multiline", editor_prefs.auto_continue_multiline,
1313 "check_auto_multiline1");
1314 add_stash_group(group, TRUE);
1318 #define COPY_PREF(dest, prefname)\
1319 (dest.prefname = priv.prefname)
1321 const GeanyFilePrefs *project_get_file_prefs(void)
1323 static GeanyFilePrefs fp;
1325 if (!app->project)
1326 return &file_prefs;
1328 fp = file_prefs;
1329 COPY_PREF(fp, final_new_line);
1330 COPY_PREF(fp, ensure_convert_new_lines);
1331 COPY_PREF(fp, strip_trailing_spaces);
1332 COPY_PREF(fp, replace_tabs);
1333 return &fp;
1337 void project_init(void)
1342 void project_finalize(void)