X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fmain.c;h=51d225765c12796d21cdaf1aff7f8f02dc5a8eea;hb=51cf173b5eaaa8c5cc6233f9c8924eb44498e89d;hp=cb5519b5f3ba2e3f0e15e189a432b2ad3b49d8b2;hpb=e422096372dfa42ad6bc8b71dfe0e2aa448e6fe3;p=pspp diff --git a/src/ui/gui/main.c b/src/ui/gui/main.c index cb5519b5f3..51d225765c 100644 --- a/src/ui/gui/main.c +++ b/src/ui/gui/main.c @@ -238,7 +238,6 @@ wait_for_splash (GApplication *app, GtkWindow *x) } } - static void on_activate (GApplication * app, gpointer ud) { @@ -250,15 +249,50 @@ on_activate (GApplication * app, gpointer ud) wait_for_splash (app, x); } +GtkWindow * +find_empty_data_window (GApplication *app) +{ + GList *wl = gtk_application_get_windows (GTK_APPLICATION (app)); + while (wl) + { + if (wl->data && PSPPIRE_IS_DATA_WINDOW (GTK_WINDOW (wl->data)) && + psppire_data_window_is_empty (PSPPIRE_DATA_WINDOW (wl->data))) + return GTK_WINDOW (wl->data); + wl = wl->next; + } + return NULL; +} + +GtkWindow * +find_psppire_window (GApplication *app) +{ + GList *wl = gtk_application_get_windows (GTK_APPLICATION (app)); + while (wl) + { + if (wl->data && PSPPIRE_IS_WINDOW (GTK_WINDOW (wl->data))) + return GTK_WINDOW (wl->data); + wl = wl->next; + } + return NULL; +} static void on_open (GApplication *app, GFile **files, gint n_files, gchar * hint, gpointer ud) { - post_initialise (app); + /* If the application is already open and we open another file + via xdg-open on GNU/Linux or via the file manager, then open is + called. Check if we already have a psppire window. */ + if (find_psppire_window (app) == NULL) + post_initialise (app); + + /* When a new data file is opened, then try to find an empty + data window which will then be replaced as in the open file + dialog */ + GtkWindow *victim = find_empty_data_window (app); gchar *file = g_file_get_parse_name (files[0]); - GtkWindow *x = psppire_preload_file (file); + GtkWindow *x = psppire_preload_file (file, victim); g_free (file); wait_for_splash (app, x);