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)  

libmain.c
Go to the documentation of this file.
1/*
2 * libmain.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2005 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/**
22 * @file: main.h
23 * Main program-related commands.
24 * Handles program initialization and cleanup.
25 */
26
27#ifdef HAVE_CONFIG_H
28# include "config.h"
29#endif
30
31#include "main.h"
32
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 "prefs.h"
50#include "printing.h"
51#include "sidebar.h"
52#ifdef HAVE_SOCKET
53# include "socket.h"
54#endif
55#include "support.h"
56#include "symbols.h"
57#include "templates.h"
58#include "toolbar.h"
59#include "tools.h"
60#include "ui_utils.h"
61#include "utils.h"
62#include "vte.h"
63#include "win32.h"
64#include "osx.h"
65
66#include <signal.h>
67#include <time.h>
68#include <sys/types.h>
69#include <sys/stat.h>
70#include <errno.h>
71#include <string.h>
72#include <stdlib.h>
73
74#include <gtk/gtk.h>
75#include <glib/gstdio.h>
76
77#ifdef G_OS_UNIX
78# include <glib-unix.h>
79#endif
80
81#ifdef HAVE_LOCALE_H
82# include <locale.h>
83#endif
84
85
87gboolean ignore_callback; /* hack workaround for GTK+ toggle button callback problem */
88
89GeanyStatus main_status;
90CommandLineOptions cl_options; /* fields initialised in parse_command_line_options */
91
92static gchar *original_cwd = NULL;
93
94static const gchar geany_lib_versions[] = "GTK %u.%u.%u, GLib %u.%u.%u";
95
96static gboolean want_plugins;
97
98/* command-line options */
99static gboolean verbose_mode = FALSE;
100static gboolean ignore_global_tags = FALSE;
101static gboolean no_msgwin = FALSE;
102static gboolean show_version = FALSE;
103static gchar *alternate_config = NULL;
104#ifdef HAVE_VTE
105static gboolean no_vte = FALSE;
106static gchar *lib_vte = NULL;
107#endif
108static gboolean generate_tags = FALSE;
109static gboolean no_preprocessing = FALSE;
110static gboolean ft_names = FALSE;
111static gboolean print_prefix = FALSE;
112#ifdef HAVE_PLUGINS
113static gboolean no_plugins = FALSE;
114#endif
115static gboolean dummy = FALSE;
116
117/* in alphabetical order of short options */
118static GOptionEntry entries[] =
119{
120 { "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") },
121 { "config", 'c', 0, G_OPTION_ARG_FILENAME, &alternate_config, N_("Use alternate configuration directory DIR"), N_("DIR") },
122 { "ft-names", 0, 0, G_OPTION_ARG_NONE, &ft_names, N_("Print internal filetype names"), NULL },
123 { "generate-tags", 'g', 0, G_OPTION_ARG_NONE, &generate_tags, N_("Generate global tags file (see documentation)"), NULL },
124 { "no-preprocessing", 'P', 0, G_OPTION_ARG_NONE, &no_preprocessing, N_("Don't preprocess C/C++ files when generating tags file"), NULL },
125#ifdef HAVE_SOCKET
126 { "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 },
127 { "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") },
128 { "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 },
129#endif
130 { "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") },
131 { "no-msgwin", 'm', 0, G_OPTION_ARG_NONE, &no_msgwin, N_("Don't show message window at startup"), NULL },
132 { "no-ctags", 'n', 0, G_OPTION_ARG_NONE, &ignore_global_tags, N_("Don't load auto completion data (see documentation)"), NULL },
133#ifdef HAVE_PLUGINS
134 { "no-plugins", 'p', 0, G_OPTION_ARG_NONE, &no_plugins, N_("Don't load plugins"), NULL },
135#endif
136 { "print-prefix", 0, 0, G_OPTION_ARG_NONE, &print_prefix, N_("Print Geany's installation prefix"), NULL },
137 { "read-only", 'r', 0, G_OPTION_ARG_NONE, &cl_options.readonly, N_("Open all FILES in read-only mode (see documentation)"), NULL },
138 { "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 },
139#ifdef HAVE_VTE
140 { "no-terminal", 't', 0, G_OPTION_ARG_NONE, &no_vte, N_("Don't load terminal support"), NULL },
141 { "vte-lib", 0, 0, G_OPTION_ARG_FILENAME, &lib_vte, N_("Use FILE as the dynamically-linked VTE library"), N_("FILE") },
142#endif
143 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_mode, N_("Be verbose"), NULL },
144 { "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Show version and exit"), NULL },
145 { "dummy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &dummy, NULL, NULL }, /* for +NNN line number arguments */
146 { NULL, 0, 0, 0, NULL, NULL, NULL }
147};
148
149
150static void setup_window_position(void)
151{
152 /* interprets the saved window geometry */
154 {
155 if (ui_prefs.geometry[2] != -1 && ui_prefs.geometry[3] != -1)
156 {
157 gtk_window_set_default_size(GTK_WINDOW(main_widgets.window),
158 ui_prefs.geometry[2], ui_prefs.geometry[3]);
159 }
160 }
161
162 if (prefs.save_winpos)
163 {
164 if (ui_prefs.geometry[0] != -1 && ui_prefs.geometry[1] != -1)
165 {
166 gtk_window_move(GTK_WINDOW(main_widgets.window),
167 ui_prefs.geometry[0], ui_prefs.geometry[1]);
168 }
169 if (ui_prefs.geometry[4] == 1)
170 {
171 gtk_window_maximize(GTK_WINDOW(main_widgets.window));
172 }
173 }
174}
175
176
177/* special things for the initial setup of the checkboxes and related stuff
178 * an action on a setting is only performed if the setting is not equal to the program default
179 * (all the following code is not perfect but it works for the moment) */
180static void apply_settings(void)
181{
183
184 /* toolbar, message window and sidebar are by default visible, so don't change it if it is true */
186 if (! ui_prefs.msgwindow_visible)
187 {
188 ignore_callback = TRUE;
189 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_messages_window1")), FALSE);
190 gtk_widget_hide(main_widgets.message_window_notebook);
191 ignore_callback = FALSE;
192 }
193 if (! ui_prefs.sidebar_visible)
194 {
195 ignore_callback = TRUE;
196 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_sidebar1")), FALSE);
197 ignore_callback = FALSE;
198 }
199
202
204
205 /* hide statusbar if desired */
207 {
208 gtk_widget_hide(ui_widgets.statusbar);
209 }
210
211 /* set the tab placements of the notebooks */
212 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.tab_pos_editor);
213 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), interface_prefs.tab_pos_msgwin);
214 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_widgets.sidebar_notebook), interface_prefs.tab_pos_sidebar);
215
216 /* whether to show notebook tabs or not */
217 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(main_widgets.notebook), interface_prefs.show_notebook_tabs);
218
219#ifdef HAVE_VTE
220 if (! vte_info.have_vte)
221#endif
222 {
223 gtk_widget_set_sensitive(
224 ui_lookup_widget(main_widgets.window, "send_selection_to_vte1"), FALSE);
225 }
226
227 if (interface_prefs.sidebar_pos != GTK_POS_LEFT)
229
230 gtk_orientable_set_orientation(GTK_ORIENTABLE(ui_lookup_widget(main_widgets.window, "vpaned1")),
232}
233
234
235static void on_window_active_changed(GtkWindow *window, GParamSpec *pspec, gpointer data)
236{
238
239 if (doc && gtk_window_is_active(window))
241}
242
243
244static void main_init(void)
245{
246 /* add our icon path in case we aren't installed in the system prefix */
247 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), utils_resource_dir(RESOURCE_DIR_ICON));
248
249 /* inits */
251
253
255 app->project = NULL;
256 ui_widgets.open_fontsel = NULL;
257 ui_widgets.open_colorsel = NULL;
258 ui_widgets.prefs_dialog = NULL;
259 main_status.main_window_realized = FALSE;
262 main_status.quitting = FALSE;
263 ignore_callback = FALSE;
264 ui_prefs.recent_queue = g_queue_new();
265 ui_prefs.recent_projects_queue = g_queue_new();
266 main_status.opening_session_files = FALSE;
267
269 g_signal_connect(main_widgets.window, "notify::is-active", G_CALLBACK(on_window_active_changed), NULL);
270
271 /* add recent projects to the Project menu */
272 ui_widgets.recent_projects_menuitem = ui_lookup_widget(main_widgets.window, "recent_projects1");
273 ui_widgets.recent_projects_menu_menubar = gtk_menu_new();
274 gtk_menu_item_set_submenu(GTK_MENU_ITEM(ui_widgets.recent_projects_menuitem),
275 ui_widgets.recent_projects_menu_menubar);
276
277 /* store important pointers for later reference */
285
286 ui_widgets.toolbar_menu = create_toolbar_popup_menu1();
287 ui_init();
288#ifdef MAC_INTEGRATION
289 osx_ui_init();
290#endif
291
292 /* set widget names for matching with GTK CSS */
293 gtk_widget_set_name(main_widgets.window, "GeanyMainWindow");
294 gtk_widget_set_name(ui_widgets.toolbar_menu, "GeanyToolbarMenu");
295 gtk_widget_set_name(main_widgets.editor_menu, "GeanyEditMenu");
296 gtk_widget_set_name(ui_lookup_widget(main_widgets.window, "menubar1"), "GeanyMenubar");
297 gtk_widget_set_name(main_widgets.toolbar, "GeanyToolbar");
298
299 gtk_window_set_default_size(GTK_WINDOW(main_widgets.window),
301}
302
303
304const gchar *main_get_version_string(void)
305{
306 static gchar full[] = VERSION " (git >= " REVISION ")";
307
308 if (utils_str_equal(REVISION, "-1"))
309 return VERSION;
310 else
311 return full;
312}
313
314
315/* get the full file path of a command-line argument
316 * N.B. the result should be freed and may contain '/../' or '/./ ' */
318{
319 gchar *result;
320
321 if (g_path_is_absolute(filename) || utils_is_uri(filename))
322 result = g_strdup(filename);
323 else
324 {
325 /* use current dir */
326 gchar *cur_dir = NULL;
327 if (original_cwd == NULL)
328 cur_dir = g_get_current_dir();
329 else
330 cur_dir = g_strdup(original_cwd);
331
332 result = g_strjoin(
333 G_DIR_SEPARATOR_S, cur_dir, filename, NULL);
334 g_free(cur_dir);
335 }
336 return result;
337}
338
339
340/* get a :line:column specifier from the end of a filename (if present),
341 * return the line/column values, and remove the specifier from the string
342 * (Note that *line and *column must both be set to -1 initially) */
343static void get_line_and_column_from_filename(gchar *filename, gint *line, gint *column)
344{
345 gsize i;
346 gint colon_count = 0;
347 gboolean have_number = FALSE;
348 gsize len;
349
350 g_assert(*line == -1 && *column == -1);
351
352 if (G_UNLIKELY(EMPTY(filename)))
353 return;
354
355 /* allow to open files like "test:0" */
356 if (g_file_test(filename, G_FILE_TEST_EXISTS))
357 return;
358
359 len = strlen(filename);
360 for (i = len - 1; i >= 1; i--)
361 {
362 gboolean is_colon = filename[i] == ':';
363 gboolean is_digit = g_ascii_isdigit(filename[i]);
364
365 if (! is_colon && ! is_digit)
366 break;
367
368 if (is_colon)
369 {
370 if (++colon_count > 1)
371 break; /* bail on 2+ colons in a row */
372 }
373 else
374 colon_count = 0;
375
376 if (is_digit)
377 have_number = TRUE;
378
379 if (is_colon && have_number)
380 {
381 gint number = atoi(&filename[i + 1]);
382
383 filename[i] = '\0';
384 have_number = FALSE;
385
386 *column = *line;
387 *line = number;
388 }
389
390 if (*column >= 0)
391 break; /* line and column are set, so we're done */
392 }
393}
394
395
396#ifdef G_OS_WIN32
397static gint get_windows_socket_port(void)
398{
399 /* Read config file early to get TCP port number as we need it for IPC before all
400 * other settings are read in load_settings() */
401 gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL);
402 GKeyFile *config = g_key_file_new();
403 gint port_number;
404
405 g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
406 port_number = utils_get_setting_integer(config, PACKAGE, "socket_remote_cmd_port",
408 geany_debug("Using TCP port number %d for IPC", port_number);
409 g_free(configfile);
410 g_key_file_free(config);
411 g_return_val_if_fail(port_number >= 1024 && port_number <= (gint)G_MAXUINT16,
413 return port_number;
414}
415
416
417static void change_working_directory_on_windows(void)
418{
419 gchar *install_dir = win32_get_installation_dir();
420
421 /* remember original working directory for use with opening files from the command line */
422 original_cwd = g_get_current_dir();
423
424 /* On Windows, change the working directory to the Geany installation path to not lock
425 * the directory of a file passed as command line argument (see bug #2626124).
426 * This also helps if plugins or other code uses relative paths to load
427 * any additional resources (e.g. share/geany-plugins/...). */
428 win32_set_working_directory(install_dir);
429
430 g_free(install_dir);
431}
432#endif
433
434
435static void setup_paths(void)
436{
437 /* convert path names to locale encoding */
440}
441
442
443/**
444 * Checks whether the main window has been realized.
445 * This is an easy indicator whether Geany is right now starting up (main window is not
446 * yet realized) or whether it has finished the startup process (main window is realized).
447 * This is because the main window is realized (i.e. actually drawn on the screen) at the
448 * end of the startup process.
449 *
450 * @note Maybe you want to use the @link pluginsignals.c @c "geany-startup-complete" signal @endlink
451 * to get notified about the completed startup process.
452 *
453 * @return @c TRUE if the Geany main window has been realized or @c FALSE otherwise.
454 *
455 * @since 0.19
456 **/
457GEANY_API_SYMBOL
458gboolean main_is_realized(void)
459{
460 return main_status.main_window_realized;
461}
462
463
464/**
465 * Initialises the gettext translation system.
466 * This is a convenience function to set up gettext for internationalisation support
467 * in external plugins. You should call this function early in @ref plugin_init().
468 * If the macro HAVE_LOCALE_H is defined, @c setlocale(LC_ALL, "") is called.
469 * The codeset for the message translations is set to UTF-8.
470 *
471 * Note that this function only setups the gettext textdomain for you. You still have
472 * to adjust the build system of your plugin to get internationalisation support
473 * working properly.
474 *
475 * If you have already used @ref PLUGIN_SET_TRANSLATABLE_INFO() you
476 * don't need to call main_locale_init() again as it has already been done.
477 *
478 * @param locale_dir The location where the translation files should be searched. This is
479 * usually the @c LOCALEDIR macro, defined by the build system.
480 * E.g. @c $prefix/share/locale.
481 * Only used on non-Windows systems. On Windows, the directory is determined
482 * by @c g_win32_get_package_installation_directory().
483 * @param package The package name, usually this is the @c GETTEXT_PACKAGE macro,
484 * defined by the build system.
485 *
486 * @since 0.16
487 **/
488GEANY_API_SYMBOL
489void main_locale_init(const gchar *locale_dir, const gchar *package)
490{
491#ifdef HAVE_LOCALE_H
492 setlocale(LC_ALL, "");
493#endif
494
495#ifdef G_OS_WIN32
496 locale_dir = utils_resource_dir(RESOURCE_DIR_LOCALE);
497#endif
498 (void) bindtextdomain(package, locale_dir);
499 (void) bind_textdomain_codeset(package, "UTF-8");
500}
501
502
503static void print_filetypes(void)
504{
505 const GSList *list, *node;
506
508 printf("Geany's filetype names:\n");
509
511 foreach_slist(node, list)
512 {
513 GeanyFiletype *ft = node->data;
514
515 printf("%s\n", ft->name);
516 }
518}
519
520
522{
523#ifdef G_OS_WIN32
524 if (verbose_mode)
525 {
526 geany_debug("Press any key to continue");
527 getchar();
528 }
529#endif
530}
531
532
533static void parse_command_line_options(gint *argc, gchar ***argv)
534{
535 GError *error = NULL;
536 GOptionContext *context;
537 gint i;
538 CommandLineOptions def_clo = {FALSE, NULL, TRUE, -1, -1, FALSE, FALSE, FALSE};
539
540 /* first initialise cl_options fields with default values */
541 cl_options = def_clo;
542
543 /* the GLib option parser can't handle the +NNN (line number) option,
544 * so we grab that here and replace it with a no-op */
545 for (i = 1; i < (*argc); i++)
546 {
547 if ((*argv)[i][0] != '+')
548 continue;
549
550 cl_options.goto_line = atoi((*argv)[i] + 1);
551 (*argv)[i] = (gchar *) "--dummy";
552 }
553
554 context = g_option_context_new(_("[FILES...]"));
555
556 g_option_context_set_summary(context, _("A fast and lightweight IDE."));
557 g_option_context_set_description(context, _("Report bugs to https://github.com/geany/geany/issues."));
558 g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
559 g_option_group_set_translation_domain(g_option_context_get_main_group(context), GETTEXT_PACKAGE);
560 g_option_context_add_group(context, gtk_get_option_group(FALSE));
561 g_option_context_parse(context, argc, argv, &error);
562 g_option_context_free(context);
563
564 if (error != NULL)
565 {
566 g_printerr("Geany: %s\n", error->message);
567 g_error_free(error);
568 exit(1);
569 }
570
572 if (app->debug_mode)
573 {
574 /* Since GLib 2.32 messages logged with levels INFO and DEBUG aren't output by the
575 * default log handler unless the G_MESSAGES_DEBUG environment variable contains the
576 * domain of the message or is set to the special value "all" */
577 g_setenv("G_MESSAGES_DEBUG", "all", FALSE);
578 }
579
580#ifdef G_OS_WIN32
581 win32_init_debug_code();
582#endif
583
584 if (show_version)
585 {
586 gchar *build_date = utils_parse_and_format_build_date(__DATE__);
587
588 printf(PACKAGE " %s (", main_get_version_string());
589 /* note for translators: library versions are printed after this */
590 printf(_("built on %s with "), build_date);
591 printf(geany_lib_versions,
592 GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
593 GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
594 printf(")\n");
595 g_free(build_date);
597 exit(0);
598 }
599
600 if (print_prefix)
601 {
602 printf("%s\n", GEANY_PREFIX);
603 printf("%s\n", GEANY_DATADIR);
604 printf("%s\n", GEANY_LIBDIR);
605 printf("%s\n", GEANY_LOCALEDIR);
607 exit(0);
608 }
609
611 {
612 geany_debug("Using alternate configuration directory");
614 }
615 else
616 {
618 }
619
620 if (generate_tags)
621 {
622 gboolean ret;
623
625 ret = symbols_generate_global_tags(*argc, *argv, ! no_preprocessing);
628 exit(ret);
629 }
630
631 if (ft_names)
632 {
635 exit(0);
636 }
637
638#ifdef HAVE_SOCKET
639 socket_info.ignore_socket = cl_options.new_instance;
640 if (cl_options.socket_filename)
641 {
642 socket_info.file_name = cl_options.socket_filename;
643 }
644#endif
645
646#ifdef HAVE_VTE
647 vte_info.lib_vte = lib_vte;
648#endif
649 cl_options.ignore_global_tags = ignore_global_tags;
650
651 if (! gtk_init_check(NULL, NULL))
652 { /* check whether we have a valid X display and exit if not */
653 g_printerr("Geany: cannot open display\n");
654 exit(1);
655 }
656
657#ifdef MAC_INTEGRATION
658 /* Create GtkosxApplication singleton - should be created shortly after gtk_init() */
659 gtkosx_application_get();
660#endif
661}
662
663
664static gint create_config_dir(void)
665{
666 gint saved_errno = 0;
667 gchar *conf_file = NULL;
668 gchar *filedefs_dir = NULL;
669 gchar *templates_dir = NULL;
670
671 if (! g_file_test(app->configdir, G_FILE_TEST_EXISTS))
672 {
673#ifndef G_OS_WIN32
674 /* if we are *not* using an alternate config directory, we check whether the old one
675 * in ~/.geany still exists and try to move it */
676 if (alternate_config == NULL)
677 {
678 gchar *old_dir = g_build_filename(g_get_home_dir(), ".geany", NULL);
679 /* move the old config dir if it exists */
680 if (g_file_test(old_dir, G_FILE_TEST_EXISTS))
681 {
683 GTK_STOCK_YES, GTK_STOCK_QUIT, _("Move it now?"),
684 "%s",
685 _("Geany needs to move your old configuration directory before starting.")))
686 exit(0);
687
688 if (! g_file_test(app->configdir, G_FILE_TEST_IS_DIR))
689 utils_mkdir(app->configdir, TRUE);
690
691 if (g_rename(old_dir, app->configdir) == 0)
692 {
693 dialogs_show_msgbox(GTK_MESSAGE_INFO,
694 _("Your configuration directory has been successfully moved from \"%s\" to \"%s\"."),
695 old_dir, app->configdir);
696 g_free(old_dir);
697 return 0;
698 }
699 else
700 {
701 dialogs_show_msgbox(GTK_MESSAGE_WARNING,
702 /* for translators: the third %s in brackets is the error message which
703 * describes why moving the dir didn't work */
704 _("Your old configuration directory \"%s\" could not be moved to \"%s\" (%s). "
705 "Please move manually the directory to the new location."),
706 old_dir, app->configdir, g_strerror(errno));
707 }
708 }
709 g_free(old_dir);
710 }
711#endif
712 geany_debug("Creating configuration directory");
713 saved_errno = utils_mkdir(app->configdir, TRUE);
714 }
715
716 conf_file = g_build_filename(app->configdir, "geany.conf", NULL);
717 filedefs_dir = g_build_filename(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL);
718 templates_dir = g_build_filename(app->configdir, GEANY_TEMPLATES_SUBDIR, NULL);
719
720 if (saved_errno == 0 && ! g_file_test(conf_file, G_FILE_TEST_EXISTS))
721 { /* check whether geany.conf can be written */
722 saved_errno = utils_is_file_writable(app->configdir);
723 }
724
725 /* make subdir for filetype definitions */
726 if (saved_errno == 0)
727 {
728 gchar *filedefs_readme = g_build_filename(app->configdir,
729 GEANY_FILEDEFS_SUBDIR, "filetypes.README", NULL);
730
731 if (! g_file_test(filedefs_dir, G_FILE_TEST_EXISTS))
732 {
733 saved_errno = utils_mkdir(filedefs_dir, FALSE);
734 }
735 if (saved_errno == 0 && ! g_file_test(filedefs_readme, G_FILE_TEST_EXISTS))
736 {
737 gchar *text = g_strconcat(
738"Copy files from ", app->datadir, "/filedefs to this directory to overwrite "
739"them. To use the defaults, just delete the file in this directory.\nFor more information read "
740"the documentation (in ", app->docdir, G_DIR_SEPARATOR_S "index.html or visit " GEANY_HOMEPAGE ").", NULL);
741 utils_write_file(filedefs_readme, text);
742 g_free(text);
743 }
744 g_free(filedefs_readme);
745 }
746
747 /* make subdir for template files */
748 if (saved_errno == 0)
749 {
750 gchar *templates_readme = g_build_filename(app->configdir, GEANY_TEMPLATES_SUBDIR,
751 "templates.README", NULL);
752
753 if (! g_file_test(templates_dir, G_FILE_TEST_EXISTS))
754 {
755 saved_errno = utils_mkdir(templates_dir, FALSE);
756 }
757 if (saved_errno == 0 && ! g_file_test(templates_readme, G_FILE_TEST_EXISTS))
758 {
759 gchar *text = g_strconcat(
760"There are several template files in this directory. For these templates you can use wildcards.\n\
761For more information read the documentation (in ", app->docdir, G_DIR_SEPARATOR_S "index.html or visit " GEANY_HOMEPAGE ").",
762 NULL);
763 utils_write_file(templates_readme, text);
764 g_free(text);
765 }
766 g_free(templates_readme);
767 }
768
769 g_free(filedefs_dir);
770 g_free(templates_dir);
771 g_free(conf_file);
772
773 return saved_errno;
774}
775
776
777/* Returns 0 if config dir is OK. */
778static gint setup_config_dir(void)
779{
780 gint mkdir_result = 0;
781
782 mkdir_result = create_config_dir();
783 if (mkdir_result != 0)
784 {
786 _("Configuration directory could not be created (%s).\nThere could be some problems "
787 "using Geany without a configuration directory.\nStart Geany anyway?"),
788 g_strerror(mkdir_result)))
789 {
790 exit(0);
791 }
792 }
793 /* make configdir a real path */
794 if (g_file_test(app->configdir, G_FILE_TEST_EXISTS))
796
797 return mkdir_result;
798}
799
800
801#ifdef G_OS_UNIX
802static gboolean signal_cb(gpointer user_data)
803{
804 gint sig = GPOINTER_TO_INT(user_data);
805 if (sig == SIGTERM)
806 {
807 geany_debug("Received SIGTERM signal");
808 main_quit();
809 }
810 return G_SOURCE_REMOVE;
811}
812#endif
813
814
815/* Used for command-line arguments at startup or from socket.
816 * this will strip any :line:col filename suffix from locale_filename */
817gboolean main_handle_filename(const gchar *locale_filename)
818{
819 GeanyDocument *doc;
820 gint line = -1, column = -1;
821 gchar *filename;
822
823 g_return_val_if_fail(locale_filename, FALSE);
824
825 /* check whether the passed filename is an URI */
826 filename = utils_get_path_from_uri(locale_filename);
827 if (filename == NULL)
828 return FALSE;
829
831 if (line >= 0)
832 cl_options.goto_line = line;
833 if (column >= 0)
834 cl_options.goto_column = column;
835
836 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
837 {
839 /* add recent file manually if opening_session_files is set */
840 if (doc != NULL && main_status.opening_session_files)
842 g_free(filename);
843 return TRUE;
844 }
846 { /* create new file with the given filename */
847 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
848
849 doc = document_find_by_filename(utf8_filename);
850 if (doc)
852 else
853 doc = document_new_file(utf8_filename, NULL, NULL);
854 if (doc != NULL)
856 g_free(utf8_filename);
857 g_free(filename);
858 return TRUE;
859 }
860 g_free(filename);
861 return FALSE;
862}
863
864
865/* open files from command line */
866static void open_cl_files(gint argc, gchar **argv)
867{
868 gint i;
869
870 for (i = 1; i < argc; i++)
871 {
872 gchar *filename = main_get_argv_filename(argv[i]);
873
874 if (g_file_test(filename, G_FILE_TEST_IS_DIR))
875 {
876 g_free(filename);
877 continue;
878 }
879
880#ifdef G_OS_WIN32
881 /* It seems argv elements are encoded in CP1252 on a German Windows */
882 SETPTR(filename, g_locale_to_utf8(filename, -1, NULL, NULL, NULL));
883#endif
885 {
886 const gchar *msg = _("Could not find file '%s'.");
887
888 g_printerr(msg, filename); /* also print to the terminal */
889 g_printerr("\n");
890 ui_set_statusbar(TRUE, msg, filename);
891 }
892 g_free(filename);
893 }
894}
895
896
898{
899 gchar *locale_filename;
900
901 g_return_if_fail(project_prefs.session_file != NULL);
902
903 locale_filename = utils_get_locale_from_utf8(project_prefs.session_file);
904
905 if (G_LIKELY(!EMPTY(locale_filename)))
906 project_load_file(locale_filename);
907
908 g_free(locale_filename);
909 g_free(project_prefs.session_file); /* no longer needed */
910}
911
912
913static void load_settings(void)
914{
915#ifdef HAVE_VTE
916 vte_info.load_vte_cmdline = !no_vte;
917#endif
919 /* let cmdline options overwrite configuration settings */
920#ifdef HAVE_VTE
921 vte_info.have_vte = vte_info.load_vte && vte_info.load_vte_cmdline;
922#endif
923 if (no_msgwin)
924 ui_prefs.msgwindow_visible = FALSE;
925
926#ifdef HAVE_PLUGINS
928#endif
929}
930
931
932void main_load_project_from_command_line(const gchar *locale_filename, gboolean use_session)
933{
934 gchar *pfile;
935
936 pfile = utils_get_path_from_uri(locale_filename);
937 if (pfile != NULL)
938 {
939 if (use_session)
941 else
942 project_load_file(pfile);
943 }
944 g_free(pfile);
945}
946
947
948static void load_startup_files(gint argc, gchar **argv)
949{
950 gboolean load_session = FALSE;
951
952 if (argc > 1 && g_str_has_suffix(argv[1], ".geany"))
953 {
954 gchar *filename = main_get_argv_filename(argv[1]);
955
956 /* project file specified: load it, but decide the session later */
958 argc--, argv++;
959 /* force session load if using project-based session files */
960 load_session = project_prefs.project_session;
961 g_free(filename);
962 }
963
964 /* Load the default session if:
965 * 1. "Load files from the last session" is active.
966 * 2. --no-session is not specified.
967 * 3. We are a primary instance.
968 * Has no effect if a CL project is loaded and using project-based session files. */
969 if (prefs.load_session && cl_options.load_session && !cl_options.new_instance)
970 {
971 if (app->project == NULL)
973 load_session = TRUE;
974 }
975
976 if (load_session)
977 {
978 /* load session files into tabs, as they are found in the session_files variable */
980
981 if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 0)
982 {
985 }
986 }
987
988 open_cl_files(argc, argv);
989}
990
991
992static gboolean send_startup_complete(gpointer data)
993{
994 g_signal_emit_by_name(geany_object, "geany-startup-complete");
995 return FALSE;
996}
997
998
999static const gchar *get_locale(void)
1000{
1001 const gchar *locale = "unknown";
1002#ifdef HAVE_LOCALE_H
1003 locale = setlocale(LC_CTYPE, NULL);
1004#endif
1005 return locale;
1006}
1007
1008
1009GEANY_EXPORT_SYMBOL
1010gint main_lib(gint argc, gchar **argv)
1011{
1012 GeanyDocument *doc;
1013 gint config_dir_result;
1014 const gchar *locale;
1015 gchar *utf8_configdir;
1016 gchar *os_info;
1017
1018#if ! GLIB_CHECK_VERSION(2, 36, 0)
1019 g_type_init();
1020#endif
1021
1023
1024 app = g_new0(GeanyApp, 1);
1025 memset(&main_status, 0, sizeof(GeanyStatus));
1026 memset(&prefs, 0, sizeof(GeanyPrefs));
1027 memset(&interface_prefs, 0, sizeof(GeanyInterfacePrefs));
1028 memset(&toolbar_prefs, 0, sizeof(GeanyToolbarPrefs));
1029 memset(&file_prefs, 0, sizeof(GeanyFilePrefs));
1030 memset(&search_prefs, 0, sizeof(GeanySearchPrefs));
1031 memset(&tool_prefs, 0, sizeof(GeanyToolPrefs));
1032 memset(&template_prefs, 0, sizeof(GeanyTemplatePrefs));
1033 memset(&ui_prefs, 0, sizeof(UIPrefs));
1034 memset(&ui_widgets, 0, sizeof(UIWidgets));
1035
1036 setup_paths();
1037
1038#ifdef ENABLE_NLS
1040#endif
1041 /* initialize TM before parsing command-line - needed for tag file generation */
1043 parse_command_line_options(&argc, &argv);
1044
1045#if ! GLIB_CHECK_VERSION(2, 32, 0)
1046 /* Initialize GLib's thread system in case any plugins want to use it or their
1047 * dependencies (e.g. WebKit, Soup, ...). Deprecated since GLIB 2.32. */
1048 if (!g_thread_supported())
1049 g_thread_init(NULL);
1050#endif
1051
1052#ifdef G_OS_UNIX
1053 g_unix_signal_add(SIGTERM, signal_cb, GINT_TO_POINTER(SIGTERM));
1054
1055 /* ignore SIGPIPE signal for preventing sudden death of program */
1056 signal(SIGPIPE, SIG_IGN);
1057#endif
1058
1059 config_dir_result = setup_config_dir();
1060#ifdef HAVE_SOCKET
1061 /* check and create (unix domain) socket for remote operation */
1063 {
1064 gushort socket_port = 0;
1065#ifdef G_OS_WIN32
1066 socket_port = (gushort) get_windows_socket_port();
1067#endif
1070 socket_info.lock_socket = socket_init(argc, argv, socket_port);
1071 /* Quit if filenames were sent to first instance or the list of open
1072 * documents has been printed */
1073 if ((socket_info.lock_socket == -2 /* socket exists */ && argc > 1) ||
1074 cl_options.list_documents)
1075 {
1077 gdk_notify_startup_complete();
1078 g_free(app->configdir);
1079 g_free(app->datadir);
1080 g_free(app->docdir);
1081 g_free(app);
1082 return 0;
1083 }
1084 /* Start a new instance if no command line strings were passed,
1085 * even if the socket already exists */
1086 else if (socket_info.lock_socket == -2 /* socket already exists */)
1087 {
1089 cl_options.new_instance = TRUE;
1090 }
1091 }
1092#endif
1093
1094#ifdef G_OS_WIN32
1095 /* after we initialized the socket code and handled command line args,
1096 * let's change the working directory on Windows to not lock it */
1097 change_working_directory_on_windows();
1098#endif
1099
1100 locale = get_locale();
1101 geany_debug("Geany %s, %s",
1103 locale);
1105 gtk_major_version, gtk_minor_version, gtk_micro_version,
1106 glib_major_version, glib_minor_version, glib_micro_version);
1107
1108 os_info = utils_get_os_info_string();
1109 if (os_info != NULL)
1110 {
1111 geany_debug("OS: %s", os_info);
1112 g_free(os_info);
1113 }
1114
1115 geany_debug("System data dir: %s", app->datadir);
1116 utf8_configdir = utils_get_utf8_from_locale(app->configdir);
1117 geany_debug("User config dir: %s", utf8_configdir);
1118 g_free(utf8_configdir);
1119
1120 /* create the object so Geany signals can be connected in init() functions */
1122
1123 /* inits */
1124 main_init();
1125
1127 editor_init();
1128
1129 /* init stash groups before loading keyfile */
1131 ui_init_prefs();
1132 search_init();
1133 project_init();
1134#ifdef HAVE_PLUGINS
1135 plugins_init();
1136#endif
1137 sidebar_init();
1138 load_settings(); /* load keyfile */
1139
1140 msgwin_init();
1141 build_init();
1145 notebook_init();
1148 navqueue_init();
1150 symbols_init();
1152
1153#ifdef HAVE_VTE
1154 vte_init();
1155#endif
1157
1158 ui_set_statusbar(TRUE, _("This is Geany %s."), main_get_version_string());
1159 if (config_dir_result != 0)
1160 {
1161 const gchar *message = _("Configuration directory could not be created (%s).");
1162 ui_set_statusbar(TRUE, message, g_strerror(config_dir_result));
1163 g_warning(message, g_strerror(config_dir_result));
1164 }
1165#ifdef HAVE_SOCKET
1166 if (socket_info.lock_socket == -1)
1167 {
1168 const gchar *message =
1169 _("IPC socket could not be created, see Help->Debug Messages for details.");
1170 ui_set_statusbar(TRUE, "%s", message);
1171 g_warning("%s", message);
1172 }
1173#endif
1174
1175 /* apply all configuration options */
1177
1178#ifdef HAVE_PLUGINS
1179 /* load any enabled plugins before we open any documents */
1180 if (want_plugins)
1182#endif
1183
1185
1186 /* set the active sidebar page after plugins have been loaded */
1187 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.sidebar_notebook), ui_prefs.sidebar_page);
1188
1189 /* load keybinding settings after plugins have added their groups */
1191
1192 /* create the custom command menu after the keybindings have been loaded to have the proper
1193 * accelerator shown for the menu items */
1195
1196 /* load any command line files or session files */
1197 main_status.opening_session_files = TRUE;
1198 load_startup_files(argc, argv);
1199 main_status.opening_session_files = FALSE;
1200
1201 /* open a new file if no other file was opened */
1203
1206
1207 doc = document_get_current();
1209 build_menu_update(doc);
1210 sidebar_update_tag_list(doc, FALSE);
1211
1213
1214 /* finally show the window */
1216 gtk_widget_show(main_widgets.window);
1217 main_status.main_window_realized = TRUE;
1218
1220
1221#ifdef HAVE_SOCKET
1222 /* register the callback of socket input */
1224 {
1225 socket_info.read_ioc = g_io_channel_unix_new(socket_info.lock_socket);
1227 G_IO_IN | G_IO_PRI | G_IO_ERR, socket_lock_input_cb, main_widgets.window);
1228 }
1229#endif
1230
1231 /* when we are really done with setting everything up and the main event loop is running,
1232 * tell other components, mainly plugins, that startup is complete */
1233 g_idle_add_full(G_PRIORITY_LOW, send_startup_complete, NULL, NULL);
1234
1235#ifdef MAC_INTEGRATION
1236 /* OS X application ready - has to be called before entering main loop */
1237 gtkosx_application_ready(gtkosx_application_get());
1238#endif
1239
1240 gtk_main();
1241 return 0;
1242}
1243
1244
1245static void queue_free(GQueue *queue)
1246{
1247 while (! g_queue_is_empty(queue))
1248 {
1249 g_free(g_queue_pop_tail(queue));
1250 }
1251 g_queue_free(queue);
1252}
1253
1254
1255static gboolean do_main_quit(void)
1256{
1258
1259 if (app->project != NULL)
1260 {
1261 if (!project_close(FALSE)) /* save project session files */
1262 return FALSE;
1263 }
1264
1265 if (!document_close_all())
1266 return FALSE;
1267
1268 geany_debug("Quitting...");
1269
1270 main_status.quitting = TRUE;
1271
1272#ifdef HAVE_SOCKET
1274#endif
1275
1276#ifdef HAVE_PLUGINS
1278#endif
1279
1280 navqueue_free();
1282 notebook_free();
1298 log_finalize();
1299
1301 g_free(app->configdir);
1302 g_free(app->datadir);
1303 g_free(app->docdir);
1304 g_free(prefs.default_open_path);
1305 g_free(prefs.custom_plugin_path);
1306 g_free(ui_prefs.custom_date_format);
1307 g_free(ui_prefs.color_picker_palette);
1313 g_free(editor_prefs.color_scheme);
1315 g_free(template_prefs.developer);
1316 g_free(template_prefs.company);
1317 g_free(template_prefs.mail);
1318 g_free(template_prefs.initials);
1319 g_free(template_prefs.version);
1320 g_free(tool_prefs.term_cmd);
1321 g_free(tool_prefs.browser_cmd);
1322 g_free(tool_prefs.grep_cmd);
1325 g_strfreev(ui_prefs.custom_commands);
1326 g_strfreev(ui_prefs.custom_commands_labels);
1327
1328 queue_free(ui_prefs.recent_queue);
1329 queue_free(ui_prefs.recent_projects_queue);
1330
1331 if (ui_widgets.prefs_dialog && GTK_IS_WIDGET(ui_widgets.prefs_dialog)) gtk_widget_destroy(ui_widgets.prefs_dialog);
1332 if (ui_widgets.open_fontsel && GTK_IS_WIDGET(ui_widgets.open_fontsel)) gtk_widget_destroy(ui_widgets.open_fontsel);
1333 if (ui_widgets.open_colorsel && GTK_IS_WIDGET(ui_widgets.open_colorsel)) gtk_widget_destroy(ui_widgets.open_colorsel);
1334#ifdef HAVE_VTE
1335 if (vte_info.have_vte) vte_close();
1336 g_free(vte_info.lib_vte);
1337 g_free(vte_info.dir);
1338#endif
1339 gtk_widget_destroy(main_widgets.window);
1340
1341 /* destroy popup menus */
1342 if (main_widgets.editor_menu && GTK_IS_WIDGET(main_widgets.editor_menu))
1343 gtk_widget_destroy(main_widgets.editor_menu);
1344 if (ui_widgets.toolbar_menu && GTK_IS_WIDGET(ui_widgets.toolbar_menu))
1345 gtk_widget_destroy(ui_widgets.toolbar_menu);
1346 if (msgwindow.popup_status_menu && GTK_IS_WIDGET(msgwindow.popup_status_menu))
1347 gtk_widget_destroy(msgwindow.popup_status_menu);
1348 if (msgwindow.popup_msg_menu && GTK_IS_WIDGET(msgwindow.popup_msg_menu))
1349 gtk_widget_destroy(msgwindow.popup_msg_menu);
1350 if (msgwindow.popup_compiler_menu && GTK_IS_WIDGET(msgwindow.popup_compiler_menu))
1351 gtk_widget_destroy(msgwindow.popup_compiler_menu);
1352
1353 g_object_unref(geany_object);
1355
1356 g_free(original_cwd);
1357 g_free(app);
1358
1360
1361 gtk_main_quit();
1362
1363 return TRUE;
1364}
1365
1366
1367static gboolean check_no_unsaved(void)
1368{
1369 guint i;
1370
1371 for (i = 0; i < documents_array->len; i++)
1372 {
1373 if (documents[i]->is_valid && documents[i]->changed)
1374 {
1375 return FALSE;
1376 }
1377 }
1378 return TRUE; /* no unsaved edits */
1379}
1380
1381
1382/* Returns false when quitting is aborted due to user cancellation */
1383gboolean main_quit(void)
1384{
1385 main_status.quitting = TRUE;
1386
1387 if (! check_no_unsaved())
1388 {
1389 if (do_main_quit())
1390 return TRUE;
1391 }
1392 else
1393 if (! prefs.confirm_exit ||
1394 dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
1395 _("Do you really want to quit?")))
1396 {
1397 if (do_main_quit())
1398 return TRUE;
1399 }
1400
1401 main_status.quitting = FALSE;
1402 return FALSE;
1403}
1404
1405/**
1406 * Reloads most of Geany's configuration files without restarting. Currently the following
1407 * files are reloaded: all template files, also new file templates and the 'New (with template)'
1408 * menus will be updated, Snippets (snippets.conf), filetype extensions (filetype_extensions.conf),
1409 * and 'settings' and 'build_settings' sections of the filetype definition files.
1410 *
1411 * Plugins may call this function if they changed any of these files (e.g. a configuration file
1412 * editor plugin).
1413 *
1414 * @since 0.15
1415 **/
1416GEANY_API_SYMBOL
1418{
1419 /* reload templates */
1422
1423 /* reload snippets */
1426
1429
1430 /* C tag names to ignore */
1432
1433 ui_set_statusbar(TRUE, _("Configuration files reloaded."));
1434}
Contains the GeanyApp.
void build_init(void)
Definition: build.c:2690
void build_menu_update(GeanyDocument *doc)
Definition: build.c:1457
void build_finalize(void)
Definition: build.c:177
Interface to the Build menu functionality.
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
void dialogs_show_msgbox(GtkMessageType type, const gchar *text,...)
Shows a message box of the type type with text.
Definition: dialogs.c:729
File related dialogs, miscellaneous dialogs, font dialog.
GeanyDocument * document_get_current(void)
Finds the current document.
Definition: document.c:371
void document_init_doclist(void)
Definition: document.c:382
gboolean document_close_all(void)
Definition: document.c:3396
GeanyDocument * document_new_file_if_non_open(void)
Definition: document.c:803
void document_grab_focus(GeanyDocument *doc)
Definition: document.c:3812
void document_show_tab(GeanyDocument *doc)
Definition: document.c:1273
gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
Definition: document.c:3674
GeanyDocument * document_find_by_filename(const gchar *utf8_filename)
Finds a document with the given filename.
Definition: document.c:183
GeanyFilePrefs file_prefs
Definition: document.c:86
GeanyDocument * document_open_file(const gchar *locale_filename, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
Opens a document specified by locale_filename.
Definition: document.c:908
GPtrArray * documents_array
Definition: document.c:87
GeanyDocument * document_new_file(const gchar *utf8_filename, GeanyFiletype *ft, const gchar *text)
Creates a new document.
Definition: document.c:824
void document_finalize(void)
Definition: document.c:388
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
void editor_snippets_init(void)
Definition: editor.c:258
void editor_init(void)
Definition: editor.c:5070
void editor_finalize(void)
Definition: editor.c:4046
gchar * text
Definition: editor.c:83
void editor_snippets_free(void)
Definition: editor.c:110
GeanyEditorPrefs editor_prefs
Definition: editor.c:77
void encodings_finalize(void)
Definition: encodings.c:391
void encodings_init(void)
Definition: encodings.c:405
void error(const errorSelection selection, const char *const format,...)
Definition: error.c:53
Filetype detection, file extensions and filetype menu items.
int errno
#define GEANY_TEMPLATES_SUBDIR
Definition: geany.h:42
#define GEANY_FILEDEFS_SUBDIR
Definition: geany.h:41
#define GEANY_WINDOW_DEFAULT_WIDTH
Definition: geany.h:51
#define GEANY_WINDOW_DEFAULT_HEIGHT
Definition: geany.h:52
#define GEANY_HOMEPAGE
Definition: geany.h:45
vString * line
Definition: geany_cobol.c:133
tokenInfo * list
GObject * geany_object
Definition: geanyobject.c:41
GObject * geany_object_new(void)
Definition: geanyobject.c:260
void highlighting_free_styles(void)
Definition: highlighting.c:421
Syntax highlighting for the different filetypes, using the Scintilla lexers.
void keybindings_load_keyfile(void)
Reloads keybinding settings from configuration file.
Definition: keybindings.c:842
void keybindings_init(void)
Definition: keybindings.c:742
void keybindings_free(void)
Definition: keybindings.c:934
Configurable keyboard shortcuts.
void configuration_save(void)
Definition: keyfile.c:632
void configuration_apply_settings(void)
Definition: keyfile.c:1318
void configuration_init(void)
Definition: keyfile.c:1383
gboolean configuration_load(void)
Definition: keyfile.c:1163
void configuration_open_files(void)
Definition: keyfile.c:1257
void configuration_finalize(void)
Definition: keyfile.c:1395
void main_load_project_from_command_line(const gchar *locale_filename, gboolean use_session)
Definition: libmain.c:932
static gboolean verbose_mode
Definition: libmain.c:99
static void wait_for_input_on_windows(void)
Definition: libmain.c:521
static gboolean no_plugins
Definition: libmain.c:113
static void setup_paths(void)
Definition: libmain.c:435
static void load_startup_files(gint argc, gchar **argv)
Definition: libmain.c:948
const gchar * main_get_version_string(void)
Definition: libmain.c:304
CommandLineOptions cl_options
Definition: libmain.c:90
void main_reload_configuration(void)
Reloads most of Geany's configuration files without restarting.
Definition: libmain.c:1417
static gboolean print_prefix
Definition: libmain.c:111
gboolean main_quit(void)
Definition: libmain.c:1383
static gboolean do_main_quit(void)
Definition: libmain.c:1255
static gboolean ignore_global_tags
Definition: libmain.c:100
static void queue_free(GQueue *queue)
Definition: libmain.c:1245
static gboolean no_preprocessing
Definition: libmain.c:109
gboolean main_handle_filename(const gchar *locale_filename)
Definition: libmain.c:817
GEANY_EXPORT_SYMBOL gint main_lib(gint argc, gchar **argv)
Definition: libmain.c:1010
static gboolean generate_tags
Definition: libmain.c:108
gboolean main_is_realized(void)
Checks whether the main window has been realized.
Definition: libmain.c:458
static gboolean show_version
Definition: libmain.c:102
static gboolean dummy
Definition: libmain.c:115
void main_locale_init(const gchar *locale_dir, const gchar *package)
Initialises the gettext translation system.
Definition: libmain.c:489
static void print_filetypes(void)
Definition: libmain.c:503
static GOptionEntry entries[]
Definition: libmain.c:118
GeanyApp * app
Definition: libmain.c:86
static void get_line_and_column_from_filename(gchar *filename, gint *line, gint *column)
Definition: libmain.c:343
static gboolean want_plugins
Definition: libmain.c:96
static const gchar * get_locale(void)
Definition: libmain.c:999
static gint create_config_dir(void)
Definition: libmain.c:664
static gchar * original_cwd
Definition: libmain.c:92
static gint setup_config_dir(void)
Definition: libmain.c:778
static gboolean check_no_unsaved(void)
Definition: libmain.c:1367
static void load_settings(void)
Definition: libmain.c:913
static void parse_command_line_options(gint *argc, gchar ***argv)
Definition: libmain.c:533
static void setup_window_position(void)
Definition: libmain.c:150
static gboolean no_msgwin
Definition: libmain.c:101
static void load_session_project_file(void)
Definition: libmain.c:897
static void on_window_active_changed(GtkWindow *window, GParamSpec *pspec, gpointer data)
Definition: libmain.c:235
static gboolean ft_names
Definition: libmain.c:110
gchar * main_get_argv_filename(const gchar *filename)
Definition: libmain.c:317
static gchar * alternate_config
Definition: libmain.c:103
static gboolean send_startup_complete(gpointer data)
Definition: libmain.c:992
static const gchar geany_lib_versions[]
Definition: libmain.c:94
gboolean ignore_callback
Definition: libmain.c:87
GeanyStatus main_status
Definition: libmain.c:89
static void apply_settings(void)
Definition: libmain.c:180
static void open_cl_files(gint argc, gchar **argv)
Definition: libmain.c:866
static void main_init(void)
Definition: libmain.c:244
void log_handlers_init(void)
Definition: log.c:151
void log_finalize(void)
Definition: log.c:218
void geany_debug(gchar const *format,...)
Definition: log.c:67
Main program-related commands.
void msgwin_finalize(void)
Definition: msgwindow.c:167
MessageWindow msgwindow
Definition: msgwindow.c:66
void msgwin_init(void)
Definition: msgwindow.c:142
Message window functions (status, compiler, messages windows).
void navqueue_free(void)
Definition: navqueue.c:67
void navqueue_init(void)
Definition: navqueue.c:54
Simple code navigation.
void notebook_init(void)
Definition: notebook.c:547
void notebook_free(void)
Definition: notebook.c:568
void plugins_finalize(void)
Definition: plugins.c:1359
void plugins_init(void)
Definition: plugins.c:1325
void plugins_load_active(void)
Definition: plugins.c:1257
signal void(* project_close)(GObject *obj, gpointer user_data)
Sent after a project is closed.
GeanyToolPrefs tool_prefs
Definition: prefs.c:67
GeanyPrefs prefs
Definition: prefs.c:66
PrintingPrefs printing_prefs
Definition: printing.c:50
void project_finalize(void)
Definition: project.c:1348
gboolean project_load_file_with_session(const gchar *locale_file_name)
Definition: project.c:274
void project_init(void)
Definition: project.c:1343
gboolean project_load_file(const gchar *locale_file_name)
Definition: project.c:1011
ProjectPrefs project_prefs
Definition: project.c:53
#define NULL
Definition: rbtree.h:150
void search_finalize(void)
Definition: search.c:285
void search_init(void)
Definition: search.c:274
GeanySearchPrefs search_prefs
Definition: search.c:78
void sidebar_finalize(void)
Definition: sidebar.c:1115
void sidebar_select_openfiles_item(GeanyDocument *doc)
Definition: sidebar.c:790
void sidebar_init(void)
Definition: sidebar.c:1085
void sidebar_update_tag_list(GeanyDocument *doc, gboolean update)
Definition: sidebar.c:188
gint socket_finalize(void)
struct SocketInfo socket_info
gint socket_init(gint argc, gchar **argv, gushort socket_port)
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data)
#define SOCKET_WINDOWS_REMOTE_CMD_PORT
Definition: socket.h:32
void filetypes_reload(void)
Definition: filetypes.c:1495
const GSList * filetypes_get_sorted_by_name(void)
Gets a list of filetype pointers sorted by name.
Definition: filetypes.c:234
void filetypes_init_types(void)
Definition: filetypes.c:314
void filetypes_reload_extensions(void)
Definition: filetypes.c:1464
void filetypes_init(void)
Definition: filetypes.c:461
void filetypes_free_types(void)
Definition: filetypes.c:854
const gchar filename[]
Definition: stash-example.c:4
Important application fields.
Definition: app.h:38
struct GeanyProject * project
Currently active project or NULL if none is open.
Definition: app.h:49
gchar * docdir
Definition: app.h:47
const TMWorkspace * tm_workspace
TagManager workspace/session tags.
Definition: app.h:48
gchar * configdir
User configuration directory, usually ~/.config/geany.
Definition: app.h:45
gchar * datadir
Definition: app.h:46
gboolean debug_mode
TRUE if debug messages should be printed.
Definition: app.h:39
Structure for representing an open tab with all its properties.
Definition: document.h:81
gchar * color_scheme
Definition: editor.h:135
gchar * comment_toggle_mark
Definition: editor.h:130
gchar * long_line_color
Definition: editor.h:107
File Prefs.
Definition: document.h:47
gboolean tab_order_beside
Definition: document.h:54
gboolean cmdline_new_files
Definition: document.h:59
gboolean tab_order_ltr
Definition: document.h:53
Represents a filetype.
Definition: filetypes.h:144
gchar * name
Untranslated short name, such as "C", "None".
Definition: filetypes.h:152
Interface preferences.
Definition: ui_utils.h:46
gint tab_pos_editor
positions of editor's tabs
Definition: ui_utils.h:53
gboolean statusbar_visible
whether the status bar is visible
Definition: ui_utils.h:56
gint sidebar_pos
position of the sidebar (left or right)
Definition: ui_utils.h:61
gint tab_pos_sidebar
positions of sidebar's tabs
Definition: ui_utils.h:55
gchar * editor_font
editor font
Definition: ui_utils.h:49
gchar * msgwin_font
message window font
Definition: ui_utils.h:51
gboolean show_notebook_tabs
whether editor tabs are visible
Definition: ui_utils.h:52
gint tab_pos_msgwin
positions of message window's tabs
Definition: ui_utils.h:54
gint msgwin_orientation
orientation of the message window
Definition: ui_utils.h:70
gchar * tagbar_font
symbol sidebar font
Definition: ui_utils.h:50
GtkWidget * window
Main window.
Definition: ui_utils.h:80
GtkWidget * notebook
Document notebook.
Definition: ui_utils.h:83
GtkWidget * message_window_notebook
Message Window notebook.
Definition: ui_utils.h:89
GtkWidget * editor_menu
Popup editor menu.
Definition: ui_utils.h:84
GtkWidget * toolbar
Main toolbar.
Definition: ui_utils.h:81
GtkWidget * project_menu
Plugins modifying the project can add their items to the Project menu.
Definition: ui_utils.h:91
GtkWidget * tools_menu
Most plugins add menu items to the Tools menu.
Definition: ui_utils.h:85
GtkWidget * sidebar_notebook
Sidebar notebook.
Definition: ui_utils.h:82
General Preferences dialog settings.
Definition: prefs.h:30
gchar * custom_plugin_path
Definition: prefs.h:40
gboolean confirm_exit
Definition: prefs.h:34
gboolean save_winpos
Definition: prefs.h:33
gboolean load_plugins
Definition: prefs.h:32
gboolean save_wingeom
Definition: prefs.h:41
gboolean load_session
Definition: prefs.h:31
gchar * default_open_path
Default path to look for files when no other path is appropriate.
Definition: prefs.h:39
Search preferences.
Definition: search.h:57
Template preferences.
Definition: templates.h:39
gchar * initials
Initials.
Definition: templates.h:43
gchar * mail
Email.
Definition: templates.h:42
gchar * company
Company.
Definition: templates.h:41
gchar * version
Initial version.
Definition: templates.h:44
gchar * developer
Name.
Definition: templates.h:40
Tools preferences.
Definition: prefs.h:50
gchar * grep_cmd
grep command
Definition: prefs.h:53
gchar * context_action_cmd
context action command
Definition: prefs.h:54
gchar * term_cmd
terminal emulator command
Definition: prefs.h:52
gchar * browser_cmd
web browser command
Definition: prefs.h:51
Toolbar settings.
Definition: toolbar.h:30
gchar * external_print_cmd
Definition: printing.h:40
gchar * page_header_datefmt
Definition: printing.h:39
gchar * file_name
Definition: socket.h:37
gint lock_socket
Definition: socket.h:39
gboolean ignore_socket
Definition: socket.h:36
guint lock_socket_tag
Definition: socket.h:40
GIOChannel * read_ioc
Definition: socket.h:38
Defines internationalization macros.
#define _(String)
Definition: support.h:42
#define bindtextdomain(Domain, Dir)
Definition: support.h:40
#define N_(String)
Definition: support.h:43
#define bind_textdomain_codeset(Domain, Codeset)
Definition: support.h:39
#define GETTEXT_PACKAGE
Definition: support.h:37
void symbols_reload_config_files(void)
Definition: symbols.c:142
int symbols_generate_global_tags(int argc, char **argv, gboolean want_preprocess)
Definition: symbols.c:1656
void symbols_finalize(void)
Definition: symbols.c:2694
void symbols_init(void)
Definition: symbols.c:2676
Tag-related functions.
void templates_init(void)
Definition: templates.c:308
GeanyTemplatePrefs template_prefs
Definition: templates.c:50
void templates_free_templates(void)
Definition: templates.c:517
Templates (prefs).
void tm_workspace_free(void)
Definition: tm_workspace.c:90
const TMWorkspace * tm_get_workspace(void)
Definition: tm_workspace.c:116
void toolbar_show_hide(void)
Definition: toolbar.c:539
GeanyToolbarPrefs toolbar_prefs
Definition: toolbar.c:48
void toolbar_finalize(void)
Definition: toolbar.c:525
void toolbar_update_ui(void)
Definition: toolbar.c:414
GtkWidget * toolbar_init(void)
Definition: toolbar.c:340
void toolbar_apply_settings(void)
Definition: toolbar.c:577
Toolbar (prefs).
void tools_create_insert_custom_command_menu_items(void)
Definition: tools.c:581
void ui_init_builder(void)
Definition: ui_utils.c:2433
void ui_create_insert_menu_items(void)
Definition: ui_utils.c:646
void ui_sidebar_show_hide(void)
Definition: ui_utils.c:1000
GtkWidget * create_toolbar_popup_menu1(void)
Definition: ui_utils.c:2398
void ui_init(void)
Definition: ui_utils.c:2578
void ui_create_recent_menus(void)
Definition: ui_utils.c:1168
GtkWidget * create_edit_menu1(void)
Definition: ui_utils.c:2380
void ui_update_popup_copy_items(GeanyDocument *doc)
Definition: ui_utils.c:486
void ui_init_prefs(void)
Definition: ui_utils.c:2332
void ui_save_buttons_toggle(gboolean enable)
Definition: ui_utils.c:830
void ui_swap_sidebar_pos(void)
Definition: ui_utils.c:2241
GeanyMainWidgets main_widgets
Definition: ui_utils.c:72
void ui_set_statusbar(gboolean log, const gchar *format,...)
Displays text on the statusbar.
Definition: ui_utils.c:168
void ui_update_view_editor_menu_items(void)
Definition: ui_utils.c:1453
UIPrefs ui_prefs
Definition: ui_utils.c:74
void ui_add_recent_document(GeanyDocument *doc)
Definition: ui_utils.c:1232
void ui_document_buttons_update(void)
Definition: ui_utils.c:946
void ui_update_fold_items(void)
Definition: ui_utils.c:562
GtkWidget * create_window1(void)
Definition: ui_utils.c:2404
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_init_stock_items(void)
Definition: ui_utils.c:2218
void ui_finalize_builder(void)
Definition: ui_utils.c:2632
void ui_update_popup_reundo_items(GeanyDocument *doc)
Definition: ui_utils.c:453
UIWidgets ui_widgets
Definition: ui_utils.c:75
GeanyInterfacePrefs interface_prefs
Definition: ui_utils.c:71
void ui_create_insert_date_menu_items(void)
Definition: ui_utils.c:784
User Interface general utility functions.
gchar * utils_get_path_from_uri(const gchar *uri)
Definition: utils.c:1704
gint utils_write_file(const gchar *filename, const gchar *text)
Writes text into a file named filename.
Definition: utils.c:209
gchar * utils_get_os_info_string(void)
Definition: utils.c:2426
gchar * utils_parse_and_format_build_date(const gchar *input)
Definition: utils.c:2261
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
const gchar * utils_resource_dir(GeanyResourceDirType type)
Definition: utils.c:2301
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_is_uri(const gchar *uri)
Definition: utils.c:1732
gboolean utils_str_equal(const gchar *a, const gchar *b)
NULL-safe string comparison.
Definition: utils.c:599
gchar * utils_get_user_config_dir(void)
Definition: utils.c:2277
gint utils_is_file_writable(const gchar *locale_filename)
Definition: utils.c:657
gchar * utils_get_real_path(const gchar *file_name)
Get a link-dereferenced, absolute version of a file name.
Definition: utils.c:2406
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