Bump API version for the Scintilla 5.1.5 change
[geany-mirror.git] / src / project.c
blob7a19990648e3b8b32ed58f83fcc159a36c01c896
1 /*
2 * project.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /** @file project.h
22 * Project Management.
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include "project.h"
31 #include "app.h"
32 #include "build.h"
33 #include "dialogs.h"
34 #include "document.h"
35 #include "editor.h"
36 #include "filetypesprivate.h"
37 #include "geanyobject.h"
38 #include "keyfile.h"
39 #include "main.h"
40 #include "projectprivate.h"
41 #include "sidebar.h"
42 #include "stash.h"
43 #include "support.h"
44 #include "ui_utils.h"
45 #include "utils.h"
46 #include "win32.h"
48 #include <string.h>
49 #include <unistd.h>
50 #include <errno.h>
53 ProjectPrefs project_prefs = { NULL, FALSE, FALSE };
56 static GeanyProjectPrivate priv;
57 static GeanyIndentPrefs indentation;
59 static GSList *stash_groups = NULL;
61 static struct
63 gchar *project_file_path; /* in UTF-8 */
64 } local_prefs = { NULL };
66 /* simple struct to keep references to the elements of the properties dialog */
67 typedef struct _PropertyDialogElements
69 GtkWidget *dialog;
70 GtkWidget *notebook;
71 GtkWidget *name;
72 GtkWidget *description;
73 GtkWidget *file_name;
74 GtkWidget *base_path;
75 GtkWidget *patterns;
76 BuildTableData build_properties;
77 gint build_page_num;
78 gboolean entries_modified;
79 } PropertyDialogElements;
82 static gboolean update_config(const PropertyDialogElements *e, gboolean new_project);
83 static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e);
84 static gboolean load_config(const gchar *filename);
85 static gboolean write_config(void);
86 static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e);
87 static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e);
88 static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line);
89 static void run_new_dialog(PropertyDialogElements *e);
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 static gboolean handle_current_session(void)
115 if (!app->project && project_prefs.project_session)
117 /* save session in case the dialog is cancelled */
118 configuration_save_default_session();
119 /* don't ask if the only doc is an unmodified new doc */
120 if (have_session_docs())
122 if (dialogs_show_question(
123 _("Move the current documents into the new project's session?")))
125 // don't reload session on closing project
126 configuration_clear_default_session();
128 else
130 if (!document_close_all())
131 return FALSE;
135 if (app->project)
136 return project_close(FALSE);
137 return TRUE;
141 /* TODO: this should be ported to Glade like the project preferences dialog,
142 * then we can get rid of the PropertyDialogElements struct altogether as
143 * widgets pointers can be accessed through ui_lookup_widget(). */
144 void project_new(void)
146 GtkWidget *vbox;
147 GtkWidget *table;
148 GtkWidget *image;
149 GtkWidget *button;
150 GtkWidget *bbox;
151 GtkWidget *label;
152 gchar *tooltip;
153 PropertyDialogElements e = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, FALSE };
155 e.dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(main_widgets.window),
156 GTK_DIALOG_DESTROY_WITH_PARENT,
157 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
159 gtk_widget_set_name(e.dialog, "GeanyDialogProject");
160 button = ui_button_new_with_image(GTK_STOCK_NEW, _("C_reate"));
161 gtk_widget_set_can_default(button, TRUE);
162 gtk_window_set_default(GTK_WINDOW(e.dialog), button);
163 gtk_dialog_add_action_widget(GTK_DIALOG(e.dialog), button, GTK_RESPONSE_OK);
165 vbox = ui_dialog_vbox_new(GTK_DIALOG(e.dialog));
167 table = gtk_table_new(3, 2, FALSE);
168 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
169 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
171 label = gtk_label_new(_("Name:"));
172 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
174 e.name = gtk_entry_new();
175 gtk_entry_set_activates_default(GTK_ENTRY(e.name), TRUE);
176 ui_entry_add_clear_icon(GTK_ENTRY(e.name));
177 gtk_entry_set_max_length(GTK_ENTRY(e.name), MAX_NAME_LEN);
178 gtk_widget_set_tooltip_text(e.name, _("Project name"));
180 ui_table_add_row(GTK_TABLE(table), 0, label, e.name, NULL);
182 label = gtk_label_new(_("Filename:"));
183 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
185 e.file_name = gtk_entry_new();
186 gtk_entry_set_activates_default(GTK_ENTRY(e.file_name), TRUE);
187 ui_entry_add_clear_icon(GTK_ENTRY(e.file_name));
188 gtk_entry_set_width_chars(GTK_ENTRY(e.file_name), 30);
189 tooltip = g_strdup_printf(
190 _("Path of the file representing the project and storing its settings. "
191 "It should normally have the \"%s\" extension."), "."GEANY_PROJECT_EXT);
192 gtk_widget_set_tooltip_text(e.file_name, tooltip);
193 g_free(tooltip);
194 button = gtk_button_new();
195 g_signal_connect(button, "clicked", G_CALLBACK(on_file_save_button_clicked), &e);
196 image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
197 gtk_container_add(GTK_CONTAINER(button), image);
198 bbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
199 gtk_box_pack_start(GTK_BOX(bbox), e.file_name, TRUE, TRUE, 0);
200 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
202 ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);
204 label = gtk_label_new(_("Base path:"));
205 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
207 e.base_path = gtk_entry_new();
208 gtk_entry_set_activates_default(GTK_ENTRY(e.base_path), TRUE);
209 ui_entry_add_clear_icon(GTK_ENTRY(e.base_path));
210 gtk_widget_set_tooltip_text(e.base_path,
211 _("Base directory of all files that make up the project. "
212 "This can be a new path, or an existing directory tree. "
213 "You can use paths relative to the project filename."));
214 bbox = ui_path_box_new(_("Choose Project Base Path"),
215 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e.base_path));
217 ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);
219 gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
221 /* signals */
222 g_signal_connect(e.name, "changed", G_CALLBACK(on_name_entry_changed), &e);
223 /* run the callback manually to initialise the base_path and file_name fields */
224 on_name_entry_changed(GTK_EDITABLE(e.name), &e);
226 g_signal_connect(e.file_name, "changed", G_CALLBACK(on_entries_changed), &e);
227 g_signal_connect(e.base_path, "changed", G_CALLBACK(on_entries_changed), &e);
229 gtk_widget_show_all(e.dialog);
230 run_new_dialog(&e);
231 gtk_widget_destroy(e.dialog);
232 document_new_file_if_non_open();
233 ui_focus_current_document();
237 static void run_new_dialog(PropertyDialogElements *e)
239 if (gtk_dialog_run(GTK_DIALOG(e->dialog)) != GTK_RESPONSE_OK ||
240 !handle_current_session())
241 return;
244 if (update_config(e, TRUE))
246 // app->project is now set
247 if (!write_config())
249 SHOW_ERR(_("Project file could not be written"));
250 destroy_project(FALSE);
252 else
254 ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name);
255 ui_add_recent_project_file(app->project->file_name);
256 return;
260 while (gtk_dialog_run(GTK_DIALOG(e->dialog)) == GTK_RESPONSE_OK);
261 // any open docs were meant to be moved into the project
262 // rewrite default session because it was cleared
263 if (have_session_docs())
264 configuration_save_default_session();
265 else
267 // reload any documents that were closed
268 configuration_reload_default_session();
269 configuration_open_files();
274 gboolean project_load_file_with_session(const gchar *locale_file_name)
276 if (project_load_file(locale_file_name))
278 if (project_prefs.project_session)
280 configuration_open_files();
281 document_new_file_if_non_open();
282 ui_focus_current_document();
284 return TRUE;
286 return FALSE;
290 static void run_open_dialog(GtkDialog *dialog)
292 while (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT)
294 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
296 if (app->project && !project_close(FALSE)) {}
297 /* try to load the config */
298 else if (! project_load_file_with_session(filename))
300 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
302 SHOW_ERR1(_("Project file \"%s\" could not be loaded."), utf8_filename);
303 gtk_widget_grab_focus(GTK_WIDGET(dialog));
304 g_free(utf8_filename);
305 g_free(filename);
306 continue;
308 g_free(filename);
309 break;
314 void project_open(void)
316 const gchar *dir = local_prefs.project_file_path;
318 #ifdef G_OS_WIN32
319 if (interface_prefs.use_native_windows_dialogs)
321 gchar *file = win32_show_project_open_dialog(main_widgets.window, _("Open Project"), dir, FALSE, TRUE);
322 if (file != NULL)
324 if (app->project && !project_close(FALSE)) {}
325 /* try to load the config */
326 else if (! project_load_file_with_session(file))
328 SHOW_ERR1(_("Project file \"%s\" could not be loaded."), file);
330 g_free(file);
333 else
334 #endif
336 GtkWidget *dialog;
337 GtkFileFilter *filter;
338 gchar *locale_path;
340 dialog = gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(main_widgets.window),
341 GTK_FILE_CHOOSER_ACTION_OPEN,
342 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
343 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
344 gtk_widget_set_name(dialog, "GeanyDialogProject");
346 /* set default Open, so pressing enter can open multiple files */
347 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
348 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
349 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
350 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
351 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window));
352 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
354 /* add FileFilters */
355 filter = gtk_file_filter_new();
356 gtk_file_filter_set_name(filter, _("All files"));
357 gtk_file_filter_add_pattern(filter, "*");
358 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
359 filter = gtk_file_filter_new();
360 gtk_file_filter_set_name(filter, _("Project files"));
361 gtk_file_filter_add_pattern(filter, "*." GEANY_PROJECT_EXT);
362 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
363 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
365 locale_path = utils_get_locale_from_utf8(dir);
366 if (g_file_test(locale_path, G_FILE_TEST_EXISTS) &&
367 g_file_test(locale_path, G_FILE_TEST_IS_DIR))
369 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
371 g_free(locale_path);
373 gtk_widget_show_all(dialog);
374 run_open_dialog(GTK_DIALOG(dialog));
375 gtk_widget_destroy(GTK_WIDGET(dialog));
380 /* Called when creating, opening, closing and updating projects. */
381 static void update_ui(void)
383 if (main_status.quitting)
384 return;
386 ui_set_window_title(NULL);
387 build_menu_update(NULL);
388 // update project name
389 sidebar_openfiles_update_all();
390 ui_update_recent_project_menu();
394 static void remove_foreach_project_filetype(gpointer data, gpointer user_data)
396 GeanyFiletype *ft = data;
397 if (ft != NULL)
399 SETPTR(ft->priv->projfilecmds, NULL);
400 SETPTR(ft->priv->projexeccmds, NULL);
401 SETPTR(ft->priv->projerror_regex_string, NULL);
402 ft->priv->project_list_entry = -1;
407 /* open_default will make function reload default session files on close */
408 gboolean project_close(gboolean open_default)
410 g_return_val_if_fail(app->project != NULL, FALSE);
412 /* save project session files, etc */
413 if (!write_config())
414 g_warning("Project file \"%s\" could not be written", app->project->file_name);
416 if (project_prefs.project_session)
418 /* close all existing tabs first */
419 if (!document_close_all())
420 return FALSE;
422 ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
423 destroy_project(open_default);
424 return TRUE;
428 static void destroy_project(gboolean open_default)
430 GSList *node;
432 g_return_if_fail(app->project != NULL);
434 g_signal_emit_by_name(geany_object, "project-before-close");
436 /* remove project filetypes build entries */
437 if (app->project->priv->build_filetypes_list != NULL)
439 g_ptr_array_foreach(app->project->priv->build_filetypes_list, remove_foreach_project_filetype, NULL);
440 g_ptr_array_free(app->project->priv->build_filetypes_list, FALSE);
443 /* remove project non filetype build menu items */
444 build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_NON_FT, -1);
445 build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_EXEC, -1);
447 g_free(app->project->name);
448 g_free(app->project->description);
449 g_free(app->project->file_name);
450 g_free(app->project->base_path);
451 g_strfreev(app->project->file_patterns);
453 g_free(app->project);
454 app->project = NULL;
456 foreach_slist(node, stash_groups)
457 stash_group_free(node->data);
459 g_slist_free(stash_groups);
460 stash_groups = NULL;
462 apply_editor_prefs(); /* ensure that global settings are restored */
464 if (project_prefs.project_session)
466 /* after closing all tabs let's open the tabs found in the default config */
467 if (open_default && cl_options.load_session)
469 configuration_reload_default_session();
470 configuration_open_files();
471 document_new_file_if_non_open();
472 ui_focus_current_document();
475 g_signal_emit_by_name(geany_object, "project-close");
477 update_ui();
481 /* Shows the file chooser dialog when base path button is clicked
482 * FIXME: this should be connected in Glade but 3.8.1 has a bug
483 * where it won't pass any objects as user data (#588824). */
484 static void on_project_properties_base_path_button_clicked(GtkWidget *button,
485 GtkWidget *base_path_entry)
487 GtkWidget *dialog;
489 g_return_if_fail(base_path_entry != NULL);
490 g_return_if_fail(GTK_IS_WIDGET(base_path_entry));
492 dialog = gtk_file_chooser_dialog_new(_("Choose Project Base Path"),
493 NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
494 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
495 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
496 NULL);
498 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
500 gtk_entry_set_text(GTK_ENTRY(base_path_entry),
501 gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
504 gtk_widget_destroy(dialog);
508 static void insert_build_page(PropertyDialogElements *e)
510 GtkWidget *build_table, *label;
511 GeanyDocument *doc = document_get_current();
512 GeanyFiletype *ft = NULL;
514 if (doc != NULL)
515 ft = doc->file_type;
517 build_table = build_commands_table(doc, GEANY_BCS_PROJ, &(e->build_properties), ft);
518 gtk_container_set_border_width(GTK_CONTAINER(build_table), 6);
519 label = gtk_label_new(_("Build"));
520 e->build_page_num = gtk_notebook_append_page(GTK_NOTEBOOK(e->notebook),
521 build_table, label);
525 static void create_properties_dialog(PropertyDialogElements *e)
527 GtkWidget *wid;
528 static guint base_path_button_handler_id = 0;
529 static guint radio_long_line_handler_id = 0;
531 e->dialog = create_project_dialog();
532 e->notebook = ui_lookup_widget(e->dialog, "project_notebook");
533 e->file_name = ui_lookup_widget(e->dialog, "label_project_dialog_filename");
534 e->name = ui_lookup_widget(e->dialog, "entry_project_dialog_name");
535 e->description = ui_lookup_widget(e->dialog, "textview_project_dialog_description");
536 e->base_path = ui_lookup_widget(e->dialog, "entry_project_dialog_base_path");
537 e->patterns = ui_lookup_widget(e->dialog, "entry_project_dialog_file_patterns");
539 gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
541 ui_entry_add_clear_icon(GTK_ENTRY(e->name));
542 ui_entry_add_clear_icon(GTK_ENTRY(e->base_path));
543 ui_entry_add_clear_icon(GTK_ENTRY(e->patterns));
545 /* Workaround for bug in Glade 3.8.1, see comment above signal handler */
546 if (base_path_button_handler_id == 0)
548 wid = ui_lookup_widget(e->dialog, "button_project_dialog_base_path");
549 base_path_button_handler_id =
550 g_signal_connect(wid, "clicked",
551 G_CALLBACK(on_project_properties_base_path_button_clicked),
552 e->base_path);
555 /* Same as above, should be in Glade but can't due to bug in 3.8.1 */
556 if (radio_long_line_handler_id == 0)
558 wid = ui_lookup_widget(e->dialog, "radio_long_line_custom_project");
559 radio_long_line_handler_id =
560 g_signal_connect(wid, "toggled",
561 G_CALLBACK(on_radio_long_line_custom_toggled),
562 ui_lookup_widget(e->dialog, "spin_long_line_project"));
567 static void show_project_properties(gboolean show_build)
569 GeanyProject *p = app->project;
570 GtkWidget *widget = NULL;
571 GtkWidget *radio_long_line_custom;
572 static PropertyDialogElements e;
573 GSList *node;
574 gchar *entry_text;
575 GtkTextBuffer *buffer;
577 g_return_if_fail(app->project != NULL);
579 if (e.dialog == NULL)
580 create_properties_dialog(&e);
582 insert_build_page(&e);
584 foreach_slist(node, stash_groups)
585 stash_group_display(node->data, e.dialog);
587 /* fill the elements with the appropriate data */
588 gtk_entry_set_text(GTK_ENTRY(e.name), p->name);
589 gtk_label_set_text(GTK_LABEL(e.file_name), p->file_name);
590 gtk_entry_set_text(GTK_ENTRY(e.base_path), p->base_path);
592 radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project");
593 switch (p->priv->long_line_behaviour)
595 case 0: widget = ui_lookup_widget(e.dialog, "radio_long_line_disabled_project"); break;
596 case 1: widget = ui_lookup_widget(e.dialog, "radio_long_line_default_project"); break;
597 case 2: widget = radio_long_line_custom; break;
599 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
601 widget = ui_lookup_widget(e.dialog, "spin_long_line_project");
602 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->priv->long_line_column);
603 on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget);
605 /* set text */
606 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e.description));
607 gtk_text_buffer_set_text(buffer, p->description ? p->description : "", -1);
609 /* set the file patterns */
610 entry_text = p->file_patterns ? g_strjoinv(" ", p->file_patterns) : g_strdup("");
611 gtk_entry_set_text(GTK_ENTRY(e.patterns), entry_text);
612 g_free(entry_text);
614 g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook);
615 gtk_widget_show_all(e.dialog);
617 /* note: notebook page must be shown before setting current page */
618 if (show_build)
619 gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
620 else
621 gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), 0);
623 while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK)
625 if (update_config(&e, FALSE))
627 g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook);
628 if (!write_config())
629 SHOW_ERR(_("Project file could not be written"));
630 else
632 ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name);
633 break;
638 build_free_fields(e.build_properties);
639 g_signal_emit_by_name(geany_object, "project-dialog-close", e.notebook);
640 gtk_notebook_remove_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
641 gtk_widget_hide(e.dialog);
645 void project_properties(void)
647 show_project_properties(FALSE);
651 void project_build_properties(void)
653 show_project_properties(TRUE);
657 /* checks whether there is an already open project and asks the user if he wants to close it or
658 * abort the current action. Returns FALSE when the current action(the caller) should be cancelled
659 * and TRUE if we can go ahead */
660 gboolean project_ask_close(void)
662 if (app->project != NULL)
664 if (!interface_prefs.warn_on_project_close ||
665 dialogs_show_question_full(NULL, GTK_STOCK_CLOSE, GTK_STOCK_CANCEL,
666 _("Do you want to close it before proceeding?"),
667 _("The '%s' project is open."), app->project->name))
669 return project_close(FALSE);
671 else
672 return FALSE;
674 else
675 return TRUE;
679 static GeanyProject *create_project(void)
681 GeanyProject *project = g_new0(GeanyProject, 1);
683 memset(&priv, 0, sizeof priv);
684 priv.indentation = &indentation;
685 project->priv = &priv;
687 init_stash_prefs();
689 project->file_patterns = NULL;
691 project->priv->long_line_behaviour = 1 /* use global settings */;
692 project->priv->long_line_column = editor_prefs.long_line_column;
694 app->project = project;
695 return project;
699 /* Verifies data for New & Properties dialogs.
700 * Creates app->project if NULL.
701 * Returns: FALSE if the user needs to change any data. */
702 static gboolean update_config(const PropertyDialogElements *e, gboolean new_project)
704 const gchar *name, *file_name, *base_path;
705 gchar *locale_filename;
706 gsize name_len;
707 gint err_code = 0;
708 GeanyProject *p;
710 g_return_val_if_fail(e != NULL, TRUE);
712 name = gtk_entry_get_text(GTK_ENTRY(e->name));
713 name_len = strlen(name);
714 if (name_len == 0)
716 SHOW_ERR(_("The specified project name is too short."));
717 gtk_widget_grab_focus(e->name);
718 return FALSE;
720 else if (name_len > MAX_NAME_LEN)
722 SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
723 gtk_widget_grab_focus(e->name);
724 return FALSE;
727 if (new_project)
728 file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
729 else
730 file_name = gtk_label_get_text(GTK_LABEL(e->file_name));
732 if (G_UNLIKELY(EMPTY(file_name)))
734 SHOW_ERR(_("You have specified an invalid project filename."));
735 gtk_widget_grab_focus(e->file_name);
736 return FALSE;
739 locale_filename = utils_get_locale_from_utf8(file_name);
740 base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
741 if (!EMPTY(base_path))
742 { /* check whether the given directory actually exists */
743 gchar *locale_path = utils_get_locale_from_utf8(base_path);
745 if (! g_path_is_absolute(locale_path))
746 { /* relative base path, so add base dir of project file name */
747 gchar *dir = g_path_get_dirname(locale_filename);
748 SETPTR(locale_path, g_build_filename(dir, locale_path, NULL));
749 g_free(dir);
752 if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
754 gboolean create_dir;
756 create_dir = dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
757 _("Create the project's base path directory?"),
758 _("The path \"%s\" does not exist."),
759 base_path);
761 if (create_dir)
762 err_code = utils_mkdir(locale_path, TRUE);
764 if (! create_dir || err_code != 0)
766 if (err_code != 0)
767 SHOW_ERR1(_("Project base directory could not be created (%s)."),
768 g_strerror(err_code));
769 gtk_widget_grab_focus(e->base_path);
770 utils_free_pointers(2, locale_path, locale_filename, NULL);
771 return FALSE;
774 g_free(locale_path);
776 /* finally test whether the given project file can be written */
777 if ((err_code = utils_is_file_writable(locale_filename)) != 0 ||
778 (err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0)
780 SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code));
781 gtk_widget_grab_focus(e->file_name);
782 g_free(locale_filename);
783 return FALSE;
785 else if (new_project && g_file_test(locale_filename, G_FILE_TEST_EXISTS) &&
786 ! dialogs_show_question_full(NULL, _("_Replace"), GTK_STOCK_CANCEL,
787 NULL,
788 _("The file '%s' already exists. Do you want to overwrite it?"),
789 file_name))
791 gtk_widget_grab_focus(e->file_name);
792 g_free(locale_filename);
793 return FALSE;
795 g_free(locale_filename);
797 if (app->project == NULL)
799 create_project();
800 new_project = TRUE;
802 p = app->project;
804 SETPTR(p->name, g_strdup(name));
805 SETPTR(p->file_name, g_strdup(file_name));
806 /* use "." if base_path is empty */
807 SETPTR(p->base_path, g_strdup(!EMPTY(base_path) ? base_path : "./"));
809 if (! new_project) /* save properties specific fields */
811 GtkTextIter start, end;
812 GtkTextBuffer *buffer;
813 GeanyDocument *doc = document_get_current();
814 GeanyBuildCommand *oldvalue;
815 GeanyFiletype *ft = doc ? doc->file_type : NULL;
816 GtkWidget *widget;
817 gchar *tmp;
818 GString *str;
819 GSList *node;
821 /* get and set the project description */
822 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
823 gtk_text_buffer_get_start_iter(buffer, &start);
824 gtk_text_buffer_get_end_iter(buffer, &end);
825 SETPTR(p->description, gtk_text_buffer_get_text(buffer, &start, &end, FALSE));
827 foreach_slist(node, stash_groups)
828 stash_group_update(node->data, e->dialog);
830 /* read the project build menu */
831 oldvalue = ft ? ft->priv->projfilecmds : NULL;
832 build_read_project(ft, e->build_properties);
834 if (ft != NULL && ft->priv->projfilecmds != oldvalue && ft->priv->project_list_entry < 0)
836 if (p->priv->build_filetypes_list == NULL)
837 p->priv->build_filetypes_list = g_ptr_array_new();
838 ft->priv->project_list_entry = p->priv->build_filetypes_list->len;
839 g_ptr_array_add(p->priv->build_filetypes_list, ft);
841 build_menu_update(doc);
843 widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project");
844 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
845 p->priv->long_line_behaviour = 0;
846 else
848 widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project");
849 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
850 p->priv->long_line_behaviour = 1;
851 else
852 /* "Custom" radio button must be checked */
853 p->priv->long_line_behaviour = 2;
856 widget = ui_lookup_widget(e->dialog, "spin_long_line_project");
857 p->priv->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
858 apply_editor_prefs();
860 /* get and set the project file patterns */
861 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns)));
862 g_strfreev(p->file_patterns);
863 g_strstrip(tmp);
864 str = g_string_new(tmp);
865 do {} while (utils_string_replace_all(str, " ", " "));
866 p->file_patterns = g_strsplit(str->str, " ", -1);
867 g_string_free(str, TRUE);
868 g_free(tmp);
871 update_ui();
873 return TRUE;
877 #ifndef G_OS_WIN32
878 static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
880 /* set filename in the file chooser dialog */
881 const gchar *utf8_filename = gtk_entry_get_text(GTK_ENTRY(entry));
882 gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
884 if (g_path_is_absolute(locale_filename))
886 if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
888 /* if the current filename is a directory, we must use
889 * gtk_file_chooser_set_current_folder(which expects a locale filename) otherwise
890 * we end up in the parent directory */
891 if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR))
892 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_filename);
893 else
894 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
896 else /* if the file doesn't yet exist, use at least the current directory */
898 gchar *locale_dir = g_path_get_dirname(locale_filename);
899 gchar *name = g_path_get_basename(utf8_filename);
901 if (g_file_test(locale_dir, G_FILE_TEST_EXISTS))
902 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dir);
903 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), name);
905 g_free(name);
906 g_free(locale_dir);
909 else if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
911 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), utf8_filename);
913 g_free(locale_filename);
915 /* run it */
916 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
918 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
919 gchar *tmp_utf8_filename = utils_get_utf8_from_locale(filename);
921 gtk_entry_set_text(GTK_ENTRY(entry), tmp_utf8_filename);
923 g_free(tmp_utf8_filename);
924 g_free(filename);
926 gtk_widget_destroy(dialog);
928 #endif
931 static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e)
933 #ifdef G_OS_WIN32
934 gchar *path = win32_show_project_open_dialog(e->dialog, _("Choose Project Filename"),
935 gtk_entry_get_text(GTK_ENTRY(e->file_name)), TRUE, TRUE);
936 if (path != NULL)
938 gtk_entry_set_text(GTK_ENTRY(e->file_name), path);
939 g_free(path);
941 #else
942 GtkWidget *dialog;
944 /* initialise the dialog */
945 dialog = gtk_file_chooser_dialog_new(_("Choose Project Filename"), NULL,
946 GTK_FILE_CHOOSER_ACTION_SAVE,
947 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
948 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
949 gtk_widget_set_name(dialog, "GeanyDialogProject");
950 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
951 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
952 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
953 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
955 run_dialog(dialog, e->file_name);
956 #endif
960 /* sets the project base path and the project file name according to the project name */
961 static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
963 gchar *base_path;
964 gchar *file_name;
965 gchar *name;
966 const gchar *project_dir = local_prefs.project_file_path;
968 if (e->entries_modified)
969 return;
971 name = gtk_editable_get_chars(editable, 0, -1);
972 if (!EMPTY(name))
974 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
975 name, G_DIR_SEPARATOR_S, NULL);
976 if (project_prefs.project_file_in_basedir)
977 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, name, G_DIR_SEPARATOR_S,
978 name, "." GEANY_PROJECT_EXT, NULL);
979 else
980 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
981 name, "." GEANY_PROJECT_EXT, NULL);
983 else
985 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
986 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
988 g_free(name);
990 gtk_entry_set_text(GTK_ENTRY(e->base_path), base_path);
991 gtk_entry_set_text(GTK_ENTRY(e->file_name), file_name);
993 e->entries_modified = FALSE;
995 g_free(base_path);
996 g_free(file_name);
1000 static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
1002 e->entries_modified = TRUE;
1006 static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line)
1008 gtk_widget_set_sensitive(spin_long_line, gtk_toggle_button_get_active(radio));
1012 gboolean project_load_file(const gchar *locale_file_name)
1014 g_return_val_if_fail(locale_file_name != NULL, FALSE);
1016 if (load_config(locale_file_name))
1018 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1020 ui_set_statusbar(TRUE, _("Project \"%s\" opened."), app->project->name);
1022 ui_add_recent_project_file(utf8_filename);
1023 g_free(utf8_filename);
1024 return TRUE;
1026 else
1028 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1030 ui_set_statusbar(TRUE, _("Project file \"%s\" could not be loaded."), utf8_filename);
1031 g_free(utf8_filename);
1033 return FALSE;
1037 /* Reads the given filename and creates a new project with the data found in the file.
1038 * At this point there should not be an already opened project in Geany otherwise it will just
1039 * return.
1040 * The filename is expected in the locale encoding. */
1041 static gboolean load_config(const gchar *filename)
1043 GKeyFile *config;
1044 GeanyProject *p;
1045 GSList *node;
1047 /* there should not be an open project */
1048 g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
1050 config = g_key_file_new();
1051 if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL))
1053 g_key_file_free(config);
1054 return FALSE;
1057 p = create_project();
1059 foreach_slist(node, stash_groups)
1060 stash_group_load_from_key_file(node->data, config);
1062 p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED);
1063 p->description = utils_get_setting_string(config, "project", "description", "");
1064 p->file_name = utils_get_utf8_from_locale(filename);
1065 p->base_path = utils_get_setting_string(config, "project", "base_path", "");
1066 p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
1068 p->priv->long_line_behaviour = utils_get_setting_integer(config, "long line marker",
1069 "long_line_behaviour", 1 /* follow global */);
1070 p->priv->long_line_column = utils_get_setting_integer(config, "long line marker",
1071 "long_line_column", editor_prefs.long_line_column);
1072 apply_editor_prefs();
1074 build_load_menu(config, GEANY_BCS_PROJ, (gpointer)p);
1075 if (project_prefs.project_session)
1077 /* save current (non-project) session (it could have been changed since program startup) */
1078 configuration_save_default_session();
1079 /* now close all open files */
1080 document_close_all();
1081 /* read session files so they can be opened with configuration_open_files() */
1082 configuration_load_session_files(config, FALSE);
1084 g_signal_emit_by_name(geany_object, "project-open", config);
1085 g_key_file_free(config);
1087 update_ui();
1088 return TRUE;
1092 static void apply_editor_prefs(void)
1094 guint i;
1096 foreach_document(i)
1097 editor_apply_update_prefs(documents[i]->editor);
1101 /* Write the project settings as well as the project session files into its configuration files.
1102 * Returns: TRUE if project file was written successfully. */
1103 static gboolean write_config(void)
1105 GeanyProject *p;
1106 GKeyFile *config;
1107 gchar *filename;
1108 gchar *data;
1109 gboolean ret = FALSE;
1110 GSList *node;
1112 g_return_val_if_fail(app->project != NULL, FALSE);
1114 p = app->project;
1116 config = g_key_file_new();
1117 /* try to load an existing config to keep manually added comments */
1118 filename = utils_get_locale_from_utf8(p->file_name);
1119 g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
1121 foreach_slist(node, stash_groups)
1122 stash_group_save_to_key_file(node->data, config);
1124 g_key_file_set_string(config, "project", "name", p->name);
1125 g_key_file_set_string(config, "project", "base_path", p->base_path);
1127 if (p->description)
1128 g_key_file_set_string(config, "project", "description", p->description);
1129 if (p->file_patterns)
1130 g_key_file_set_string_list(config, "project", "file_patterns",
1131 (const gchar**) p->file_patterns, g_strv_length(p->file_patterns));
1133 // editor settings
1134 g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->priv->long_line_behaviour);
1135 g_key_file_set_integer(config, "long line marker", "long_line_column", p->priv->long_line_column);
1137 /* store the session files into the project too */
1138 if (project_prefs.project_session)
1139 configuration_save_session_files(config);
1140 build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ);
1141 g_signal_emit_by_name(geany_object, "project-save", config);
1142 /* write the file */
1143 data = g_key_file_to_data(config, NULL, NULL);
1144 ret = (utils_write_file(filename, data) == 0);
1146 g_free(data);
1147 g_free(filename);
1148 g_key_file_free(config);
1150 return ret;
1154 /** Forces the project file rewrite and emission of the project-save signal. Plugins
1155 * can use this function to save additional project data outside the project dialog.
1157 * @since 1.25
1159 GEANY_API_SYMBOL
1160 void project_write_config(void)
1162 if (!write_config())
1163 SHOW_ERR(_("Project file could not be written"));
1167 /* Constructs the project's base path which is used for "Make all" and "Execute".
1168 * The result is an absolute string in UTF-8 encoding which is either the same as
1169 * base path if it is absolute or it is built out of project file name's dir and base_path.
1170 * If there is no project or project's base_path is invalid, NULL will be returned.
1171 * The returned string should be freed when no longer needed. */
1172 gchar *project_get_base_path(void)
1174 GeanyProject *project = app->project;
1176 if (project && !EMPTY(project->base_path))
1178 if (g_path_is_absolute(project->base_path))
1179 return g_strdup(project->base_path);
1180 else
1181 { /* build base_path out of project file name's dir and base_path */
1182 gchar *path;
1183 gchar *dir = g_path_get_dirname(project->file_name);
1185 if (utils_str_equal(project->base_path, "./"))
1186 return dir;
1188 path = g_build_filename(dir, project->base_path, NULL);
1189 g_free(dir);
1190 return path;
1193 return NULL;
1197 /* This is to save project-related global settings, NOT project file settings. */
1198 void project_save_prefs(GKeyFile *config)
1200 GeanyProject *project = app->project;
1202 if (cl_options.load_session)
1204 const gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
1206 g_key_file_set_string(config, "project", "session_file", utf8_filename);
1208 g_key_file_set_string(config, "project", "project_file_path",
1209 FALLBACK(local_prefs.project_file_path, ""));
1213 void project_load_prefs(GKeyFile *config)
1215 if (cl_options.load_session)
1217 g_return_if_fail(project_prefs.session_file == NULL);
1218 project_prefs.session_file = utils_get_setting_string(config, "project",
1219 "session_file", "");
1221 local_prefs.project_file_path = utils_get_setting_string(config, "project",
1222 "project_file_path", NULL);
1223 if (local_prefs.project_file_path == NULL)
1225 local_prefs.project_file_path = g_build_filename(g_get_home_dir(), PROJECT_DIR, NULL);
1230 /* Initialize project-related preferences in the Preferences dialog. */
1231 void project_setup_prefs(void)
1233 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1234 GtkWidget *path_btn = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_button");
1235 static gboolean callback_setup = FALSE;
1237 g_return_if_fail(local_prefs.project_file_path != NULL);
1239 gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
1240 if (! callback_setup)
1241 { /* connect the callback only once */
1242 callback_setup = TRUE;
1243 ui_setup_open_button_callback(path_btn, NULL,
1244 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(path_entry));
1249 /* Update project-related preferences after using the Preferences dialog. */
1250 void project_apply_prefs(void)
1252 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1253 const gchar *str;
1255 str = gtk_entry_get_text(GTK_ENTRY(path_entry));
1256 SETPTR(local_prefs.project_file_path, g_strdup(str));
1260 static void add_stash_group(StashGroup *group, gboolean apply_defaults)
1262 GKeyFile *kf;
1264 stash_groups = g_slist_prepend(stash_groups, group);
1265 if (!apply_defaults)
1266 return;
1268 kf = g_key_file_new();
1269 stash_group_load_from_key_file(group, kf);
1270 g_key_file_free(kf);
1274 static void init_stash_prefs(void)
1276 StashGroup *group;
1278 group = stash_group_new("indentation");
1279 /* copy global defaults */
1280 indentation = *editor_get_indent_prefs(NULL);
1281 stash_group_set_use_defaults(group, FALSE);
1282 add_stash_group(group, FALSE);
1284 stash_group_add_spin_button_integer(group, &indentation.width,
1285 "indent_width", 4, "spin_indent_width_project");
1286 stash_group_add_radio_buttons(group, (gint*)(gpointer)&indentation.type,
1287 "indent_type", GEANY_INDENT_TYPE_TABS,
1288 "radio_indent_spaces_project", GEANY_INDENT_TYPE_SPACES,
1289 "radio_indent_tabs_project", GEANY_INDENT_TYPE_TABS,
1290 "radio_indent_both_project", GEANY_INDENT_TYPE_BOTH,
1291 NULL);
1292 /* This is a 'hidden' pref for backwards-compatibility */
1293 stash_group_add_integer(group, &indentation.hard_tab_width,
1294 "indent_hard_tab_width", 8);
1295 stash_group_add_toggle_button(group, &indentation.detect_type,
1296 "detect_indent", FALSE, "check_detect_indent_type_project");
1297 stash_group_add_toggle_button(group, &indentation.detect_width,
1298 "detect_indent_width", FALSE, "check_detect_indent_width_project");
1299 stash_group_add_combo_box(group, (gint*)(gpointer)&indentation.auto_indent_mode,
1300 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project");
1302 group = stash_group_new("file_prefs");
1303 stash_group_add_toggle_button(group, &priv.final_new_line,
1304 "final_new_line", file_prefs.final_new_line, "check_new_line1");
1305 stash_group_add_toggle_button(group, &priv.ensure_convert_new_lines,
1306 "ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1");
1307 stash_group_add_toggle_button(group, &priv.strip_trailing_spaces,
1308 "strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
1309 stash_group_add_toggle_button(group, &priv.replace_tabs,
1310 "replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
1311 add_stash_group(group, TRUE);
1313 group = stash_group_new("editor");
1314 stash_group_add_toggle_button(group, &priv.line_wrapping,
1315 "line_wrapping", editor_prefs.line_wrapping, "check_line_wrapping1");
1316 stash_group_add_spin_button_integer(group, &priv.line_break_column,
1317 "line_break_column", editor_prefs.line_break_column, "spin_line_break1");
1318 stash_group_add_toggle_button(group, &priv.auto_continue_multiline,
1319 "auto_continue_multiline", editor_prefs.auto_continue_multiline,
1320 "check_auto_multiline1");
1321 add_stash_group(group, TRUE);
1325 #define COPY_PREF(dest, prefname)\
1326 (dest.prefname = priv.prefname)
1328 const GeanyFilePrefs *project_get_file_prefs(void)
1330 static GeanyFilePrefs fp;
1332 if (!app->project)
1333 return &file_prefs;
1335 fp = file_prefs;
1336 COPY_PREF(fp, final_new_line);
1337 COPY_PREF(fp, ensure_convert_new_lines);
1338 COPY_PREF(fp, strip_trailing_spaces);
1339 COPY_PREF(fp, replace_tabs);
1340 return &fp;
1344 void project_init(void)
1349 void project_finalize(void)