/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 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>
-#include "data/any-reader.h"
#include "data/dataset.h"
+#include "data/session.h"
#include "language/lexer/lexer.h"
#include "libpspp/message.h"
+#include "libpspp/str.h"
#include "ui/gui/aggregate-dialog.h"
-#include "ui/gui/binomial-dialog.h"
-#include "ui/gui/chi-square-dialog.h"
+#include "ui/gui/autorecode-dialog.h"
+#include "ui/gui/builder-wrapper.h"
#include "ui/gui/comments-dialog.h"
-#include "ui/gui/compute-dialog.h"
-#include "ui/gui/correlation-dialog.h"
-#include "ui/gui/crosstabs-dialog.h"
-#include "ui/gui/descriptives-dialog.h"
-#include "ui/gui/examine-dialog.h"
+#include "ui/gui/entry-dialog.h"
#include "ui/gui/executor.h"
-#include "ui/gui/factor-dialog.h"
-#include "ui/gui/find-dialog.h"
-#include "ui/gui/frequencies-dialog.h"
-#include "ui/gui/goto-case-dialog.h"
#include "ui/gui/help-menu.h"
#include "ui/gui/helper.h"
-#include "ui/gui/k-related-dialog.h"
+#include "ui/gui/helper.h"
#include "ui/gui/oneway-anova-dialog.h"
#include "ui/gui/psppire-data-window.h"
+#include "ui/gui/psppire-dialog-action.h"
#include "ui/gui/psppire-syntax-window.h"
#include "ui/gui/psppire-window.h"
#include "ui/gui/psppire.h"
-#include "ui/gui/rank-dialog.h"
#include "ui/gui/recode-dialog.h"
-#include "ui/gui/regression-dialog.h"
-#include "ui/gui/reliability-dialog.h"
-#include "ui/gui/roc-dialog.h"
#include "ui/gui/select-cases-dialog.h"
-#include "ui/gui/sort-cases-dialog.h"
#include "ui/gui/split-file-dialog.h"
-#include "ui/gui/t-test-independent-samples-dialog.h"
-#include "ui/gui/t-test-one-sample.h"
-#include "ui/gui/t-test-paired-samples.h"
#include "ui/gui/text-data-import-dialog.h"
-#include "ui/gui/transpose-dialog.h"
-#include "ui/gui/variable-info-dialog.h"
#include "ui/gui/weight-cases-dialog.h"
#include "ui/syntax-gen.h"
+#include "gl/c-strcase.h"
+#include "gl/c-strcasestr.h"
+#include "gl/xvasprintf.h"
+
#include <gettext.h>
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
-
+struct session *the_session;
+struct ll_list all_data_windows = LL_INITIALIZER (all_data_windows);
static void psppire_data_window_class_init (PsppireDataWindowClass *class);
static void psppire_data_window_init (PsppireDataWindow *data_editor);
static void psppire_data_window_iface_init (PsppireWindowIface *iface);
static void psppire_data_window_dispose (GObject *object);
+static void psppire_data_window_finalize (GObject *object);
+static void psppire_data_window_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void psppire_data_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static guint psppire_data_window_add_ui (PsppireDataWindow *, GtkUIManager *);
+static void psppire_data_window_remove_ui (PsppireDataWindow *,
+ GtkUIManager *, guint);
GType
psppire_data_window_get_type (void)
static GObjectClass *parent_class ;
+enum {
+ PROP_DATASET = 1
+};
+
static void
psppire_data_window_class_init (PsppireDataWindowClass *class)
{
parent_class = g_type_class_peek_parent (class);
object_class->dispose = psppire_data_window_dispose;
+ object_class->finalize = psppire_data_window_finalize;
+ object_class->set_property = psppire_data_window_set_property;
+ object_class->get_property = psppire_data_window_get_property;
+
+ g_object_class_install_property (
+ object_class, PROP_DATASET,
+ g_param_spec_pointer ("dataset", "Dataset",
+ "'struct datset *' represented by the window",
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
}
\f
-
-
-extern PsppireVarStore *the_var_store;
-extern struct dataset *the_dataset;
-extern PsppireDataStore *the_data_store ;
-
-extern GtkRecentManager *the_recent_mgr;
-
-static void
-set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
-{
- GtkAction *edit_paste = get_action_assert (de->builder, "edit_paste");
-
- gtk_action_set_sensitive (edit_paste, x);
-}
-
-static void
-set_cut_copy_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
-{
- GtkAction *edit_copy = get_action_assert (de->builder, "edit_copy");
- GtkAction *edit_cut = get_action_assert (de->builder, "edit_cut");
-
- gtk_action_set_sensitive (edit_copy, x);
- gtk_action_set_sensitive (edit_cut, x);
-}
-
/* Run the EXECUTE command. */
static void
execute (PsppireDataWindow *dw)
}
else
{
- PsppireVarStore *vs = NULL;
PsppireDict *dict = NULL;
struct variable *var ;
gchar *text ;
- g_object_get (de->data_editor, "var-store", &vs, NULL);
- g_object_get (vs, "dictionary", &dict, NULL);
+ g_object_get (de->data_editor, "dictionary", &dict, NULL);
var = psppire_dict_get_variable (dict, filter_index);
else
{
struct variable *var ;
- PsppireVarStore *vs = NULL;
PsppireDict *dict = NULL;
gchar *text;
- g_object_get (de->data_editor, "var-store", &vs, NULL);
- g_object_get (vs, "dictionary", &dict, NULL);
+ g_object_get (de->data_editor, "dictionary", &dict, NULL);
var = psppire_dict_get_variable (dict, weight_index);
}
#endif
-
static gboolean
-load_file (PsppireWindow *de, const gchar *file_name)
+name_has_por_suffix (const gchar *name)
{
- gchar *utf8_file_name;
- struct string filename;
- gchar *syntax;
- bool ok;
-
- ds_init_empty (&filename);
-
- utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
-
- syntax_gen_string (&filename, ss_cstr (utf8_file_name));
-
- g_free (utf8_file_name);
-
- syntax = g_strdup_printf ("GET FILE=%s.", ds_cstr (&filename));
- ds_destroy (&filename);
-
- ok = execute_syntax (PSPPIRE_DATA_WINDOW (de),
- lex_reader_for_string (syntax));
- g_free (syntax);
- return ok;
+ size_t length = strlen (name);
+ return length > 4 && !c_strcasecmp (&name[length - 4], ".por");
}
-static GtkWidget *
-sysfile_chooser_dialog (PsppireWindow *toplevel)
+static gboolean
+name_has_sav_suffix (const gchar *name)
{
- GtkWidget *dialog =
- gtk_file_chooser_dialog_new (_("Open"),
- GTK_WINDOW (toplevel),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
-
- GtkFileFilter *filter;
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Data and Syntax Files"));
- gtk_file_filter_add_pattern (filter, "*.sav");
- gtk_file_filter_add_pattern (filter, "*.SAV");
- gtk_file_filter_add_pattern (filter, "*.por");
- gtk_file_filter_add_pattern (filter, "*.POR");
- gtk_file_filter_add_pattern (filter, "*.sps");
- gtk_file_filter_add_pattern (filter, "*.SPS");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
- gtk_file_filter_add_pattern (filter, "*.sav");
- gtk_file_filter_add_pattern (filter, "*.SAV");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
- gtk_file_filter_add_pattern (filter, "*.por");
- gtk_file_filter_add_pattern (filter, "*.POR");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
- gtk_file_filter_add_pattern (filter, "*.sps");
- gtk_file_filter_add_pattern (filter, "*.SPS");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("All Files"));
- gtk_file_filter_add_pattern (filter, "*");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- {
- gchar *dir_name;
- gchar *filename = NULL;
- g_object_get (toplevel, "filename", &filename, NULL);
-
- if ( ! g_path_is_absolute (filename))
- {
- gchar *path =
- g_build_filename (g_get_current_dir (), filename, NULL);
- dir_name = g_path_get_dirname (path);
- g_free (path);
- }
- else
- {
- dir_name = g_path_get_dirname (filename);
- }
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
- dir_name);
- free (dir_name);
- }
+ size_t length = strlen (name);
+ return length > 4 && !c_strcasecmp (&name[length - 4], ".sav");
+}
- return dialog;
+/* Returns true if NAME has a suffix which might denote a PSPP file */
+static gboolean
+name_has_suffix (const gchar *name)
+{
+ return name_has_por_suffix (name) || name_has_sav_suffix (name);
}
-/* Callback for the data_open action.
- Prompts for a filename and opens it */
-static void
-open_window (PsppireWindow *de)
+static gboolean
+load_file (PsppireWindow *de, const gchar *file_name, gpointer syn)
{
- GtkWidget *dialog = sysfile_chooser_dialog (de);
+ const char *mime_type = NULL;
+ gchar *syntax = NULL;
+ bool ok;
- switch (gtk_dialog_run (GTK_DIALOG (dialog)))
+ if (syn == NULL)
{
- case GTK_RESPONSE_ACCEPT:
- {
- gchar *name =
- gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ gchar *utf8_file_name;
+ struct string filename;
+ ds_init_empty (&filename);
+
+ utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
+
+ syntax_gen_string (&filename, ss_cstr (utf8_file_name));
+
+ g_free (utf8_file_name);
+
+ syntax = g_strdup_printf ("GET FILE=%s.", ds_cstr (&filename));
+ ds_destroy (&filename);
- gchar *sysname = convert_glib_filename_to_system_filename (name, NULL);
+ }
+ else
+ {
+ syntax = syn;
+ }
- if (any_reader_may_open (sysname))
- psppire_window_load (de, name);
- else
- open_syntax_window (name);
+ ok = execute_syntax (PSPPIRE_DATA_WINDOW (de),
+ lex_reader_for_string (syntax));
+ g_free (syntax);
- g_free (sysname);
- g_free (name);
- }
- break;
- default:
- break;
+ if (ok && syn == NULL)
+ {
+ if (name_has_por_suffix (file_name))
+ mime_type = "application/x-spss-por";
+ else if (name_has_sav_suffix (file_name))
+ mime_type = "application/x-spss-sav";
+
+ add_most_recent (file_name, mime_type);
}
- gtk_widget_destroy (dialog);
-}
-
-/* Returns true if NAME has a suffix which might denote a PSPP file */
-static gboolean
-name_has_suffix (const gchar *name)
-{
- if ( g_str_has_suffix (name, ".sav"))
- return TRUE;
- if ( g_str_has_suffix (name, ".SAV"))
- return TRUE;
- if ( g_str_has_suffix (name, ".por"))
- return TRUE;
- if ( g_str_has_suffix (name, ".POR"))
- return TRUE;
-
- return FALSE;
+ return ok;
}
-
/* Save DE to file */
static void
save_file (PsppireWindow *w)
{
+ const gchar *file_name = NULL;
gchar *utf8_file_name = NULL;
- gchar *file_name = NULL;
GString *fnx;
struct string filename ;
PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (w);
gchar *syntax;
- g_object_get (w, "filename", &file_name, NULL);
+ file_name = psppire_window_get_filename (w);
fnx = g_string_new (file_name);
}
-static void
-insert_case (PsppireDataWindow *dw)
-{
- psppire_data_editor_insert_case (dw->data_editor);
-}
-
-static void
-on_insert_variable (PsppireDataWindow *dw)
-{
- psppire_data_editor_insert_variable (dw->data_editor);
-}
-
-
static void
display_dict (PsppireDataWindow *de)
{
static void
sysfile_info (PsppireDataWindow *de)
{
- GtkWidget *dialog = sysfile_chooser_dialog (PSPPIRE_WINDOW (de));
+ GtkWidget *dialog = psppire_window_file_chooser_dialog (PSPPIRE_WINDOW (de));
if ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (dialog)))
{
}
-/* Callback for data_save_as action. Prompt for a filename and save */
+/* PsppireWindow 'pick_filename' callback: prompt for a filename to save as. */
static void
-data_save_as_dialog (PsppireDataWindow *de)
+data_pick_filename (PsppireWindow *window)
{
+ PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (window);
+ GtkFileFilter *filter = gtk_file_filter_new ();
GtkWidget *button_sys;
GtkWidget *dialog =
gtk_file_chooser_dialog_new (_("Save"),
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
- GtkFileFilter *filter = gtk_file_filter_new ();
+ g_object_set (dialog, "local-only", FALSE, NULL);
+
gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
- gtk_file_filter_add_pattern (filter, "*.sav");
- gtk_file_filter_add_pattern (filter, "*.SAV");
+ gtk_file_filter_add_mime_type (filter, "application/x-spss-sav");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
- gtk_file_filter_add_pattern (filter, "*.por");
- gtk_file_filter_add_pattern (filter, "*.POR");
+ gtk_file_filter_add_mime_type (filter, "application/x-spss-por");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
filter = gtk_file_filter_new ();
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox);
}
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
+ TRUE);
+
switch (gtk_dialog_run (GTK_DIALOG (dialog)))
{
case GTK_RESPONSE_ACCEPT:
psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str);
- save_file (PSPPIRE_WINDOW (de));
-
g_string_free (filename, TRUE);
}
break;
gtk_widget_destroy (dialog);
}
-
-/* Callback for data_save action.
- */
-static void
-data_save (PsppireWindow *de)
+static bool
+confirm_delete_dataset (PsppireDataWindow *de,
+ const char *old_dataset,
+ const char *new_dataset,
+ const char *existing_dataset)
{
- const gchar *fn = psppire_window_get_filename (de);
+ GtkWidget *dialog;
+ int result;
- if ( NULL != fn)
- psppire_window_save (de);
- else
- data_save_as_dialog (PSPPIRE_DATA_WINDOW (de));
-}
+ dialog = gtk_message_dialog_new (
+ GTK_WINDOW (de), 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s",
+ _("Delete Existing Dataset?"));
+ gtk_message_dialog_format_secondary_text (
+ GTK_MESSAGE_DIALOG (dialog),
+ _("Renaming \"%s\" to \"%s\" will destroy the existing "
+ "dataset named \"%s\". Are you sure that you want to do this?"),
+ old_dataset, new_dataset, existing_dataset);
-/* Callback for data_new action.
- Performs the NEW FILE command */
-static void
-new_file (PsppireDataWindow *de)
-{
- execute_const_syntax_string (de, "NEW FILE.");
- psppire_window_set_filename (PSPPIRE_WINDOW (de), NULL);
-}
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_DELETE, GTK_RESPONSE_OK,
+ NULL);
+ g_object_set (dialog, "icon-name", "pspp", NULL);
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
-static void
-on_edit_paste (PsppireDataWindow *de)
-{
- psppire_data_editor_clip_paste (de->data_editor);
-}
+ gtk_widget_destroy (dialog);
-static void
-on_edit_copy (PsppireDataWindow *de)
-{
- psppire_data_editor_clip_copy (de->data_editor);
+ return result == GTK_RESPONSE_OK;
}
-
-
static void
-on_edit_cut (PsppireDataWindow *de)
+on_rename_dataset (PsppireDataWindow *de)
{
- psppire_data_editor_clip_cut (de->data_editor);
+ struct dataset *ds = de->dataset;
+ struct session *session = dataset_session (ds);
+ const char *old_name = dataset_name (ds);
+ struct dataset *existing_dataset;
+ char *new_name;
+ char *prompt;
+
+ prompt = xasprintf (_("Please enter a new name for dataset \"%s\":"),
+ old_name);
+ new_name = entry_dialog_run (GTK_WINDOW (de), _("Rename Dataset"), prompt,
+ old_name);
+ free (prompt);
+
+ if (new_name == NULL)
+ return;
+
+ existing_dataset = session_lookup_dataset (session, new_name);
+ if (existing_dataset == NULL || existing_dataset == ds
+ || confirm_delete_dataset (de, old_name, new_name,
+ dataset_name (existing_dataset)))
+ g_free (execute_syntax_string (de, g_strdup_printf ("DATASET NAME %s.",
+ new_name)));
+
+ free (new_name);
}
-
static void
status_bar_activate (PsppireDataWindow *de, GtkToggleAction *action)
{
static void
-file_quit (void)
+file_quit (PsppireDataWindow *de)
{
/* FIXME: Need to be more intelligent here.
Give the user the opportunity to save any unsaved data.
*/
- g_object_unref (the_data_store);
-
psppire_quit ();
}
-
static void
on_recent_data_select (GtkMenuShell *menushell,
PsppireWindow *window)
g_free (uri);
- psppire_window_load (window, file);
+ open_data_window (window, file, NULL);
g_free (file);
}
+static char *
+charset_from_mime_type (const char *mime_type)
+{
+ const char *charset;
+ struct string s;
+ const char *p;
+
+ if (mime_type == NULL)
+ return NULL;
+
+ charset = c_strcasestr (mime_type, "charset=");
+ if (charset == NULL)
+ return NULL;
+
+ ds_init_empty (&s);
+ p = charset + 8;
+ if (*p == '"')
+ {
+ /* Parse a "quoted-string" as defined by RFC 822. */
+ for (p++; *p != '\0' && *p != '"'; p++)
+ {
+ if (*p != '\\')
+ ds_put_byte (&s, *p);
+ else if (*++p != '\0')
+ ds_put_byte (&s, *p);
+ }
+ }
+ else
+ {
+ /* Parse a "token" as defined by RFC 2045. */
+ while (*p > 32 && *p < 127 && strchr ("()<>@,;:\\\"/[]?=", *p) == NULL)
+ ds_put_byte (&s, *p++);
+ }
+ if (!ds_is_empty (&s))
+ return ds_steal_cstr (&s);
+
+ ds_destroy (&s);
+ return NULL;
+}
+
static void
on_recent_files_select (GtkMenuShell *menushell, gpointer user_data)
{
+ GtkRecentInfo *item;
+ char *encoding;
+ GtkWidget *se;
gchar *file;
- GtkWidget *se ;
-
- gchar *uri =
- gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
+ /* Get the file name and its encoding. */
+ item = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (menushell));
+ file = g_filename_from_uri (gtk_recent_info_get_uri (item), NULL, NULL);
+ encoding = charset_from_mime_type (gtk_recent_info_get_mime_type (item));
+ gtk_recent_info_unref (item);
- file = g_filename_from_uri (uri, NULL, NULL);
+ se = psppire_syntax_window_new (encoding);
- g_free (uri);
+ free (encoding);
- se = psppire_syntax_window_new ();
-
- if ( psppire_window_load (PSPPIRE_WINDOW (se), file) )
+ if ( psppire_window_load (PSPPIRE_WINDOW (se), file, NULL) )
gtk_widget_show (se);
else
gtk_widget_destroy (se);
g_free (file);
}
-
static void
-enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
+set_unsaved (gpointer w)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
- gtk_action_set_visible (de->delete_cases, case_num != -1);
+ psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
}
-
static void
-enable_delete_variables (GtkWidget *w, gint var, gpointer data)
+on_switch_page (PsppireDataEditor *de, gpointer p,
+ gint pagenum, PsppireDataWindow *dw)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
- gtk_action_set_visible (de->delete_variables, var != -1);
+ GtkWidget *page_menu_item;
+ gboolean is_ds;
+ const char *path;
+
+ is_ds = pagenum == PSPPIRE_DATA_EDITOR_DATA_VIEW;
+ path = (is_ds
+ ? "/ui/menubar/view/view_data"
+ : "/ui/menubar/view/view_variables");
+ page_menu_item = gtk_ui_manager_get_widget (dw->ui_manager, path);
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (page_menu_item), TRUE);
}
-/* Callback for when the datasheet/varsheet is selected */
static void
-on_switch_sheet (GtkNotebook *notebook,
- GtkNotebookPage *page,
- guint page_num,
- gpointer user_data)
+on_ui_manager_changed (PsppireDataEditor *de,
+ GParamSpec *pspec UNUSED,
+ PsppireDataWindow *dw)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
-
- GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
-
- GtkWidget *view_data =
- gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_data");
-
- GtkWidget *view_variables =
- gtk_ui_manager_get_widget (uim,"/ui/menubar/view/view_variables");
+ GtkUIManager *uim = psppire_data_editor_get_ui_manager (de);
+ if (uim == dw->uim)
+ return;
- switch (page_num)
+ if (dw->uim)
{
- case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
- gtk_widget_hide (view_variables);
- gtk_widget_show (view_data);
- gtk_action_set_sensitive (de->insert_variable, TRUE);
- gtk_action_set_sensitive (de->insert_case, FALSE);
- gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
- break;
- case PSPPIRE_DATA_EDITOR_DATA_VIEW:
- gtk_widget_show (view_variables);
- gtk_widget_hide (view_data);
- gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
- gtk_action_set_sensitive (de->insert_case, TRUE);
- break;
- default:
- g_assert_not_reached ();
- break;
+ psppire_data_window_remove_ui (dw, dw->uim, dw->merge_id);
+ g_object_unref (dw->uim);
+ dw->uim = NULL;
}
-#if 0
- update_paste_menuitem (de, page_num);
-#endif
-}
-
-
-
-static void
-set_unsaved (gpointer w)
-{
- psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
+ dw->uim = uim;
+ if (dw->uim)
+ {
+ g_object_ref (dw->uim);
+ dw->merge_id = psppire_data_window_add_ui (dw, dw->uim);
+ }
}
-
/* Connects the action called ACTION_NAME to HANDLER passing DW as the auxilliary data.
Returns a pointer to the action
*/
GCallback handler)
{
GtkAction *action = get_action_assert (dw->builder, action_name);
-
+
g_signal_connect_swapped (action, "activate", handler, dw);
return action;
}
+/* Only a data file with at least one variable can be saved. */
+static void
+enable_save (PsppireDataWindow *dw)
+{
+ gboolean enable = psppire_dict_get_var_cnt (dw->dict) > 0;
+
+ gtk_action_set_sensitive (get_action_assert (dw->builder, "file_save"),
+ enable);
+ gtk_action_set_sensitive (get_action_assert (dw->builder, "file_save_as"),
+ enable);
+}
+
+/* Initializes as much of a PsppireDataWindow as we can and must before the
+ dataset has been set.
+
+ In particular, the 'menu' member is required in case the "filename" property
+ is set before the "dataset" property: otherwise PsppireWindow will try to
+ modify the menu as part of the "filename" property_set() function and end up
+ with a Gtk-CRITICAL since 'menu' is NULL. */
static void
psppire_data_window_init (PsppireDataWindow *de)
+{
+ de->builder = builder_new ("data-editor.ui");
+
+ de->ui_manager = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
+
+ PSPPIRE_WINDOW (de)->menu =
+ GTK_MENU_SHELL (gtk_ui_manager_get_widget (de->ui_manager, "/ui/menubar/windows/windows_minimise_all")->parent);
+
+ de->uim = NULL;
+ de->merge_id = 0;
+}
+
+static void
+psppire_data_window_finish_init (PsppireDataWindow *de,
+ struct dataset *ds)
{
static const struct dataset_callbacks cbs =
{
transformation_change_callback, /* transformations_changed */
};
- PsppireVarStore *vs;
- PsppireDict *dict = NULL;
-
GtkWidget *menubar;
GtkWidget *hb ;
GtkWidget *sb ;
GtkWidget *box = gtk_vbox_new (FALSE, 0);
- de->builder = builder_new ("data-editor.ui");
+
+ de->dataset = ds;
+ de->dict = psppire_dict_new_from_dict (dataset_dict (ds));
+ de->data_store = psppire_data_store_new (de->dict);
+ psppire_data_store_set_reader (de->data_store, NULL);
menubar = get_widget_assert (de->builder, "menubar");
hb = get_widget_assert (de->builder, "handlebox1");
sb = get_widget_assert (de->builder, "status-bar");
+ de->uim = NULL;
+ de->merge_id = 0;
+
de->data_editor =
- PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
+ PSPPIRE_DATA_EDITOR (psppire_data_editor_new (de->dict, de->data_store));
+ g_signal_connect (de->data_editor, "switch-page",
+ G_CALLBACK (on_switch_page), de);
- g_signal_connect_swapped (the_data_store, "case-changed",
+ g_signal_connect_swapped (de->data_store, "case-changed",
G_CALLBACK (set_unsaved), de);
- g_signal_connect_swapped (the_data_store, "case-inserted",
+ g_signal_connect_swapped (de->data_store, "case-inserted",
G_CALLBACK (set_unsaved), de);
- g_signal_connect_swapped (the_data_store, "cases-deleted",
+ g_signal_connect_swapped (de->data_store, "cases-deleted",
G_CALLBACK (set_unsaved), de);
- dataset_set_callbacks (the_dataset, &cbs, de);
+ dataset_set_callbacks (de->dataset, &cbs, de);
connect_help (de->builder);
gtk_container_add (GTK_CONTAINER (de), box);
- set_cut_copy_menuitem_sensitivity (de, FALSE);
-
- g_signal_connect_swapped (de->data_editor, "data-selection-changed",
- G_CALLBACK (set_cut_copy_menuitem_sensitivity), de);
-
-
- set_paste_menuitem_sensitivity (de, FALSE);
-
- g_signal_connect_swapped (de->data_editor, "data-available-changed",
- G_CALLBACK (set_paste_menuitem_sensitivity), de);
-
- vs = the_var_store;
-
- g_assert(vs); /* Traps a possible bug in w32 build */
-
- g_object_get (vs, "dictionary", &dict, NULL);
-
- g_signal_connect (dict, "weight-changed",
+ g_signal_connect (de->dict, "weight-changed",
G_CALLBACK (on_weight_change),
de);
- g_signal_connect (dict, "filter-changed",
+ g_signal_connect (de->dict, "filter-changed",
G_CALLBACK (on_filter_change),
de);
- g_signal_connect (dict, "split-changed",
+ g_signal_connect (de->dict, "split-changed",
G_CALLBACK (on_split_change),
de);
-
- connect_action (de, "edit_copy", G_CALLBACK (on_edit_copy));
-
- connect_action (de, "edit_cut", G_CALLBACK (on_edit_cut));
-
- connect_action (de, "file_new_data", G_CALLBACK (new_file));
-
- connect_action (de, "file_import-text", G_CALLBACK (text_data_import_assistant));
-
- connect_action (de, "file_save", G_CALLBACK (data_save));
-
- connect_action (de, "file_open", G_CALLBACK (open_window));
-
- connect_action (de, "file_save_as", G_CALLBACK (data_save_as_dialog));
-
+ g_signal_connect_swapped (de->dict, "backend-changed",
+ G_CALLBACK (enable_save), de);
+ g_signal_connect_swapped (de->dict, "variable-inserted",
+ G_CALLBACK (enable_save), de);
+ g_signal_connect_swapped (de->dict, "variable-deleted",
+ G_CALLBACK (enable_save), de);
+ enable_save (de);
+
+ connect_action (de, "file_new_data", G_CALLBACK (create_data_window));
+ connect_action (de, "file_import", G_CALLBACK (text_data_import_assistant));
+ connect_action (de, "file_save", G_CALLBACK (psppire_window_save));
+ connect_action (de, "file_open", G_CALLBACK (psppire_window_open));
+ connect_action (de, "file_save_as", G_CALLBACK (psppire_window_save_as));
+ connect_action (de, "rename_dataset", G_CALLBACK (on_rename_dataset));
connect_action (de, "file_information_working-file", G_CALLBACK (display_dict));
-
connect_action (de, "file_information_external-file", G_CALLBACK (sysfile_info));
- connect_action (de, "edit_paste", G_CALLBACK (on_edit_paste));
-
- de->insert_case = connect_action (de, "edit_insert-case", G_CALLBACK (insert_case));
-
- de->insert_variable = connect_action (de, "action_insert-variable", G_CALLBACK (on_insert_variable));
-
- de->invoke_goto_dialog = connect_action (de, "edit_goto-case", G_CALLBACK (goto_case_dialog));
-
g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de);
- {
- de->delete_cases = get_action_assert (de->builder, "edit_clear-cases");
-
- g_signal_connect_swapped (de->delete_cases, "activate", G_CALLBACK (psppire_data_editor_delete_cases), de->data_editor);
-
- gtk_action_set_visible (de->delete_cases, FALSE);
- }
-
-
- {
- de->delete_variables = get_action_assert (de->builder, "edit_clear-variables");
-
- g_signal_connect_swapped (de->delete_variables, "activate", G_CALLBACK (psppire_data_editor_delete_variables), de->data_editor);
-
- gtk_action_set_visible (de->delete_variables, FALSE);
- }
-
-
- connect_action (de, "data_transpose", G_CALLBACK (transpose_dialog));
-
connect_action (de, "data_select-cases", G_CALLBACK (select_cases_dialog));
-
- connect_action (de, "data_sort-cases", G_CALLBACK (sort_cases_dialog));
-
connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog));
-
- connect_action (de, "transform_compute", G_CALLBACK (compute_dialog));
-
- connect_action (de, "edit_find", G_CALLBACK (find_dialog));
-
+ connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog));
connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog));
-
connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog));
-
-
- connect_action (de, "utilities_variables", G_CALLBACK (variable_info_dialog));
-
connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog));
-
- connect_action (de, "indep-t-test", G_CALLBACK (t_test_independent_samples_dialog));
-
- connect_action (de, "paired-t-test", G_CALLBACK (t_test_paired_samples_dialog));
-
- connect_action (de, "one-sample-t-test", G_CALLBACK (t_test_one_sample_dialog));
-
connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
-
- connect_action (de, "transform_rank", G_CALLBACK (rank_dialog));
-
connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
-
connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog));
- connect_action (de, "analyze_descriptives", G_CALLBACK (descriptives_dialog));
-
- connect_action (de, "analyze_frequencies", G_CALLBACK (frequencies_dialog));
-
- connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog));
-
- connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog));
-
- connect_action (de, "linear-regression", G_CALLBACK (regression_dialog));
-
- connect_action (de, "reliability", G_CALLBACK (reliability_dialog));
-
- connect_action (de, "roc-curve", G_CALLBACK (roc_dialog));
-
- connect_action (de, "correlation", G_CALLBACK (correlation_dialog));
-
- connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
-
- connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
-
- connect_action (de, "binomial", G_CALLBACK (binomial_dialog));
-
- connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
-
-
{
- GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
-
GtkWidget *recent_data =
- gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-data");
+ gtk_ui_manager_get_widget (de->ui_manager, "/ui/menubar/file/file_recent-data");
GtkWidget *recent_files =
- gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
+ gtk_ui_manager_get_widget (de->ui_manager, "/ui/menubar/file/file_recent-files");
+
+ GtkWidget *menu_data = gtk_recent_chooser_menu_new_for_manager (
+ gtk_recent_manager_get_default ());
- GtkWidget *menu_data =
- gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
+ GtkWidget *menu_files = gtk_recent_chooser_menu_new_for_manager (
+ gtk_recent_manager_get_default ());
- GtkWidget *menu_files =
- gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
+ g_object_set (menu_data, "show-tips", TRUE, NULL);
+ g_object_set (menu_files, "show-tips", TRUE, NULL);
{
GtkRecentFilter *filter = gtk_recent_filter_new ();
- gtk_recent_filter_add_pattern (filter, "*.sav");
- gtk_recent_filter_add_pattern (filter, "*.SAV");
- gtk_recent_filter_add_pattern (filter, "*.por");
- gtk_recent_filter_add_pattern (filter, "*.POR");
+ gtk_recent_filter_add_mime_type (filter, "application/x-spss-sav");
+ gtk_recent_filter_add_mime_type (filter, "application/x-spss-por");
gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);
connect_action (de, "file_new_syntax", G_CALLBACK (create_syntax_window));
- g_signal_connect (de->data_editor,
- "cases-selected",
- G_CALLBACK (enable_delete_cases),
- de);
-
- g_signal_connect (de->data_editor,
- "variables-selected",
- G_CALLBACK (enable_delete_variables),
- de);
-
-
- g_signal_connect (de->data_editor,
- "switch-page",
- G_CALLBACK (on_switch_sheet), de);
-
gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
g_signal_connect_swapped (get_action_assert (de->builder, "windows_split"), "toggled", G_CALLBACK (toggle_split_window), de);
- {
- GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
+ merge_help_menu (de->ui_manager);
- merge_help_menu (uim);
-
- PSPPIRE_WINDOW (de)->menu =
- GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
- }
-
- {
- GtkWidget *data_sheet_cases_popup_menu = get_widget_assert (de->builder,
- "datasheet-cases-popup");
-
- GtkWidget *var_sheet_variable_popup_menu = get_widget_assert (de->builder,
- "varsheet-variable-popup");
-
- GtkWidget *data_sheet_variable_popup_menu = get_widget_assert (de->builder,
- "datasheet-variable-popup");
-
- g_signal_connect_swapped (get_action_assert (de->builder, "sort-up"), "activate",
- G_CALLBACK (psppire_data_editor_sort_ascending),
- de->data_editor);
-
- g_signal_connect_swapped (get_action_assert (de->builder, "sort-down"), "activate",
- G_CALLBACK (psppire_data_editor_sort_descending),
- de->data_editor);
-
- g_object_set (de->data_editor,
- "datasheet-column-menu", data_sheet_variable_popup_menu,
- "datasheet-row-menu", data_sheet_cases_popup_menu,
- "varsheet-row-menu", var_sheet_variable_popup_menu,
- NULL);
- }
+ g_signal_connect (de->data_editor, "notify::ui-manager",
+ G_CALLBACK (on_ui_manager_changed), de);
+ on_ui_manager_changed (de->data_editor, NULL, de);
gtk_widget_show (GTK_WIDGET (de->data_editor));
gtk_widget_show (box);
+
+ ll_push_head (&all_data_windows, &de->ll);
}
static void
{
PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (object);
+ if (dw->uim)
+ {
+ psppire_data_window_remove_ui (dw, dw->uim, dw->merge_id);
+ g_object_unref (dw->uim);
+ dw->uim = NULL;
+ }
+
if (dw->builder != NULL)
{
g_object_unref (dw->builder);
dw->builder = NULL;
}
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ if (dw->dict)
+ {
+ g_signal_handlers_disconnect_by_func (dw->dict,
+ G_CALLBACK (enable_save), dw);
+ g_signal_handlers_disconnect_by_func (dw->dict,
+ G_CALLBACK (on_weight_change), dw);
+ g_signal_handlers_disconnect_by_func (dw->dict,
+ G_CALLBACK (on_filter_change), dw);
+ g_signal_handlers_disconnect_by_func (dw->dict,
+ G_CALLBACK (on_split_change), dw);
+
+ g_object_unref (dw->dict);
+ dw->dict = NULL;
+ }
+
+ if (dw->data_store)
+ {
+ g_object_unref (dw->data_store);
+ dw->data_store = NULL;
+ }
+
+ if (dw->ll.next != NULL)
+ {
+ ll_remove (&dw->ll);
+ dw->ll.next = NULL;
+ }
+
+ if (G_OBJECT_CLASS (parent_class)->dispose)
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+psppire_data_window_finalize (GObject *object)
+{
+ PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (object);
+
+ if (dw->dataset)
+ {
+ struct dataset *dataset = dw->dataset;
+ struct session *session = dataset_session (dataset);
+
+ dw->dataset = NULL;
+
+ dataset_set_callbacks (dataset, NULL, NULL);
+ session_set_active_dataset (session, NULL);
+ dataset_destroy (dataset);
+ }
+
+ if (G_OBJECT_CLASS (parent_class)->finalize)
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+psppire_data_window_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireDataWindow *window = PSPPIRE_DATA_WINDOW (object);
+
+ switch (prop_id)
+ {
+ case PROP_DATASET:
+ psppire_data_window_finish_init (window, g_value_get_pointer (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+static void
+psppire_data_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireDataWindow *window = PSPPIRE_DATA_WINDOW (object);
+
+ switch (prop_id)
+ {
+ case PROP_DATASET:
+ g_value_set_pointer (value, window->dataset);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+static guint
+psppire_data_window_add_ui (PsppireDataWindow *pdw, GtkUIManager *uim)
+{
+ gchar *ui_string;
+ guint merge_id;
+ GList *list;
+
+ ui_string = gtk_ui_manager_get_ui (uim);
+ merge_id = gtk_ui_manager_add_ui_from_string (pdw->ui_manager, ui_string,
+ -1, NULL);
+ g_free (ui_string);
+
+ g_return_val_if_fail (merge_id != 0, 0);
+
+ list = gtk_ui_manager_get_action_groups (uim);
+ for (; list != NULL; list = list->next)
+ {
+ GtkActionGroup *action_group = list->data;
+ GList *actions = gtk_action_group_list_actions (action_group);
+ GList *action;
+
+ for (action = actions; action != NULL; action = action->next)
+ {
+ GtkAction *a = action->data;
+
+ if (PSPPIRE_IS_DIALOG_ACTION (a))
+ g_object_set (a, "manager", pdw->ui_manager, NULL);
+ }
+
+ gtk_ui_manager_insert_action_group (pdw->ui_manager, action_group, 0);
+ }
+
+ gtk_window_add_accel_group (GTK_WINDOW (pdw),
+ gtk_ui_manager_get_accel_group (uim));
+
+ return merge_id;
+}
+
+static void
+psppire_data_window_remove_ui (PsppireDataWindow *pdw,
+ GtkUIManager *uim, guint merge_id)
+{
+ GList *list;
+
+ g_return_if_fail (merge_id != 0);
+
+ gtk_ui_manager_remove_ui (pdw->ui_manager, merge_id);
+
+ list = gtk_ui_manager_get_action_groups (uim);
+ for (; list != NULL; list = list->next)
+ {
+ GtkActionGroup *action_group = list->data;
+ gtk_ui_manager_remove_action_group (pdw->ui_manager, action_group);
+ }
+
+ gtk_window_remove_accel_group (GTK_WINDOW (pdw),
+ gtk_ui_manager_get_accel_group (uim));
}
GtkWidget*
-psppire_data_window_new (void)
+psppire_data_window_new (struct dataset *ds)
{
- return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
- /* TRANSLATORS: This will form a filename. Please avoid whitespace. */
- "filename", _("PSPP-data"),
- "description", _("Data Editor"),
- NULL));
+ GtkWidget *dw;
+
+ if (the_session == NULL)
+ the_session = session_create (NULL);
+
+ if (ds == NULL)
+ {
+ char *dataset_name = session_generate_dataset_name (the_session);
+ ds = dataset_create (the_session, dataset_name);
+ free (dataset_name);
+ }
+ assert (dataset_session (ds) == the_session);
+
+ dw = GTK_WIDGET (
+ g_object_new (
+ psppire_data_window_get_type (),
+ "description", _("Data Editor"),
+ "dataset", ds,
+ NULL));
+
+ if (dataset_name (ds) != NULL)
+ g_object_set (dw, "id", dataset_name (ds), (void *) NULL);
+
+ return dw;
}
+bool
+psppire_data_window_is_empty (PsppireDataWindow *dw)
+{
+ return psppire_dict_get_var_cnt (dw->dict) == 0;
+}
static void
psppire_data_window_iface_init (PsppireWindowIface *iface)
{
iface->save = save_file;
+ iface->pick_filename = data_pick_filename;
iface->load = load_file;
}
+\f
+PsppireDataWindow *
+psppire_default_data_window (void)
+{
+ if (ll_is_empty (&all_data_windows))
+ create_data_window ();
+ return ll_data (ll_head (&all_data_windows), PsppireDataWindow, ll);
+}
+
+void
+psppire_data_window_set_default (PsppireDataWindow *pdw)
+{
+ ll_remove (&pdw->ll);
+ ll_push_head (&all_data_windows, &pdw->ll);
+}
+
+void
+psppire_data_window_undefault (PsppireDataWindow *pdw)
+{
+ ll_remove (&pdw->ll);
+ ll_push_tail (&all_data_windows, &pdw->ll);
+}
+
+PsppireDataWindow *
+psppire_data_window_for_dataset (struct dataset *ds)
+{
+ PsppireDataWindow *pdw;
+
+ ll_for_each (pdw, PsppireDataWindow, ll, &all_data_windows)
+ if (pdw->dataset == ds)
+ return pdw;
+
+ return NULL;
+}
+
+PsppireDataWindow *
+psppire_data_window_for_data_store (PsppireDataStore *data_store)
+{
+ PsppireDataWindow *pdw;
+
+ ll_for_each (pdw, PsppireDataWindow, ll, &all_data_windows)
+ if (pdw->data_store == data_store)
+ return pdw;
+
+ return NULL;
+}
+
+void
+create_data_window (void)
+{
+ gtk_widget_show (psppire_data_window_new (NULL));
+}
+
+void
+open_data_window (PsppireWindow *victim, const char *file_name, gpointer hint)
+{
+ GtkWidget *window;
+
+ if (PSPPIRE_IS_DATA_WINDOW (victim)
+ && psppire_data_window_is_empty (PSPPIRE_DATA_WINDOW (victim)))
+ {
+ window = GTK_WIDGET (victim);
+ gtk_widget_hide (GTK_WIDGET (PSPPIRE_DATA_WINDOW (window)->data_editor));
+ }
+ else
+ window = psppire_data_window_new (NULL);
+
+ psppire_window_load (PSPPIRE_WINDOW (window), file_name, hint);
+ gtk_widget_show_all (window);
+}