From bc2fe92e07a84846843f51bd0bc5e935c0f98aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 24 Jan 2023 18:46:53 +0100 Subject: [PATCH] #46: Add open callback to GApplication --- main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index c31a426..f6f68fe 100644 --- a/main.c +++ b/main.c @@ -171,6 +171,16 @@ static void gapp_activate(GApplication *app, gpointer user_data) gtk_widget_show(GTK_WIDGET(main_window)); } +/** + * @brief Activation of GUI when opening a file from commandline + * @param app he GApplication reference + * @param user_data Used to store the individual GUI instances. + */ +static void gapp_activate_open(GApplication *app, gpointer user_data) +{ + gapp_activate(app, user_data); +} + /** * @brief Start the graphical interface. * @@ -201,10 +211,11 @@ static int start_gui(int argc, char **argv) application_domain = g_string_new(NULL); g_string_printf(application_domain, "de.shimatta.gds_render_%s", _app_git_commit); - gapp = gtk_application_new(application_domain->str, G_APPLICATION_FLAGS_NONE); + gapp = gtk_application_new(application_domain->str, G_APPLICATION_HANDLES_OPEN); g_string_free(application_domain, TRUE); g_application_register(G_APPLICATION(gapp), NULL, NULL); + g_signal_connect(gapp, "open", G_CALLBACK(gapp_activate_open), &appdata); g_signal_connect(gapp, "activate", G_CALLBACK(gapp_activate), &appdata); if (g_application_get_is_remote(G_APPLICATION(gapp)) == TRUE) { @@ -311,7 +322,8 @@ int main(int argc, char **argv) goto ret_status; } - if (argc >= 2) { + /* A minimum of a file name and a cell or analyze command are needed to use CLI */ + if (argc >= 2 && (analyze || cellname || output_paths)) { if (scale < 1) { printf(_("Scale < 1 not allowed. Setting to 1\n")); scale = 1;