Improve tag-goto popup
[geany-mirror.git] / src / libmain.c
blobd849bfa45b1473dd595144d67ec26375833f4080
1 /*
2 * libmain.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005 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 /**
22 * @file: main.h
23 * Main program-related commands.
24 * Handles program initialization and cleanup.
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include "main.h"
33 #include "app.h"
34 #include "build.h"
35 #include "callbacks.h"
36 #include "dialogs.h"
37 #include "document.h"
38 #include "encodingsprivate.h"
39 #include "filetypes.h"
40 #include "geanyobject.h"
41 #include "highlighting.h"
42 #include "keybindings.h"
43 #include "keyfile.h"
44 #include "log.h"
45 #include "msgwindow.h"
46 #include "navqueue.h"
47 #include "notebook.h"
48 #include "plugins.h"
49 #include "projectprivate.h"
50 #include "prefs.h"
51 #include "printing.h"
52 #include "sidebar.h"
53 #ifdef HAVE_SOCKET
54 # include "socket.h"
55 #endif
56 #include "support.h"
57 #include "symbols.h"
58 #include "templates.h"
59 #include "toolbar.h"
60 #include "tools.h"
61 #include "ui_utils.h"
62 #include "utils.h"
63 #include "vte.h"
64 #include "win32.h"
65 #include "osx.h"
67 #include <signal.h>
68 #include <time.h>
69 #include <sys/types.h>
70 #include <sys/stat.h>
71 #include <errno.h>
72 #include <string.h>
73 #include <stdlib.h>
75 #include <gtk/gtk.h>
76 #include <glib/gstdio.h>
78 #ifdef G_OS_UNIX
79 # include <glib-unix.h>
80 #endif
82 #ifdef HAVE_LOCALE_H
83 # include <locale.h>
84 #endif
87 GeanyApp *app;
88 gboolean ignore_callback; /* hack workaround for GTK+ toggle button callback problem */
90 GeanyStatus main_status;
91 CommandLineOptions cl_options; /* fields initialised in parse_command_line_options */
93 static gchar *original_cwd = NULL;
95 static const gchar geany_lib_versions[] = "GTK %u.%u.%u, GLib %u.%u.%u";
97 static gboolean want_plugins;
99 /* command-line options */
100 static gboolean verbose_mode = FALSE;
101 static gboolean ignore_global_tags = FALSE;
102 static gboolean no_msgwin = FALSE;
103 static gboolean show_version = FALSE;
104 static gchar *alternate_config = NULL;
105 #ifdef HAVE_VTE
106 static gboolean no_vte = FALSE;
107 static gchar *lib_vte = NULL;
108 #endif
109 static gboolean generate_tags = FALSE;
110 static gboolean no_preprocessing = FALSE;
111 static gboolean ft_names = FALSE;
112 static gboolean print_prefix = FALSE;
113 #ifdef HAVE_PLUGINS
114 static gboolean no_plugins = FALSE;
115 #endif
116 static gboolean dummy = FALSE;
118 /* in alphabetical order of short options */
119 static GOptionEntry entries[] =
121 { "column", 0, 0, G_OPTION_ARG_INT, &cl_options.goto_column, N_("Set initial column number to COLUMN for the first opened file (useful in conjunction with --line)"), N_("COLUMN") },
122 { "config", 'c', 0, G_OPTION_ARG_FILENAME, &alternate_config, N_("Use alternate configuration directory DIR"), N_("DIR") },
123 { "ft-names", 0, 0, G_OPTION_ARG_NONE, &ft_names, N_("Print internal filetype names"), NULL },
124 { "generate-tags", 'g', 0, G_OPTION_ARG_NONE, &generate_tags, N_("Generate global tags file (see documentation)"), NULL },
125 { "no-preprocessing", 'P', 0, G_OPTION_ARG_NONE, &no_preprocessing, N_("Don't preprocess C/C++ files when generating tags file"), NULL },
126 #ifdef HAVE_SOCKET
127 { "new-instance", 'i', 0, G_OPTION_ARG_NONE, &cl_options.new_instance, N_("Don't open files in a running instance, force opening a new instance"), NULL },
128 { "socket-file", 0, 0, G_OPTION_ARG_FILENAME, &cl_options.socket_filename, N_("Use socket filename FILE for communication with a running Geany instance"), N_("FILE") },
129 { "list-documents", 0, 0, G_OPTION_ARG_NONE, &cl_options.list_documents, N_("Return a list of open documents in a running Geany instance"), NULL },
130 #endif
131 { "line", 'l', 0, G_OPTION_ARG_INT, &cl_options.goto_line, N_("Set initial line number to LINE for the first opened file"), N_("LINE") },
132 { "no-msgwin", 'm', 0, G_OPTION_ARG_NONE, &no_msgwin, N_("Don't show message window at startup"), NULL },
133 { "no-ctags", 'n', 0, G_OPTION_ARG_NONE, &ignore_global_tags, N_("Don't load auto completion data (see documentation)"), NULL },
134 #ifdef HAVE_PLUGINS
135 { "no-plugins", 'p', 0, G_OPTION_ARG_NONE, &no_plugins, N_("Don't load plugins"), NULL },
136 #endif
137 { "print-prefix", 0, 0, G_OPTION_ARG_NONE, &print_prefix, N_("Print Geany's installation prefix"), NULL },
138 { "read-only", 'r', 0, G_OPTION_ARG_NONE, &cl_options.readonly, N_("Open all FILES in read-only mode (see documentation)"), NULL },
139 { "no-session", 's', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &cl_options.load_session, N_("Don't load the previous session's files"), NULL },
140 #ifdef HAVE_VTE
141 { "no-terminal", 't', 0, G_OPTION_ARG_NONE, &no_vte, N_("Don't load terminal support"), NULL },
142 { "vte-lib", 0, 0, G_OPTION_ARG_FILENAME, &lib_vte, N_("Use FILE as the dynamically-linked VTE library"), N_("FILE") },
143 #endif
144 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_mode, N_("Be verbose"), NULL },
145 { "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Show version and exit"), NULL },
146 { "dummy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &dummy, NULL, NULL }, /* for +NNN line number arguments */
147 { NULL, 0, 0, 0, NULL, NULL, NULL }
151 static void setup_window_position(void)
153 /* interprets the saved window geometry */
154 if (prefs.save_wingeom)
156 if (ui_prefs.geometry[2] != -1 && ui_prefs.geometry[3] != -1)
158 gtk_window_set_default_size(GTK_WINDOW(main_widgets.window),
159 ui_prefs.geometry[2], ui_prefs.geometry[3]);
163 if (prefs.save_winpos)
165 if (ui_prefs.geometry[0] != -1 && ui_prefs.geometry[1] != -1)
167 gtk_window_move(GTK_WINDOW(main_widgets.window),
168 ui_prefs.geometry[0], ui_prefs.geometry[1]);
170 if (ui_prefs.geometry[4] == 1)
172 gtk_window_maximize(GTK_WINDOW(main_widgets.window));
178 /* special things for the initial setup of the checkboxes and related stuff
179 * an action on a setting is only performed if the setting is not equal to the program default
180 * (all the following code is not perfect but it works for the moment) */
181 static void apply_settings(void)
183 ui_update_fold_items();
185 /* toolbar, message window and sidebar are by default visible, so don't change it if it is true */
186 toolbar_show_hide();
187 if (! ui_prefs.msgwindow_visible)
189 ignore_callback = TRUE;
190 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_messages_window1")), FALSE);
191 gtk_widget_hide(main_widgets.message_window_notebook);
192 ignore_callback = FALSE;
194 if (! ui_prefs.sidebar_visible)
196 ignore_callback = TRUE;
197 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_sidebar1")), FALSE);
198 ignore_callback = FALSE;
201 toolbar_apply_settings();
202 toolbar_update_ui();
204 ui_update_view_editor_menu_items();
206 /* hide statusbar if desired */
207 if (! interface_prefs.statusbar_visible)
209 gtk_widget_hide(ui_widgets.statusbar);
212 /* set the tab placements of the notebooks */
213 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.tab_pos_editor);
214 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), interface_prefs.tab_pos_msgwin);
215 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.sidebar_notebook), interface_prefs.tab_pos_sidebar);
217 /* whether to show notebook tabs or not */
218 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
220 #ifdef HAVE_VTE
221 if (! vte_info.have_vte)
222 #endif
224 gtk_widget_set_sensitive(
225 ui_lookup_widget(main_widgets.window, "send_selection_to_vte1"), FALSE);
228 if (interface_prefs.sidebar_pos != GTK_POS_LEFT)
229 ui_swap_sidebar_pos();
231 gtk_orientable_set_orientation(GTK_ORIENTABLE(ui_lookup_widget(main_widgets.window, "vpaned1")),
232 interface_prefs.msgwin_orientation);
236 static void on_window_active_changed(GtkWindow *window, GParamSpec *pspec, gpointer data)
238 GeanyDocument *doc = document_get_current();
240 if (doc && gtk_window_is_active(window))
241 document_check_disk_status(doc, TRUE);
245 static void main_init(void)
247 /* add our icon path in case we aren't installed in the system prefix */
248 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), utils_resource_dir(RESOURCE_DIR_ICON));
250 /* inits */
251 ui_init_stock_items();
253 ui_init_builder();
255 main_widgets.window = NULL;
256 app->project = NULL;
257 ui_widgets.open_fontsel = NULL;
258 ui_widgets.open_colorsel = NULL;
259 ui_widgets.prefs_dialog = NULL;
260 main_status.main_window_realized = FALSE;
261 file_prefs.tab_order_ltr = FALSE;
262 file_prefs.tab_order_beside = FALSE;
263 main_status.quitting = FALSE;
264 ignore_callback = FALSE;
265 ui_prefs.recent_queue = g_queue_new();
266 ui_prefs.recent_projects_queue = g_queue_new();
267 main_status.opening_session_files = 0;
269 main_widgets.window = create_window1();
270 g_signal_connect(main_widgets.window, "notify::is-active", G_CALLBACK(on_window_active_changed), NULL);
272 /* add recent projects to the Project menu */
273 ui_widgets.recent_projects_menuitem = ui_lookup_widget(main_widgets.window, "recent_projects1");
274 ui_widgets.recent_projects_menu_menubar = gtk_menu_new();
275 gtk_menu_item_set_submenu(GTK_MENU_ITEM(ui_widgets.recent_projects_menuitem),
276 ui_widgets.recent_projects_menu_menubar);
278 /* store important pointers for later reference */
279 main_widgets.toolbar = toolbar_init();
280 main_widgets.sidebar_notebook = ui_lookup_widget(main_widgets.window, "notebook3");
281 main_widgets.notebook = ui_lookup_widget(main_widgets.window, "notebook1");
282 main_widgets.editor_menu = create_edit_menu1();
283 main_widgets.tools_menu = ui_lookup_widget(main_widgets.window, "tools1_menu");
284 main_widgets.message_window_notebook = ui_lookup_widget(main_widgets.window, "notebook_info");
285 main_widgets.project_menu = ui_lookup_widget(main_widgets.window, "menu_project1_menu");
287 ui_widgets.toolbar_menu = create_toolbar_popup_menu1();
288 ui_init();
289 #ifdef MAC_INTEGRATION
290 osx_ui_init();
291 #endif
293 /* set widget names for matching with GTK CSS */
294 gtk_widget_set_name(main_widgets.window, "GeanyMainWindow");
295 gtk_widget_set_name(ui_widgets.toolbar_menu, "GeanyToolbarMenu");
296 gtk_widget_set_name(main_widgets.editor_menu, "GeanyEditMenu");
297 gtk_widget_set_name(ui_lookup_widget(main_widgets.window, "menubar1"), "GeanyMenubar");
298 gtk_widget_set_name(main_widgets.toolbar, "GeanyToolbar");
300 gtk_window_set_default_size(GTK_WINDOW(main_widgets.window),
301 GEANY_WINDOW_DEFAULT_WIDTH, GEANY_WINDOW_DEFAULT_HEIGHT);
305 const gchar *main_get_version_string(void)
307 static gchar full[] = PACKAGE_VERSION " (git >= " REVISION ")";
309 if (utils_str_equal(REVISION, "-1"))
310 return PACKAGE_VERSION;
311 else
312 return full;
316 /* get the full file path of a command-line argument
317 * N.B. the result should be freed and may contain '/../' or '/./ ' */
318 gchar *main_get_argv_filename(const gchar *filename)
320 gchar *result;
322 if (g_path_is_absolute(filename) || utils_is_uri(filename))
323 result = g_strdup(filename);
324 else
326 /* use current dir */
327 gchar *cur_dir = NULL;
328 if (original_cwd == NULL)
329 cur_dir = g_get_current_dir();
330 else
331 cur_dir = g_strdup(original_cwd);
333 result = g_strjoin(
334 G_DIR_SEPARATOR_S, cur_dir, filename, NULL);
335 g_free(cur_dir);
337 return result;
341 /* get a :line:column specifier from the end of a filename (if present),
342 * return the line/column values, and remove the specifier from the string
343 * (Note that *line and *column must both be set to -1 initially) */
344 static void get_line_and_column_from_filename(gchar *filename, gint *line, gint *column)
346 gsize i;
347 gint colon_count = 0;
348 gboolean have_number = FALSE;
349 gsize len;
351 g_assert(*line == -1 && *column == -1);
353 if (G_UNLIKELY(EMPTY(filename)))
354 return;
356 /* allow to open files like "test:0" */
357 if (g_file_test(filename, G_FILE_TEST_EXISTS))
358 return;
360 len = strlen(filename);
361 for (i = len - 1; i >= 1; i--)
363 gboolean is_colon = filename[i] == ':';
364 gboolean is_digit = g_ascii_isdigit(filename[i]);
366 if (! is_colon && ! is_digit)
367 break;
369 if (is_colon)
371 if (++colon_count > 1)
372 break; /* bail on 2+ colons in a row */
374 else
375 colon_count = 0;
377 if (is_digit)
378 have_number = TRUE;
380 if (is_colon && have_number)
382 gint number = atoi(&filename[i + 1]);
384 filename[i] = '\0';
385 have_number = FALSE;
387 *column = *line;
388 *line = number;
391 if (*column >= 0)
392 break; /* line and column are set, so we're done */
397 #ifdef G_OS_WIN32
398 static gint get_windows_socket_port(void)
400 /* Read config file early to get TCP port number as we need it for IPC before all
401 * other settings are read in load_settings() */
402 gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL);
403 GKeyFile *config = g_key_file_new();
404 gint port_number;
406 g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
407 port_number = utils_get_setting_integer(config, PACKAGE, "socket_remote_cmd_port",
408 SOCKET_WINDOWS_REMOTE_CMD_PORT);
409 geany_debug("Using TCP port number %d for IPC", port_number);
410 g_free(configfile);
411 g_key_file_free(config);
412 g_return_val_if_fail(port_number >= 1024 && port_number <= (gint)G_MAXUINT16,
413 SOCKET_WINDOWS_REMOTE_CMD_PORT);
414 return port_number;
418 static void change_working_directory_on_windows(void)
420 gchar *install_dir = win32_get_installation_dir();
422 /* remember original working directory for use with opening files from the command line */
423 original_cwd = g_get_current_dir();
425 /* On Windows, change the working directory to the Geany installation path to not lock
426 * the directory of a file passed as command line argument (see bug #2626124).
427 * This also helps if plugins or other code uses relative paths to load
428 * any additional resources (e.g. share/geany-plugins/...). */
429 win32_set_working_directory(install_dir);
431 g_free(install_dir);
433 #endif
436 static void setup_paths(void)
438 /* convert path names to locale encoding */
439 app->datadir = utils_get_locale_from_utf8(utils_resource_dir(RESOURCE_DIR_DATA));
440 app->docdir = utils_get_locale_from_utf8(utils_resource_dir(RESOURCE_DIR_DOC));
445 * Checks whether the main window has been realized.
446 * This is an easy indicator whether Geany is right now starting up (main window is not
447 * yet realized) or whether it has finished the startup process (main window is realized).
448 * This is because the main window is realized (i.e. actually drawn on the screen) at the
449 * end of the startup process.
451 * @note Maybe you want to use the @link pluginsignals.c @c "geany-startup-complete" signal @endlink
452 * to get notified about the completed startup process.
454 * @return @c TRUE if the Geany main window has been realized or @c FALSE otherwise.
456 * @since 0.19
458 GEANY_API_SYMBOL
459 gboolean main_is_realized(void)
461 return main_status.main_window_realized;
466 * Initialises the gettext translation system.
467 * This is a convenience function to set up gettext for internationalisation support
468 * in external plugins. You should call this function early in @ref plugin_init().
469 * If the macro HAVE_LOCALE_H is defined, @c setlocale(LC_ALL, "") is called.
470 * The codeset for the message translations is set to UTF-8.
472 * Note that this function only setups the gettext textdomain for you. You still have
473 * to adjust the build system of your plugin to get internationalisation support
474 * working properly.
476 * If you have already used @ref PLUGIN_SET_TRANSLATABLE_INFO() you
477 * don't need to call main_locale_init() again as it has already been done.
479 * @param locale_dir The location where the translation files should be searched. This is
480 * usually the @c LOCALEDIR macro, defined by the build system.
481 * E.g. @c $prefix/share/locale.
482 * Only used on non-Windows systems. On Windows, the directory is determined
483 * by @c g_win32_get_package_installation_directory().
484 * @param package The package name, usually this is the @c GETTEXT_PACKAGE macro,
485 * defined by the build system.
487 * @since 0.16
489 GEANY_API_SYMBOL
490 void main_locale_init(const gchar *locale_dir, const gchar *package)
492 #ifdef HAVE_LOCALE_H
493 setlocale(LC_ALL, "");
494 #endif
496 #ifdef G_OS_WIN32
497 locale_dir = utils_resource_dir(RESOURCE_DIR_LOCALE);
498 #endif
499 (void) bindtextdomain(package, locale_dir);
500 (void) bind_textdomain_codeset(package, "UTF-8");
504 static void print_filetypes(void)
506 const GSList *list, *node;
508 filetypes_init_types();
509 printf("Geany's filetype names:\n");
511 list = filetypes_get_sorted_by_name();
512 foreach_slist(node, list)
514 GeanyFiletype *ft = node->data;
516 printf("%s\n", ft->name);
518 filetypes_free_types();
522 static void wait_for_input_on_windows(void)
524 #ifdef G_OS_WIN32
525 if (verbose_mode)
527 geany_debug("Press any key to continue");
528 getchar();
530 #endif
534 static void parse_command_line_options(gint *argc, gchar ***argv)
536 GError *error = NULL;
537 GOptionContext *context;
538 gint i;
539 CommandLineOptions def_clo = {FALSE, NULL, TRUE, -1, -1, FALSE, FALSE, FALSE};
541 /* first initialise cl_options fields with default values */
542 cl_options = def_clo;
544 /* the GLib option parser can't handle the +NNN (line number) option,
545 * so we grab that here and replace it with a no-op */
546 for (i = 1; i < (*argc); i++)
548 if ((*argv)[i][0] != '+')
549 continue;
551 cl_options.goto_line = atoi((*argv)[i] + 1);
552 (*argv)[i] = (gchar *) "--dummy";
555 context = g_option_context_new(_("[FILES...]"));
557 g_option_context_set_summary(context, _("A fast and lightweight IDE."));
558 g_option_context_set_description(context, _("Report bugs to https://github.com/geany/geany/issues."));
559 g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
560 g_option_group_set_translation_domain(g_option_context_get_main_group(context), GETTEXT_PACKAGE);
561 g_option_context_add_group(context, gtk_get_option_group(FALSE));
562 g_option_context_parse(context, argc, argv, &error);
563 g_option_context_free(context);
565 if (error != NULL)
567 g_printerr("Geany: %s\n", error->message);
568 g_error_free(error);
569 exit(1);
572 app->debug_mode = verbose_mode;
573 if (app->debug_mode)
575 /* Since GLib 2.32 messages logged with levels INFO and DEBUG aren't output by the
576 * default log handler unless the G_MESSAGES_DEBUG environment variable contains the
577 * domain of the message or is set to the special value "all" */
578 g_setenv("G_MESSAGES_DEBUG", "all", FALSE);
581 #ifdef G_OS_WIN32
582 win32_init_debug_code();
583 #endif
585 if (show_version)
587 gchar *build_date = utils_parse_and_format_build_date(__DATE__);
589 printf(PACKAGE " %s (", main_get_version_string());
590 /* note for translators: library versions are printed after this */
591 printf(_("built on %s with "), build_date);
592 printf(geany_lib_versions,
593 GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
594 GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
595 printf(")\n");
596 g_free(build_date);
597 wait_for_input_on_windows();
598 exit(0);
601 if (print_prefix)
603 printf("%s\n", GEANY_PREFIX);
604 printf("%s\n", GEANY_DATADIR);
605 printf("%s\n", GEANY_LIBDIR);
606 printf("%s\n", GEANY_LOCALEDIR);
607 wait_for_input_on_windows();
608 exit(0);
611 if (alternate_config)
613 geany_debug("Using alternate configuration directory");
614 app->configdir = alternate_config;
616 else
618 app->configdir = utils_get_user_config_dir();
621 if (generate_tags)
623 gboolean ret;
625 filetypes_init_types();
626 ret = symbols_generate_global_tags(*argc, *argv, ! no_preprocessing);
627 filetypes_free_types();
628 wait_for_input_on_windows();
629 exit(ret);
632 if (ft_names)
634 print_filetypes();
635 wait_for_input_on_windows();
636 exit(0);
639 #ifdef HAVE_SOCKET
640 socket_info.ignore_socket = cl_options.new_instance;
641 if (cl_options.socket_filename)
643 socket_info.file_name = cl_options.socket_filename;
645 #endif
647 #ifdef HAVE_VTE
648 vte_info.lib_vte = lib_vte;
649 #endif
650 cl_options.ignore_global_tags = ignore_global_tags;
652 if (! gtk_init_check(NULL, NULL))
653 { /* check whether we have a valid X display and exit if not */
654 g_printerr("Geany: cannot open display\n");
655 exit(1);
658 #ifdef MAC_INTEGRATION
659 /* Create GtkosxApplication singleton - should be created shortly after gtk_init() */
660 gtkosx_application_get();
661 #endif
665 static gint create_config_dir(void)
667 gint saved_errno = 0;
668 gchar *conf_file = NULL;
669 gchar *filedefs_dir = NULL;
670 gchar *templates_dir = NULL;
672 if (! g_file_test(app->configdir, G_FILE_TEST_EXISTS))
674 #ifndef G_OS_WIN32
675 /* if we are *not* using an alternate config directory, we check whether the old one
676 * in ~/.geany still exists and try to move it */
677 if (alternate_config == NULL)
679 gchar *old_dir = g_build_filename(g_get_home_dir(), ".geany", NULL);
680 /* move the old config dir if it exists */
681 if (g_file_test(old_dir, G_FILE_TEST_EXISTS))
683 if (! dialogs_show_question_full(main_widgets.window,
684 GTK_STOCK_YES, GTK_STOCK_QUIT, _("Move it now?"),
685 "%s",
686 _("Geany needs to move your old configuration directory before starting.")))
687 exit(0);
689 if (! g_file_test(app->configdir, G_FILE_TEST_IS_DIR))
690 utils_mkdir(app->configdir, TRUE);
692 if (g_rename(old_dir, app->configdir) == 0)
694 dialogs_show_msgbox(GTK_MESSAGE_INFO,
695 _("Your configuration directory has been successfully moved from \"%s\" to \"%s\"."),
696 old_dir, app->configdir);
697 g_free(old_dir);
698 return 0;
700 else
702 dialogs_show_msgbox(GTK_MESSAGE_WARNING,
703 /* for translators: the third %s in brackets is the error message which
704 * describes why moving the dir didn't work */
705 _("Your old configuration directory \"%s\" could not be moved to \"%s\" (%s). "
706 "Please move manually the directory to the new location."),
707 old_dir, app->configdir, g_strerror(errno));
710 g_free(old_dir);
712 #endif
713 geany_debug("Creating configuration directory");
714 saved_errno = utils_mkdir(app->configdir, TRUE);
717 conf_file = g_build_filename(app->configdir, "geany.conf", NULL);
718 filedefs_dir = g_build_filename(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL);
719 templates_dir = g_build_filename(app->configdir, GEANY_TEMPLATES_SUBDIR, NULL);
721 if (saved_errno == 0 && ! g_file_test(conf_file, G_FILE_TEST_EXISTS))
722 { /* check whether geany.conf can be written */
723 saved_errno = utils_is_file_writable(app->configdir);
726 /* make subdir for filetype definitions */
727 if (saved_errno == 0)
729 gchar *filedefs_readme = g_build_filename(app->configdir,
730 GEANY_FILEDEFS_SUBDIR, "filetypes.README", NULL);
732 if (! g_file_test(filedefs_dir, G_FILE_TEST_EXISTS))
734 saved_errno = utils_mkdir(filedefs_dir, FALSE);
736 if (saved_errno == 0 && ! g_file_test(filedefs_readme, G_FILE_TEST_EXISTS))
738 gchar *text = g_strconcat(
739 "Copy files from ", app->datadir, "/filedefs to this directory to overwrite "
740 "them. To use the defaults, just delete the file in this directory.\nFor more information read "
741 "the documentation (in ", app->docdir, G_DIR_SEPARATOR_S "index.html or visit " GEANY_HOMEPAGE ").", NULL);
742 utils_write_file(filedefs_readme, text);
743 g_free(text);
745 g_free(filedefs_readme);
748 /* make subdir for template files */
749 if (saved_errno == 0)
751 gchar *templates_readme = g_build_filename(app->configdir, GEANY_TEMPLATES_SUBDIR,
752 "templates.README", NULL);
754 if (! g_file_test(templates_dir, G_FILE_TEST_EXISTS))
756 saved_errno = utils_mkdir(templates_dir, FALSE);
758 if (saved_errno == 0 && ! g_file_test(templates_readme, G_FILE_TEST_EXISTS))
760 gchar *text = g_strconcat(
761 "There are several template files in this directory. For these templates you can use wildcards.\n\
762 For more information read the documentation (in ", app->docdir, G_DIR_SEPARATOR_S "index.html or visit " GEANY_HOMEPAGE ").",
763 NULL);
764 utils_write_file(templates_readme, text);
765 g_free(text);
767 g_free(templates_readme);
770 g_free(filedefs_dir);
771 g_free(templates_dir);
772 g_free(conf_file);
774 return saved_errno;
778 /* Returns 0 if config dir is OK. */
779 static gint setup_config_dir(void)
781 gint mkdir_result = 0;
783 mkdir_result = create_config_dir();
784 if (mkdir_result != 0)
786 if (! dialogs_show_question(
787 _("Configuration directory could not be created (%s).\nThere could be some problems "
788 "using Geany without a configuration directory.\nStart Geany anyway?"),
789 g_strerror(mkdir_result)))
791 exit(0);
794 /* make configdir a real path */
795 if (g_file_test(app->configdir, G_FILE_TEST_EXISTS))
796 SETPTR(app->configdir, utils_get_real_path(app->configdir));
798 return mkdir_result;
802 #ifdef G_OS_UNIX
803 static gboolean signal_cb(gpointer user_data)
805 gint sig = GPOINTER_TO_INT(user_data);
806 if (sig == SIGTERM)
808 geany_debug("Received SIGTERM signal");
809 main_quit();
811 return G_SOURCE_REMOVE;
813 #endif
816 /* Used for command-line arguments at startup or from socket.
817 * this will strip any :line:col filename suffix from locale_filename */
818 gboolean main_handle_filename(const gchar *locale_filename)
820 GeanyDocument *doc;
821 gint line = -1, column = -1;
822 gchar *filename;
824 g_return_val_if_fail(locale_filename, FALSE);
826 /* check whether the passed filename is an URI */
827 filename = utils_get_path_from_uri(locale_filename);
828 if (filename == NULL)
829 return FALSE;
831 get_line_and_column_from_filename(filename, &line, &column);
832 if (line >= 0)
833 cl_options.goto_line = line;
834 if (column >= 0)
835 cl_options.goto_column = column;
837 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
839 doc = document_open_file(filename, cl_options.readonly, NULL, NULL);
840 /* add recent file manually if opening_session_files is set */
841 if (doc != NULL && main_status.opening_session_files)
842 ui_add_recent_document(doc);
843 g_free(filename);
844 return TRUE;
846 else if (file_prefs.cmdline_new_files)
847 { /* create new file with the given filename */
848 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
850 doc = document_find_by_filename(utf8_filename);
851 if (doc)
852 document_show_tab_idle(doc);
853 else
854 doc = document_new_file(utf8_filename, NULL, NULL);
855 g_free(utf8_filename);
856 g_free(filename);
857 return TRUE;
859 g_free(filename);
860 return FALSE;
864 /* open files from command line */
865 static void open_cl_files(gint argc, gchar **argv)
867 gint i;
869 for (i = 1; i < argc; i++)
871 gchar *filename = main_get_argv_filename(argv[i]);
873 if (g_file_test(filename, G_FILE_TEST_IS_DIR))
875 g_free(filename);
876 continue;
879 #ifdef G_OS_WIN32
880 /* It seems argv elements are encoded in CP1252 on a German Windows */
881 SETPTR(filename, g_locale_to_utf8(filename, -1, NULL, NULL, NULL));
882 #endif
883 if (filename && ! main_handle_filename(filename))
885 const gchar *msg = _("Could not find file '%s'.");
887 g_printerr(msg, filename); /* also print to the terminal */
888 g_printerr("\n");
889 ui_set_statusbar(TRUE, msg, filename);
891 g_free(filename);
896 static void load_session_project_file(void)
898 gchar *locale_filename;
900 g_return_if_fail(project_prefs.session_file != NULL);
902 locale_filename = utils_get_locale_from_utf8(project_prefs.session_file);
904 if (G_LIKELY(!EMPTY(locale_filename)))
905 project_load_file(locale_filename);
907 g_free(locale_filename);
908 g_free(project_prefs.session_file); /* no longer needed */
912 static void load_settings(void)
914 #ifdef HAVE_VTE
915 vte_info.load_vte_cmdline = !no_vte;
916 #endif
917 configuration_load();
918 /* let cmdline options overwrite configuration settings */
919 #ifdef HAVE_VTE
920 vte_info.have_vte = vte_info.load_vte && vte_info.load_vte_cmdline;
921 #endif
922 if (no_msgwin)
923 ui_prefs.msgwindow_visible = FALSE;
925 #ifdef HAVE_PLUGINS
926 want_plugins = prefs.load_plugins && !no_plugins;
927 #endif
931 void main_load_project_from_command_line(const gchar *locale_filename, gboolean use_session)
933 gchar *pfile;
935 pfile = utils_get_path_from_uri(locale_filename);
936 if (pfile != NULL)
938 if (use_session)
939 project_load_file_with_session(pfile);
940 else
941 project_load_file(pfile);
943 g_free(pfile);
947 static void load_startup_files(gint argc, gchar **argv)
949 gboolean load_session = FALSE;
951 if (argc > 1 && g_str_has_suffix(argv[1], ".geany"))
953 gchar *filename = main_get_argv_filename(argv[1]);
955 /* project file specified: load it, but decide the session later */
956 main_load_project_from_command_line(filename, FALSE);
957 argc--, argv++;
958 /* force session load if using project-based session files */
959 load_session = TRUE;
960 g_free(filename);
963 /* Load the default session if:
964 * 1. "Load files from the last session" is active.
965 * 2. --no-session is not specified.
966 * 3. We are a primary instance.
967 * Has no effect if a CL project is loaded and using project-based session files. */
968 if (prefs.load_session && cl_options.load_session && !cl_options.new_instance)
970 if (app->project == NULL)
971 load_session_project_file();
972 if (app->project == NULL)
973 configuration_load_default_session();
974 load_session = TRUE;
977 if (load_session)
979 /* load session files into tabs, as they are found in the session_files variable */
980 if (app->project != NULL)
982 configuration_open_files(app->project->priv->session_files);
983 app->project->priv->session_files = NULL;
985 else
987 configuration_open_default_session();
990 if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 0)
992 ui_update_popup_copy_items(NULL);
993 ui_update_popup_reundo_items(NULL);
997 open_cl_files(argc, argv);
1001 static gboolean send_startup_complete(gpointer data)
1003 g_signal_emit_by_name(geany_object, "geany-startup-complete");
1004 return FALSE;
1008 static const gchar *get_locale(void)
1010 const gchar *locale = "unknown";
1011 #ifdef HAVE_LOCALE_H
1012 locale = setlocale(LC_CTYPE, NULL);
1013 #endif
1014 return locale;
1018 GEANY_EXPORT_SYMBOL
1019 void main_init_headless(void)
1021 #if ! GLIB_CHECK_VERSION(2, 36, 0)
1022 g_type_init();
1023 #endif
1025 app = g_new0(GeanyApp, 1);
1026 memset(&main_status, 0, sizeof(GeanyStatus));
1027 memset(&prefs, 0, sizeof(GeanyPrefs));
1028 memset(&interface_prefs, 0, sizeof(GeanyInterfacePrefs));
1029 memset(&toolbar_prefs, 0, sizeof(GeanyToolbarPrefs));
1030 memset(&file_prefs, 0, sizeof(GeanyFilePrefs));
1031 memset(&search_prefs, 0, sizeof(GeanySearchPrefs));
1032 memset(&tool_prefs, 0, sizeof(GeanyToolPrefs));
1033 memset(&template_prefs, 0, sizeof(GeanyTemplatePrefs));
1034 memset(&ui_prefs, 0, sizeof(UIPrefs));
1035 memset(&ui_widgets, 0, sizeof(UIWidgets));
1039 GEANY_EXPORT_SYMBOL
1040 gint main_lib(gint argc, gchar **argv)
1042 GeanyDocument *doc;
1043 gint config_dir_result;
1044 const gchar *locale;
1045 gchar *utf8_configdir;
1046 gchar *os_info;
1048 main_init_headless();
1050 log_handlers_init();
1052 setup_paths();
1054 #ifdef ENABLE_NLS
1055 main_locale_init(utils_resource_dir(RESOURCE_DIR_LOCALE), GETTEXT_PACKAGE);
1056 #endif
1057 /* initialize TM before parsing command-line - needed for tag file generation */
1058 app->tm_workspace = tm_get_workspace();
1059 parse_command_line_options(&argc, &argv);
1061 #if ! GLIB_CHECK_VERSION(2, 32, 0)
1062 /* Initialize GLib's thread system in case any plugins want to use it or their
1063 * dependencies (e.g. WebKit, Soup, ...). Deprecated since GLIB 2.32. */
1064 if (!g_thread_supported())
1065 g_thread_init(NULL);
1066 #endif
1068 #ifdef G_OS_UNIX
1069 g_unix_signal_add(SIGTERM, signal_cb, GINT_TO_POINTER(SIGTERM));
1071 /* ignore SIGPIPE signal for preventing sudden death of program */
1072 signal(SIGPIPE, SIG_IGN);
1073 #endif
1075 config_dir_result = setup_config_dir();
1076 #ifdef HAVE_SOCKET
1077 /* check and create (unix domain) socket for remote operation */
1078 if (! socket_info.ignore_socket)
1080 gushort socket_port = 0;
1081 #ifdef G_OS_WIN32
1082 socket_port = (gushort) get_windows_socket_port();
1083 #endif
1084 socket_info.lock_socket = -1;
1085 socket_info.lock_socket_tag = 0;
1086 socket_info.lock_socket = socket_init(argc, argv, socket_port);
1087 /* Quit if filenames were sent to first instance or the list of open
1088 * documents has been printed */
1089 if ((socket_info.lock_socket == -2 /* socket exists */ && argc > 1) ||
1090 cl_options.list_documents)
1092 socket_finalize();
1093 gdk_notify_startup_complete();
1094 g_free(app->configdir);
1095 g_free(app->datadir);
1096 g_free(app->docdir);
1097 g_free(app);
1098 return 0;
1100 /* Start a new instance if no command line strings were passed,
1101 * even if the socket already exists */
1102 else if (socket_info.lock_socket == -2 /* socket already exists */)
1104 socket_info.ignore_socket = TRUE;
1105 cl_options.new_instance = TRUE;
1108 #endif
1110 #ifdef G_OS_WIN32
1111 /* after we initialized the socket code and handled command line args,
1112 * let's change the working directory on Windows to not lock it */
1113 change_working_directory_on_windows();
1114 #endif
1116 locale = get_locale();
1117 geany_debug("Geany %s, %s",
1118 main_get_version_string(),
1119 locale);
1120 geany_debug(geany_lib_versions,
1121 gtk_major_version, gtk_minor_version, gtk_micro_version,
1122 glib_major_version, glib_minor_version, glib_micro_version);
1124 os_info = utils_get_os_info_string();
1125 if (os_info != NULL)
1127 geany_debug("OS: %s", os_info);
1128 g_free(os_info);
1131 geany_debug("System data dir: %s", app->datadir);
1132 utf8_configdir = utils_get_utf8_from_locale(app->configdir);
1133 geany_debug("User config dir: %s", utf8_configdir);
1134 g_free(utf8_configdir);
1136 /* create the object so Geany signals can be connected in init() functions */
1137 geany_object = geany_object_new();
1139 /* inits */
1140 main_init();
1142 encodings_init();
1143 editor_init();
1145 /* init stash groups before loading keyfile */
1146 configuration_init();
1147 ui_init_prefs();
1148 search_init();
1149 project_init();
1150 #ifdef HAVE_PLUGINS
1151 plugins_init();
1152 #endif
1153 sidebar_init();
1154 load_settings(); /* load keyfile */
1156 msgwin_init();
1157 build_init();
1158 ui_create_insert_menu_items();
1159 ui_create_insert_date_menu_items();
1160 keybindings_init();
1161 notebook_init();
1162 filetypes_init();
1163 templates_init();
1164 navqueue_init();
1165 document_init_doclist();
1166 symbols_init();
1167 editor_snippets_init();
1169 #ifdef HAVE_VTE
1170 vte_init();
1171 #endif
1172 ui_create_recent_menus();
1174 ui_set_statusbar(TRUE, _("This is Geany %s."), main_get_version_string());
1175 if (config_dir_result != 0)
1177 const gchar *message = _("Configuration directory could not be created (%s).");
1178 ui_set_statusbar(TRUE, message, g_strerror(config_dir_result));
1179 g_warning(message, g_strerror(config_dir_result));
1181 #ifdef HAVE_SOCKET
1182 if (socket_info.lock_socket == -1)
1184 const gchar *message =
1185 _("IPC socket could not be created, see Help->Debug Messages for details.");
1186 ui_set_statusbar(TRUE, "%s", message);
1187 g_warning("%s", message);
1189 #endif
1191 /* apply all configuration options */
1192 apply_settings();
1194 #ifdef HAVE_PLUGINS
1195 /* load any enabled plugins before we open any documents */
1196 if (want_plugins)
1197 plugins_load_active();
1198 #endif
1200 ui_sidebar_show_hide();
1202 /* set the active sidebar page after plugins have been loaded */
1203 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.sidebar_notebook), ui_prefs.sidebar_page);
1205 /* load keybinding settings after plugins have added their groups */
1206 keybindings_load_keyfile();
1208 /* create the custom command menu after the keybindings have been loaded to have the proper
1209 * accelerator shown for the menu items */
1210 tools_create_insert_custom_command_menu_items();
1212 /* load any command line files or session files */
1213 main_status.opening_session_files++;
1214 load_startup_files(argc, argv);
1215 main_status.opening_session_files--;
1217 /* open a new file if no other file was opened */
1218 document_new_file_if_non_open();
1220 ui_document_buttons_update();
1221 ui_save_buttons_toggle(FALSE);
1223 doc = document_get_current();
1224 sidebar_select_openfiles_item(doc);
1225 build_menu_update(doc);
1226 sidebar_update_tag_list(doc, FALSE);
1228 setup_window_position();
1230 /* finally show the window */
1231 document_grab_focus(doc);
1232 gtk_widget_show(main_widgets.window);
1233 main_status.main_window_realized = TRUE;
1235 configuration_apply_settings();
1237 #ifdef HAVE_SOCKET
1238 /* register the callback of socket input */
1239 if (! socket_info.ignore_socket && socket_info.lock_socket > 0)
1241 socket_info.read_ioc = g_io_channel_unix_new(socket_info.lock_socket);
1242 socket_info.lock_socket_tag = g_io_add_watch(socket_info.read_ioc,
1243 G_IO_IN | G_IO_PRI | G_IO_ERR, socket_lock_input_cb, main_widgets.window);
1245 #endif
1247 /* when we are really done with setting everything up and the main event loop is running,
1248 * tell other components, mainly plugins, that startup is complete */
1249 g_idle_add_full(G_PRIORITY_LOW, send_startup_complete, NULL, NULL);
1251 #ifdef MAC_INTEGRATION
1252 /* OS X application ready - has to be called before entering main loop */
1253 gtkosx_application_ready(gtkosx_application_get());
1254 #endif
1256 gtk_main();
1257 return 0;
1261 static void queue_free(GQueue *queue)
1263 while (! g_queue_is_empty(queue))
1265 g_free(g_queue_pop_tail(queue));
1267 g_queue_free(queue);
1271 static gboolean do_main_quit(void)
1273 configuration_save();
1275 if (app->project != NULL)
1277 if (!project_close(FALSE)) /* save project session files */
1278 return FALSE;
1281 if (!document_close_all())
1282 return FALSE;
1284 geany_debug("Quitting...");
1286 main_status.quitting = TRUE;
1288 #ifdef HAVE_SOCKET
1289 socket_finalize();
1290 #endif
1292 #ifdef HAVE_PLUGINS
1293 plugins_finalize();
1294 #endif
1296 navqueue_free();
1297 keybindings_free();
1298 notebook_free();
1299 highlighting_free_styles();
1300 templates_free_templates();
1301 msgwin_finalize();
1302 search_finalize();
1303 build_finalize();
1304 document_finalize();
1305 symbols_finalize();
1306 project_finalize();
1307 editor_finalize();
1308 editor_snippets_free();
1309 encodings_finalize();
1310 toolbar_finalize();
1311 sidebar_finalize();
1312 configuration_finalize();
1313 filetypes_free_types();
1314 log_finalize();
1316 tm_workspace_free();
1317 g_free(app->configdir);
1318 g_free(app->datadir);
1319 g_free(app->docdir);
1320 g_free(prefs.default_open_path);
1321 g_free(prefs.custom_plugin_path);
1322 g_free(ui_prefs.custom_date_format);
1323 g_free(ui_prefs.color_picker_palette);
1324 g_free(interface_prefs.editor_font);
1325 g_free(interface_prefs.tagbar_font);
1326 g_free(interface_prefs.msgwin_font);
1327 g_free(editor_prefs.long_line_color);
1328 g_free(editor_prefs.comment_toggle_mark);
1329 g_free(editor_prefs.color_scheme);
1330 g_free(tool_prefs.context_action_cmd);
1331 g_free(template_prefs.developer);
1332 g_free(template_prefs.company);
1333 g_free(template_prefs.mail);
1334 g_free(template_prefs.initials);
1335 g_free(template_prefs.version);
1336 g_free(tool_prefs.term_cmd);
1337 g_free(tool_prefs.browser_cmd);
1338 g_free(tool_prefs.grep_cmd);
1339 g_free(printing_prefs.external_print_cmd);
1340 g_free(printing_prefs.page_header_datefmt);
1341 g_strfreev(ui_prefs.custom_commands);
1342 g_strfreev(ui_prefs.custom_commands_labels);
1344 queue_free(ui_prefs.recent_queue);
1345 queue_free(ui_prefs.recent_projects_queue);
1347 if (ui_widgets.prefs_dialog && GTK_IS_WIDGET(ui_widgets.prefs_dialog)) gtk_widget_destroy(ui_widgets.prefs_dialog);
1348 if (ui_widgets.open_fontsel && GTK_IS_WIDGET(ui_widgets.open_fontsel)) gtk_widget_destroy(ui_widgets.open_fontsel);
1349 if (ui_widgets.open_colorsel && GTK_IS_WIDGET(ui_widgets.open_colorsel)) gtk_widget_destroy(ui_widgets.open_colorsel);
1350 #ifdef HAVE_VTE
1351 if (vte_info.have_vte) vte_close();
1352 g_free(vte_info.lib_vte);
1353 g_free(vte_info.dir);
1354 #endif
1355 gtk_widget_destroy(main_widgets.window);
1357 /* destroy popup menus */
1358 if (main_widgets.editor_menu && GTK_IS_WIDGET(main_widgets.editor_menu))
1359 gtk_widget_destroy(main_widgets.editor_menu);
1360 if (ui_widgets.toolbar_menu && GTK_IS_WIDGET(ui_widgets.toolbar_menu))
1361 gtk_widget_destroy(ui_widgets.toolbar_menu);
1362 if (msgwindow.popup_status_menu && GTK_IS_WIDGET(msgwindow.popup_status_menu))
1363 gtk_widget_destroy(msgwindow.popup_status_menu);
1364 if (msgwindow.popup_msg_menu && GTK_IS_WIDGET(msgwindow.popup_msg_menu))
1365 gtk_widget_destroy(msgwindow.popup_msg_menu);
1366 if (msgwindow.popup_compiler_menu && GTK_IS_WIDGET(msgwindow.popup_compiler_menu))
1367 gtk_widget_destroy(msgwindow.popup_compiler_menu);
1369 g_object_unref(geany_object);
1370 geany_object = NULL;
1372 g_free(original_cwd);
1373 g_free(app);
1375 ui_finalize_builder();
1377 gtk_main_quit();
1379 return TRUE;
1383 static gboolean check_no_unsaved(void)
1385 guint i;
1387 for (i = 0; i < documents_array->len; i++)
1389 if (documents[i]->is_valid && documents[i]->changed)
1391 return FALSE;
1394 return TRUE; /* no unsaved edits */
1398 /* Returns false when quitting is aborted due to user cancellation */
1399 gboolean main_quit(void)
1401 main_status.quitting = TRUE;
1403 if (! check_no_unsaved())
1405 if (do_main_quit())
1406 return TRUE;
1408 else
1409 if (! prefs.confirm_exit ||
1410 dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
1411 _("Do you really want to quit?")))
1413 if (do_main_quit())
1414 return TRUE;
1417 main_status.quitting = FALSE;
1418 return FALSE;
1422 * Reloads most of Geany's configuration files without restarting. Currently the following
1423 * files are reloaded: all template files, also new file templates and the 'New (with template)'
1424 * menus will be updated, Snippets (snippets.conf), filetype extensions (filetype_extensions.conf),
1425 * and 'settings' and 'build_settings' sections of the filetype definition files.
1427 * Plugins may call this function if they changed any of these files (e.g. a configuration file
1428 * editor plugin).
1430 * @since 0.15
1432 GEANY_API_SYMBOL
1433 void main_reload_configuration(void)
1435 /* reload templates */
1436 templates_free_templates();
1437 templates_init();
1439 /* reload snippets */
1440 editor_snippets_free();
1441 editor_snippets_init();
1443 filetypes_reload_extensions();
1444 filetypes_reload();
1446 /* C tag names to ignore */
1447 symbols_reload_config_files();
1449 ui_set_statusbar(TRUE, _("Configuration files reloaded."));