/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2004, 2005, 2006, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation
+ Copyright (C) 2004, 2005, 2006, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
+ 2020 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <gtk/gtk.h>
#include <stdlib.h>
-#if ENABLE_RELOCATABLE && defined(__APPLE__)
#include <sys/stat.h>
+#if ENABLE_RELOCATABLE && defined(__APPLE__)
+#include <sys/resource.h>
+static const bool apple_relocatable = true;
+#else
+static const bool apple_relocatable = false;
+#if HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#else
+/* Dummy definitions to keep the compiler happy. */
+struct rlimit
+{
+ int rlim_cur;
+ int rlim_max;
+};
+#define RLIMIT_NOFILE 0
+#endif
#endif
#include "language/lexer/include-path.h"
}
}
-
static void
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);
g_option_context_set_ignore_unknown_options (oc, FALSE);
g_option_context_add_main_entries (oc, oe, NULL);
g_option_context_parse (oc, argc, argv, NULL);
+ g_option_context_free (oc);
}
-#if ENABLE_RELOCATABLE && defined(__APPLE__)
static void
pspp_macos_setenv (const char * progname)
{
}
}
}
-#endif
int
main (int argc, char *argv[])
{
-
-#if ENABLE_RELOCATABLE && defined(__APPLE__)
- /* remove MacOS session identifier from the command line args */
- gint newargc = 0;
- for (gint i = 0; i < argc; i++)
+ if (apple_relocatable)
{
- if (!g_str_has_prefix (argv[i], "-psn_"))
+ /* remove MacOS session identifier from the command line args */
+ gint newargc = 0;
+ for (gint i = 0; i < argc; i++)
{
- argv[newargc] = argv[i];
- newargc++;
+ if (!g_str_has_prefix (argv[i], "-psn_"))
+ {
+ argv[newargc] = argv[i];
+ newargc++;
+ }
}
+ if (argc > newargc)
+ {
+ argv[newargc] = NULL; /* glib expects NULL terminated array */
+ argc = newargc;
+ }
+ pspp_macos_setenv (argv[0]);
}
- if (argc > newargc)
- {
- argv[newargc] = NULL; /* glib expects NULL terminated array */
- argc = newargc;
- }
- pspp_macos_setenv (argv[0]);
-#endif
set_program_name (argv[0]);