/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2012 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 <config.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtkbox.h>
+#include <gtk/gtk.h>
#include <stdlib.h>
-#include "data/any-reader.h"
-#include "data/procedure.h"
-#include "language/syntax-string-source.h"
+#include "data/dataset.h"
+#include "data/session.h"
+#include "language/lexer/lexer.h"
#include "libpspp/message.h"
-#include "ui/gui/about.h"
+#include "libpspp/str.h"
+#include "ui/gui/aggregate-dialog.h"
+#include "ui/gui/autorecode-dialog.h"
+#include "ui/gui/binomial-dialog.h"
+#include "ui/gui/builder-wrapper.h"
+#include "ui/gui/chi-square-dialog.h"
#include "ui/gui/comments-dialog.h"
#include "ui/gui/compute-dialog.h"
#include "ui/gui/correlation-dialog.h"
+#include "ui/gui/count-dialog.h"
#include "ui/gui/crosstabs-dialog.h"
#include "ui/gui/descriptives-dialog.h"
+#include "ui/gui/entry-dialog.h"
#include "ui/gui/examine-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/helper.h"
+#include "ui/gui/k-means-dialog.h"
+#include "ui/gui/k-related-dialog.h"
+#include "ui/gui/npar-two-sample-related.h"
#include "ui/gui/oneway-anova-dialog.h"
#include "ui/gui/psppire-data-window.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/runs-dialog.h"
+#include "ui/gui/ks-one-sample-dialog.h"
#include "ui/gui/recode-dialog.h"
#include "ui/gui/regression-dialog.h"
#include "ui/gui/reliability-dialog.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/univariate-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_base_finalize (PsppireDataWindowClass *, gpointer);
-static void psppire_data_window_base_init (PsppireDataWindowClass *class);
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_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);
GType
psppire_data_window_get_type (void)
static const GTypeInfo psppire_data_window_info =
{
sizeof (PsppireDataWindowClass),
- (GBaseInitFunc) psppire_data_window_base_init,
- (GBaseFinalizeFunc) psppire_data_window_base_finalize,
+ NULL,
+ NULL,
(GClassInitFunc)psppire_data_window_class_init,
(GClassFinalizeFunc) NULL,
NULL,
g_type_register_static (PSPPIRE_TYPE_WINDOW, "PsppireDataWindow",
&psppire_data_window_info, 0);
-
+
g_type_add_interface_static (psppire_data_window_type,
PSPPIRE_TYPE_WINDOW_MODEL,
&window_interface_info);
static GObjectClass *parent_class ;
-static void
-psppire_data_window_finalize (GObject *object)
-{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (object);
-
- g_object_unref (de->builder);
-
- if (G_OBJECT_CLASS (parent_class)->finalize)
- (*G_OBJECT_CLASS (parent_class)->finalize) (object);
-}
-
+enum {
+ PROP_DATASET = 1
+};
static void
psppire_data_window_class_init (PsppireDataWindowClass *class)
-{
- parent_class = g_type_class_peek_parent (class);
-}
-
-
-static void
-psppire_data_window_base_init (PsppireDataWindowClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- object_class->finalize = psppire_data_window_finalize;
-}
-
+ parent_class = g_type_class_peek_parent (class);
+ object_class->dispose = psppire_data_window_dispose;
+ object_class->set_property = psppire_data_window_set_property;
+ object_class->get_property = psppire_data_window_get_property;
-static void
-psppire_data_window_base_finalize (PsppireDataWindowClass *class,
- gpointer class_data)
-{
+ 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)
{
/* Run the EXECUTE command. */
static void
-execute (GtkMenuItem *mi, gpointer data)
+execute (PsppireDataWindow *dw)
{
- struct getl_interface *sss = create_syntax_string_source ("EXECUTE.");
-
- execute_syntax (sss);
+ execute_const_syntax_string (dw, "EXECUTE.");
}
static void
g_object_get (de->data_editor, "var-store", &vs, NULL);
g_object_get (vs, "dictionary", &dict, NULL);
-
+
var = psppire_dict_get_variable (dict, weight_index);
text = g_strdup_printf (_("Weight by %s"), var_get_name (var));
}
#endif
-
static gboolean
-load_file (PsppireWindow *de, const gchar *file_name)
+name_has_por_suffix (const gchar *name)
{
- gchar *native_file_name;
- struct getl_interface *sss;
- struct string filename;
-
- ds_init_empty (&filename);
-
- native_file_name =
- convert_glib_filename_to_system_filename (file_name, NULL);
-
- syntax_gen_string (&filename, ss_cstr (native_file_name));
-
- g_free (native_file_name);
-
- sss = create_syntax_string_source ("GET FILE=%s.",
- ds_cstr (&filename));
-
- ds_destroy (&filename);
-
- if (execute_syntax (sss) )
- return TRUE;
-
- return FALSE;
+ 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);
+ size_t length = strlen (name);
+ return length > 4 && !c_strcasecmp (&name[length - 4], ".sav");
+}
- 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);
+/* 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);
+}
- 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);
+static gboolean
+load_file (PsppireWindow *de, const gchar *file_name)
+{
+ struct string filename;
+ gchar *utf8_file_name;
+ const char *mime_type;
+ gchar *syntax;
+ bool ok;
- {
- gchar *dir_name;
- gchar *filename = NULL;
- g_object_get (toplevel, "filename", &filename, NULL);
+ ds_init_empty (&filename);
- 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);
- }
+ utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
- return dialog;
-}
+ syntax_gen_string (&filename, ss_cstr (utf8_file_name));
-/* Callback for the data_open action.
- Prompts for a filename and opens it */
-static void
-open_window (GtkAction *action, PsppireWindow *de)
-{
- GtkWidget *dialog = sysfile_chooser_dialog (de);
+ g_free (utf8_file_name);
- switch (gtk_dialog_run (GTK_DIALOG (dialog)))
- {
- case GTK_RESPONSE_ACCEPT:
- {
- gchar *name =
- gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ syntax = g_strdup_printf ("GET FILE=%s.", ds_cstr (&filename));
+ ds_destroy (&filename);
- if (any_reader_may_open (name))
- 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 (name);
- }
- break;
- default:
- break;
- }
+ mime_type = (name_has_por_suffix (file_name)
+ ? "application/x-spss-por"
+ : "application/x-spss-sav");
- gtk_widget_destroy (dialog);
-}
+ add_most_recent (file_name, mime_type);
-/* 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)
{
- gchar *native_file_name = NULL;
- gchar *file_name = NULL;
+ const gchar *file_name = NULL;
+ gchar *utf8_file_name = NULL;
GString *fnx;
- struct getl_interface *sss;
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);
ds_init_empty (&filename);
- native_file_name =
- convert_glib_filename_to_system_filename (fnx->str, NULL);
+ utf8_file_name = g_filename_to_utf8 (fnx->str, -1, NULL, NULL, NULL);
g_string_free (fnx, TRUE);
- syntax_gen_string (&filename, ss_cstr (native_file_name));
- g_free (native_file_name);
+ syntax_gen_string (&filename, ss_cstr (utf8_file_name));
+ g_free (utf8_file_name);
- if ( de->save_as_portable )
- {
- sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
- ds_cstr (&filename));
- }
- else
- {
- sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
- ds_cstr (&filename));
- }
+ syntax = g_strdup_printf ("%s OUTFILE=%s.",
+ de->save_as_portable ? "EXPORT" : "SAVE",
+ ds_cstr (&filename));
ds_destroy (&filename);
- execute_syntax (sss);
+ g_free (execute_syntax_string (de, syntax));
}
static void
-insert_case (GtkAction *action, gpointer data)
+insert_case (PsppireDataWindow *dw)
{
- PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (data);
psppire_data_editor_insert_case (dw->data_editor);
}
static void
-on_insert_variable (GtkAction *action, gpointer data)
+on_insert_variable (PsppireDataWindow *dw)
{
- PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (data);
psppire_data_editor_insert_variable (dw->data_editor);
}
static void
display_dict (PsppireDataWindow *de)
{
-
- struct getl_interface *sss =
- create_syntax_string_source ("DISPLAY DICTIONARY.");
-
- execute_syntax (sss);
+ execute_const_syntax_string (de, "DISPLAY DICTIONARY.");
}
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)))
{
struct string filename;
- struct getl_interface *sss;
gchar *file_name =
gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- gchar *native_file_name =
- convert_glib_filename_to_system_filename (file_name, NULL);
+ gchar *utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL,
+ NULL);
+
+ gchar *syntax;
ds_init_empty (&filename);
- syntax_gen_string (&filename, ss_cstr (native_file_name));
+ syntax_gen_string (&filename, ss_cstr (utf8_file_name));
- g_free (native_file_name);
+ g_free (utf8_file_name);
- sss = create_syntax_string_source ("SYSFILE INFO %s.",
- ds_cstr (&filename));
- execute_syntax (sss);
+ syntax = g_strdup_printf ("SYSFILE INFO %s.", ds_cstr (&filename));
+ g_free (execute_syntax_string (de, syntax));
}
gtk_widget_destroy (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 delete 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 (GtkAction *action, PsppireDataWindow *de)
-{
- struct getl_interface *sss =
- create_syntax_string_source ("NEW FILE.");
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_DELETE, GTK_RESPONSE_OK,
+ NULL);
- execute_syntax (sss);
+ g_object_set (dialog, "icon-name", "pspp", NULL);
- psppire_window_set_filename (PSPPIRE_WINDOW (de), NULL);
-}
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return result == GTK_RESPONSE_OK;
+}
static void
-on_edit_paste (GtkAction *a, gpointer data)
+on_rename_dataset (PsppireDataWindow *de)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
+ 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
+on_edit_paste (PsppireDataWindow *de)
+{
psppire_data_editor_clip_paste (de->data_editor);
}
static void
-on_edit_copy (GtkMenuItem *m, gpointer data)
+on_edit_copy (PsppireDataWindow *de)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
psppire_data_editor_clip_copy (de->data_editor);
}
static void
-on_edit_cut (GtkMenuItem *m, gpointer data)
+on_edit_cut (PsppireDataWindow *de)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
psppire_data_editor_clip_cut (de->data_editor);
}
static void
-status_bar_activate (GtkToggleAction *action, gpointer data)
+status_bar_activate (PsppireDataWindow *de, GtkToggleAction *action)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
GtkWidget *statusbar = get_widget_assert (de->builder, "status-bar");
- if ( gtk_toggle_action_get_active (action) )
+ if ( gtk_toggle_action_get_active (action))
gtk_widget_show (statusbar);
else
gtk_widget_hide (statusbar);
static void
-grid_lines_activate (GtkToggleAction *action, gpointer data)
+grid_lines_activate (PsppireDataWindow *de, GtkToggleAction *action)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
const gboolean grid_visible = gtk_toggle_action_get_active (action);
psppire_data_editor_show_grid (de->data_editor, grid_visible);
}
static void
-data_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
+data_view_activate (PsppireDataWindow *de)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW);
}
static void
-variable_view_activate (GtkCheckMenuItem *menuitem, gpointer data)
+variable_view_activate (PsppireDataWindow *de)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
gtk_notebook_set_current_page (GTK_NOTEBOOK (de->data_editor), PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
}
static void
-fonts_activate (GtkMenuItem *menuitem, gpointer data)
+fonts_activate (PsppireDataWindow *de)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (de));
PangoFontDescription *current_font;
gchar *font_name;
/* Callback for the value labels action */
static void
-toggle_value_labels (GtkToggleAction *ta, gpointer data)
+toggle_value_labels (PsppireDataWindow *de, GtkToggleAction *ta)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
}
static void
-toggle_split_window (GtkToggleAction *ta, gpointer data)
+toggle_split_window (PsppireDataWindow *de, GtkToggleAction *ta)
{
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
psppire_data_editor_split_window (de->data_editor,
gtk_toggle_action_get_active (ta));
}
static void
-file_quit (GtkCheckMenuItem *menuitem, gpointer data)
+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 GtkWidget *
-create_data_sheet_cases_popup_menu (PsppireDataWindow *de)
-{
- GtkWidget *menu = gtk_menu_new ();
-
- GtkWidget *insert_case =
- gtk_menu_item_new_with_label (_("Insert Case"));
-
- GtkWidget *delete_case =
- gtk_menu_item_new_with_label (_("Clear"));
-
-
- gtk_action_connect_proxy (de->delete_cases,
- delete_case);
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_case);
-
- g_signal_connect_swapped (insert_case, "activate",
- G_CALLBACK (gtk_action_activate),
- de->insert_case);
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu),
- gtk_separator_menu_item_new ());
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_case);
-
-
- gtk_widget_show_all (menu);
-
- return menu;
-}
-
-
-static GtkWidget *
-create_var_sheet_variable_popup_menu (PsppireDataWindow *de)
-{
- GtkWidget *menu = gtk_menu_new ();
-
- GtkWidget *insert_variable =
- gtk_menu_item_new_with_label (_("Insert Variable"));
-
- GtkWidget *delete_variable =
- gtk_menu_item_new_with_label (_("Clear"));
-
-
- gtk_action_connect_proxy (de->delete_variables,
- delete_variable);
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
-
- g_signal_connect_swapped (insert_variable, "activate",
- G_CALLBACK (gtk_action_activate),
- de->insert_variable);
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu),
- gtk_separator_menu_item_new ());
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_variable);
-
-
- gtk_widget_show_all (menu);
-
- return menu;
-}
-
-
static void
on_recent_data_select (GtkMenuShell *menushell,
PsppireWindow *window)
g_free (uri);
- psppire_window_load (window, file);
+ open_data_window (window, file);
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));
-
- file = g_filename_from_uri (uri, NULL, NULL);
+ /* 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);
- g_free (uri);
+ se = psppire_syntax_window_new (encoding);
- se = psppire_syntax_window_new ();
+ free (encoding);
if ( psppire_window_load (PSPPIRE_WINDOW (se), file) )
gtk_widget_show (se);
}
+
static void
enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
{
switch (page_num)
{
case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
- gtk_widget_hide (view_variables);
- gtk_widget_show (view_data);
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (view_variables),
+ TRUE);
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_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (view_data), TRUE);
gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
gtk_action_set_sensitive (de->insert_case, TRUE);
break;
psppire_window_set_unsaved (PSPPIRE_WINDOW (w));
}
+
+/* Connects the action called ACTION_NAME to HANDLER passing DW as the auxilliary data.
+ Returns a pointer to the action
+*/
+static GtkAction *
+connect_action (PsppireDataWindow *dw, const char *action_name,
+ GCallback handler)
+{
+ GtkAction *action = get_action_assert (dw->builder, action_name);
+
+ g_signal_connect_swapped (action, "activate", handler, dw);
+
+ return action;
+}
+
+/* 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)
{
- PsppireVarStore *vs;
- PsppireDict *dict = NULL;
+ GtkUIManager *uim;
+
+ de->builder = builder_new ("data-editor.ui");
+
+ uim = 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 (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
+}
+
+static void
+psppire_data_window_finish_init (PsppireDataWindow *de,
+ struct dataset *ds)
+{
+ static const struct dataset_callbacks cbs =
+ {
+ set_unsaved, /* changed */
+ transformation_change_callback, /* transformations_changed */
+ };
+
+ PsppireDict *dict;
GtkWidget *menubar;
GtkWidget *hb ;
GtkWidget *sb ;
GtkWidget *box = gtk_vbox_new (FALSE, 0);
- de->builder = builder_new ("data-editor.ui");
+
+ de->dataset = ds;
+ dict = psppire_dict_new_from_dict (dataset_dict (ds));
+ de->var_store = psppire_var_store_new (dict);
+ de->data_store = psppire_data_store_new (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->data_editor =
- PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
+ PSPPIRE_DATA_EDITOR (psppire_data_editor_new (de, de->var_store,
+ de->data_store));
- 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_callback (the_dataset, set_unsaved, de);
+ dataset_set_callbacks (de->dataset, &cbs, de);
connect_help (de->builder);
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);
+ 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);
-
- dataset_add_transform_change_callback (the_dataset,
- transformation_change_callback,
- de);
-
-
- vs = the_var_store;
-
- g_assert(vs); /* Traps a possible bug in w32 build */
-
- g_object_get (vs, "dictionary", &dict, NULL);
+ G_CALLBACK (set_paste_menuitem_sensitivity), de);
g_signal_connect (dict, "weight-changed",
G_CALLBACK (on_weight_change),
de);
- g_signal_connect (get_action_assert (de->builder, "edit_copy"),
- "activate",
- G_CALLBACK (on_edit_copy), de);
+ connect_action (de, "edit_copy", G_CALLBACK (on_edit_copy));
- g_signal_connect (get_action_assert (de->builder, "edit_cut"),
- "activate",
- G_CALLBACK (on_edit_cut), de);
+ connect_action (de, "edit_cut", G_CALLBACK (on_edit_cut));
+ connect_action (de, "file_new_data", G_CALLBACK (create_data_window));
+ connect_action (de, "file_import-text", 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));
- {
- GtkAction *action_data_new =
- get_action_assert (de->builder, "file_new_data");
-
- g_object_set (action_data_new,
- "tooltip", _("New data file"),
- "stock-id", "gtk-new",
- NULL);
-
- g_signal_connect (action_data_new, "activate",
- G_CALLBACK (new_file), de);
- }
-
-
-
- {
- GtkAction *invoke_text_import_assistant =
- get_action_assert (de->builder, "file_import-text");
-
- g_object_set (invoke_text_import_assistant,
- "tooltip", _("Import text data file"),
- "stock-id", "gtk-convert",
- NULL);
-
- g_signal_connect (invoke_text_import_assistant, "activate",
- G_CALLBACK (text_data_import_assistant), de);
- }
+ 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));
- {
- GtkAction *action_data_save = get_action_assert (de->builder, "file_save");
+ connect_action (de, "edit_paste", G_CALLBACK (on_edit_paste));
- g_signal_connect_swapped (action_data_save, "activate",
- G_CALLBACK (data_save), de);
- }
+ 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));
- {
- GtkAction *action_data_open = get_action_assert (de->builder, "file_open");
+ de->invoke_goto_dialog = connect_action (de, "edit_goto-case", G_CALLBACK (goto_case_dialog));
- g_signal_connect (action_data_open, "activate",
- G_CALLBACK (open_window), de);
- }
+ g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de);
{
- GtkAction *action_data_save_as =
- get_action_assert (de->builder, "file_save_as");
+ de->delete_cases = get_action_assert (de->builder, "edit_clear-cases");
- g_object_set (action_data_save_as,
- "tooltip", _("Save data to file"),
- "stock-id", "gtk-save-as",
- NULL);
+ g_signal_connect_swapped (de->delete_cases, "activate", G_CALLBACK (psppire_data_editor_delete_cases), de->data_editor);
- g_signal_connect_swapped (action_data_save_as, "activate",
- G_CALLBACK (data_save_as_dialog), de);
+ gtk_action_set_visible (de->delete_cases, FALSE);
}
{
- GtkAction *action_info_working_file =
- get_action_assert (de->builder, "file_information_working-file");
+ 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);
- g_signal_connect_swapped (action_info_working_file, "activate",
- G_CALLBACK (display_dict), de);
+ gtk_action_set_visible (de->delete_variables, FALSE);
}
- {
- GtkAction *action_info_external_file =
- get_action_assert (de->builder, "file_information_external-file");
+ 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));
- g_signal_connect_swapped (action_info_external_file, "activate",
- G_CALLBACK (sysfile_info), de);
- }
+ connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog));
+ connect_action (de, "transform_compute", G_CALLBACK (compute_dialog));
+ connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog));
+ connect_action (de, "edit_find", G_CALLBACK (find_dialog));
- g_signal_connect (get_action_assert (de->builder, "edit_paste"), "activate",
- G_CALLBACK (on_edit_paste),
- de);
+ connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog));
- {
- de->insert_case = get_action_assert (de->builder, "edit_insert-case");
- g_signal_connect (de->insert_case, "activate",
- G_CALLBACK (insert_case),
- de);
-
- }
+ connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog));
- {
- de->insert_variable = get_action_assert (de->builder, "action_insert-variable");
- g_signal_connect (de->insert_variable, "activate",
- G_CALLBACK (on_insert_variable),
- de);
-
+ 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));
- de->invoke_goto_dialog = get_action_assert (de->builder, "edit_goto-case");
- g_signal_connect (de->invoke_goto_dialog, "activate", G_CALLBACK (goto_case_dialog), de);
+ 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));
- {
- GtkAction *value_labels_action = get_action_assert (de->builder, "view_value-labels");
- g_signal_connect (value_labels_action, "toggled",
- G_CALLBACK (toggle_value_labels), de);
- }
-
- {
- de->delete_cases =
- get_action_assert (de->builder, "edit_clear-cases");
-
-
- g_object_set (de->delete_cases,
- "label", _("Clear"),
- "tooltip", _("Delete the cases at the selected position(s)"),
- "stock-id", "gtk-clear",
- NULL);
-
- 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_object_set (de->delete_variables,
- "label", _("Clear"),
- "tooltip", _("Delete the variables at the selected position(s)"),
- "stock-id", "gtk-clear",
- NULL);
-
-
- 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);
- }
-
-
-
- {
- GtkAction *invoke_transpose_dialog =
- get_action_assert (de->builder, "data_transpose");
-
-
- g_object_set (invoke_transpose_dialog,
- "tooltip", _("Transpose the cases with the variables"),
- "stock-id", "pspp-transpose",
- NULL);
-
- g_signal_connect (invoke_transpose_dialog, "activate",
- G_CALLBACK (transpose_dialog), de);
- }
-
-
- {
- GtkAction *invoke_sort_cases_dialog =
- get_action_assert (de->builder, "data_sort-cases");
-
-
- g_object_set (invoke_sort_cases_dialog,
- "tooltip", _("Sort cases in the active file"),
- "stock-id", "gtk-sort-ascending",
- NULL);
-
- g_signal_connect (invoke_sort_cases_dialog, "activate",
- G_CALLBACK (sort_cases_dialog), de);
- }
-
-
-
- {
- GtkAction *invoke_compute_dialog =
- get_action_assert (de->builder, "transform_compute");
-
- g_object_set (invoke_compute_dialog,
- "tooltip", _("Compute new values for a variable"),
- "stock-id", "pspp-compute",
- NULL);
-
- g_signal_connect (invoke_compute_dialog, "activate",
- G_CALLBACK (compute_dialog), de);
- }
-
- {
- GtkAction *invoke_find_dialog = get_action_assert (de->builder, "edit_find");
-
- g_signal_connect (invoke_find_dialog, "activate",
- G_CALLBACK (find_dialog), de);
- }
-
+ connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
- {
- GtkAction *invoke_split_file_dialog = get_action_assert (de->builder, "data_split-file");
-
- g_signal_connect (invoke_split_file_dialog, "activate",
- G_CALLBACK (split_file_dialog), de);
- }
-
-
- {
- GtkAction *invoke_weight_cases_dialog = get_action_assert (de->builder, "data_weight-cases");
-
- g_signal_connect (invoke_weight_cases_dialog, "activate",
- G_CALLBACK (weight_cases_dialog), de);
- }
-
-
-
- {
- GtkAction *invoke_variable_info_dialog = get_action_assert (de->builder, "utilities_variables");
-
- g_signal_connect (invoke_variable_info_dialog, "activate",
- G_CALLBACK (variable_info_dialog), de);
- }
-
-
-
- {
- GtkAction *invoke_oneway_anova_dialog =
- get_action_assert (de->builder, "oneway-anova");
-
- g_object_set (invoke_oneway_anova_dialog,
- "tooltip", _("Perform one way analysis of variance"),
- NULL);
-
- g_signal_connect (invoke_oneway_anova_dialog, "activate",
- G_CALLBACK (oneway_anova_dialog), de);
- }
-
-
- {
- GtkAction *invoke_t_test_independent_samples_dialog =
- get_action_assert (de->builder, "indep-t-test");
-
-
- g_object_set (invoke_t_test_independent_samples_dialog,
- "tooltip",
- _("Calculate T Test for samples from independent groups"),
- NULL);
-
- g_signal_connect (invoke_t_test_independent_samples_dialog, "activate",
- G_CALLBACK (t_test_independent_samples_dialog), de);
- }
-
-
- {
- GtkAction *invoke_t_test_paired_samples_dialog =
- get_action_assert (de->builder, "paired-t-test");
-
- g_object_set (invoke_t_test_paired_samples_dialog,
- "tooltip",
- _("Calculate T Test for paired samples"),
- NULL);
-
- g_signal_connect (invoke_t_test_paired_samples_dialog, "activate",
- G_CALLBACK (t_test_paired_samples_dialog), de);
- }
-
-
- {
- GtkAction *invoke_t_test_one_sample_dialog =
- get_action_assert (de->builder, "one-sample-t-test");
-
- g_object_set (invoke_t_test_one_sample_dialog,
- "tooltip",
- _("Calculate T Test for sample from a single distribution"),
- NULL);
-
- g_signal_connect (invoke_t_test_one_sample_dialog, "activate",
- G_CALLBACK (t_test_one_sample_dialog), de);
- }
-
-
- {
- GtkAction *invoke_comments_dialog =
- get_action_assert (de->builder, "utilities_comments");
-
-
- g_object_set (invoke_comments_dialog,
- "tooltip",
- _("Commentary text for the data file"),
- NULL);
-
- g_signal_connect (invoke_comments_dialog, "activate",
- G_CALLBACK (comments_dialog), de);
- }
-
-
-
- {
- GtkAction *invoke_rank_dialog =
- get_action_assert (de->builder, "transform_rank");
-
- g_object_set (invoke_rank_dialog,
- "stock-id", "pspp-rank-cases",
- "tooltip", _("Rank Cases"),
- NULL);
-
- g_signal_connect (invoke_rank_dialog, "activate",
- G_CALLBACK (rank_dialog), de);
- }
-
-
- {
- GtkAction *invoke_recode_same_dialog =
- get_action_assert (de->builder, "transform_recode-same");
-
- g_object_set (invoke_recode_same_dialog,
- "stock-id", "pspp-recode-same",
- "tooltip", _("Recode values into the same variables"),
- NULL);
-
- g_signal_connect (invoke_recode_same_dialog, "activate",
- G_CALLBACK (recode_same_dialog), de);
- }
-
-
- {
- GtkAction *invoke_recode_different_dialog =
- get_action_assert (de->builder, "transform_recode-different");
-
- g_object_set (invoke_recode_different_dialog,
- "stock-id", "pspp-recode-different",
- "tooltip", _("Recode values into different variables"),
- NULL);
-
- g_signal_connect (invoke_recode_different_dialog, "activate",
- G_CALLBACK (recode_different_dialog), de);
- }
-
-
- {
- GtkAction *invoke_descriptives_dialog =
- get_action_assert (de->builder, "analyze_descriptives");
-
- g_object_set (invoke_descriptives_dialog,
- "tooltip", _("Calculate descriptive statistics (mean, variance, ...)"),
- "stock-id", "pspp-descriptives",
- NULL);
-
- g_signal_connect (invoke_descriptives_dialog, "activate",
- G_CALLBACK (descriptives_dialog), de);
- }
-
-
- {
- GtkAction *invoke_frequencies_dialog =
- get_action_assert (de->builder, "analyze_frequencies");
-
- g_object_set (invoke_frequencies_dialog,
- "tooltip", _("Generate frequency statistics"),
- "stock-id", "pspp-frequencies",
- NULL);
-
- g_signal_connect (invoke_frequencies_dialog, "activate",
- G_CALLBACK (frequencies_dialog), de);
- }
-
-
- {
- GtkAction *invoke_crosstabs_dialog =
- get_action_assert (de->builder, "crosstabs");
-
- g_object_set (invoke_crosstabs_dialog,
- "tooltip", _("Generate crosstabulations"),
- "stock-id", "pspp-crosstabs",
- NULL);
-
- g_signal_connect (invoke_crosstabs_dialog, "activate",
- G_CALLBACK (crosstabs_dialog), de);
- }
-
-
-
- {
- GtkAction *invoke_examine_dialog =
- get_action_assert (de->builder, "analyze_explore");
-
- g_object_set (invoke_examine_dialog,
- "tooltip", _("Examine Data by Factors"),
- "stock-id", "pspp-examine",
- NULL);
-
- g_signal_connect (invoke_examine_dialog, "activate",
- G_CALLBACK (examine_dialog), de);
- }
-
-
- {
- GtkAction *invoke_regression_dialog =
- get_action_assert (de->builder, "linear-regression");
-
- g_object_set (invoke_regression_dialog,
- "tooltip", _("Estimate parameters of the linear model"),
- "stock-id", "pspp-regression",
- NULL
- );
-
- g_signal_connect (invoke_regression_dialog, "activate",
- G_CALLBACK (regression_dialog), de);
- }
-
- {
- GtkAction *invoke_reliability_dialog =
- get_action_assert (de->builder, "reliability");
-
- g_object_set (invoke_reliability_dialog,
- "tooltip", _("Reliability Analysis"),
- "stock-id", "pspp-reliability",
- NULL
- );
-
- g_signal_connect (invoke_reliability_dialog, "activate",
- G_CALLBACK (reliability_dialog), de);
- }
-
- {
- GtkAction *invoke_roc_dialog =
- get_action_assert (de->builder, "roc-curve");
-
- g_object_set (invoke_roc_dialog,
- "tooltip", _("ROC Curve"),
- "stock-id", "pspp-roc",
- NULL
- );
+ connect_action (de, "transform_rank", G_CALLBACK (rank_dialog));
- g_signal_connect (invoke_roc_dialog, "activate",
- G_CALLBACK (roc_dialog), de);
- }
-
- {
- GtkAction *invoke_correlation_dialog =
- get_action_assert (de->builder, "correlation");
+ connect_action (de, "transform_count", G_CALLBACK (count_dialog));
+
+ connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
+
+ connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog));
- g_object_set (invoke_correlation_dialog,
- "tooltip", _("Bivariate Correlation"),
- "stock-id", "pspp-correlation",
- NULL
- );
+ 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));
- g_signal_connect (invoke_correlation_dialog, "activate",
- G_CALLBACK (correlation_dialog), de);
- }
+ connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog));
- {
- GtkAction *invoke_factor_dialog =
- get_action_assert (de->builder, "factor-analysis");
+ connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
- g_object_set (invoke_factor_dialog,
- "tooltip", _("Principal Axis Factoring and Principal Components Analysis"),
- "stock-id", "pspp-factor",
- NULL
- );
+ connect_action (de, "correlation", G_CALLBACK (correlation_dialog));
+
+ connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
- g_signal_connect (invoke_factor_dialog, "activate",
- G_CALLBACK (factor_dialog), de);
- }
+ connect_action (de, "k-means", G_CALLBACK (k_means_dialog));
+ connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
+ connect_action (de, "binomial", G_CALLBACK (binomial_dialog));
+ connect_action (de, "runs", G_CALLBACK (runs_dialog));
+ connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog));
+ connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
+ connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog));
+
{
GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files");
- GtkWidget *menu_data =
- gtk_recent_chooser_menu_new_for_manager (the_recent_mgr);
+ GtkWidget *menu_data = 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);
+ GtkWidget *menu_files = gtk_recent_chooser_menu_new_for_manager (
+ gtk_recent_manager_get_default ());
+
+ 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);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu_data);
- g_signal_connect (menu_data, "selection-done",
- G_CALLBACK (on_recent_data_select),
- de);
+ g_signal_connect (menu_data, "selection-done", G_CALLBACK (on_recent_data_select), de);
{
GtkRecentFilter *filter = gtk_recent_filter_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu_files);
- g_signal_connect (menu_files, "selection-done",
- G_CALLBACK (on_recent_files_select),
- de);
-
- }
-
- g_signal_connect (get_action_assert (de->builder,"file_new_syntax"),
- "activate",
- G_CALLBACK (create_syntax_window),
- NULL);
-
+ g_signal_connect (menu_files, "selection-done", G_CALLBACK (on_recent_files_select), de);
- {
- GtkAction *abt = get_action_assert (de->builder, "help_about");
- g_object_set (abt, "stock-id", "gtk-about", NULL);
- g_signal_connect (abt,
- "activate",
- G_CALLBACK (about_new),
- de);
}
-
- g_signal_connect (get_action_assert (de->builder,"help_reference"),
- "activate",
- G_CALLBACK (reference_manual),
- de);
+ connect_action (de, "file_new_syntax", G_CALLBACK (create_syntax_window));
g_signal_connect (de->data_editor,
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 (get_action_assert (de->builder, "view_statusbar"),
- "activate",
- G_CALLBACK (status_bar_activate), de);
-
+ connect_action (de, "view_statusbar", G_CALLBACK (status_bar_activate));
- g_signal_connect (get_action_assert (de->builder, "view_gridlines"),
- "activate",
- G_CALLBACK (grid_lines_activate), de);
+ connect_action (de, "view_gridlines", G_CALLBACK (grid_lines_activate));
+ connect_action (de, "view_data", G_CALLBACK (data_view_activate));
+ connect_action (de, "view_variables", G_CALLBACK (variable_view_activate));
- g_signal_connect (get_action_assert (de->builder, "view_data"),
- "activate",
- G_CALLBACK (data_view_activate), de);
+ connect_action (de, "view_fonts", G_CALLBACK (fonts_activate));
- g_signal_connect (get_action_assert (de->builder, "view_variables"),
- "activate",
- G_CALLBACK (variable_view_activate), de);
+ connect_action (de, "file_quit", G_CALLBACK (file_quit));
+ connect_action (de, "transform_run-pending", G_CALLBACK (execute));
- {
- GtkAction *font_action =
- get_action_assert (de->builder, "view_fonts");
-
- g_object_set (font_action,
- "stock-id", "gtk-select-font",
- NULL);
-
- g_signal_connect (font_action,
- "activate",
- G_CALLBACK (fonts_activate), de);
- }
-
-
-
- g_signal_connect (get_action_assert (de->builder, "file_quit"),
- "activate",
- G_CALLBACK (file_quit), de);
-
- g_signal_connect (get_action_assert (de->builder, "transform_run-pending"),
- "activate",
- G_CALLBACK (execute), de);
-
-
- g_signal_connect (get_action_assert (de->builder, "windows_minimise_all"),
- "activate",
- G_CALLBACK (psppire_window_minimise_all), NULL);
+ connect_action (de, "windows_minimise_all", G_CALLBACK (psppire_window_minimise_all));
+ g_signal_connect_swapped (get_action_assert (de->builder, "windows_split"), "toggled", G_CALLBACK (toggle_split_window), de);
{
- GtkAction *split_window_action =
- get_action_assert (de->builder, "windows_split");
-
- g_object_set (split_window_action,
- "tooltip", _("Split the window vertically and horizontally"),
- "stock-id", "pspp-split-window",
- NULL);
+ GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
- g_signal_connect (split_window_action, "toggled",
- G_CALLBACK (toggle_split_window),
- de);
+ merge_help_menu (uim);
}
{
- GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
+ GtkWidget *data_sheet_cases_popup_menu = get_widget_assert (de->builder,
+ "datasheet-cases-popup");
- PSPPIRE_WINDOW (de)->menu =
- GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all")->parent);
- }
+ GtkWidget *var_sheet_variable_popup_menu = get_widget_assert (de->builder,
+ "varsheet-variable-popup");
- {
- GtkMenu *data_sheet_variable_popup_menu = get_widget_assert (de->builder,
- "datasheet-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_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);
-
- GtkMenu *var_sheet_variable_popup_menu =
- GTK_MENU (create_var_sheet_variable_popup_menu (de));
-
- GtkMenu *data_sheet_cases_popup_menu =
- GTK_MENU (create_data_sheet_cases_popup_menu (de));
+ G_CALLBACK (psppire_data_editor_sort_descending),
+ de->data_editor);
g_object_set (de->data_editor,
"datasheet-column-menu", data_sheet_variable_popup_menu,
gtk_widget_show (GTK_WIDGET (de->data_editor));
gtk_widget_show (box);
+
+ ll_push_head (&all_data_windows, &de->ll);
}
+static void
+psppire_data_window_dispose (GObject *object)
+{
+ PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (object);
-GtkWidget*
-psppire_data_window_new (void)
+ if (dw->builder != NULL)
+ {
+ g_object_unref (dw->builder);
+ dw->builder = NULL;
+ }
+
+ if (dw->var_store)
+ {
+ g_object_unref (dw->var_store);
+ dw->var_store = 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_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- return GTK_WIDGET (g_object_new (psppire_data_window_get_type (),
- "description", _("Data Editor"),
- NULL));
+ 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;
+ };
}
+GtkWidget*
+psppire_data_window_new (struct dataset *ds)
+{
+ GtkWidget *dw;
+ if (the_session == NULL)
+ the_session = session_create ();
+ if (ds == NULL)
+ {
+ static int n_datasets;
+ char *dataset_name;
-\f
+ dataset_name = xasprintf ("DataSet%d", ++n_datasets);
+ 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 (),
+ /* TRANSLATORS: This will form a filename. Please avoid whitespace. */
+ "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_var_store_get_var_cnt (dw->var_store) == 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;
+}
+
+void
+create_data_window (void)
+{
+ gtk_widget_show (psppire_data_window_new (NULL));
+}
+
+void
+open_data_window (PsppireWindow *victim, const char *file_name)
+{
+ GtkWidget *window;
+
+ if (PSPPIRE_IS_DATA_WINDOW (victim)
+ && psppire_data_window_is_empty (PSPPIRE_DATA_WINDOW (victim)))
+ window = GTK_WIDGET (victim);
+ else
+ window = psppire_data_window_new (NULL);
+
+ psppire_window_load (PSPPIRE_WINDOW (window), file_name);
+ gtk_widget_show (window);
+}