~ubuntu-branches/ubuntu/raring/geany/raring-proposed

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (9 hardy)
  • mto: (3.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      main.c - this file is part of Geany, a fast and lightweight IDE
3
3
 *
4
 
 *      Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
 
4
 *      Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
 
5
 *      Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
5
6
 *
6
7
 *      This program is free software; you can redistribute it and/or modify
7
8
 *      it under the terms of the GNU General Public License as published by
17
18
 *      along with this program; if not, write to the Free Software
18
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20
 *
20
 
 * $Id: main.c 830 2006-09-22 11:38:14Z ntrel $
 
21
 * $Id: main.c 2492 2008-04-16 15:44:29Z ntrel $
21
22
 */
22
23
 
 
24
/*
 
25
 * Program initialization and cleanup.
 
26
 */
23
27
 
24
28
#include <signal.h>
25
29
#include <time.h>
31
35
 
32
36
#include "geany.h"
33
37
 
 
38
#if HAVE_LOCALE_H
 
39
# include <locale.h>
 
40
#endif
 
41
 
34
42
#include "main.h"
 
43
#include "prefix.h"
 
44
#include "prefs.h"
35
45
#include "interface.h"
36
46
#include "support.h"
37
47
#include "callbacks.h"
39
49
#include "ui_utils.h"
40
50
#include "utils.h"
41
51
#include "document.h"
 
52
#include "filetypes.h"
42
53
#include "keyfile.h"
43
54
#include "win32.h"
44
55
#include "msgwindow.h"
48
59
#include "treeviews.h"
49
60
#include "notebook.h"
50
61
#include "keybindings.h"
51
 
#include "sci_cb.h"
 
62
#include "editor.h"
52
63
#include "search.h"
 
64
#include "build.h"
 
65
#include "highlighting.h"
 
66
#include "symbols.h"
 
67
#include "project.h"
 
68
#include "tools.h"
 
69
#include "navqueue.h"
 
70
#include "plugins.h"
 
71
#include "printing.h"
53
72
 
54
73
#ifdef HAVE_SOCKET
55
74
# include "socket.h"
59
78
# include "vte.h"
60
79
#endif
61
80
 
62
 
#define N_(String) (String)
63
 
 
64
 
 
65
 
 
66
 
CommandLineOptions cl_options;  // fields initialised in parse_command_line_options
67
 
 
 
81
#ifndef N_
 
82
# define N_(String) (String)
 
83
#endif
 
84
 
 
85
 
 
86
GeanyApp *app;
 
87
 
 
88
GeanyStatus      main_status;
 
89
CommandLineOptions cl_options;  /* fields initialised in parse_command_line_options */
 
90
 
 
91
 
 
92
static gboolean want_plugins;
 
93
 
 
94
/* command-line options */
68
95
static gboolean debug_mode = FALSE;
69
96
static gboolean ignore_global_tags = FALSE;
70
97
static gboolean no_msgwin = FALSE;
78
105
static gboolean ignore_socket = FALSE;
79
106
#endif
80
107
static gboolean generate_datafiles = FALSE;
 
108
static gboolean generate_tags = FALSE;
 
109
static gboolean no_preprocessing = FALSE;
 
110
static gboolean ft_names = FALSE;
 
111
static gboolean print_prefix = FALSE;
 
112
#ifdef HAVE_PLUGINS
 
113
static gboolean no_plugins = FALSE;
 
114
#endif
 
115
static gboolean dummy = FALSE;
81
116
 
 
117
/* in alphabetical order of short options */
82
118
static GOptionEntry entries[] =
83
119
{
84
 
        { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("runs in debug mode (means being verbose)"), NULL },
 
120
        { "column", 0, 0, G_OPTION_ARG_INT, &cl_options.goto_column, N_("Set initial column number for the first opened file (useful in conjunction with --line)"), NULL },
 
121
        { "config", 'c', 0, G_OPTION_ARG_FILENAME, &alternate_config, N_("Use an alternate configuration directory"), NULL },
 
122
        { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("Runs in debug mode (means being verbose)"), NULL },
 
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, NULL, NULL },
 
126
        { "generate-data-files", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &generate_datafiles, NULL, NULL },
 
127
#ifdef HAVE_SOCKET
 
128
        { "new-instance", 'i', 0, G_OPTION_ARG_NONE, &ignore_socket, N_("Don't open files in a running instance, force opening a new instance"), NULL },
 
129
#endif
 
130
        { "line", 'l', 0, G_OPTION_ARG_INT, &cl_options.goto_line, N_("Set initial line number for the first opened file"), NULL },
 
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 },
85
137
        { "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 },
86
 
        { "no-ctags", 'n', 0, G_OPTION_ARG_NONE, &ignore_global_tags, N_("don't load auto completion data (see documentation)"), NULL },
87
 
#ifdef HAVE_SOCKET
88
 
        { "new-instance", 'i', 0, G_OPTION_ARG_NONE, &ignore_socket, N_("don't open files in a running instance, force opening a new instance"), NULL },
89
 
#endif
90
 
        { "config", 'c', 0, G_OPTION_ARG_FILENAME, &alternate_config, N_("use an alternate configuration directory"), NULL },
91
 
        { "no-msgwin", 'm', 0, G_OPTION_ARG_NONE, &no_msgwin, N_("don't show message window at startup"), NULL },
92
138
#ifdef HAVE_VTE
93
 
        { "no-terminal", 't', 0, G_OPTION_ARG_NONE, &no_vte, N_("don't load terminal support"), NULL },
94
 
        { "vte-lib", 'l', 0, G_OPTION_ARG_FILENAME, &lib_vte, N_("filename of libvte.so"), NULL },
 
139
        { "no-terminal", 't', 0, G_OPTION_ARG_NONE, &no_vte, N_("Don't load terminal support"), NULL },
 
140
        { "vte-lib", 0, 0, G_OPTION_ARG_FILENAME, &lib_vte, N_("Filename of libvte.so"), NULL },
95
141
#endif
96
 
        { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("show version and exit"), NULL },
97
 
        { "generate-data-files", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &generate_datafiles, "", NULL },
 
142
        { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("Show version and exit"), NULL },
 
143
        { "dummy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &dummy, NULL, NULL }, /* for +NNN line number arguments */
98
144
        { NULL, 0, 0, 0, NULL, NULL, NULL }
99
145
};
100
146
 
114
160
        }
115
161
}
116
162
 
 
163
 
117
164
/* special things for the initial setup of the checkboxes and related stuff
118
165
 * an action on a setting is only performed if the setting is not equal to the program default
119
166
 * (all the following code is not perfect but it works for the moment) */
121
168
{
122
169
        ui_update_fold_items();
123
170
 
124
 
        // toolbar, message window and sidebar are by default visible, so don't change it if it is true
125
 
        if (! app->toolbar_visible)
 
171
        /* toolbar, message window and sidebar are by default visible, so don't change it if it is true */
 
172
        if (! prefs.toolbar_visible)
126
173
        {
127
174
                app->ignore_callback = TRUE;
128
175
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_show_toolbar1")), FALSE);
129
176
                gtk_widget_hide(app->toolbar);
130
177
                app->ignore_callback = FALSE;
131
178
        }
132
 
        if (! app->msgwindow_visible)
 
179
        if (! ui_prefs.msgwindow_visible)
133
180
        {
134
181
                app->ignore_callback = TRUE;
135
182
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_show_messages_window1")), FALSE);
136
183
                gtk_widget_hide(lookup_widget(app->window, "scrolledwindow1"));
137
184
                app->ignore_callback = FALSE;
138
185
        }
139
 
        if (! app->sidebar_visible)
 
186
        if (! ui_prefs.sidebar_visible)
140
187
        {
141
188
                app->ignore_callback = TRUE;
142
189
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_show_sidebar1")), FALSE);
143
190
                app->ignore_callback = FALSE;
144
191
        }
145
 
        ui_treeviews_show_hide(TRUE);
146
 
        // sets the icon style of the toolbar
147
 
        switch (app->toolbar_icon_style)
 
192
        ui_sidebar_show_hide();
 
193
        /* sets the icon style of the toolbar */
 
194
        switch (prefs.toolbar_icon_style)
148
195
        {
149
196
                case GTK_TOOLBAR_BOTH:
150
197
                {
151
 
                        //gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "images_and_text1")), TRUE);
152
 
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->toolbar_menu, "images_and_text2")), TRUE);
 
198
                        /*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "images_and_text1")), TRUE);*/
 
199
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(ui_widgets.toolbar_menu, "images_and_text2")), TRUE);
153
200
                        break;
154
201
                }
155
202
                case GTK_TOOLBAR_ICONS:
156
203
                {
157
 
                        //gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "images_only1")), TRUE);
158
 
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->toolbar_menu, "images_only2")), TRUE);
 
204
                        /*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "images_only1")), TRUE);*/
 
205
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(ui_widgets.toolbar_menu, "images_only2")), TRUE);
159
206
                        break;
160
207
                }
161
208
                case GTK_TOOLBAR_TEXT:
162
209
                {
163
 
                        //gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "text_only1")), TRUE);
164
 
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->toolbar_menu, "text_only2")), TRUE);
 
210
                        /*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "text_only1")), TRUE);*/
 
211
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(ui_widgets.toolbar_menu, "text_only2")), TRUE);
165
212
                        break;
166
213
                }
167
214
        }
168
 
        gtk_toolbar_set_style(GTK_TOOLBAR(app->toolbar), app->toolbar_icon_style);
 
215
        gtk_toolbar_set_style(GTK_TOOLBAR(app->toolbar), prefs.toolbar_icon_style);
169
216
 
170
 
        // sets the icon size of the toolbar, use user preferences (.gtkrc) if not set
171
 
        if (app->toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR ||
172
 
                app->toolbar_icon_size == GTK_ICON_SIZE_LARGE_TOOLBAR)
 
217
        /* sets the icon size of the toolbar, use user preferences (.gtkrc) if not set */
 
218
        if (prefs.toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR ||
 
219
                prefs.toolbar_icon_size == GTK_ICON_SIZE_LARGE_TOOLBAR)
173
220
        {
174
 
                gtk_toolbar_set_icon_size(GTK_TOOLBAR(app->toolbar), app->toolbar_icon_size);
 
221
                gtk_toolbar_set_icon_size(GTK_TOOLBAR(app->toolbar), prefs.toolbar_icon_size);
175
222
        }
176
 
        ui_update_toolbar_icons(app->toolbar_icon_size);
 
223
        ui_update_toolbar_icons(prefs.toolbar_icon_size);
177
224
 
178
 
        // line number and markers margin are by default enabled
179
 
        if (! app->show_markers_margin)
 
225
        /* line number and markers margin are by default enabled */
 
226
        if (! editor_prefs.show_markers_margin)
180
227
        {
181
228
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_markers_margin1")), FALSE);
182
 
                app->show_markers_margin = FALSE;
 
229
                editor_prefs.show_markers_margin = FALSE;
183
230
        }
184
 
        if (! app->show_linenumber_margin)
 
231
        if (! editor_prefs.show_linenumber_margin)
185
232
        {
186
233
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_linenumber_margin1")), FALSE);
187
 
                app->show_linenumber_margin = FALSE;
188
 
        }
189
 
 
190
 
        // interprets the saved window geometry
191
 
        if (app->pref_main_save_winpos && app->geometry[0] != -1)
192
 
        {
193
 
                gtk_window_move(GTK_WINDOW(app->window), app->geometry[0], app->geometry[1]);
194
 
                gtk_window_set_default_size(GTK_WINDOW(app->window), app->geometry[2], app->geometry[3]);
 
234
                editor_prefs.show_linenumber_margin = FALSE;
 
235
        }
 
236
 
 
237
        /* interprets the saved window geometry */
 
238
        if (prefs.save_winpos && ui_prefs.geometry[0] != -1)
 
239
        {
 
240
                gtk_window_move(GTK_WINDOW(app->window), ui_prefs.geometry[0], ui_prefs.geometry[1]);
 
241
                gtk_window_set_default_size(GTK_WINDOW(app->window), ui_prefs.geometry[2], ui_prefs.geometry[3]);
 
242
                if (ui_prefs.geometry[4] == 1)
 
243
                        gtk_window_maximize(GTK_WINDOW(app->window));
 
244
        }
 
245
 
 
246
        /* hide statusbar if desired */
 
247
        if (! prefs.statusbar_visible)
 
248
        {
 
249
                gtk_widget_hide(app->statusbar);
195
250
        }
196
251
 
197
252
        app->ignore_callback = TRUE;
198
253
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
199
 
                                lookup_widget(app->window, "menu_line_breaking1")), app->pref_editor_line_breaking);
 
254
                                lookup_widget(app->window, "menu_line_breaking1")), editor_prefs.line_wrapping);
200
255
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
201
 
                                lookup_widget(app->window, "menu_use_auto_indention1")), app->pref_editor_use_auto_indention);
 
256
                                lookup_widget(app->window, "menu_use_auto_indentation1")),
 
257
                                (editor_prefs.indent_mode != INDENT_NONE));
202
258
        app->ignore_callback = FALSE;
203
259
 
 
260
        /* connect the toolbar dropdown menu for the new button */
204
261
        gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(
205
 
                        lookup_widget(app->window, "menutoolbutton1")), app->new_file_menu);
 
262
                        lookup_widget(app->window, "menutoolbutton1")), ui_widgets.new_file_menu);
206
263
 
207
 
        // set the tab placements of the notebooks
208
 
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->notebook), app->tab_pos_editor);
209
 
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), app->tab_pos_msgwin);
210
 
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->treeview_notebook), app->tab_pos_sidebar);
 
264
        /* set the tab placements of the notebooks */
 
265
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->notebook), prefs.tab_pos_editor);
 
266
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), prefs.tab_pos_msgwin);
 
267
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->treeview_notebook), prefs.tab_pos_sidebar);
211
268
 
212
269
        ui_update_toolbar_items();
 
270
 
 
271
        /* whether to show notebook tabs or not */
 
272
        gtk_notebook_set_show_tabs(GTK_NOTEBOOK(app->notebook), prefs.show_notebook_tabs);
213
273
}
214
274
 
215
275
 
216
276
static void main_init(void)
217
277
{
218
 
        // inits
 
278
        /* inits */
219
279
        app->window                             = NULL;
220
 
        app->open_fontsel               = NULL;
221
 
        app->open_colorsel              = NULL;
222
 
        app->open_filesel               = NULL;
223
 
        app->save_filesel               = NULL;
224
 
        app->prefs_dialog               = NULL;
225
 
        app->default_tag_tree   = NULL;
226
 
        app->main_window_realized= FALSE;
227
 
        app->tab_order_ltr              = FALSE;
228
 
        app->quitting                   = FALSE;
 
280
        app->project                    = NULL;
 
281
        ui_widgets.open_fontsel         = NULL;
 
282
        ui_widgets.open_colorsel        = NULL;
 
283
        ui_widgets.open_filesel         = NULL;
 
284
        ui_widgets.save_filesel         = NULL;
 
285
        ui_widgets.prefs_dialog         = NULL;
 
286
        tv.default_tag_tree     = NULL;
 
287
        main_status.main_window_realized= FALSE;
 
288
        prefs.tab_order_ltr             = FALSE;
 
289
        main_status.quitting                    = FALSE;
229
290
        app->ignore_callback    = FALSE;
230
 
        app->tm_workspace                               = tm_get_workspace();
231
 
        app->recent_queue                               = g_queue_new();
232
 
        app->opening_session_files              = FALSE;
233
 
        html_entities                                   = NULL;
 
291
        app->tm_workspace               = tm_get_workspace();
 
292
        ui_prefs.recent_queue                           = g_queue_new();
 
293
        main_status.opening_session_files               = FALSE;
234
294
 
235
295
        app->window = create_window1();
236
 
        app->new_file_menu = gtk_menu_new();
 
296
        ui_widgets.new_file_menu = gtk_menu_new();
 
297
        ui_widgets.recent_files_toolbar = gtk_menu_new();
 
298
        ui_widgets.recent_files_menuitem = lookup_widget(app->window, "recent_files1");
 
299
        ui_widgets.recent_files_menubar = gtk_menu_new();
 
300
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(ui_widgets.recent_files_menuitem),
 
301
                                                        ui_widgets.recent_files_menubar);
237
302
 
238
 
        // store important pointers in the MyApp structure
 
303
        /* store important pointers for later reference */
239
304
        app->toolbar = lookup_widget(app->window, "toolbar1");
240
 
        app->tagbar = lookup_widget(app->window, "scrolledwindow2");
241
305
        app->treeview_notebook = lookup_widget(app->window, "notebook3");
242
306
        app->notebook = lookup_widget(app->window, "notebook1");
243
307
        app->statusbar = lookup_widget(app->window, "statusbar");
244
308
        app->popup_menu = create_edit_menu1();
245
 
        app->toolbar_menu = create_toolbar_popup_menu1();
246
 
        app->compile_button = lookup_widget(app->window, "toolbutton13");
247
 
        app->run_button = lookup_widget(app->window, "toolbutton26");
248
 
        app->popup_goto_items[0] = lookup_widget(app->popup_menu, "goto_tag_definition1");
249
 
        app->popup_goto_items[1] = lookup_widget(app->popup_menu, "goto_tag_declaration1");
250
 
        app->popup_goto_items[2] = lookup_widget(app->popup_menu, "find_usage1");
251
 
        app->popup_items[0] = lookup_widget(app->popup_menu, "cut1");
252
 
        app->popup_items[1] = lookup_widget(app->popup_menu, "copy1");
253
 
        app->popup_items[2] = lookup_widget(app->popup_menu, "delete1");
254
 
        app->popup_items[3] = lookup_widget(app->popup_menu, "to_lower_case1");
255
 
        app->popup_items[4] = lookup_widget(app->popup_menu, "to_upper_case1");
256
 
        app->menu_copy_items[0] = lookup_widget(app->window, "menu_cut1");
257
 
        app->menu_copy_items[1] = lookup_widget(app->window, "menu_copy1");
258
 
        app->menu_copy_items[2] = lookup_widget(app->window, "menu_delete1");
259
 
        app->menu_copy_items[3] = lookup_widget(app->window, "menu_to_lower_case2");
260
 
        app->menu_copy_items[4] = lookup_widget(app->window, "menu_to_upper_case2");
261
 
        app->menu_insert_include_item[0] = lookup_widget(app->popup_menu, "insert_include1");
262
 
        app->menu_insert_include_item[1] = lookup_widget(app->window, "insert_include2");
263
 
        app->save_buttons[0] = lookup_widget(app->window, "menu_save1");
264
 
        app->save_buttons[1] = lookup_widget(app->window, "toolbutton10");
265
 
        app->save_buttons[2] = lookup_widget(app->window, "menu_save_all1");
266
 
        app->save_buttons[3] = lookup_widget(app->window, "toolbutton22");
267
 
        app->sensitive_buttons[0] = lookup_widget(app->window, "menu_close1");
268
 
        app->sensitive_buttons[1] = lookup_widget(app->window, "toolbutton15");
269
 
        app->sensitive_buttons[2] = lookup_widget(app->window, "menu_change_font1");
270
 
        app->sensitive_buttons[3] = lookup_widget(app->window, "entry1");
271
 
        app->sensitive_buttons[4] = lookup_widget(app->window, "toolbutton18");
272
 
        app->sensitive_buttons[5] = lookup_widget(app->window, "toolbutton20");
273
 
        app->sensitive_buttons[6] = lookup_widget(app->window, "toolbutton21");
274
 
        app->sensitive_buttons[7] = lookup_widget(app->window, "menu_close_all1");
275
 
        app->sensitive_buttons[8] = lookup_widget(app->window, "menu_save_all1");
276
 
        app->sensitive_buttons[9] = lookup_widget(app->window, "toolbutton22");
277
 
        app->sensitive_buttons[10] = app->compile_button;
278
 
        app->sensitive_buttons[11] = lookup_widget(app->window, "menu_save_as1");
279
 
        app->sensitive_buttons[12] = lookup_widget(app->window, "toolbutton23");
280
 
        app->sensitive_buttons[13] = lookup_widget(app->window, "menu_count_words1");
281
 
        app->sensitive_buttons[14] = lookup_widget(app->window, "menu_build1");
282
 
        app->sensitive_buttons[15] = lookup_widget(app->window, "add_comments1");
283
 
        app->sensitive_buttons[16] = lookup_widget(app->window, "search1");
284
 
        app->sensitive_buttons[17] = lookup_widget(app->window, "menu_paste1");
285
 
        app->sensitive_buttons[18] = lookup_widget(app->window, "menu_undo2");
286
 
        app->sensitive_buttons[19] = lookup_widget(app->window, "preferences2");
287
 
        app->sensitive_buttons[20] = lookup_widget(app->window, "menu_reload1");
288
 
        app->sensitive_buttons[21] = lookup_widget(app->window, "menu_item4");
289
 
        app->sensitive_buttons[22] = lookup_widget(app->window, "menu_markers_margin1");
290
 
        app->sensitive_buttons[23] = lookup_widget(app->window, "menu_linenumber_margin1");
291
 
        app->sensitive_buttons[24] = lookup_widget(app->window, "menu_choose_color1");
292
 
        app->sensitive_buttons[25] = lookup_widget(app->window, "menu_zoom_in1");
293
 
        app->sensitive_buttons[26] = lookup_widget(app->window, "menu_zoom_out1");
294
 
        app->sensitive_buttons[27] = lookup_widget(app->window, "normal_size1");
295
 
        app->sensitive_buttons[28] = lookup_widget(app->window, "toolbutton24");
296
 
        app->sensitive_buttons[29] = lookup_widget(app->window, "toolbutton25");
297
 
        app->sensitive_buttons[30] = lookup_widget(app->window, "entry_goto_line");
298
 
        app->sensitive_buttons[31] = lookup_widget(app->window, "treeview6");
299
 
        app->sensitive_buttons[32] = lookup_widget(app->window, "print1");
300
 
        app->sensitive_buttons[33] = lookup_widget(app->window, "menu_reload_as1");
301
 
        app->sensitive_buttons[34] = lookup_widget(app->window, "menu_select_all1");
302
 
        app->sensitive_buttons[35] = lookup_widget(app->window, "insert_date1");
303
 
        app->sensitive_buttons[36] = lookup_widget(app->window, "menu_format1");
304
 
        app->redo_items[0] = lookup_widget(app->popup_menu, "redo1");
305
 
        app->redo_items[1] = lookup_widget(app->window, "menu_redo2");
306
 
        app->redo_items[2] = lookup_widget(app->window, "toolbutton_redo");
307
 
        app->undo_items[0] = lookup_widget(app->popup_menu, "undo1");
308
 
        app->undo_items[1] = lookup_widget(app->window, "menu_undo2");
309
 
        app->undo_items[2] = lookup_widget(app->window, "toolbutton_undo");
310
 
 
311
 
        msgwin_init();
312
 
        search_init();
 
309
        ui_widgets.toolbar_menu = create_toolbar_popup_menu1();
 
310
        ui_widgets.print_page_setup = lookup_widget(app->window, "page_setup1");
 
311
        ui_widgets.popup_goto_items[0] = lookup_widget(app->popup_menu, "goto_tag_definition1");
 
312
        ui_widgets.popup_goto_items[1] = lookup_widget(app->popup_menu, "goto_tag_declaration1");
 
313
        ui_widgets.popup_goto_items[2] = lookup_widget(app->popup_menu, "find_usage1");
 
314
        ui_widgets.popup_copy_items[0] = lookup_widget(app->popup_menu, "cut1");
 
315
        ui_widgets.popup_copy_items[1] = lookup_widget(app->popup_menu, "copy1");
 
316
        ui_widgets.popup_copy_items[2] = lookup_widget(app->popup_menu, "delete1");
 
317
        ui_widgets.menu_copy_items[0] = lookup_widget(app->window, "menu_cut1");
 
318
        ui_widgets.menu_copy_items[1] = lookup_widget(app->window, "menu_copy1");
 
319
        ui_widgets.menu_copy_items[2] = lookup_widget(app->window, "menu_delete1");
 
320
        ui_widgets.menu_insert_include_items[0] = lookup_widget(app->popup_menu, "insert_include1");
 
321
        ui_widgets.menu_insert_include_items[1] = lookup_widget(app->window, "insert_include2");
 
322
        ui_widgets.save_buttons[0] = lookup_widget(app->window, "menu_save1");
 
323
        ui_widgets.save_buttons[1] = lookup_widget(app->window, "toolbutton10");
 
324
        ui_widgets.save_buttons[2] = lookup_widget(app->window, "menu_save_all1");
 
325
        ui_widgets.save_buttons[3] = lookup_widget(app->window, "toolbutton22");
 
326
        ui_widgets.redo_items[0] = lookup_widget(app->popup_menu, "redo1");
 
327
        ui_widgets.redo_items[1] = lookup_widget(app->window, "menu_redo2");
 
328
        ui_widgets.redo_items[2] = lookup_widget(app->window, "toolbutton_redo");
 
329
        ui_widgets.undo_items[0] = lookup_widget(app->popup_menu, "undo1");
 
330
        ui_widgets.undo_items[1] = lookup_widget(app->window, "menu_undo2");
 
331
        ui_widgets.undo_items[2] = lookup_widget(app->window, "toolbutton_undo");
 
332
 
 
333
        ui_init();
 
334
 
 
335
        /* set widget names for matching with .gtkrc-2.0 */
 
336
        gtk_widget_set_name(app->window, "GeanyMainWindow");
 
337
        gtk_widget_set_name(ui_widgets.toolbar_menu, "GeanyToolbarMenu");
 
338
        gtk_widget_set_name(app->popup_menu, "GeanyEditMenu");
 
339
 
 
340
#if ! GTK_CHECK_VERSION(2, 10, 0)
 
341
        /* hide Page setup menu item, it isn't supported with non-GTK printing */
 
342
        gtk_widget_hide(ui_widgets.print_page_setup);
 
343
#endif
 
344
 
313
345
}
314
346
 
315
347
 
323
355
                result = g_strdup(filename);
324
356
        else
325
357
        {
326
 
                //use current dir
 
358
                /* use current dir */
327
359
                gchar *cur_dir = g_get_current_dir();
 
360
 
328
361
                result = g_strjoin(
329
362
                        G_DIR_SEPARATOR_S, cur_dir, filename, NULL);
330
363
                g_free(cur_dir);
333
366
}
334
367
 
335
368
 
336
 
static void setup_paths()
 
369
/* get a :line:column specifier from the end of a filename (if present),
 
370
 * return the line/column values, and remove the specifier from the string
 
371
 * (Note that *line and *column must both be set to -1 initially) */
 
372
static void get_line_and_column_from_filename(gchar *filename, gint *line, gint *column)
 
373
{
 
374
        gsize i;
 
375
        gint colon_count = 0;
 
376
        gboolean have_number = FALSE;
 
377
        gsize len;
 
378
 
 
379
        g_assert(*line == -1 && *column == -1);
 
380
 
 
381
        if (! NZV(filename))
 
382
                return;
 
383
 
 
384
        len = strlen(filename);
 
385
        for (i = len - 1; i >= 1; i--)
 
386
        {
 
387
                gboolean is_colon = filename[i] == ':';
 
388
                gboolean is_digit = g_ascii_isdigit(filename[i]);
 
389
 
 
390
                if (! is_colon && ! is_digit)
 
391
                        break;
 
392
 
 
393
                if (is_colon)
 
394
                {
 
395
                        if (++colon_count > 1)
 
396
                                break;  /* bail on 2+ colons in a row */
 
397
                }
 
398
                else
 
399
                        colon_count = 0;
 
400
 
 
401
                if (is_digit)
 
402
                        have_number = TRUE;
 
403
 
 
404
                if (is_colon && have_number)
 
405
                {
 
406
                        gint number = atoi(&filename[i + 1]);
 
407
 
 
408
                        filename[i] = '\0';
 
409
                        have_number = FALSE;
 
410
 
 
411
                        *column = *line;
 
412
                        *line = number;
 
413
                }
 
414
 
 
415
                if (*column >= 0)
 
416
                        break;  /* line and column are set, so we're done */
 
417
        }
 
418
}
 
419
 
 
420
 
 
421
static void setup_paths(void)
337
422
{
338
423
        gchar *data_dir;
339
424
        gchar *doc_dir;
340
425
 
341
 
        // set paths
 
426
        /* set paths */
342
427
#ifdef G_OS_WIN32
343
 
        // take the installation directory(the one where geany.exe is located) as the base for the
344
 
        // language catalogs, documentation and data files
 
428
        /* use the installation directory(the one where geany.exe is located) as the base for the
 
429
         * documentation and data files */
345
430
        gchar *install_dir = g_win32_get_package_installation_directory("geany", NULL);
346
431
 
347
 
        data_dir = g_strconcat(install_dir, "\\data", NULL); // e.g. C:\Program Files\geany\data
 
432
        data_dir = g_strconcat(install_dir, "\\data", NULL); /* e.g. C:\Program Files\geany\data */
348
433
        doc_dir = g_strconcat(install_dir, "\\doc", NULL);
349
434
 
350
435
        g_free(install_dir);
351
436
#else
352
 
        data_dir = g_strdup(PACKAGE_DATA_DIR "/" PACKAGE "/"); // e.g. /usr/share/geany
353
 
        doc_dir = g_strdup(PACKAGE_DATA_DIR "/doc/" PACKAGE "/html/");
 
437
        data_dir = g_strconcat(GEANY_DATADIR, "/geany/", NULL); /* e.g. /usr/share/geany */
 
438
        doc_dir = g_strconcat(GEANY_DOCDIR, "/html/", NULL);
354
439
#endif
355
440
 
356
 
        app->datadir = data_dir;
357
 
        app->docdir = doc_dir;
 
441
        /* convert path names to locale encoding */
 
442
        app->datadir = utils_get_locale_from_utf8(data_dir);
 
443
        app->docdir = utils_get_locale_from_utf8(doc_dir);
 
444
 
 
445
        g_free(data_dir);
 
446
        g_free(doc_dir);
358
447
}
359
448
 
360
449
 
361
 
static void locale_init()
 
450
static void locale_init(void)
362
451
{
 
452
#ifdef ENABLE_NLS
363
453
        gchar *locale_dir = NULL;
364
454
 
 
455
#if HAVE_LOCALE_H
 
456
        setlocale(LC_ALL, "");
 
457
#endif
 
458
 
365
459
#ifdef G_OS_WIN32
366
 
        locale_dir = g_strdup(app->datadir);
 
460
        gchar *install_dir = g_win32_get_package_installation_directory("geany", NULL);
 
461
        /* e.g. C:\Program Files\geany\lib\locale */
 
462
        locale_dir = g_strconcat(install_dir, "\\lib\\locale", NULL);
 
463
        g_free(install_dir);
367
464
#else
368
 
        locale_dir = g_strdup(PACKAGE_LOCALE_DIR);
 
465
        locale_dir = g_strdup(GEANY_LOCALEDIR);
369
466
#endif
370
467
 
371
 
#ifdef ENABLE_NLS
372
468
        bindtextdomain(GETTEXT_PACKAGE, locale_dir);
373
469
        bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
374
470
        textdomain(GETTEXT_PACKAGE);
375
 
#endif
376
471
        g_free(locale_dir);
 
472
#endif
377
473
}
378
474
 
379
475
 
380
476
static void parse_command_line_options(gint *argc, gchar ***argv)
381
477
{
 
478
        GError *error = NULL;
382
479
        GOptionContext *context;
383
 
        GError *error = NULL;
 
480
        gint i;
384
481
 
385
 
        // first initialise cl_options fields with default values
 
482
        /* first initialise cl_options fields with default values */
386
483
        cl_options.load_session = TRUE;
387
 
 
388
 
        context = g_option_context_new(_(" - A fast and lightweight IDE"));
 
484
        cl_options.goto_line = -1;
 
485
        cl_options.goto_column = -1;
 
486
 
 
487
        /* the GLib option parser can't handle the +NNN (line number) option,
 
488
         * so we grab that here and replace it with a no-op */
 
489
        for (i = 1; i < (*argc); i++)
 
490
        {
 
491
                if ((*argv)[i][0] != '+')
 
492
                        continue;
 
493
 
 
494
                cl_options.goto_line = atoi((*argv)[i] + 1);
 
495
                (*argv)[i] = "--dummy";
 
496
        }
 
497
 
 
498
        context = g_option_context_new(_("[FILES...]"));
389
499
        g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
390
500
        g_option_group_set_translation_domain(g_option_context_get_main_group(context), GETTEXT_PACKAGE);
391
 
        g_option_context_add_group(context, gtk_get_option_group(TRUE));
 
501
        g_option_context_add_group(context, gtk_get_option_group(FALSE));
392
502
        g_option_context_parse(context, argc, argv, &error);
393
503
        g_option_context_free(context);
394
504
 
 
505
        if (error != NULL)
 
506
        {
 
507
                g_printerr("Geany: %s\n", error->message);
 
508
                g_error_free(error);
 
509
                exit(1);
 
510
        }
 
511
 
395
512
        if (show_version)
396
513
        {
397
514
                printf(PACKAGE " " VERSION " ");
403
520
                exit(0);
404
521
        }
405
522
 
 
523
        if (print_prefix)
 
524
        {
 
525
                printf("%s\n", GEANY_PREFIX);
 
526
                printf("%s\n", GEANY_DATADIR);
 
527
                printf("%s\n", GEANY_LIBDIR);
 
528
                printf("%s\n", GEANY_LOCALEDIR);
 
529
                exit(0);
 
530
        }
 
531
 
 
532
#ifdef GEANY_DEBUG
 
533
        app->debug_mode = TRUE;
 
534
        geany_debug("debug mode built in (can't be disabled)");
 
535
#else
406
536
        app->debug_mode = debug_mode;
407
 
#ifdef GEANY_DEBUG
408
 
        geany_debug("debug mode built in (can't be disabled)");
409
 
#endif
410
 
        geany_debug("GTK+ runtime version: %u.%u.%u",
411
 
                gtk_major_version, gtk_minor_version, gtk_micro_version);
 
537
#endif
 
538
 
 
539
#ifdef G_OS_WIN32
 
540
        win32_init_debug_code();
 
541
#endif
412
542
 
413
543
        if (alternate_config)
414
544
        {
416
546
                app->configdir = alternate_config;
417
547
        }
418
548
        else
419
 
                app->configdir = g_strconcat(GEANY_HOME_DIR, G_DIR_SEPARATOR_S, ".", PACKAGE, NULL);
 
549
        {
 
550
#ifdef G_OS_WIN32
 
551
                gchar *appdata;
 
552
 
 
553
                appdata = win32_get_appdata_folder();
 
554
                if (appdata != NULL)
 
555
                {
 
556
                        app->configdir = g_strconcat(appdata, G_DIR_SEPARATOR_S, "Geany", NULL);
 
557
                        g_free(appdata);
 
558
                }
 
559
                else
 
560
                {
 
561
                        app->configdir = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, "Geany", NULL);
 
562
                }
 
563
#else
 
564
                app->configdir = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, ".geany", NULL);
 
565
#endif
 
566
        }
 
567
 
 
568
#ifdef GEANY_DEBUG
 
569
        if (generate_datafiles)
 
570
        {
 
571
                filetypes_init_types();
 
572
                configuration_generate_data_files();    /* currently only filetype_extensions.conf */
 
573
                exit(0);
 
574
        }
 
575
#endif
 
576
        if (generate_tags)
 
577
        {
 
578
                gboolean ret;
 
579
 
 
580
                filetypes_init_types();
 
581
                configuration_read_filetype_extensions();       /* needed for *.lang.tags filetype matching */
 
582
                ret = symbols_generate_global_tags(*argc, *argv, ! no_preprocessing);
 
583
                exit(ret);
 
584
        }
 
585
 
 
586
        if (ft_names)
 
587
        {
 
588
                printf("Geany's internal filetype names:\n");
 
589
                filetypes_init_types();
 
590
                for (i = 0; i < GEANY_MAX_FILE_TYPES; i++)
 
591
                {
 
592
                        printf("%s\n", filetypes[i]->name);
 
593
                }
 
594
                filetypes_free_types();
 
595
                exit(0);
 
596
        }
420
597
 
421
598
#ifdef HAVE_SOCKET
422
599
        socket_info.ignore_socket = ignore_socket;
 
600
        if (ignore_socket)
 
601
                cl_options.load_session = FALSE;
423
602
#endif
424
603
#ifdef HAVE_VTE
425
604
        vte_info.lib_vte = lib_vte;
426
605
#endif
427
 
        app->ignore_global_tags = ignore_global_tags;
 
606
        cl_options.ignore_global_tags = ignore_global_tags;
 
607
 
 
608
        if (! gtk_init_check(NULL, NULL))
 
609
        {       /* check whether we have a valid X display and exit if not */
 
610
                g_printerr("Geany: cannot open display\n");
 
611
                exit(1);
 
612
        }
428
613
}
429
614
 
430
615
 
431
 
// Returns 0 if config dir is OK.
432
 
static gint setup_config_dir()
 
616
/* Returns 0 if config dir is OK. */
 
617
static gint setup_config_dir(void)
433
618
{
434
619
        gint mkdir_result = 0;
435
 
 
436
 
        mkdir_result = utils_make_settings_dir(app->configdir, app->datadir, app->docdir);
 
620
        gchar *tmp = app->configdir;
 
621
 
 
622
        /* convert configdir to locale encoding to avoid troubles */
 
623
        app->configdir = utils_get_locale_from_utf8(app->configdir);
 
624
        g_free(tmp);
 
625
 
 
626
        mkdir_result = utils_make_settings_dir();
437
627
        if (mkdir_result != 0)
438
628
        {
439
629
                if (! dialogs_show_question(
457
647
}
458
648
 
459
649
 
 
650
static void handle_cl_filename(gchar *const filename)
 
651
{
 
652
        gint idx;
 
653
 
 
654
        if (filename != NULL)
 
655
        {
 
656
                gint line = -1, column = -1;
 
657
 
 
658
                get_line_and_column_from_filename(filename, &line, &column);
 
659
                if (line >= 0)
 
660
                        cl_options.goto_line = line;
 
661
                if (column >= 0)
 
662
                        cl_options.goto_column = column;
 
663
        }
 
664
 
 
665
        if (filename != NULL &&
 
666
                g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
 
667
        {
 
668
                idx = document_open_file(filename, FALSE, NULL, NULL);
 
669
                /* add recent file manually because opening_session_files is set */
 
670
                if (DOC_IDX_VALID(idx))
 
671
                        ui_add_recent_file(doc_list[idx].file_name);
 
672
        }
 
673
        else if (filename != NULL)
 
674
        {       /* create new file if it doesn't exist */
 
675
                idx = document_new_file(filename, NULL, NULL);
 
676
                if (DOC_IDX_VALID(idx))
 
677
                {
 
678
                        ui_add_recent_file(doc_list[idx].file_name);
 
679
                }
 
680
        }
 
681
        else
 
682
        {
 
683
                const gchar *msg = _("Could not find file '%s'.");
 
684
 
 
685
                g_printerr(msg, filename);      /* also print to the terminal */
 
686
                g_printerr("\n");
 
687
                ui_set_statusbar(TRUE, msg, filename);
 
688
        }
 
689
}
 
690
 
 
691
 
 
692
/* open files from command line */
 
693
static gboolean open_cl_files(gint argc, gchar **argv)
 
694
{
 
695
        gint i;
 
696
 
 
697
        if (argc <= 1) return FALSE;
 
698
 
 
699
        document_delay_colourise();
 
700
 
 
701
        for (i = 1; i < argc; i++)
 
702
        {
 
703
                gchar *filename = get_argv_filename(argv[i]);
 
704
 
 
705
                handle_cl_filename(filename);
 
706
                g_free(filename);
 
707
        }
 
708
        document_colourise_new();
 
709
        return TRUE;
 
710
}
 
711
 
 
712
 
 
713
static void load_project_file(void)
 
714
{
 
715
        gchar *locale_filename;
 
716
 
 
717
        g_return_if_fail(project_prefs.session_file != NULL);
 
718
 
 
719
        locale_filename = utils_get_locale_from_utf8(project_prefs.session_file);
 
720
 
 
721
        if (*locale_filename)
 
722
                project_load_file(locale_filename);
 
723
 
 
724
        g_free(locale_filename);
 
725
        g_free(project_prefs.session_file);     /* no longer needed */
 
726
}
 
727
 
 
728
 
 
729
static void load_settings(void)
 
730
{
 
731
        configuration_load();
 
732
        /* let cmdline options overwrite configuration settings */
 
733
#ifdef HAVE_VTE
 
734
        vte_info.have_vte = (no_vte) ? FALSE : vte_info.load_vte;
 
735
#endif
 
736
        if (no_msgwin) ui_prefs.msgwindow_visible = FALSE;
 
737
 
 
738
#ifdef HAVE_PLUGINS
 
739
        want_plugins = prefs.load_plugins && !no_plugins;
 
740
#endif
 
741
}
 
742
 
 
743
 
460
744
gint main(gint argc, gchar **argv)
461
745
{
462
746
        gint idx;
463
747
        gint config_dir_result;
464
748
 
465
 
        app = g_new0(MyApp, 1);
 
749
        app = g_new0(GeanyApp, 1);
 
750
        memset(&main_status, 0, sizeof(GeanyStatus));
 
751
        memset(&prefs, 0, sizeof(GeanyPrefs));
 
752
        memset(&ui_prefs, 0, sizeof(UIPrefs));
 
753
        memset(&ui_widgets, 0, sizeof(UIWidgets));
466
754
 
467
755
        setup_paths();
468
756
        locale_init();
469
757
        parse_command_line_options(&argc, &argv);
470
758
 
471
 
        gtk_set_locale();
472
 
 
473
759
        signal(SIGTERM, signal_cb);
474
760
#ifdef G_OS_UNIX
 
761
        /* SIGQUIT is used to kill spawned children and we get also this signal, so ignore */
 
762
        signal(SIGQUIT, SIG_IGN);
475
763
        /* ignore SIGPIPE signal for preventing sudden death of program */
476
764
        signal(SIGPIPE, SIG_IGN);
477
765
#endif
478
766
 
479
767
        config_dir_result = setup_config_dir();
480
768
#ifdef HAVE_SOCKET
481
 
    // check and create (unix domain) socket for remote operation
 
769
    /* check and create (unix domain) socket for remote operation */
482
770
        if (! socket_info.ignore_socket)
483
771
        {
484
772
                socket_info.lock_socket = -1;
485
773
                socket_info.lock_socket_tag = 0;
486
774
                socket_info.lock_socket = socket_init(argc, argv);
487
 
                if (socket_info.lock_socket < 0)
 
775
                if (socket_info.lock_socket == -2)
488
776
                {
489
 
                        // Socket exists
490
 
                        if (argc > 1)   // filenames were sent to first instance, so quit
 
777
                        /* Socket exists */
 
778
                        if (argc > 1)   /* filenames were sent to first instance, so quit */
491
779
                        {
492
780
                                g_free(app->configdir);
493
781
                                g_free(app->datadir);
495
783
                                g_free(app);
496
784
                                return 0;
497
785
                        }
498
 
                        // Start a new instance if no command line strings were passed
 
786
                        /* Start a new instance if no command line strings were passed */
499
787
                        socket_info.ignore_socket = TRUE;
500
788
                        cl_options.load_session = FALSE;
501
789
                }
502
790
        }
503
791
#endif
504
792
 
505
 
        gtk_init(&argc, &argv);
 
793
        geany_debug("Geany %s, GTK+ %u.%u.%u, GLib %u.%u.%u",
 
794
                VERSION,
 
795
                gtk_major_version, gtk_minor_version, gtk_micro_version,
 
796
                glib_major_version, glib_minor_version, glib_micro_version);
506
797
 
507
 
        // inits
 
798
        /* inits */
508
799
        main_init();
509
800
        gtk_widget_set_size_request(app->window, GEANY_WINDOW_MINIMAL_WIDTH, GEANY_WINDOW_MINIMAL_HEIGHT);
510
801
        gtk_window_set_default_size(GTK_WINDOW(app->window), GEANY_WINDOW_DEFAULT_WIDTH, GEANY_WINDOW_DEFAULT_HEIGHT);
511
802
        encodings_init();
512
803
 
513
 
        configuration_load();
514
 
        // do this here to let cmdline options overwrite configuration settings
515
 
#ifdef HAVE_VTE
516
 
        vte_info.have_vte = (no_vte) ? FALSE : vte_info.load_vte;
517
 
#endif
518
 
        if (no_msgwin) app->msgwindow_visible = FALSE;
 
804
        load_settings();
519
805
 
 
806
        msgwin_init();
 
807
        build_init();
 
808
        search_init();
520
809
        ui_create_insert_menu_items();
521
810
        ui_create_insert_date_menu_items();
522
811
        keybindings_init();
 
812
        tools_create_insert_custom_command_menu_items();
523
813
        notebook_init();
 
814
        filetypes_init();
524
815
        templates_init();
 
816
        navqueue_init();
525
817
        document_init_doclist();
526
 
        filetypes_init_types();
527
 
        if (generate_datafiles)
528
 
        {
529
 
                configuration_generate_data_files();
530
 
                exit(0);
531
 
        }
 
818
        treeviews_init();
532
819
        configuration_read_filetype_extensions();
533
 
 
534
 
        gtk_window_set_icon(GTK_WINDOW(app->window), ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE));
535
 
 
536
 
        // registering some basic events
 
820
        configuration_read_snippets();
 
821
 
 
822
        /* set window icon */
 
823
        {
 
824
                GdkPixbuf *pb;
 
825
 
 
826
                pb = ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE);
 
827
                gtk_window_set_icon(GTK_WINDOW(app->window), pb);
 
828
                g_object_unref(pb);     /* free our reference */
 
829
        }
 
830
 
 
831
        /* registering some basic events */
537
832
        g_signal_connect(G_OBJECT(app->window), "delete_event", G_CALLBACK(on_exit_clicked), NULL);
538
 
        g_signal_connect(G_OBJECT(app->window), "configure-event", G_CALLBACK(on_window_configure_event), NULL);
539
 
        g_signal_connect(G_OBJECT(app->window), "key-press-event", G_CALLBACK(on_window_key_press_event), NULL);
 
833
        g_signal_connect(G_OBJECT(app->window), "key-press-event", G_CALLBACK(keybindings_got_event), NULL);
540
834
        g_signal_connect(G_OBJECT(app->toolbar), "button-press-event", G_CALLBACK(toolbar_popup_menu), NULL);
 
835
        g_signal_connect(G_OBJECT(lookup_widget(app->window, "textview_scribble")),
 
836
                                                        "motion-notify-event", G_CALLBACK(on_motion_event), NULL);
 
837
        g_signal_connect(G_OBJECT(lookup_widget(app->window, "entry1")),
 
838
                                                        "motion-notify-event", G_CALLBACK(on_motion_event), NULL);
 
839
        g_signal_connect(G_OBJECT(lookup_widget(app->window, "entry_goto_line")),
 
840
                                                        "motion-notify-event", G_CALLBACK(on_motion_event), NULL);
541
841
 
542
 
        treeviews_prepare_openfiles();
543
 
        treeviews_create_taglist_popup_menu();
544
 
        treeviews_create_openfiles_popup_menu();
545
 
        msgwin_prepare_status_tree_view();
546
 
        msgwin_prepare_msg_tree_view();
547
 
        msgwin_prepare_compiler_tree_view();
548
 
        msgwindow.popup_status_menu = msgwin_create_message_popup_menu(3);
549
 
        msgwindow.popup_msg_menu = msgwin_create_message_popup_menu(4);
550
 
        msgwindow.popup_compiler_menu = msgwin_create_message_popup_menu(5);
551
842
#ifdef HAVE_VTE
552
843
        vte_init();
553
844
#endif
554
845
        ui_create_recent_menu();
555
846
 
556
 
        msgwin_status_add(_("This is Geany %s."), VERSION);
 
847
        ui_set_statusbar(TRUE, _("This is Geany %s."), VERSION);
557
848
        if (config_dir_result != 0)
558
 
                msgwin_status_add(_("Configuration directory could not be created (%s)."),
 
849
                ui_set_statusbar(TRUE, _("Configuration directory could not be created (%s)."),
559
850
                        g_strerror(config_dir_result));
560
851
 
561
 
        // apply all configuration options
 
852
        /* apply all configuration options */
562
853
        apply_settings();
563
854
 
564
 
        // open files from command line
565
 
        app->opening_session_files = TRUE;
566
 
        if (argc > 1)
 
855
#ifdef HAVE_PLUGINS
 
856
        /* load any enabled plugins before we open any documents */
 
857
        if (want_plugins)
 
858
                plugins_init();
 
859
#endif
 
860
 
 
861
        /* load keybinding settings after plugins have added their groups */
 
862
        keybindings_load_keyfile();
 
863
 
 
864
        /* load any command line files or session files */
 
865
        main_status.opening_session_files = TRUE;
 
866
        if (! open_cl_files(argc, argv))
567
867
        {
568
 
                gint i, opened = 0;
569
 
                for(i = 1; i < argc; i++)
 
868
                if (prefs.load_session && cl_options.load_session)
570
869
                {
571
 
                        if (argv[i] && g_file_test(argv[i], G_FILE_TEST_IS_REGULAR || G_FILE_TEST_IS_SYMLINK))
 
870
                        load_project_file();
 
871
 
 
872
                        /* load session files into tabs, as they are found in the session_files variable */
 
873
                        if (! configuration_open_files())
572
874
                        {
573
 
                                if (opened < GEANY_MAX_OPEN_FILES)
574
 
                                {
575
 
                                        gchar *filename = get_argv_filename(argv[i]);
576
 
                                        document_open_file(-1, filename, 0, FALSE, NULL, NULL);
577
 
                                        g_free(filename);
578
 
                                        opened++;
579
 
                                }
580
 
                                else
581
 
                                {
582
 
                                        dialogs_show_error(
583
 
                        _("You have opened too many files. There is a limit of %d concurrent open files."),
584
 
                        GEANY_MAX_OPEN_FILES);
585
 
                                        break;
586
 
                                }
 
875
                                ui_update_popup_copy_items(-1);
 
876
                                ui_update_popup_reundo_items(-1);
587
877
                        }
588
878
                }
589
879
        }
590
 
        else if (app->pref_main_load_session && cl_options.load_session)
591
 
        {
592
 
                if (! configuration_open_files())
593
 
                {
594
 
                        ui_update_popup_copy_items(-1);
595
 
                        ui_update_popup_reundo_items(-1);
596
 
                }
597
 
        }
598
 
        app->opening_session_files = FALSE;
599
 
 
600
 
        // open a new file if no other file was opened
601
 
        if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0) document_new_file(NULL);
602
 
 
603
 
        ui_close_buttons_toggle();
 
880
        main_status.opening_session_files = FALSE;
 
881
 
 
882
        /* open a new file if no other file was opened */
 
883
        document_new_file_if_non_open();
 
884
 
 
885
        ui_document_buttons_update();
604
886
        ui_save_buttons_toggle(FALSE);
605
887
 
606
888
        idx = document_get_cur_idx();
607
889
        gtk_widget_grab_focus(GTK_WIDGET(doc_list[idx].sci));
608
 
        gtk_tree_model_foreach(GTK_TREE_MODEL(tv.store_openfiles), treeviews_find_node, GINT_TO_POINTER(idx));
609
 
        ui_build_show_hide(idx);
610
 
        ui_update_tag_list(idx, FALSE);
611
 
 
612
 
#ifdef G_OS_WIN32
613
 
        // hide "Build" menu item, at least until it is available for Windows
614
 
        gtk_widget_hide(app->compile_button);
615
 
        {
616
 
                GtkWidget *compiler_tab;
617
 
                compiler_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(msgwindow.notebook),
618
 
                        gtk_notebook_get_nth_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_COMPILER));
619
 
                gtk_widget_set_sensitive(compiler_tab, FALSE);
620
 
        }
621
 
#endif
622
 
 
623
 
        // finally realize the window to show the user what we have done
 
890
        treeviews_select_openfiles_item(idx);
 
891
        build_menu_update(idx);
 
892
        treeviews_update_tag_list(idx, FALSE);
 
893
 
 
894
        /* finally realize the window to show the user what we have done */
624
895
        gtk_widget_show(app->window);
625
 
        app->main_window_realized = TRUE;
 
896
        main_status.main_window_realized = TRUE;
626
897
 
627
898
        configuration_apply_settings();
628
899
 
629
900
#ifdef HAVE_SOCKET
630
 
        // register the callback of socket input
 
901
        /* register the callback of socket input */
631
902
        if (! socket_info.ignore_socket && socket_info.lock_socket > 0)
632
903
        {
633
904
                socket_info.read_ioc = g_io_channel_unix_new(socket_info.lock_socket);
636
907
        }
637
908
#endif
638
909
 
639
 
        //g_timeout_add(0, (GSourceFunc)destroyapp, NULL); // useful for start time tests
 
910
        /*g_timeout_add(0, (GSourceFunc)destroyapp, NULL);*/ /* useful for start time tests*/
640
911
        gtk_main();
641
912
        return 0;
642
913
}
643
914
 
 
915
 
 
916
void main_quit()
 
917
{
 
918
        geany_debug("Quitting...");
 
919
 
 
920
#ifdef HAVE_SOCKET
 
921
        socket_finalize();
 
922
#endif
 
923
 
 
924
#ifdef HAVE_PLUGINS
 
925
        if (want_plugins)
 
926
                plugins_free();
 
927
#endif
 
928
 
 
929
        navqueue_free();
 
930
        keybindings_free();
 
931
        filetypes_save_commands();
 
932
        filetypes_free_types();
 
933
        highlighting_free_styles();
 
934
        templates_free_templates();
 
935
        msgwin_finalize();
 
936
        search_finalize();
 
937
        build_finalize();
 
938
        document_finalize();
 
939
        symbols_finalize();
 
940
        editor_finalize();
 
941
        encodings_finalize();
 
942
 
 
943
        tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
 
944
        g_free(app->configdir);
 
945
        g_free(app->datadir);
 
946
        g_free(app->docdir);
 
947
        g_free(prefs.default_open_path);
 
948
        g_free(ui_prefs.custom_date_format);
 
949
        g_free(prefs.editor_font);
 
950
        g_free(prefs.tagbar_font);
 
951
        g_free(prefs.msgwin_font);
 
952
        g_free(editor_prefs.long_line_color);
 
953
        g_free(prefs.context_action_cmd);
 
954
        g_free(prefs.template_developer);
 
955
        g_free(prefs.template_company);
 
956
        g_free(prefs.template_mail);
 
957
        g_free(prefs.template_initial);
 
958
        g_free(prefs.template_version);
 
959
        g_free(prefs.tools_make_cmd);
 
960
        g_free(prefs.tools_term_cmd);
 
961
        g_free(prefs.tools_browser_cmd);
 
962
        g_free(prefs.tools_grep_cmd);
 
963
        g_free(printing_prefs.external_print_cmd);
 
964
        g_free(printing_prefs.page_header_datefmt);
 
965
        g_strfreev(ui_prefs.custom_commands);
 
966
        while (! g_queue_is_empty(ui_prefs.recent_queue))
 
967
        {
 
968
                g_free(g_queue_pop_tail(ui_prefs.recent_queue));
 
969
        }
 
970
        g_queue_free(ui_prefs.recent_queue);
 
971
 
 
972
        if (ui_widgets.prefs_dialog && GTK_IS_WIDGET(ui_widgets.prefs_dialog)) gtk_widget_destroy(ui_widgets.prefs_dialog);
 
973
        if (ui_widgets.save_filesel && GTK_IS_WIDGET(ui_widgets.save_filesel)) gtk_widget_destroy(ui_widgets.save_filesel);
 
974
        if (ui_widgets.open_filesel && GTK_IS_WIDGET(ui_widgets.open_filesel)) gtk_widget_destroy(ui_widgets.open_filesel);
 
975
        if (ui_widgets.open_fontsel && GTK_IS_WIDGET(ui_widgets.open_fontsel)) gtk_widget_destroy(ui_widgets.open_fontsel);
 
976
        if (ui_widgets.open_colorsel && GTK_IS_WIDGET(ui_widgets.open_colorsel)) gtk_widget_destroy(ui_widgets.open_colorsel);
 
977
        if (tv.default_tag_tree && GTK_IS_WIDGET(tv.default_tag_tree))
 
978
        {
 
979
                g_object_unref(tv.default_tag_tree);
 
980
                gtk_widget_destroy(tv.default_tag_tree);
 
981
        }
 
982
#ifdef HAVE_VTE
 
983
        if (vte_info.have_vte) vte_close();
 
984
        g_free(vte_info.lib_vte);
 
985
        g_free(vte_info.dir);
 
986
#endif
 
987
        gtk_widget_destroy(app->window);
 
988
 
 
989
        /* destroy popup menus */
 
990
        if (app->popup_menu && GTK_IS_WIDGET(app->popup_menu))
 
991
                                        gtk_widget_destroy(app->popup_menu);
 
992
        if (ui_widgets.toolbar_menu && GTK_IS_WIDGET(ui_widgets.toolbar_menu))
 
993
                                        gtk_widget_destroy(ui_widgets.toolbar_menu);
 
994
        if (tv.popup_taglist && GTK_IS_WIDGET(tv.popup_taglist))
 
995
                                        gtk_widget_destroy(tv.popup_taglist);
 
996
        if (tv.popup_openfiles && GTK_IS_WIDGET(tv.popup_openfiles))
 
997
                                        gtk_widget_destroy(tv.popup_openfiles);
 
998
        if (msgwindow.popup_status_menu && GTK_IS_WIDGET(msgwindow.popup_status_menu))
 
999
                                        gtk_widget_destroy(msgwindow.popup_status_menu);
 
1000
        if (msgwindow.popup_msg_menu && GTK_IS_WIDGET(msgwindow.popup_msg_menu))
 
1001
                                        gtk_widget_destroy(msgwindow.popup_msg_menu);
 
1002
        if (msgwindow.popup_compiler_menu && GTK_IS_WIDGET(msgwindow.popup_compiler_menu))
 
1003
                                        gtk_widget_destroy(msgwindow.popup_compiler_menu);
 
1004
 
 
1005
        g_free(app);
 
1006
 
 
1007
        gtk_main_quit();
 
1008
}
 
1009
 
 
1010
 
 
1011
/* malloc compatibility code */
 
1012
#undef malloc
 
1013
void *malloc(size_t n);
 
1014
 
 
1015
/* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */
 
1016
void *rpl_malloc(size_t n)
 
1017
{
 
1018
        if (n == 0)
 
1019
                n = 1;
 
1020
        return malloc(n);
 
1021
}