78
105
static gboolean ignore_socket = FALSE;
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;
113
static gboolean no_plugins = FALSE;
115
static gboolean dummy = FALSE;
117
/* in alphabetical order of short options */
82
118
static GOptionEntry entries[] =
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 },
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 },
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 },
134
{ "no-plugins", 'p', 0, G_OPTION_ARG_NONE, &no_plugins, N_("Don't load plugins"), NULL },
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 },
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 },
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 },
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 },
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 }
122
169
ui_update_fold_items();
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)
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;
132
if (! app->msgwindow_visible)
179
if (! ui_prefs.msgwindow_visible)
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;
139
if (! app->sidebar_visible)
186
if (! ui_prefs.sidebar_visible)
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;
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)
149
196
case GTK_TOOLBAR_BOTH:
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);
155
202
case GTK_TOOLBAR_ICONS:
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);
161
208
case GTK_TOOLBAR_TEXT:
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);
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);
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)
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);
176
ui_update_toolbar_icons(app->toolbar_icon_size);
223
ui_update_toolbar_icons(prefs.toolbar_icon_size);
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)
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;
184
if (! app->show_linenumber_margin)
231
if (! editor_prefs.show_linenumber_margin)
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;
190
// interprets the saved window geometry
191
if (app->pref_main_save_winpos && app->geometry[0] != -1)
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;
237
/* interprets the saved window geometry */
238
if (prefs.save_winpos && ui_prefs.geometry[0] != -1)
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));
246
/* hide statusbar if desired */
247
if (! prefs.statusbar_visible)
249
gtk_widget_hide(app->statusbar);
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;
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);
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);
212
269
ui_update_toolbar_items();
271
/* whether to show notebook tabs or not */
272
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(app->notebook), prefs.show_notebook_tabs);
216
276
static void main_init(void)
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;
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;
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);
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");
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");
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");
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);
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)
375
gint colon_count = 0;
376
gboolean have_number = FALSE;
379
g_assert(*line == -1 && *column == -1);
384
len = strlen(filename);
385
for (i = len - 1; i >= 1; i--)
387
gboolean is_colon = filename[i] == ':';
388
gboolean is_digit = g_ascii_isdigit(filename[i]);
390
if (! is_colon && ! is_digit)
395
if (++colon_count > 1)
396
break; /* bail on 2+ colons in a row */
404
if (is_colon && have_number)
406
gint number = atoi(&filename[i + 1]);
416
break; /* line and column are set, so we're done */
421
static void setup_paths(void)
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);
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);
350
435
g_free(install_dir);
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);
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);
361
static void locale_init()
450
static void locale_init(void)
363
453
gchar *locale_dir = NULL;
456
setlocale(LC_ALL, "");
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);
368
locale_dir = g_strdup(PACKAGE_LOCALE_DIR);
465
locale_dir = g_strdup(GEANY_LOCALEDIR);
372
468
bindtextdomain(GETTEXT_PACKAGE, locale_dir);
373
469
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
374
470
textdomain(GETTEXT_PACKAGE);
376
471
g_free(locale_dir);
380
476
static void parse_command_line_options(gint *argc, gchar ***argv)
478
GError *error = NULL;
382
479
GOptionContext *context;
383
GError *error = NULL;
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;
388
context = g_option_context_new(_(" - A fast and lightweight IDE"));
484
cl_options.goto_line = -1;
485
cl_options.goto_column = -1;
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++)
491
if ((*argv)[i][0] != '+')
494
cl_options.goto_line = atoi((*argv)[i] + 1);
495
(*argv)[i] = "--dummy";
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);
507
g_printerr("Geany: %s\n", error->message);
395
512
if (show_version)
397
514
printf(PACKAGE " " VERSION " ");
650
static void handle_cl_filename(gchar *const filename)
654
if (filename != NULL)
656
gint line = -1, column = -1;
658
get_line_and_column_from_filename(filename, &line, &column);
660
cl_options.goto_line = line;
662
cl_options.goto_column = column;
665
if (filename != NULL &&
666
g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
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);
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))
678
ui_add_recent_file(doc_list[idx].file_name);
683
const gchar *msg = _("Could not find file '%s'.");
685
g_printerr(msg, filename); /* also print to the terminal */
687
ui_set_statusbar(TRUE, msg, filename);
692
/* open files from command line */
693
static gboolean open_cl_files(gint argc, gchar **argv)
697
if (argc <= 1) return FALSE;
699
document_delay_colourise();
701
for (i = 1; i < argc; i++)
703
gchar *filename = get_argv_filename(argv[i]);
705
handle_cl_filename(filename);
708
document_colourise_new();
713
static void load_project_file(void)
715
gchar *locale_filename;
717
g_return_if_fail(project_prefs.session_file != NULL);
719
locale_filename = utils_get_locale_from_utf8(project_prefs.session_file);
721
if (*locale_filename)
722
project_load_file(locale_filename);
724
g_free(locale_filename);
725
g_free(project_prefs.session_file); /* no longer needed */
729
static void load_settings(void)
731
configuration_load();
732
/* let cmdline options overwrite configuration settings */
734
vte_info.have_vte = (no_vte) ? FALSE : vte_info.load_vte;
736
if (no_msgwin) ui_prefs.msgwindow_visible = FALSE;
739
want_plugins = prefs.load_plugins && !no_plugins;
460
744
gint main(gint argc, gchar **argv)
463
747
gint config_dir_result;
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));
469
757
parse_command_line_options(&argc, &argv);
473
759
signal(SIGTERM, signal_cb);
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);
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)
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)
490
if (argc > 1) // filenames were sent to first instance, so quit
778
if (argc > 1) /* filenames were sent to first instance, so quit */
492
780
g_free(app->configdir);
493
781
g_free(app->datadir);
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;
505
gtk_init(&argc, &argv);
793
geany_debug("Geany %s, GTK+ %u.%u.%u, GLib %u.%u.%u",
795
gtk_major_version, gtk_minor_version, gtk_micro_version,
796
glib_major_version, glib_minor_version, glib_micro_version);
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();
513
configuration_load();
514
// do this here to let cmdline options overwrite configuration settings
516
vte_info.have_vte = (no_vte) ? FALSE : vte_info.load_vte;
518
if (no_msgwin) app->msgwindow_visible = FALSE;
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();
524
815
templates_init();
525
817
document_init_doclist();
526
filetypes_init_types();
527
if (generate_datafiles)
529
configuration_generate_data_files();
532
819
configuration_read_filetype_extensions();
534
gtk_window_set_icon(GTK_WINDOW(app->window), ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE));
536
// registering some basic events
820
configuration_read_snippets();
822
/* set window icon */
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 */
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);
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);
554
845
ui_create_recent_menu();
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));
561
// apply all configuration options
852
/* apply all configuration options */
562
853
apply_settings();
564
// open files from command line
565
app->opening_session_files = TRUE;
856
/* load any enabled plugins before we open any documents */
861
/* load keybinding settings after plugins have added their groups */
862
keybindings_load_keyfile();
864
/* load any command line files or session files */
865
main_status.opening_session_files = TRUE;
866
if (! open_cl_files(argc, argv))
569
for(i = 1; i < argc; i++)
868
if (prefs.load_session && cl_options.load_session)
571
if (argv[i] && g_file_test(argv[i], G_FILE_TEST_IS_REGULAR || G_FILE_TEST_IS_SYMLINK))
872
/* load session files into tabs, as they are found in the session_files variable */
873
if (! configuration_open_files())
573
if (opened < GEANY_MAX_OPEN_FILES)
575
gchar *filename = get_argv_filename(argv[i]);
576
document_open_file(-1, filename, 0, FALSE, NULL, NULL);
583
_("You have opened too many files. There is a limit of %d concurrent open files."),
584
GEANY_MAX_OPEN_FILES);
875
ui_update_popup_copy_items(-1);
876
ui_update_popup_reundo_items(-1);
590
else if (app->pref_main_load_session && cl_options.load_session)
592
if (! configuration_open_files())
594
ui_update_popup_copy_items(-1);
595
ui_update_popup_reundo_items(-1);
598
app->opening_session_files = FALSE;
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);
603
ui_close_buttons_toggle();
880
main_status.opening_session_files = FALSE;
882
/* open a new file if no other file was opened */
883
document_new_file_if_non_open();
885
ui_document_buttons_update();
604
886
ui_save_buttons_toggle(FALSE);
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);
613
// hide "Build" menu item, at least until it is available for Windows
614
gtk_widget_hide(app->compile_button);
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);
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);
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;
627
898
configuration_apply_settings();
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)
633
904
socket_info.read_ioc = g_io_channel_unix_new(socket_info.lock_socket);
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*/
918
geany_debug("Quitting...");
931
filetypes_save_commands();
932
filetypes_free_types();
933
highlighting_free_styles();
934
templates_free_templates();
941
encodings_finalize();
943
tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
944
g_free(app->configdir);
945
g_free(app->datadir);
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))
968
g_free(g_queue_pop_tail(ui_prefs.recent_queue));
970
g_queue_free(ui_prefs.recent_queue);
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))
979
g_object_unref(tv.default_tag_tree);
980
gtk_widget_destroy(tv.default_tag_tree);
983
if (vte_info.have_vte) vte_close();
984
g_free(vte_info.lib_vte);
985
g_free(vte_info.dir);
987
gtk_widget_destroy(app->window);
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);
1011
/* malloc compatibility code */
1013
void *malloc(size_t n);
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)