geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

project.c
Go to the documentation of this file.
1/*
2 * project.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2007 The Geany contributors
5 *
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.
10 *
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.
15 *
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.
19 */
20
21/** @file project.h
22 * Project Management.
23 */
24
25#ifdef HAVE_CONFIG_H
26# include "config.h"
27#endif
28
29#include "project.h"
30
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"
47
48#include <string.h>
49#include <unistd.h>
50#include <errno.h>
51
52
53ProjectPrefs project_prefs = { NULL, FALSE, FALSE };
54
55
58
59static GSList *stash_groups = NULL;
60
61static struct
62{
63 gchar *project_file_path; /* in UTF-8 */
65
66/* simple struct to keep references to the elements of the properties dialog */
68{
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;
80
81
82static gboolean update_config(const PropertyDialogElements *e, gboolean new_project);
83static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e);
84static gboolean load_config(const gchar *filename);
85static gboolean write_config(void);
86static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e);
87static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e);
88static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line);
90static void apply_editor_prefs(void);
91static void init_stash_prefs(void);
92static void destroy_project(gboolean open_default);
93
94
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")
101
102
103// returns whether we have working documents open
104static gboolean have_session_docs(void)
105{
106 gint npages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
108
109 return npages > 1 || (npages == 1 && (doc->file_name || doc->changed));
110}
111
112
113static gboolean handle_current_session(void)
114{
115 if (!app->project && project_prefs.project_session)
116 {
117 /* save session in case the dialog is cancelled */
119 /* don't ask if the only doc is an unmodified new doc */
120 if (have_session_docs())
121 {
123 _("Move the current documents into the new project's session?")))
124 {
125 // don't reload session on closing project
127 }
128 else
129 {
130 if (!document_close_all())
131 return FALSE;
132 }
133 }
134 }
135 if (app->project)
136 return project_close(FALSE);
137 return TRUE;
138}
139
140
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(). */
144void project_new(void)
145{
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 };
154
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);
158
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);
164
165 vbox = ui_dialog_vbox_new(GTK_DIALOG(e.dialog));
166
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);
170
171 label = gtk_label_new(_("Name:"));
172 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
173
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"));
179
180 ui_table_add_row(GTK_TABLE(table), 0, label, e.name, NULL);
181
182 label = gtk_label_new(_("Filename:"));
183 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
184
185 e.file_name = gtk_entry_new();
186 gtk_entry_set_activates_default(GTK_ENTRY(e.file_name), TRUE);
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);
201
202 ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);
203
204 label = gtk_label_new(_("Base path:"));
205 gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
206
207 e.base_path = gtk_entry_new();
208 gtk_entry_set_activates_default(GTK_ENTRY(e.base_path), TRUE);
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));
216
217 ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);
218
219 gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
220
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);
225
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);
228
230 run_new_dialog(&e);
231 gtk_widget_destroy(e.dialog);
234}
235
236
238{
239 if (gtk_dialog_run(GTK_DIALOG(e->dialog)) != GTK_RESPONSE_OK ||
241 return;
242 do
243 {
244 if (update_config(e, TRUE))
245 {
246 // app->project is now set
247 if (!write_config())
248 {
249 SHOW_ERR(_("Project file could not be written"));
250 destroy_project(FALSE);
251 }
252 else
253 {
254 ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name);
256 return;
257 }
258 }
259 }
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())
265 else
266 {
267 // reload any documents that were closed
270 }
271}
272
273
274gboolean project_load_file_with_session(const gchar *locale_file_name)
275{
276 if (project_load_file(locale_file_name))
277 {
278 if (project_prefs.project_session)
279 {
283 }
284 return TRUE;
285 }
286 return FALSE;
287}
288
289
290static void run_open_dialog(GtkDialog *dialog)
291{
292 while (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT)
293 {
294 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
295
296 if (app->project && !project_close(FALSE)) {}
297 /* try to load the config */
299 {
300 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
301
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;
307 }
308 g_free(filename);
309 break;
310 }
311}
312
313
314void project_open(void)
315{
316 const gchar *dir = local_prefs.project_file_path;
317
318#ifdef G_OS_WIN32
320 {
321 gchar *file = win32_show_project_open_dialog(main_widgets.window, _("Open Project"), dir, FALSE, TRUE);
322 if (file != NULL)
323 {
324 if (app->project && !project_close(FALSE)) {}
325 /* try to load the config */
326 else if (! project_load_file_with_session(file))
327 {
328 SHOW_ERR1(_("Project file \"%s\" could not be loaded."), file);
329 }
330 g_free(file);
331 }
332 }
333 else
334#endif
335 {
336 GtkWidget *dialog;
337 GtkFileFilter *filter;
338 gchar *locale_path;
339
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");
345
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);
353
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);
364
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))
368 {
369 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
370 }
371 g_free(locale_path);
372
374 run_open_dialog(GTK_DIALOG(dialog));
375 gtk_widget_destroy(GTK_WIDGET(dialog));
376 }
377}
378
379
380/* Called when creating, opening, closing and updating projects. */
381static void update_ui(void)
382{
383 if (main_status.quitting)
384 return;
385
388 // update project name
391}
392
393
394static void remove_foreach_project_filetype(gpointer data, gpointer user_data)
395{
396 GeanyFiletype *ft = data;
397 if (ft != NULL)
398 {
402 ft->priv->project_list_entry = -1;
403 }
404}
405
406
407/* open_default will make function reload default session files on close */
408gboolean project_close(gboolean open_default)
409{
410 g_return_val_if_fail(app->project != NULL, FALSE);
411
412 /* save project session files, etc */
413 if (!write_config())
414 g_warning("Project file \"%s\" could not be written", app->project->file_name);
415
416 if (project_prefs.project_session)
417 {
418 /* close all existing tabs first */
419 if (!document_close_all())
420 return FALSE;
421 }
422 ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
423 destroy_project(open_default);
424 return TRUE;
425}
426
427
428static void destroy_project(gboolean open_default)
429{
430 GSList *node;
431
432 g_return_if_fail(app->project != NULL);
433
434 g_signal_emit_by_name(geany_object, "project-before-close");
435
436 /* remove project filetypes build entries */
438 {
440 g_ptr_array_free(app->project->priv->build_filetypes_list, FALSE);
441 }
442
443 /* remove project non filetype build menu items */
446
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);
452
453 g_free(app->project);
454 app->project = NULL;
455
457 stash_group_free(node->data);
458
459 g_slist_free(stash_groups);
461
462 apply_editor_prefs(); /* ensure that global settings are restored */
463
464 if (project_prefs.project_session)
465 {
466 /* after closing all tabs let's open the tabs found in the default config */
467 if (open_default && cl_options.load_session)
468 {
473 }
474 }
475 g_signal_emit_by_name(geany_object, "project-close");
476
477 update_ui();
478}
479
480
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). */
485 GtkWidget *base_path_entry)
486{
487 GtkWidget *dialog;
488
489 g_return_if_fail(base_path_entry != NULL);
490 g_return_if_fail(GTK_IS_WIDGET(base_path_entry));
491
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);
497
498 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
499 {
500 gtk_entry_set_text(GTK_ENTRY(base_path_entry),
501 gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
502 }
503
504 gtk_widget_destroy(dialog);
505}
506
507
509{
510 GtkWidget *build_table, *label;
512 GeanyFiletype *ft = NULL;
513
514 if (doc != NULL)
515 ft = doc->file_type;
516
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);
522}
523
524
526{
527 GtkWidget *wid;
528 static guint base_path_button_handler_id = 0;
529 static guint radio_long_line_handler_id = 0;
530
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");
538
539 gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
540
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));
544
545 /* Workaround for bug in Glade 3.8.1, see comment above signal handler */
546 if (base_path_button_handler_id == 0)
547 {
548 wid = ui_lookup_widget(e->dialog, "button_project_dialog_base_path");
549 base_path_button_handler_id =
550 g_signal_connect(wid, "clicked",
552 e->base_path);
553 }
554
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)
557 {
558 wid = ui_lookup_widget(e->dialog, "radio_long_line_custom_project");
559 radio_long_line_handler_id =
560 g_signal_connect(wid, "toggled",
562 ui_lookup_widget(e->dialog, "spin_long_line_project"));
563 }
564}
565
566
567static void show_project_properties(gboolean show_build)
568{
570 GtkWidget *widget = NULL;
571 GtkWidget *radio_long_line_custom;
572 static PropertyDialogElements e;
573 GSList *node;
574 gchar *entry_text;
575 GtkTextBuffer *buffer;
576
577 g_return_if_fail(app->project != NULL);
578
579 if (e.dialog == NULL)
581
583
585 stash_group_display(node->data, e.dialog);
586
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);
591
592 radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project");
593 switch (p->priv->long_line_behaviour)
594 {
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;
598 }
599 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
600
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);
604
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);
608
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);
613
614 g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook);
616
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);
622
623 while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK)
624 {
625 if (update_config(&e, FALSE))
626 {
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
631 {
632 ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name);
633 break;
634 }
635 }
636 }
637
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);
642}
643
644
646{
648}
649
650
652{
654}
655
656
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 */
660gboolean project_ask_close(void)
661{
662 if (app->project != NULL)
663 {
664 if (dialogs_show_question_full(NULL, GTK_STOCK_CLOSE, GTK_STOCK_CANCEL,
665 _("Do you want to close it before proceeding?"),
666 _("The '%s' project is open."), app->project->name))
667 {
668 return project_close(FALSE);
669 }
670 else
671 return FALSE;
672 }
673 else
674 return TRUE;
675}
676
677
679{
680 GeanyProject *project = g_new0(GeanyProject, 1);
681
682 memset(&priv, 0, sizeof priv);
684 project->priv = &priv;
685
687
688 project->file_patterns = NULL;
689
690 project->priv->long_line_behaviour = 1 /* use global settings */;
692
693 app->project = project;
694 return project;
695}
696
697
698/* Verifies data for New & Properties dialogs.
699 * Creates app->project if NULL.
700 * Returns: FALSE if the user needs to change any data. */
701static gboolean update_config(const PropertyDialogElements *e, gboolean new_project)
702{
703 const gchar *name, *file_name, *base_path;
704 gchar *locale_filename;
705 gsize name_len;
706 gint err_code = 0;
707 GeanyProject *p;
708
709 g_return_val_if_fail(e != NULL, TRUE);
710
711 name = gtk_entry_get_text(GTK_ENTRY(e->name));
712 name_len = strlen(name);
713 if (name_len == 0)
714 {
715 SHOW_ERR(_("The specified project name is too short."));
716 gtk_widget_grab_focus(e->name);
717 return FALSE;
718 }
719 else if (name_len > MAX_NAME_LEN)
720 {
721 SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
722 gtk_widget_grab_focus(e->name);
723 return FALSE;
724 }
725
726 if (new_project)
727 file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
728 else
729 file_name = gtk_label_get_text(GTK_LABEL(e->file_name));
730
731 if (G_UNLIKELY(EMPTY(file_name)))
732 {
733 SHOW_ERR(_("You have specified an invalid project filename."));
734 gtk_widget_grab_focus(e->file_name);
735 return FALSE;
736 }
737
738 locale_filename = utils_get_locale_from_utf8(file_name);
739 base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
740 if (!EMPTY(base_path))
741 { /* check whether the given directory actually exists */
742 gchar *locale_path = utils_get_locale_from_utf8(base_path);
743
744 if (! g_path_is_absolute(locale_path))
745 { /* relative base path, so add base dir of project file name */
746 gchar *dir = g_path_get_dirname(locale_filename);
747 SETPTR(locale_path, g_build_filename(dir, locale_path, NULL));
748 g_free(dir);
749 }
750
751 if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
752 {
753 gboolean create_dir;
754
755 create_dir = dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
756 _("Create the project's base path directory?"),
757 _("The path \"%s\" does not exist."),
758 base_path);
759
760 if (create_dir)
761 err_code = utils_mkdir(locale_path, TRUE);
762
763 if (! create_dir || err_code != 0)
764 {
765 if (err_code != 0)
766 SHOW_ERR1(_("Project base directory could not be created (%s)."),
767 g_strerror(err_code));
768 gtk_widget_grab_focus(e->base_path);
769 utils_free_pointers(2, locale_path, locale_filename, NULL);
770 return FALSE;
771 }
772 }
773 g_free(locale_path);
774 }
775 /* finally test whether the given project file can be written */
776 if ((err_code = utils_is_file_writable(locale_filename)) != 0 ||
777 (err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0)
778 {
779 SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code));
780 gtk_widget_grab_focus(e->file_name);
781 g_free(locale_filename);
782 return FALSE;
783 }
784 else if (new_project && g_file_test(locale_filename, G_FILE_TEST_EXISTS) &&
785 ! dialogs_show_question_full(NULL, _("_Replace"), GTK_STOCK_CANCEL,
786 NULL,
787 _("The file '%s' already exists. Do you want to overwrite it?"),
788 file_name))
789 {
790 gtk_widget_grab_focus(e->file_name);
791 g_free(locale_filename);
792 return FALSE;
793 }
794 g_free(locale_filename);
795
796 if (app->project == NULL)
797 {
799 new_project = TRUE;
800 }
801 p = app->project;
802
803 SETPTR(p->name, g_strdup(name));
804 SETPTR(p->file_name, g_strdup(file_name));
805 /* use "." if base_path is empty */
806 SETPTR(p->base_path, g_strdup(!EMPTY(base_path) ? base_path : "./"));
807
808 if (! new_project) /* save properties specific fields */
809 {
810 GtkTextIter start, end;
811 GtkTextBuffer *buffer;
813 GeanyBuildCommand *oldvalue;
814 GeanyFiletype *ft = doc ? doc->file_type : NULL;
815 GtkWidget *widget;
816 gchar *tmp;
817 GString *str;
818 GSList *node;
819
820 /* get and set the project description */
821 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
822 gtk_text_buffer_get_start_iter(buffer, &start);
823 gtk_text_buffer_get_end_iter(buffer, &end);
824 SETPTR(p->description, gtk_text_buffer_get_text(buffer, &start, &end, FALSE));
825
827 stash_group_update(node->data, e->dialog);
828
829 /* read the project build menu */
830 oldvalue = ft ? ft->priv->projfilecmds : NULL;
832
833 if (ft != NULL && ft->priv->projfilecmds != oldvalue && ft->priv->project_list_entry < 0)
834 {
835 if (p->priv->build_filetypes_list == NULL)
836 p->priv->build_filetypes_list = g_ptr_array_new();
838 g_ptr_array_add(p->priv->build_filetypes_list, ft);
839 }
841
842 widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project");
843 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
845 else
846 {
847 widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project");
848 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
850 else
851 /* "Custom" radio button must be checked */
853 }
854
855 widget = ui_lookup_widget(e->dialog, "spin_long_line_project");
856 p->priv->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
858
859 /* get and set the project file patterns */
860 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns)));
861 g_strfreev(p->file_patterns);
862 g_strstrip(tmp);
863 str = g_string_new(tmp);
864 do {} while (utils_string_replace_all(str, " ", " "));
865 p->file_patterns = g_strsplit(str->str, " ", -1);
866 g_string_free(str, TRUE);
867 g_free(tmp);
868 }
869
870 update_ui();
871
872 return TRUE;
873}
874
875
876#ifndef G_OS_WIN32
877static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
878{
879 /* set filename in the file chooser dialog */
880 const gchar *utf8_filename = gtk_entry_get_text(GTK_ENTRY(entry));
881 gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
882
883 if (g_path_is_absolute(locale_filename))
884 {
885 if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
886 {
887 /* if the current filename is a directory, we must use
888 * gtk_file_chooser_set_current_folder(which expects a locale filename) otherwise
889 * we end up in the parent directory */
890 if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR))
891 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_filename);
892 else
893 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
894 }
895 else /* if the file doesn't yet exist, use at least the current directory */
896 {
897 gchar *locale_dir = g_path_get_dirname(locale_filename);
898 gchar *name = g_path_get_basename(utf8_filename);
899
900 if (g_file_test(locale_dir, G_FILE_TEST_EXISTS))
901 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dir);
902 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), name);
903
904 g_free(name);
905 g_free(locale_dir);
906 }
907 }
908 else if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
909 {
910 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), utf8_filename);
911 }
912 g_free(locale_filename);
913
914 /* run it */
915 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
916 {
917 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
918 gchar *tmp_utf8_filename = utils_get_utf8_from_locale(filename);
919
920 gtk_entry_set_text(GTK_ENTRY(entry), tmp_utf8_filename);
921
922 g_free(tmp_utf8_filename);
923 g_free(filename);
924 }
925 gtk_widget_destroy(dialog);
926}
927#endif
928
929
930static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e)
931{
932#ifdef G_OS_WIN32
933 gchar *path = win32_show_project_open_dialog(e->dialog, _("Choose Project Filename"),
934 gtk_entry_get_text(GTK_ENTRY(e->file_name)), TRUE, TRUE);
935 if (path != NULL)
936 {
937 gtk_entry_set_text(GTK_ENTRY(e->file_name), path);
938 g_free(path);
939 }
940#else
941 GtkWidget *dialog;
942
943 /* initialise the dialog */
944 dialog = gtk_file_chooser_dialog_new(_("Choose Project Filename"), NULL,
945 GTK_FILE_CHOOSER_ACTION_SAVE,
946 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
947 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
948 gtk_widget_set_name(dialog, "GeanyDialogProject");
949 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
950 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
951 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
952 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
953
955#endif
956}
957
958
959/* sets the project base path and the project file name according to the project name */
960static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
961{
962 gchar *base_path;
963 gchar *file_name;
964 gchar *name;
965 const gchar *project_dir = local_prefs.project_file_path;
966
967 if (e->entries_modified)
968 return;
969
970 name = gtk_editable_get_chars(editable, 0, -1);
971 if (!EMPTY(name))
972 {
973 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
974 name, G_DIR_SEPARATOR_S, NULL);
975 if (project_prefs.project_file_in_basedir)
976 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, name, G_DIR_SEPARATOR_S,
978 else
979 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
981 }
982 else
983 {
984 base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
985 file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
986 }
987 g_free(name);
988
989 gtk_entry_set_text(GTK_ENTRY(e->base_path), base_path);
990 gtk_entry_set_text(GTK_ENTRY(e->file_name), file_name);
991
992 e->entries_modified = FALSE;
993
994 g_free(base_path);
995 g_free(file_name);
996}
997
998
999static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
1000{
1001 e->entries_modified = TRUE;
1002}
1003
1004
1005static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line)
1006{
1007 gtk_widget_set_sensitive(spin_long_line, gtk_toggle_button_get_active(radio));
1008}
1009
1010
1011gboolean project_load_file(const gchar *locale_file_name)
1012{
1013 g_return_val_if_fail(locale_file_name != NULL, FALSE);
1014
1015 if (load_config(locale_file_name))
1016 {
1017 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1018
1019 ui_set_statusbar(TRUE, _("Project \"%s\" opened."), app->project->name);
1020
1021 ui_add_recent_project_file(utf8_filename);
1022 g_free(utf8_filename);
1023 return TRUE;
1024 }
1025 else
1026 {
1027 gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
1028
1029 ui_set_statusbar(TRUE, _("Project file \"%s\" could not be loaded."), utf8_filename);
1030 g_free(utf8_filename);
1031 }
1032 return FALSE;
1033}
1034
1035
1036/* Reads the given filename and creates a new project with the data found in the file.
1037 * At this point there should not be an already opened project in Geany otherwise it will just
1038 * return.
1039 * The filename is expected in the locale encoding. */
1040static gboolean load_config(const gchar *filename)
1041{
1042 GKeyFile *config;
1043 GeanyProject *p;
1044 GSList *node;
1045
1046 /* there should not be an open project */
1047 g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
1048
1049 config = g_key_file_new();
1050 if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL))
1051 {
1052 g_key_file_free(config);
1053 return FALSE;
1054 }
1055
1056 p = create_project();
1057
1059 stash_group_load_from_key_file(node->data, config);
1060
1061 p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED);
1062 p->description = utils_get_setting_string(config, "project", "description", "");
1064 p->base_path = utils_get_setting_string(config, "project", "base_path", "");
1065 p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
1066
1067 p->priv->long_line_behaviour = utils_get_setting_integer(config, "long line marker",
1068 "long_line_behaviour", 1 /* follow global */);
1069 p->priv->long_line_column = utils_get_setting_integer(config, "long line marker",
1070 "long_line_column", editor_prefs.long_line_column);
1072
1073 build_load_menu(config, GEANY_BCS_PROJ, (gpointer)p);
1074 if (project_prefs.project_session)
1075 {
1076 /* save current (non-project) session (it could have been changed since program startup) */
1078 /* now close all open files */
1080 /* read session files so they can be opened with configuration_open_files() */
1081 configuration_load_session_files(config, FALSE);
1082 }
1083 g_signal_emit_by_name(geany_object, "project-open", config);
1084 g_key_file_free(config);
1085
1086 update_ui();
1087 return TRUE;
1088}
1089
1090
1091static void apply_editor_prefs(void)
1092{
1093 guint i;
1094
1097}
1098
1099
1100/* Write the project settings as well as the project session files into its configuration files.
1101 * Returns: TRUE if project file was written successfully. */
1102static gboolean write_config(void)
1103{
1104 GeanyProject *p;
1105 GKeyFile *config;
1106 gchar *filename;
1107 gchar *data;
1108 gboolean ret = FALSE;
1109 GSList *node;
1110
1111 g_return_val_if_fail(app->project != NULL, FALSE);
1112
1113 p = app->project;
1114
1115 config = g_key_file_new();
1116 /* try to load an existing config to keep manually added comments */
1118 g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
1119
1121 stash_group_save_to_key_file(node->data, config);
1122
1123 g_key_file_set_string(config, "project", "name", p->name);
1124 g_key_file_set_string(config, "project", "base_path", p->base_path);
1125
1126 if (p->description)
1127 g_key_file_set_string(config, "project", "description", p->description);
1128 if (p->file_patterns)
1129 g_key_file_set_string_list(config, "project", "file_patterns",
1130 (const gchar**) p->file_patterns, g_strv_length(p->file_patterns));
1131
1132 // editor settings
1133 g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->priv->long_line_behaviour);
1134 g_key_file_set_integer(config, "long line marker", "long_line_column", p->priv->long_line_column);
1135
1136 /* store the session files into the project too */
1137 if (project_prefs.project_session)
1139 build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ);
1140 g_signal_emit_by_name(geany_object, "project-save", config);
1141 /* write the file */
1142 data = g_key_file_to_data(config, NULL, NULL);
1143 ret = (utils_write_file(filename, data) == 0);
1144
1145 g_free(data);
1146 g_free(filename);
1147 g_key_file_free(config);
1148
1149 return ret;
1150}
1151
1152
1153/** Forces the project file rewrite and emission of the project-save signal. Plugins
1154 * can use this function to save additional project data outside the project dialog.
1155 *
1156 * @since 1.25
1157 */
1158GEANY_API_SYMBOL
1160{
1161 if (!write_config())
1162 SHOW_ERR(_("Project file could not be written"));
1163}
1164
1165
1166/* Constructs the project's base path which is used for "Make all" and "Execute".
1167 * The result is an absolute string in UTF-8 encoding which is either the same as
1168 * base path if it is absolute or it is built out of project file name's dir and base_path.
1169 * If there is no project or project's base_path is invalid, NULL will be returned.
1170 * The returned string should be freed when no longer needed. */
1172{
1173 GeanyProject *project = app->project;
1174
1175 if (project && !EMPTY(project->base_path))
1176 {
1177 if (g_path_is_absolute(project->base_path))
1178 return g_strdup(project->base_path);
1179 else
1180 { /* build base_path out of project file name's dir and base_path */
1181 gchar *path;
1182 gchar *dir = g_path_get_dirname(project->file_name);
1183
1184 if (utils_str_equal(project->base_path, "./"))
1185 return dir;
1186
1187 path = g_build_filename(dir, project->base_path, NULL);
1188 g_free(dir);
1189 return path;
1190 }
1191 }
1192 return NULL;
1193}
1194
1195
1196/* This is to save project-related global settings, NOT project file settings. */
1197void project_save_prefs(GKeyFile *config)
1198{
1199 GeanyProject *project = app->project;
1200
1201 if (cl_options.load_session)
1202 {
1203 const gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
1204
1205 g_key_file_set_string(config, "project", "session_file", utf8_filename);
1206 }
1207 g_key_file_set_string(config, "project", "project_file_path",
1208 FALLBACK(local_prefs.project_file_path, ""));
1209}
1210
1211
1212void project_load_prefs(GKeyFile *config)
1213{
1214 if (cl_options.load_session)
1215 {
1216 g_return_if_fail(project_prefs.session_file == NULL);
1217 project_prefs.session_file = utils_get_setting_string(config, "project",
1218 "session_file", "");
1219 }
1220 local_prefs.project_file_path = utils_get_setting_string(config, "project",
1221 "project_file_path", NULL);
1222 if (local_prefs.project_file_path == NULL)
1223 {
1224 local_prefs.project_file_path = g_build_filename(g_get_home_dir(), PROJECT_DIR, NULL);
1225 }
1226}
1227
1228
1229/* Initialize project-related preferences in the Preferences dialog. */
1231{
1232 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1233 GtkWidget *path_btn = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_button");
1234 static gboolean callback_setup = FALSE;
1235
1236 g_return_if_fail(local_prefs.project_file_path != NULL);
1237
1238 gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
1239 if (! callback_setup)
1240 { /* connect the callback only once */
1241 callback_setup = TRUE;
1243 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(path_entry));
1244 }
1245}
1246
1247
1248/* Update project-related preferences after using the Preferences dialog. */
1250{
1251 GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
1252 const gchar *str;
1253
1254 str = gtk_entry_get_text(GTK_ENTRY(path_entry));
1255 SETPTR(local_prefs.project_file_path, g_strdup(str));
1256}
1257
1258
1259static void add_stash_group(StashGroup *group, gboolean apply_defaults)
1260{
1261 GKeyFile *kf;
1262
1263 stash_groups = g_slist_prepend(stash_groups, group);
1264 if (!apply_defaults)
1265 return;
1266
1267 kf = g_key_file_new();
1269 g_key_file_free(kf);
1270}
1271
1272
1273static void init_stash_prefs(void)
1274{
1276
1277 group = stash_group_new("indentation");
1278 /* copy global defaults */
1281 add_stash_group(group, FALSE);
1282
1284 "indent_width", 4, "spin_indent_width_project");
1286 "indent_type", GEANY_INDENT_TYPE_TABS,
1287 "radio_indent_spaces_project", GEANY_INDENT_TYPE_SPACES,
1288 "radio_indent_tabs_project", GEANY_INDENT_TYPE_TABS,
1289 "radio_indent_both_project", GEANY_INDENT_TYPE_BOTH,
1290 NULL);
1291 /* This is a 'hidden' pref for backwards-compatibility */
1293 "indent_hard_tab_width", 8);
1295 "detect_indent", FALSE, "check_detect_indent_type_project");
1297 "detect_indent_width", FALSE, "check_detect_indent_width_project");
1299 "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project");
1300
1301 group = stash_group_new("file_prefs");
1303 "final_new_line", file_prefs.final_new_line, "check_new_line1");
1305 "ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1");
1307 "strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
1309 "replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
1310 add_stash_group(group, TRUE);
1311
1312 group = stash_group_new("editor");
1314 "line_wrapping", editor_prefs.line_wrapping, "check_line_wrapping1");
1316 "line_break_column", editor_prefs.line_break_column, "spin_line_break1");
1318 "auto_continue_multiline", editor_prefs.auto_continue_multiline,
1319 "check_auto_multiline1");
1320 add_stash_group(group, TRUE);
1321}
1322
1323
1324#define COPY_PREF(dest, prefname)\
1325 (dest.prefname = priv.prefname)
1326
1328{
1329 static GeanyFilePrefs fp;
1330
1331 if (!app->project)
1332 return &file_prefs;
1333
1334 fp = file_prefs;
1335 COPY_PREF(fp, final_new_line);
1336 COPY_PREF(fp, ensure_convert_new_lines);
1337 COPY_PREF(fp, strip_trailing_spaces);
1338 COPY_PREF(fp, replace_tabs);
1339 return &fp;
1340}
1341
1342
1344{
1345}
1346
1347
1349{
1350}
Contains the GeanyApp.
void build_free_fields(BuildTableData table_data)
Definition: build.c:2076
void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
Definition: build.c:2576
void build_menu_update(GeanyDocument *doc)
Definition: build.c:1457
void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
Definition: build.c:2356
GtkWidget * build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, BuildTableData *table_data, GeanyFiletype *ft)
Definition: build.c:1946
void build_read_project(GeanyFiletype *ft, BuildTableData build_properties)
Definition: build.c:2196
void build_remove_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, const gint cmd)
Remove the specified Build menu item.
Definition: build.c:546
const gchar * label
Definition: build.c:2676
Interface to the Build menu functionality.
@ GEANY_GBG_NON_FT
non filetype items.
Definition: build.h:37
@ GEANY_GBG_EXEC
execute items
Definition: build.h:38
@ GEANY_BCS_PROJ
Project file if open.
Definition: build.h:50
gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn, const gchar *extra_text, const gchar *main_text,...)
Definition: dialogs.c:1393
gboolean dialogs_show_question(const gchar *text,...)
Shows a question message box with text and Yes/No buttons.
Definition: dialogs.c:1370
File related dialogs, miscellaneous dialogs, font dialog.
GeanyDocument * document_get_current(void)
Finds the current document.
Definition: document.c:371
gboolean document_close_all(void)
Definition: document.c:3396
GeanyDocument * document_new_file_if_non_open(void)
Definition: document.c:803
const gchar * name
Definition: document.c:3219
GeanyFilePrefs file_prefs
Definition: document.c:86
Document related actions: new, save, open, etc.
#define documents
Wraps GeanyData::documents_array so it can be used with C array syntax.
Definition: document.h:130
#define foreach_document(i)
Iterates all valid document indexes.
Definition: document.h:153
const GeanyIndentPrefs * editor_get_indent_prefs(GeanyEditor *editor)
Gets the indentation prefs for the editor.
Definition: editor.c:1267
void editor_apply_update_prefs(GeanyEditor *editor)
Definition: editor.c:5161
GeanyEditorPrefs editor_prefs
Definition: editor.c:77
Editor-related functions for GeanyEditor.
@ GEANY_AUTOINDENT_CURRENTCHARS
Definition: editor.h:58
@ GEANY_INDENT_TYPE_BOTH
Both.
Definition: editor.h:48
@ GEANY_INDENT_TYPE_TABS
Tabs.
Definition: editor.h:47
@ GEANY_INDENT_TYPE_SPACES
Spaces.
Definition: editor.h:46
static GtkWidget * path_entry
Definition: filebrowser.c:85
static gchar ** filter
Definition: filebrowser.c:89
#define GEANY_STRING_UNTITLED
Definition: geany.h:49
GObject * geany_object
Definition: geanyobject.c:41
void configuration_reload_default_session(void)
Definition: keyfile.c:1149
void configuration_open_files(void)
Definition: keyfile.c:1257
void configuration_clear_default_session(void)
Definition: keyfile.c:1125
void configuration_save_default_session(void)
Definition: keyfile.c:1104
void configuration_load_session_files(GKeyFile *config, gboolean read_recent_files)
Definition: keyfile.c:691
void configuration_save_session_files(GKeyFile *config)
Definition: keyfile.c:398
CommandLineOptions cl_options
Definition: libmain.c:90
GeanyApp * app
Definition: libmain.c:86
GeanyStatus main_status
Definition: libmain.c:89
Main program-related commands.
static gboolean update_config(const PropertyDialogElements *e, gboolean new_project)
Definition: project.c:701
static gboolean write_config(void)
Definition: project.c:1102
static void show_project_properties(gboolean show_build)
Definition: project.c:567
void project_build_properties(void)
Definition: project.c:651
struct _PropertyDialogElements PropertyDialogElements
static void run_new_dialog(PropertyDialogElements *e)
Definition: project.c:237
gchar * project_get_base_path(void)
Definition: project.c:1171
static void apply_editor_prefs(void)
Definition: project.c:1091
static void init_stash_prefs(void)
Definition: project.c:1273
gboolean project_close(gboolean open_default)
Definition: project.c:408
void project_write_config(void)
Forces the project file rewrite and emission of the project-save signal.
Definition: project.c:1159
void project_apply_prefs(void)
Definition: project.c:1249
static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
Definition: project.c:877
static void destroy_project(gboolean open_default)
Definition: project.c:428
static void run_open_dialog(GtkDialog *dialog)
Definition: project.c:290
static gboolean handle_current_session(void)
Definition: project.c:113
void project_finalize(void)
Definition: project.c:1348
static GeanyProjectPrivate priv
Definition: project.c:56
gboolean project_load_file_with_session(const gchar *locale_file_name)
Definition: project.c:274
void project_init(void)
Definition: project.c:1343
static void insert_build_page(PropertyDialogElements *e)
Definition: project.c:508
static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
Definition: project.c:999
gchar * project_file_path
Definition: project.c:63
void project_load_prefs(GKeyFile *config)
Definition: project.c:1212
#define PROJECT_DIR
Definition: project.c:100
gboolean project_load_file(const gchar *locale_file_name)
Definition: project.c:1011
static void create_properties_dialog(PropertyDialogElements *e)
Definition: project.c:525
static GeanyProject * create_project(void)
Definition: project.c:678
static void on_project_properties_base_path_button_clicked(GtkWidget *button, GtkWidget *base_path_entry)
Definition: project.c:484
ProjectPrefs project_prefs
Definition: project.c:53
void project_setup_prefs(void)
Definition: project.c:1230
#define SHOW_ERR(args)
Definition: project.c:95
static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line)
Definition: project.c:1005
const GeanyFilePrefs * project_get_file_prefs(void)
Definition: project.c:1327
#define SHOW_ERR1(args, more)
Definition: project.c:96
void project_open(void)
Definition: project.c:314
static gboolean load_config(const gchar *filename)
Definition: project.c:1040
#define COPY_PREF(dest, prefname)
Definition: project.c:1324
gboolean project_ask_close(void)
Definition: project.c:660
static struct @102 local_prefs
static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e)
Definition: project.c:930
static void add_stash_group(StashGroup *group, gboolean apply_defaults)
Definition: project.c:1259
static GSList * stash_groups
Definition: project.c:59
static GeanyIndentPrefs indentation
Definition: project.c:57
void project_save_prefs(GKeyFile *config)
Definition: project.c:1197
static void update_ui(void)
Definition: project.c:381
static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
Definition: project.c:960
void project_properties(void)
Definition: project.c:645
static gboolean have_session_docs(void)
Definition: project.c:104
void project_new(void)
Definition: project.c:144
static void remove_foreach_project_filetype(gpointer data, gpointer user_data)
Definition: project.c:394
#define MAX_NAME_LEN
Definition: project.c:97
Project Management.
#define GEANY_PROJECT_EXT
Definition: project.h:30
#define NULL
Definition: rbtree.h:150
GtkWidget * entry
Definition: search.c:118
void sidebar_openfiles_update_all(void)
Definition: sidebar.c:542
StashGroup * group
Definition: stash-example.c:1
const gchar filename[]
Definition: stash-example.c:4
stash_group_update(group, dialog)
GtkWidget * dialog
stash_group_add_toggle_button(group, &want_handle, "handle", TRUE, "check_handle")
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
gtk_widget_show_all(dialog)
stash_group_display(group, dialog)
void stash_group_add_spin_button_integer(StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id)
Adds a GtkSpinButton widget pref.
Definition: stash.c:896
void stash_group_add_radio_buttons(StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id, gint enum_id,...)
Adds a GtkRadioButton widget group pref.
Definition: stash.c:845
void stash_group_save_to_key_file(StashGroup *group, GKeyFile *keyfile)
Writes group settings into key values in keyfile.
Definition: stash.c:286
void stash_group_add_integer(StashGroup *group, gint *setting, const gchar *key_name, gint default_value)
Adds integer setting.
Definition: stash.c:485
void stash_group_load_from_key_file(StashGroup *group, GKeyFile *keyfile)
Reads key values from keyfile into the group settings.
Definition: stash.c:275
void stash_group_add_combo_box(StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id)
Adds a GtkComboBox widget pref.
Definition: stash.c:912
void stash_group_set_use_defaults(StashGroup *group, gboolean use_defaults)
Definition: stash.c:440
StashGroup * stash_group_new(const gchar *name)
Creates a new group.
Definition: stash.c:360
void stash_group_free(StashGroup *group)
Frees a group.
Definition: stash.c:407
Lightweight library for reading/writing GKeyFile settings and synchronizing widgets with C variables.
struct GeanyProject * project
Currently active project or NULL if none is open.
Definition: app.h:49
Structure for representing an open tab with all its properties.
Definition: document.h:81
gchar * file_name
The UTF-8 encoded file name.
Definition: document.h:92
gboolean changed
Whether this document has been changed since it was last saved.
Definition: document.h:107
GeanyFiletype * file_type
The filetype for this document, it's only a reference to one of the elements of the global filetypes ...
Definition: document.h:101
gboolean line_wrapping
Definition: editor.h:112
gboolean auto_continue_multiline
Definition: editor.h:129
gint line_break_column
Definition: editor.h:128
gint long_line_column
Definition: editor.h:106
File Prefs.
Definition: document.h:47
gboolean strip_trailing_spaces
Definition: document.h:51
gboolean final_new_line
Definition: document.h:50
gboolean ensure_convert_new_lines
Definition: document.h:61
gboolean replace_tabs
Definition: document.h:52
GeanyBuildCommand * projfilecmds
GeanyBuildCommand * projexeccmds
Represents a filetype.
Definition: filetypes.h:144
struct GeanyFiletypePrivate * priv
Definition: filetypes.h:171
Indentation prefs that might be different according to project or filetype.
Definition: editor.h:83
gboolean detect_type
Definition: editor.h:90
GeanyIndentType type
Whether to use tabs, spaces or both to indent.
Definition: editor.h:85
gboolean detect_width
Definition: editor.h:91
gint hard_tab_width
Width of a tab, but only when using GEANY_INDENT_TYPE_BOTH.
Definition: editor.h:88
GeanyAutoIndent auto_indent_mode
Definition: editor.h:89
gint width
Indent width.
Definition: editor.h:84
gboolean use_native_windows_dialogs
whether to use native Windows' dialogs (only used on Windows)
Definition: ui_utils.h:67
GtkWidget * window
Main window.
Definition: ui_utils.h:80
GtkWidget * notebook
Document notebook.
Definition: ui_utils.h:83
struct GeanyIndentPrefs * indentation
GPtrArray * build_filetypes_list
gboolean auto_continue_multiline
gboolean ensure_convert_new_lines
gboolean strip_trailing_spaces
Structure for representing a project.
Definition: project.h:35
GStrv file_patterns
Array of filename extension patterns.
Definition: project.h:43
gchar * file_name
Where the project file is stored (in UTF-8).
Definition: project.h:38
gchar * description
Short description of the project.
Definition: project.h:37
struct GeanyProjectPrivate * priv
Definition: project.h:45
gchar * base_path
Base path of the project directory (in UTF-8, maybe relative).
Definition: project.h:39
gchar * name
The name of the project.
Definition: project.h:36
GtkWidget * dialog
Definition: project.c:69
GtkWidget * file_name
Definition: project.c:73
GtkWidget * notebook
Definition: project.c:70
GtkWidget * patterns
Definition: project.c:75
GtkWidget * description
Definition: project.c:72
GtkWidget * base_path
Definition: project.c:74
GtkWidget * name
Definition: project.c:71
gboolean entries_modified
Definition: project.c:78
BuildTableData build_properties
Definition: project.c:76
Defines internationalization macros.
#define _(String)
Definition: support.h:42
#define FALLBACK(X, Y)
void ui_table_add_row(GtkTable *table, gint row,...)
Packs all GtkWidgets passed after the row argument into a table, using one widget per cell.
Definition: ui_utils.c:2066
GtkWidget * ui_dialog_vbox_new(GtkDialog *dialog)
Makes a fixed border for dialogs without increasing the button box border.
Definition: ui_utils.c:1499
GtkWidget * create_project_dialog(void)
Definition: ui_utils.c:2392
void ui_add_recent_project_file(const gchar *utf8_filename)
Definition: ui_utils.c:1257
GtkWidget * ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry)
Creates a GtkHBox with entry packed into it and an open button which runs a file chooser,...
Definition: ui_utils.c:1917
void ui_set_window_title(GeanyDocument *doc)
Definition: ui_utils.c:366
GeanyMainWidgets main_widgets
Definition: ui_utils.c:72
void ui_entry_add_clear_icon(GtkEntry *entry)
Adds a small clear icon to the right end of the passed entry.
Definition: ui_utils.c:1604
void ui_set_statusbar(gboolean log, const gchar *format,...)
Displays text on the statusbar.
Definition: ui_utils.c:168
void ui_focus_current_document(void)
Definition: ui_utils.c:3100
GtkWidget * ui_button_new_with_image(const gchar *stock_id, const gchar *text)
Creates a GtkButton with custom text and a stock image similar to gtk_button_new_from_stock().
Definition: ui_utils.c:1552
void ui_update_recent_project_menu(void)
Definition: ui_utils.c:1296
GtkWidget * ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
Returns a widget from a name in a component, usually created by Glade.
Definition: ui_utils.c:2743
void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title, GtkFileChooserAction action, GtkEntry *entry)
Definition: ui_utils.c:1950
UIWidgets ui_widgets
Definition: ui_utils.c:75
GeanyInterfacePrefs interface_prefs
Definition: ui_utils.c:71
User Interface general utility functions.
gint utils_write_file(const gchar *filename, const gchar *text)
Writes text into a file named filename.
Definition: utils.c:209
guint utils_string_replace_all(GString *haystack, const gchar *needle, const gchar *replace)
Replaces all occurrences of needle in haystack with replace.
Definition: utils.c:1529
gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value)
Wraps g_key_file_get_integer() to add a default value argument.
Definition: utils.c:805
gchar * utils_get_utf8_from_locale(const gchar *locale_text)
Converts the given string (in locale encoding) into UTF-8 encoding.
Definition: utils.c:1272
gint utils_mkdir(const gchar *path, gboolean create_parent_dirs)
Creates a directory if it doesn't already exist.
Definition: utils.c:1359
gboolean utils_str_equal(const gchar *a, const gchar *b)
NULL-safe string comparison.
Definition: utils.c:599
gchar * utils_get_setting_string(GKeyFile *config, const gchar *section, const gchar *key, const gchar *default_value)
Wraps g_key_file_get_string() to add a default value argument.
Definition: utils.c:867
void utils_free_pointers(gsize arg_count,...)
Definition: utils.c:1293
gint utils_is_file_writable(const gchar *locale_filename)
Definition: utils.c:657
gchar * utils_get_locale_from_utf8(const gchar *utf8_text)
Converts the given UTF-8 encoded string into locale encoding.
Definition: utils.c:1243
General utility functions, non-GTK related.
#define foreach_slist(node, list)
Iterates all the nodes in list.
Definition: utils.h:121
#define SETPTR(ptr, result)
Assigns result to ptr, then frees the old value.
Definition: utils.h:50
#define EMPTY(ptr)
Returns TRUE if ptr is NULL or *ptr is FALSE.
Definition: utils.h:38