Merge pull request #3903 from techee/win_msg
[geany-mirror.git] / src / project.c
blob22815385c5bd66e66607d2318305956d1d864d1e
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"
47 #include <string.h>
48 #include <unistd.h>
49 #include <errno.h>
52 ProjectPrefs project_prefs = { NULL, FALSE };
55 static GeanyProjectPrivate priv;
56 static GeanyIndentPrefs indentation;
58 static GSList *stash_groups = NULL;
60 static struct
62 gchar *project_file_path; /* in UTF-8 */
63 } local_prefs = { NULL };
65 /* simple struct to keep references to the elements of the properties dialog */
66 typedef struct _PropertyDialogElements
68 GtkWidget *dialog;
69 GtkWidget *notebook;
70 GtkWidget *name;
71 GtkWidget *description;
72 GtkWidget *file_name;
73 GtkWidget *base_path;
74 GtkWidget *patterns;
75 BuildTableData build_properties;
76 gint build_page_num;
77 gboolean entries_modified;
78 } PropertyDialogElements;
81 static gboolean update_config(const PropertyDialogElements *e, gboolean new_project);
82 static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e);
83 static gboolean load_config(const gchar *filename);
84 static gboolean write_config(void);
85 static void update_new_project_dlg(GtkEditable *editable, PropertyDialogElements *e,
86 const gchar *base_p);
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 run_new_dialog(PropertyDialogElements *e);
91 static void apply_editor_prefs(void);
92 static void init_stash_prefs(void);
93 static void destroy_project(gboolean open_default);
96 #define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args)
97 #define SHOW_ERR1(args, more) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args, more)
98 #define MAX_NAME_LEN 50
99 /* "projects" is part of the default project base path so be careful when translating
100 * please avoid special characters and spaces, look at the source for details or ask Frank */
101 #define PROJECT_DIR _("projects")
104 // returns whether we have working documents open
105 static gboolean have_session_docs(void)
107 gint npages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
108 GeanyDocument *doc = document_get_current();
110 return npages > 1 || (npages == 1 && (doc->file_name || doc->changed));
114 static gboolean handle_current_session(void)
116 if (!app->project)
118 /* save session in case the dialog is cancelled */
119 configuration_save_default_session();
120 /* don't ask if the only doc is an unmodified new doc */
121 if (have_session_docs())
123 if (dialogs_show_question(
124 _("Move the current documents into the new project's session?")))
126 // don't reload session on closing project
127 configuration_clear_default_session();
129 else
131 if (!document_close_all())
132 return FALSE;
136 if (app->project)
137 return project_close(FALSE);
138 return TRUE;
142 /* TODO: this should be ported to Glade like the project preferences dialog,
143 * then we can get rid of the PropertyDialogElements struct altogether as
144 * widgets pointers can be accessed through ui_lookup_widget(). */
145 void project_new(gboolean from_folder)
147 GtkWidget *vbox;
148 GtkWidget *table;
149 GtkWidget *image;
150 GtkWidget *button;
151 GtkWidget *bbox;
152 GtkWidget *label;
153 gchar *tooltip;
154 gchar *base_path = NULL;
155 PropertyDialogElements e = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, FALSE };
157 if (from_folder)
159 GeanyDocument *doc = document_get_current();
160 gchar *start_path;
162 if (doc && doc->file_name)
163 start_path = g_path_get_dirname(doc->file_name);
164 else if (!EMPTY(local_prefs.project_file_path))
165 start_path = g_strdup(local_prefs.project_file_path);
166 else
167 start_path = utils_get_utf8_from_locale(g_get_home_dir());
169 base_path = ui_get_project_directory(start_path);
170 g_free(start_path);
172 if (!base_path)
173 return;
176 e.dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(main_widgets.window),
177 GTK_DIALOG_DESTROY_WITH_PARENT,
178 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
180 gtk_widget_set_name(e.dialog, "GeanyDialogProject");
181 button = ui_button_new_with_image(GTK_STOCK_NEW, _("C_reate"));
182 gtk_widget_set_can_default(button, TRUE);
183 gtk_window_set_default(GTK_WINDOW(e.dialog), button);
184 gtk_dialog_add_action_widget(GTK_DIALOG(e.dialog), button, GTK_RESPONSE_OK);
186 vbox = ui_dialog_vbox_new(GTK_DIALOG(e.dialog));
188 table = gtk_table_new(3, 2, FALSE);
189 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
190 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
192 label = gtk_label_new(_("Name:"));
193 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
195 e.name = gtk_entry_new();
196 gtk_entry_set_activates_default(GTK_ENTRY(e.name), TRUE);
197 ui_entry_add_clear_icon(GTK_ENTRY(e.name));
198 gtk_entry_set_max_length(GTK_ENTRY(e.name), MAX_NAME_LEN);
199 gtk_widget_set_tooltip_text(e.name, _("Project name"));
201 ui_table_add_row(GTK_TABLE(table), 0, label, e.name, NULL);
203 label = gtk_label_new(_("Filename:"));
204 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
206 e.file_name = gtk_entry_new();
207 gtk_entry_set_activates_default(GTK_ENTRY(e.file_name), TRUE);
208 ui_entry_add_clear_icon(GTK_ENTRY(e.file_name));
209 gtk_entry_set_width_chars(GTK_ENTRY(e.file_name), 40);
210 tooltip = g_strdup_printf(
211 _("Path of the file representing the project and storing its settings. "
212 "It should normally have the \"%s\" extension."), "."GEANY_PROJECT_EXT);
213 gtk_widget_set_tooltip_text(e.file_name, tooltip);
214 g_free(tooltip);
215 button = gtk_button_new();
216 g_signal_connect(button, "clicked", G_CALLBACK(on_file_save_button_clicked), &e);
217 image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
218 gtk_container_add(GTK_CONTAINER(button), image);
219 bbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
220 gtk_box_pack_start(GTK_BOX(bbox), e.file_name, TRUE, TRUE, 0);
221 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
223 ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);
225 label = gtk_label_new(_("Base path:"));
226 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
228 e.base_path = gtk_entry_new();
229 gtk_entry_set_activates_default(GTK_ENTRY(e.base_path), TRUE);
230 ui_entry_add_clear_icon(GTK_ENTRY(e.base_path));
231 gtk_widget_set_tooltip_text(e.base_path,
232 _("Base directory of all files that make up the project. "
233 "This can be a new path, or an existing directory tree. "
234 "You can use paths relative to the project filename."));
235 bbox = ui_path_box_new(_("Choose Project Base Path"),
236 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e.base_path));
238 ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);
240 gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
242 if (base_path)
244 update_new_project_dlg(GTK_EDITABLE(e.name), &e, base_path);
245 g_free(base_path);
247 else
249 /* signals */
250 g_signal_connect(e.name, "changed", G_CALLBACK(on_name_entry_changed), &e);
251 g_signal_connect(e.file_name, "changed", G_CALLBACK(on_entries_changed), &e);
252 g_signal_connect(e.base_path, "changed", G_CALLBACK(on_entries_changed), &e);
254 update_new_project_dlg(GTK_EDITABLE(e.name), &e, NULL);
257 gtk_widget_show_all(e.dialog);
258 run_new_dialog(&e);
259 gtk_widget_destroy(e.dialog);
260 document_new_file_if_non_open();
261 ui_focus_current_document();
265 static void run_new_dialog(PropertyDialogElements *e)
267 if (gtk_dialog_run(GTK_DIALOG(e->dialog)) != GTK_RESPONSE_OK ||
268 !handle_current_session())
269 return;
272 if (update_config(e, TRUE))
274 // app->project is now set
275 if (!write_config())
277 SHOW_ERR(_("Project file could not be written"));
278 destroy_project(FALSE);
280 else
282 ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name);
283 ui_add_recent_project_file(app->project->file_name);
284 return;
288 while (gtk_dialog_run(GTK_DIALOG(e->dialog)) == GTK_RESPONSE_OK);
289 // any open docs were meant to be moved into the project
290 // rewrite default session because it was cleared
291 if (have_session_docs())
292 configuration_save_default_session();
293 else
295 // reload any documents that were closed
296 configuration_load_default_session();
297 configuration_open_default_session();
302 gboolean project_load_file_with_session(const gchar *locale_file_name)
304 if (project_load_file(locale_file_name))
306 configuration_open_files(app->project->priv->session_files);
307 app->project->priv->session_files = NULL;
308 document_new_file_if_non_open();
309 ui_focus_current_document();
310 return TRUE;
312 return FALSE;
316 static void run_open_dialog(GtkFileChooser *dialog)
318 while (dialogs_file_chooser_run(dialog) == GTK_RESPONSE_ACCEPT)
320 gchar *filename = gtk_file_chooser_get_filename(dialog);
322 if (app->project && !project_close(FALSE)) {}
323 /* try to load the config */
324 else if (! project_load_file_with_session(filename))
326 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
328 SHOW_ERR1(_("Project file \"%s\" could not be loaded."), utf8_filename);
329 if (GTK_IS_WIDGET(dialog))
330 gtk_widget_grab_focus(GTK_WIDGET(dialog));
331 g_free(utf8_filename);
332 g_free(filename);
333 continue;
335 g_free(filename);
336 break;
341 void project_open(void)
343 const gchar *dir = local_prefs.project_file_path;
344 gchar *locale_path;
345 GtkFileChooser *dialog;
346 GtkFileFilter *filter;
348 if (interface_prefs.use_native_windows_dialogs)
349 dialog = GTK_FILE_CHOOSER(gtk_file_chooser_native_new(_("Open Project"),
350 GTK_WINDOW(main_widgets.window), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL));
351 else
353 dialog = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(main_widgets.window),
354 GTK_FILE_CHOOSER_ACTION_OPEN,
355 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
356 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL));
357 gtk_widget_set_name(GTK_WIDGET(dialog), "GeanyDialogProject");
359 /* set default Open, so pressing enter can open multiple files */
360 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
361 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
362 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
363 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
364 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window));
365 gtk_widget_show_all(GTK_WIDGET(dialog));
368 gtk_file_chooser_set_select_multiple(dialog, TRUE);
370 /* add FileFilters */
371 filter = gtk_file_filter_new();
372 gtk_file_filter_set_name(filter, _("All files"));
373 gtk_file_filter_add_pattern(filter, "*");
374 gtk_file_chooser_add_filter(dialog, filter);
375 filter = gtk_file_filter_new();
376 gtk_file_filter_set_name(filter, _("Project files"));
377 gtk_file_filter_add_pattern(filter, "*." GEANY_PROJECT_EXT);
378 gtk_file_chooser_add_filter(dialog, filter);
379 gtk_file_chooser_set_filter(dialog, filter);
381 locale_path = utils_get_locale_from_utf8(dir);
382 if (g_file_test(locale_path, G_FILE_TEST_EXISTS) &&
383 g_file_test(locale_path, G_FILE_TEST_IS_DIR))
385 gtk_file_chooser_set_current_folder(dialog, locale_path);
387 g_free(locale_path);
389 run_open_dialog(dialog);
390 dialogs_file_chooser_destroy(dialog);
394 /* Called when creating, opening, closing and updating projects. */
395 static void update_ui(void)
397 if (main_status.quitting)
398 return;
400 ui_set_window_title(NULL);
401 build_menu_update(NULL);
402 // update project name
403 sidebar_openfiles_update_all();
404 ui_update_recent_project_menu();
408 static void remove_foreach_project_filetype(gpointer data, gpointer user_data)
410 GeanyFiletype *ft = data;
411 if (ft != NULL)
413 SETPTR(ft->priv->projfilecmds, NULL);
414 SETPTR(ft->priv->projexeccmds, NULL);
415 SETPTR(ft->priv->projerror_regex_string, NULL);
416 ft->priv->project_list_entry = -1;
421 /* open_default will make function reload default session files on close */
422 gboolean project_close(gboolean open_default)
424 g_return_val_if_fail(app->project != NULL, FALSE);
426 /* save project session files, etc */
427 if (!write_config())
428 g_warning("Project file \"%s\" could not be written", app->project->file_name);
430 /* close all existing tabs first */
431 if (!document_close_all())
432 return FALSE;
434 ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
435 destroy_project(open_default);
436 return TRUE;
440 static void destroy_project(gboolean open_default)
442 GSList *node;
444 g_return_if_fail(app->project != NULL);
446 g_signal_emit_by_name(geany_object, "project-before-close");
448 /* remove project filetypes build entries */
449 if (app->project->priv->build_filetypes_list != NULL)
451 g_ptr_array_foreach(app->project->priv->build_filetypes_list, remove_foreach_project_filetype, NULL);
452 g_ptr_array_free(app->project->priv->build_filetypes_list, FALSE);
455 /* remove project non filetype build menu items */
456 build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_NON_FT, -1);
457 build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_EXEC, -1);
459 g_free(app->project->name);
460 g_free(app->project->description);
461 g_free(app->project->file_name);
462 g_free(app->project->base_path);
463 g_strfreev(app->project->file_patterns);
465 g_free(app->project);
466 app->project = NULL;
468 foreach_slist(node, stash_groups)
469 stash_group_free(node->data);
471 g_slist_free(stash_groups);
472 stash_groups = NULL;
474 apply_editor_prefs(); /* ensure that global settings are restored */
476 /* after closing all tabs let's open the tabs found in the default config */
477 if (open_default && cl_options.load_session)
479 configuration_load_default_session();
480 configuration_open_default_session();
481 document_new_file_if_non_open();
482 ui_focus_current_document();
484 g_signal_emit_by_name(geany_object, "project-close");
486 update_ui();
490 /* Shows the file chooser dialog when base path button is clicked
491 * FIXME: this should be connected in Glade but 3.8.1 has a bug
492 * where it won't pass any objects as user data (#588824). */
493 static void on_project_properties_base_path_button_clicked(GtkWidget *button,
494 GtkWidget *base_path_entry)
496 GtkFileChooser *dialog;
498 g_return_if_fail(base_path_entry != NULL);
499 g_return_if_fail(GTK_IS_WIDGET(base_path_entry));
501 if (interface_prefs.use_native_windows_dialogs)
502 dialog = GTK_FILE_CHOOSER(gtk_file_chooser_native_new(_("Choose Project Base Path"),
503 NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, NULL, NULL));
504 else
505 dialog = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new(_("Choose Project Base Path"),
506 NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
507 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
508 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
509 NULL));
511 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
513 gtk_entry_set_text(GTK_ENTRY(base_path_entry),
514 gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
517 dialogs_file_chooser_destroy(dialog);
521 static void insert_build_page(PropertyDialogElements *e)
523 GtkWidget *build_table, *label;
524 GeanyDocument *doc = document_get_current();
525 GeanyFiletype *ft = NULL;
527 if (doc != NULL)
528 ft = doc->file_type;
530 build_table = build_commands_table(doc, GEANY_BCS_PROJ, &(e->build_properties), ft);
531 gtk_container_set_border_width(GTK_CONTAINER(build_table), 6);
532 label = gtk_label_new(_("Build"));
533 e->build_page_num = gtk_notebook_append_page(GTK_NOTEBOOK(e->notebook),
534 build_table, label);
538 static void create_properties_dialog(PropertyDialogElements *e)
540 GtkWidget *wid;
541 static guint base_path_button_handler_id = 0;
542 static guint radio_long_line_handler_id = 0;
544 e->dialog = create_project_dialog();
545 e->notebook = ui_lookup_widget(e->dialog, "project_notebook");
546 e->file_name = ui_lookup_widget(e->dialog, "label_project_dialog_filename");
547 e->name = ui_lookup_widget(e->dialog, "entry_project_dialog_name");
548 e->description = ui_lookup_widget(e->dialog, "textview_project_dialog_description");
549 e->base_path = ui_lookup_widget(e->dialog, "entry_project_dialog_base_path");
550 e->patterns = ui_lookup_widget(e->dialog, "entry_project_dialog_file_patterns");
552 gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
554 ui_entry_add_clear_icon(GTK_ENTRY(e->name));
555 ui_entry_add_clear_icon(GTK_ENTRY(e->base_path));
556 ui_entry_add_clear_icon(GTK_ENTRY(e->patterns));
558 /* Workaround for bug in Glade 3.8.1, see comment above signal handler */
559 if (base_path_button_handler_id == 0)
561 wid = ui_lookup_widget(e->dialog, "button_project_dialog_base_path");
562 base_path_button_handler_id =
563 g_signal_connect(wid, "clicked",
564 G_CALLBACK(on_project_properties_base_path_button_clicked),
565 e->base_path);
568 /* Same as above, should be in Glade but can't due to bug in 3.8.1 */
569 if (radio_long_line_handler_id == 0)
571 wid = ui_lookup_widget(e->dialog, "radio_long_line_custom_project");
572 radio_long_line_handler_id =
573 g_signal_connect(wid, "toggled",
574 G_CALLBACK(on_radio_long_line_custom_toggled),
575 ui_lookup_widget(e->dialog, "spin_long_line_project"));
580 static void show_project_properties(gboolean show_build)
582 GeanyProject *p = app->project;
583 GtkWidget *widget = NULL;
584 GtkWidget *radio_long_line_custom;
585 static PropertyDialogElements e;
586 GSList *node;
587 gchar *entry_text;
588 GtkTextBuffer *buffer;
590 g_return_if_fail(app->project != NULL);
592 if (e.dialog == NULL)
593 create_properties_dialog(&e);
595 insert_build_page(&e);
597 foreach_slist(node, stash_groups)
598 stash_group_display(node->data, e.dialog);
600 /* fill the elements with the appropriate data */
601 gtk_entry_set_text(GTK_ENTRY(e.name), p->name);
602 gtk_label_set_text(GTK_LABEL(e.file_name), p->file_name);
603 gtk_entry_set_text(GTK_ENTRY(e.base_path), p->base_path);
605 radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project");
606 switch (p->priv->long_line_behaviour)
608 case 0: widget = ui_lookup_widget(e.dialog, "radio_long_line_disabled_project"); break;
609 case 1: widget = ui_lookup_widget(e.dialog, "radio_long_line_default_project"); break;
610 case 2: widget = radio_long_line_custom; break;
612 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
614 widget = ui_lookup_widget(e.dialog, "spin_long_line_project");
615 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->priv->long_line_column);
616 on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget);
618 /* set text */
619 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e.description));
620 gtk_text_buffer_set_text(buffer, p->description ? p->description : "", -1);
622 /* set the file patterns */
623 entry_text = p->file_patterns ? g_strjoinv(" ", p->file_patterns) : g_strdup("");
624 gtk_entry_set_text(GTK_ENTRY(e.patterns), entry_text);
625 g_free(entry_text);
627 g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook);
628 gtk_widget_show_all(e.dialog);
630 /* note: notebook page must be shown before setting current page */
631 if (show_build)
632 gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
633 else
634 gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), 0);
636 while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK)
638 if (update_config(&e, FALSE))
640 g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook);
641 if (!write_config())
642 SHOW_ERR(_("Project file could not be written"));
643 else
645 ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name);
646 break;
651 build_free_fields(e.build_properties);
652 g_signal_emit_by_name(geany_object, "project-dialog-close", e.notebook);
653 gtk_notebook_remove_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
654 gtk_widget_hide(e.dialog);
658 void project_properties(void)
660 show_project_properties(FALSE);
664 void project_build_properties(void)
666 show_project_properties(TRUE);
670 /* checks whether there is an already open project and asks the user if he wants to close it or
671 * abort the current action. Returns FALSE when the current action(the caller) should be cancelled
672 * and TRUE if we can go ahead */
673 gboolean project_ask_close(void)
675 if (app->project != NULL)
677 if (!interface_prefs.warn_on_project_close ||
678 dialogs_show_question_full(NULL, GTK_STOCK_CLOSE, GTK_STOCK_CANCEL,
679 _("Do you want to close it before proceeding?"),
680 _("The '%s' project is open."), app->project->name))
682 return project_close(FALSE);
684 else
685 return FALSE;
687 else
688 return TRUE;
692 static GeanyProject *create_project(void)
694 GeanyProject *project = g_new0(GeanyProject, 1);
696 memset(&priv, 0, sizeof priv);
697 priv.indentation = &indentation;
698 project->priv = &priv;
700 init_stash_prefs();
702 project->file_patterns = NULL;
704 project->priv->long_line_behaviour = 1 /* use global settings */;
705 project->priv->long_line_column = editor_prefs.long_line_column;
707 app->project = project;
708 return project;
712 /* Verifies data for New & Properties dialogs.
713 * Creates app->project if NULL.
714 * Returns: FALSE if the user needs to change any data. */
715 static gboolean update_config(const PropertyDialogElements *e, gboolean new_project)
717 const gchar *name, *file_name, *base_path;
718 gchar *locale_filename;
719 gsize name_len;
720 gint err_code = 0;
721 GeanyProject *p;
723 g_return_val_if_fail(e != NULL, TRUE);
725 name = gtk_entry_get_text(GTK_ENTRY(e->name));
726 name_len = strlen(name);
727 if (name_len == 0)
729 SHOW_ERR(_("The specified project name is too short."));
730 gtk_widget_grab_focus(e->name);
731 return FALSE;
733 else if (name_len > MAX_NAME_LEN)
735 SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
736 gtk_widget_grab_focus(e->name);
737 return FALSE;
740 if (new_project)
741 file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
742 else
743 file_name = gtk_label_get_text(GTK_LABEL(e->file_name));
745 if (G_UNLIKELY(EMPTY(file_name)))
747 SHOW_ERR(_("You have specified an invalid project filename."));
748 gtk_widget_grab_focus(e->file_name);
749 return FALSE;
752 locale_filename = utils_get_locale_from_utf8(file_name);
753 base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
754 if (!EMPTY(base_path))
755 { /* check whether the given directory actually exists */
756 gchar *locale_path = utils_get_locale_from_utf8(base_path);
758 if (! g_path_is_absolute(locale_path))
759 { /* relative base path, so add base dir of project file name */
760 gchar *dir = g_path_get_dirname(locale_filename);
761 SETPTR(locale_path, g_build_filename(dir, locale_path, NULL));
762 g_free(dir);
765 if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
767 gboolean create_dir;
769 create_dir = dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
770 _("Create the project's base path directory?"),
771 _("The path \"%s\" does not exist."),
772 base_path);
774 if (create_dir)
775 err_code = utils_mkdir(locale_path, TRUE);
777 if (! create_dir || err_code != 0)
779 if (err_code != 0)
780 SHOW_ERR1(_("Project base directory could not be created (%s)."),
781 g_strerror(err_code));
782 gtk_widget_grab_focus(e->base_path);
783 utils_free_pointers(2, locale_path, locale_filename, NULL);
784 return FALSE;
787 g_free(locale_path);
789 /* finally test whether the given project file can be written */
790 if ((err_code = utils_is_file_writable(locale_filename)) != 0 ||
791 (err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0)
793 SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code));
794 gtk_widget_grab_focus(e->file_name);
795 g_free(locale_filename);
796 return FALSE;
798 else if (new_project && g_file_test(locale_filename, G_FILE_TEST_EXISTS) &&
799 ! dialogs_show_question_full(NULL, _("_Replace"), GTK_STOCK_CANCEL,
800 NULL,
801 _("The file '%s' already exists. Do you want to overwrite it?"),
802 file_name))
804 gtk_widget_grab_focus(e->file_name);
805 g_free(locale_filename);
806 return FALSE;
808 g_free(locale_filename);
810 if (app->project == NULL)
812 create_project();
813 new_project = TRUE;
815 p = app->project;
817 SETPTR(p->name, g_strdup(name));
818 SETPTR(p->file_name, g_strdup(file_name));
819 /* use "." if base_path is empty */
820 SETPTR(p->base_path, g_strdup(!EMPTY(base_path) ? base_path : "./"));
822 if (! new_project) /* save properties specific fields */
824 GtkTextIter start, end;
825 GtkTextBuffer *buffer;
826 GeanyDocument *doc = document_get_current();
827 GeanyBuildCommand *oldvalue;
828 GeanyFiletype *ft = doc ? doc->file_type : NULL;
829 GtkWidget *widget;
830 gchar *tmp;
831 GString *str;
832 GSList *node;
834 /* get and set the project description */
835 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
836 gtk_text_buffer_get_start_iter(buffer, &start);
837 gtk_text_buffer_get_end_iter(buffer, &end);
838 SETPTR(p->description, gtk_text_buffer_get_text(buffer, &start, &end, FALSE));
840 foreach_slist(node, stash_groups)
841 stash_group_update(node->data, e->dialog);
843 /* read the project build menu */
844 oldvalue = ft ? ft->priv->projfilecmds : NULL;
845 build_read_project(ft, e->build_properties);
847 if (ft != NULL && ft->priv->projfilecmds != oldvalue && ft->priv->project_list_entry < 0)
849 if (p->priv->build_filetypes_list == NULL)
850 p->priv->build_filetypes_list = g_ptr_array_new();
851 ft->priv->project_list_entry = p->priv->build_filetypes_list->len;
852 g_ptr_array_add(p->priv->build_filetypes_list, ft);
854 build_menu_update(doc);
856 widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project");
857 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
858 p->priv->long_line_behaviour = 0;
859 else
861 widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project");
862 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
863 p->priv->long_line_behaviour = 1;
864 else
865 /* "Custom" radio button must be checked */
866 p->priv->long_line_behaviour = 2;
869 widget = ui_lookup_widget(e->dialog, "spin_long_line_project");
870 p->priv->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
871 apply_editor_prefs();
873 /* get and set the project file patterns */
874 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns)));
875 g_strfreev(p->file_patterns);
876 g_strstrip(tmp);
877 str = g_string_new(tmp);
878 do {} while (utils_string_replace_all(str, " ", " "));
879 p->file_patterns = g_strsplit(str->str, " ", -1);
880 g_string_free(str, TRUE);
881 g_free(tmp);
884 update_ui();
886 return TRUE;
890 static void run_dialog(GtkFileChooser *dialog, GtkWidget *entry)
892 /* set filename in the file chooser dialog */
893 const gchar *utf8_filename = gtk_entry_get_text(GTK_ENTRY(entry));
894 gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
896 if (g_path_is_absolute(locale_filename))
898 if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
900 /* if the current filename is a directory, we must use
901 * gtk_file_chooser_set_current_folder(which expects a locale filename) otherwise
902 * we end up in the parent directory */
903 if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR))
904 gtk_file_chooser_set_current_folder(dialog, locale_filename);
905 else
906 gtk_file_chooser_set_filename(dialog, utf8_filename);
908 else /* if the file doesn't yet exist, use at least the current directory */
910 gchar *locale_dir = g_path_get_dirname(locale_filename);
911 gchar *name = g_path_get_basename(utf8_filename);
913 if (g_file_test(locale_dir, G_FILE_TEST_EXISTS))
914 gtk_file_chooser_set_current_folder(dialog, locale_dir);
915 gtk_file_chooser_set_current_name(dialog, name);
917 g_free(name);
918 g_free(locale_dir);
921 else if (gtk_file_chooser_get_action(dialog) != GTK_FILE_CHOOSER_ACTION_OPEN)
923 gtk_file_chooser_set_current_name(dialog, utf8_filename);
925 g_free(locale_filename);
927 /* run it */
928 if (dialogs_file_chooser_run(dialog) == GTK_RESPONSE_ACCEPT)
930 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
931 gchar *tmp_utf8_filename = utils_get_utf8_from_locale(filename);
933 gtk_entry_set_text(GTK_ENTRY(entry), tmp_utf8_filename);
935 g_free(tmp_utf8_filename);
936 g_free(filename);
938 dialogs_file_chooser_destroy(dialog);
942 static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e)
944 GtkFileChooser *dialog;
946 /* initialise the dialog */
947 if (interface_prefs.use_native_windows_dialogs)
948 dialog = GTK_FILE_CHOOSER(gtk_file_chooser_native_new(_("Choose Project Filename"),
949 NULL, GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL));
950 else
952 dialog = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new(_("Choose Project Filename"), NULL,
953 GTK_FILE_CHOOSER_ACTION_SAVE,
954 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
955 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL));
956 gtk_widget_set_name(GTK_WIDGET(dialog), "GeanyDialogProject");
957 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
958 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
959 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
960 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
963 run_dialog(dialog, e->file_name);
967 /* sets the New Project dialog entries according to the base path or project name */
968 static void update_new_project_dlg(GtkEditable *editable, PropertyDialogElements *e,
969 const gchar *base_p)
971 gchar *base_path;
972 gchar *file_name;
973 gchar *project_dir = NULL;
975 if (e->entries_modified)
976 return;
978 if (!EMPTY(local_prefs.project_file_path))
979 project_dir = g_strdup(local_prefs.project_file_path);
980 else
982 GeanyDocument *doc = document_get_current();
984 if (doc && doc->file_name)
985 project_dir = g_path_get_dirname(doc->file_name);
986 else
987 project_dir = utils_get_utf8_from_locale(g_get_home_dir());
990 if (!EMPTY(base_p))
992 gchar *name = g_path_get_basename(base_p);
994 base_path = g_strdup(base_p);
995 gtk_entry_set_text(GTK_ENTRY(e->name), name);
996 if (project_prefs.project_file_in_basedir)
997 file_name = g_strconcat(base_path, G_DIR_SEPARATOR_S,
998 name, "." GEANY_PROJECT_EXT, NULL);
999 else
1000 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
1001 name, "." GEANY_PROJECT_EXT, NULL);
1002 g_free(name);
1004 else
1006 gchar *name = gtk_editable_get_chars(editable, 0, -1);
1007 if (!EMPTY(name))
1009 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
1010 name, G_DIR_SEPARATOR_S, NULL);
1011 if (project_prefs.project_file_in_basedir)
1012 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, name, G_DIR_SEPARATOR_S,
1013 name, "." GEANY_PROJECT_EXT, NULL);
1014 else
1015 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
1016 name, "." GEANY_PROJECT_EXT, NULL);
1018 else
1020 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
1021 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
1023 g_free(name);
1026 gtk_entry_set_text(GTK_ENTRY(e->base_path), base_path);
1027 gtk_entry_set_text(GTK_ENTRY(e->file_name), file_name);
1029 e->entries_modified = FALSE;
1031 g_free(base_path);
1032 g_free(file_name);
1033 g_free(project_dir);
1037 static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
1039 update_new_project_dlg(editable, e, NULL);
1043 static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
1045 e->entries_modified = TRUE;
1049 static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line)
1051 gtk_widget_set_sensitive(spin_long_line, gtk_toggle_button_get_active(radio));
1055 gboolean project_load_file(const gchar *locale_file_name)
1057 g_return_val_if_fail(locale_file_name != NULL, FALSE);
1059 if (load_config(locale_file_name))
1061 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1063 ui_set_statusbar(TRUE, _("Project \"%s\" opened."), app->project->name);
1065 ui_add_recent_project_file(utf8_filename);
1066 g_free(utf8_filename);
1067 return TRUE;
1069 else
1071 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1073 ui_set_statusbar(TRUE, _("Project file \"%s\" could not be loaded."), utf8_filename);
1074 g_free(utf8_filename);
1076 return FALSE;
1080 /* Reads the given filename and creates a new project with the data found in the file.
1081 * At this point there should not be an already opened project in Geany otherwise it will just
1082 * return.
1083 * The filename is expected in the locale encoding. */
1084 static gboolean load_config(const gchar *filename)
1086 GKeyFile *config;
1087 GeanyProject *p;
1088 GSList *node;
1090 /* there should not be an open project */
1091 g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
1093 config = g_key_file_new();
1094 if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL))
1096 g_key_file_free(config);
1097 return FALSE;
1100 p = create_project();
1102 foreach_slist(node, stash_groups)
1103 stash_group_load_from_key_file(node->data, config);
1105 p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED);
1106 p->description = utils_get_setting_string(config, "project", "description", "");
1107 p->file_name = utils_get_utf8_from_locale(filename);
1108 p->base_path = utils_get_setting_string(config, "project", "base_path", "");
1109 p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
1111 p->priv->long_line_behaviour = utils_get_setting_integer(config, "long line marker",
1112 "long_line_behaviour", 1 /* follow global */);
1113 p->priv->long_line_column = utils_get_setting_integer(config, "long line marker",
1114 "long_line_column", editor_prefs.long_line_column);
1115 apply_editor_prefs();
1117 build_load_menu(config, GEANY_BCS_PROJ, (gpointer)p);
1118 /* save current (non-project) session (it could have been changed since program startup) */
1119 if (!main_status.opening_session_files)
1121 configuration_save_default_session();
1122 /* now close all open files */
1123 document_close_all();
1125 /* read session files so they can be opened with configuration_open_files() */
1126 p->priv->session_files = configuration_load_session_files(config);
1127 g_signal_emit_by_name(geany_object, "project-open", config);
1128 g_key_file_free(config);
1130 update_ui();
1131 return TRUE;
1135 static void apply_editor_prefs(void)
1137 guint i;
1139 foreach_document(i)
1140 editor_apply_update_prefs(documents[i]->editor);
1144 /* Write the project settings as well as the project session files into its configuration files.
1145 * Returns: TRUE if project file was written successfully. */
1146 static gboolean write_config(void)
1148 GeanyProject *p;
1149 GKeyFile *config;
1150 gchar *filename;
1151 gchar *data;
1152 gboolean ret = FALSE;
1153 GSList *node;
1155 g_return_val_if_fail(app->project != NULL, FALSE);
1157 p = app->project;
1159 config = g_key_file_new();
1160 /* try to load an existing config to keep manually added comments */
1161 filename = utils_get_locale_from_utf8(p->file_name);
1162 g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
1164 foreach_slist(node, stash_groups)
1165 stash_group_save_to_key_file(node->data, config);
1167 g_key_file_set_string(config, "project", "name", p->name);
1168 g_key_file_set_string(config, "project", "base_path", p->base_path);
1170 if (p->description)
1171 g_key_file_set_string(config, "project", "description", p->description);
1172 if (p->file_patterns)
1173 g_key_file_set_string_list(config, "project", "file_patterns",
1174 (const gchar**) p->file_patterns, g_strv_length(p->file_patterns));
1176 // editor settings
1177 g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->priv->long_line_behaviour);
1178 g_key_file_set_integer(config, "long line marker", "long_line_column", p->priv->long_line_column);
1180 /* store the session files into the project too */
1181 configuration_save_session_files(config);
1182 build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ);
1183 g_signal_emit_by_name(geany_object, "project-save", config);
1184 /* write the file */
1185 data = g_key_file_to_data(config, NULL, NULL);
1186 ret = (utils_write_file(filename, data) == 0);
1188 g_free(data);
1189 g_free(filename);
1190 g_key_file_free(config);
1192 return ret;
1196 /** Forces the project file rewrite and emission of the project-save signal. Plugins
1197 * can use this function to save additional project data outside the project dialog.
1199 * @since 1.25
1201 GEANY_API_SYMBOL
1202 void project_write_config(void)
1204 if (!write_config())
1205 SHOW_ERR(_("Project file could not be written"));
1209 /* Constructs the project's base path which is used for "Make all" and "Execute".
1210 * The result is an absolute string in UTF-8 encoding which is either the same as
1211 * base path if it is absolute or it is built out of project file name's dir and base_path.
1212 * If there is no project or project's base_path is invalid, NULL will be returned.
1213 * The returned string should be freed when no longer needed. */
1214 gchar *project_get_base_path(void)
1216 GeanyProject *project = app->project;
1218 if (project && !EMPTY(project->base_path))
1220 if (g_path_is_absolute(project->base_path))
1221 return g_strdup(project->base_path);
1222 else
1223 { /* build base_path out of project file name's dir and base_path */
1224 gchar *path;
1225 gchar *dir = g_path_get_dirname(project->file_name);
1227 if (utils_str_equal(project->base_path, "./"))
1228 return dir;
1230 path = g_build_filename(dir, project->base_path, NULL);
1231 g_free(dir);
1232 return path;
1235 return NULL;
1239 /* This is to save project-related global settings, NOT project file settings. */
1240 void project_save_prefs(GKeyFile *config)
1242 GeanyProject *project = app->project;
1244 if (cl_options.load_session)
1246 const gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
1248 g_key_file_set_string(config, "project", "session_file", utf8_filename);
1250 g_key_file_set_string(config, "project", "project_file_path",
1251 FALLBACK(local_prefs.project_file_path, ""));
1255 void project_load_prefs(GKeyFile *config)
1257 if (cl_options.load_session)
1259 g_return_if_fail(project_prefs.session_file == NULL);
1260 project_prefs.session_file = utils_get_setting_string(config, "project",
1261 "session_file", "");
1263 local_prefs.project_file_path = utils_get_setting_string(config, "project",
1264 "project_file_path", NULL);
1265 if (local_prefs.project_file_path == NULL)
1267 local_prefs.project_file_path = g_build_filename(g_get_home_dir(), PROJECT_DIR, NULL);
1272 /* Initialize project-related preferences in the Preferences dialog. */
1273 void project_setup_prefs(void)
1275 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1276 GtkWidget *path_btn = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_button");
1277 static gboolean callback_setup = FALSE;
1279 g_return_if_fail(local_prefs.project_file_path != NULL);
1281 gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
1282 if (! callback_setup)
1283 { /* connect the callback only once */
1284 callback_setup = TRUE;
1285 ui_setup_open_button_callback(path_btn, NULL,
1286 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(path_entry));
1291 /* Update project-related preferences after using the Preferences dialog. */
1292 void project_apply_prefs(void)
1294 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1295 const gchar *str;
1297 str = gtk_entry_get_text(GTK_ENTRY(path_entry));
1298 SETPTR(local_prefs.project_file_path, g_strdup(str));
1302 static void add_stash_group(StashGroup *group, gboolean apply_defaults)
1304 GKeyFile *kf;
1306 stash_groups = g_slist_prepend(stash_groups, group);
1307 if (!apply_defaults)
1308 return;
1310 kf = g_key_file_new();
1311 stash_group_load_from_key_file(group, kf);
1312 g_key_file_free(kf);
1316 static void init_stash_prefs(void)
1318 StashGroup *group;
1320 group = stash_group_new("indentation");
1321 /* copy global defaults */
1322 indentation = *editor_get_indent_prefs(NULL);
1323 stash_group_set_use_defaults(group, FALSE);
1324 add_stash_group(group, FALSE);
1326 stash_group_add_spin_button_integer(group, &indentation.width,
1327 "indent_width", 4, "spin_indent_width_project");
1328 stash_group_add_radio_buttons(group, (gint*)(gpointer)&indentation.type,
1329 "indent_type", GEANY_INDENT_TYPE_TABS,
1330 "radio_indent_spaces_project", GEANY_INDENT_TYPE_SPACES,
1331 "radio_indent_tabs_project", GEANY_INDENT_TYPE_TABS,
1332 "radio_indent_both_project", GEANY_INDENT_TYPE_BOTH,
1333 NULL);
1334 /* This is a 'hidden' pref for backwards-compatibility */
1335 stash_group_add_integer(group, &indentation.hard_tab_width,
1336 "indent_hard_tab_width", 8);
1337 stash_group_add_toggle_button(group, &indentation.detect_type,
1338 "detect_indent", FALSE, "check_detect_indent_type_project");
1339 stash_group_add_toggle_button(group, &indentation.detect_width,
1340 "detect_indent_width", FALSE, "check_detect_indent_width_project");
1341 stash_group_add_combo_box(group, (gint*)(gpointer)&indentation.auto_indent_mode,
1342 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project");
1344 group = stash_group_new("file_prefs");
1345 stash_group_add_toggle_button(group, &priv.final_new_line,
1346 "final_new_line", file_prefs.final_new_line, "check_new_line1");
1347 stash_group_add_toggle_button(group, &priv.ensure_convert_new_lines,
1348 "ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1");
1349 stash_group_add_toggle_button(group, &priv.strip_trailing_spaces,
1350 "strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
1351 stash_group_add_toggle_button(group, &priv.replace_tabs,
1352 "replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
1353 add_stash_group(group, TRUE);
1355 group = stash_group_new("editor");
1356 stash_group_add_toggle_button(group, &priv.line_wrapping,
1357 "line_wrapping", editor_prefs.line_wrapping, "check_line_wrapping1");
1358 stash_group_add_spin_button_integer(group, &priv.line_break_column,
1359 "line_break_column", editor_prefs.line_break_column, "spin_line_break1");
1360 stash_group_add_toggle_button(group, &priv.auto_continue_multiline,
1361 "auto_continue_multiline", editor_prefs.auto_continue_multiline,
1362 "check_auto_multiline1");
1363 add_stash_group(group, TRUE);
1367 #define COPY_PREF(dest, prefname)\
1368 (dest.prefname = priv.prefname)
1370 const GeanyFilePrefs *project_get_file_prefs(void)
1372 static GeanyFilePrefs fp;
1374 if (!app->project)
1375 return &file_prefs;
1377 fp = file_prefs;
1378 COPY_PREF(fp, final_new_line);
1379 COPY_PREF(fp, ensure_convert_new_lines);
1380 COPY_PREF(fp, strip_trailing_spaces);
1381 COPY_PREF(fp, replace_tabs);
1382 return &fp;
1386 void project_init(void)
1391 void project_finalize(void)