From 95f1b12d750510bdc079b442cf0b55ac61b78371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 13 Dec 2015 00:29:30 +0100 Subject: [PATCH] Open files session files after entering main loop This change makes the main window show immediately after launching Geany so it's immediately visible Geany started. With big files/projects this gives users better feedback about it's starting than not showing anything until all the files are ready. --- src/libmain.c | 52 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/libmain.c b/src/libmain.c index 7420d1e095..a194732db4 100644 --- a/src/libmain.c +++ b/src/libmain.c @@ -144,6 +144,12 @@ static GOptionEntry entries[] = { NULL, 0, 0, 0, NULL, NULL, NULL } }; +static struct +{ + gint argc; + gchar **argv; +} args; + static void setup_window_position(void) { @@ -1003,10 +1009,35 @@ static void setup_gtk2_styles(void) #endif +static gboolean open_documents(gpointer user_data) +{ + GeanyDocument *doc; + + /* load any command line files or session files */ + main_status.opening_session_files = TRUE; + load_startup_files(args.argc, args.argv); + main_status.opening_session_files = FALSE; + + /* open a new file if no other file was opened */ + document_new_file_if_non_open(); + + ui_document_buttons_update(); + ui_save_buttons_toggle(FALSE); + + doc = document_get_current(); + sidebar_select_openfiles_item(doc); + build_menu_update(doc); + sidebar_update_tag_list(doc, FALSE); + + document_grab_focus(doc); + + return FALSE; +} + + GEANY_EXPORT_SYMBOL gint main_lib(gint argc, gchar **argv) { - GeanyDocument *doc; gint config_dir_result; const gchar *locale; @@ -1163,21 +1194,9 @@ gint main_lib(gint argc, gchar **argv) * accelerator shown for the menu items */ tools_create_insert_custom_command_menu_items(); - /* load any command line files or session files */ - main_status.opening_session_files = TRUE; - load_startup_files(argc, argv); - main_status.opening_session_files = FALSE; - - /* open a new file if no other file was opened */ - document_new_file_if_non_open(); - - ui_document_buttons_update(); - ui_save_buttons_toggle(FALSE); - - doc = document_get_current(); - sidebar_select_openfiles_item(doc); - build_menu_update(doc); - sidebar_update_tag_list(doc, FALSE); + args.argc = argc; + args.argv = argv; + g_idle_add(open_documents, NULL); #ifdef G_OS_WIN32 /* Manually realise the main window to be able to set the position but don't show it. @@ -1187,7 +1206,6 @@ gint main_lib(gint argc, gchar **argv) setup_window_position(); /* finally show the window */ - document_grab_focus(doc); configuration_apply_settings(); gtk_widget_show(main_widgets.window); main_status.main_window_realized = TRUE;