From b0c8b28cd7408466052e5182b69e09f150343154 Mon Sep 17 00:00:00 2001
From: John Darrington
Date: Sun, 22 Jan 2012 17:52:34 +0100
Subject: [PATCH 1/3] New object PsppireDialogAction
This object is a subclass of GtkAction. It will be used in upcoming
commits to provide a common interface for the behaviour of dialog boxes.
---
src/ui/gui/automake.mk | 2 +
src/ui/gui/psppire-dialog-action.c | 224 ++++++++++++++++++++++++++++++++++++
src/ui/gui/psppire-dialog-action.h | 85 ++++++++++++++
3 files changed, 311 insertions(+), 0 deletions(-)
create mode 100644 src/ui/gui/psppire-dialog-action.c
create mode 100644 src/ui/gui/psppire-dialog-action.h
diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk
index 76e7ae0..7dcc799 100644
--- a/src/ui/gui/automake.mk
+++ b/src/ui/gui/automake.mk
@@ -212,6 +212,8 @@ src_ui_gui_psppire_SOURCES = \
src/ui/gui/psppire-data-window.c \
src/ui/gui/psppire-data-window.h \
src/ui/gui/psppire-dialog.h \
+ src/ui/gui/psppire-dialog-action.c \
+ src/ui/gui/psppire-dialog-action.h \
src/ui/gui/psppire-dict.c \
src/ui/gui/psppire-dict.h \
src/ui/gui/psppire-dictview.c \
diff --git a/src/ui/gui/psppire-dialog-action.c b/src/ui/gui/psppire-dialog-action.c
new file mode 100644
index 0000000..84c76b7
--- /dev/null
+++ b/src/ui/gui/psppire-dialog-action.c
@@ -0,0 +1,224 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+
+#include
+
+#include "psppire-dialog-action.h"
+#include "psppire-dialog.h"
+#include "executor.h"
+#include "helper.h"
+#include "psppire-data-window.h"
+
+static void psppire_dialog_action_init (PsppireDialogAction *act);
+static void psppire_dialog_action_class_init (PsppireDialogActionClass *class);
+
+static void psppire_dialog_action_finalize (GObject *object);
+static void psppire_dialog_action_dispose (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+/* Properties */
+enum
+{
+ PROP_0,
+ PROP_MANAGER,
+ PROP_TOPLEVEL,
+};
+
+static void
+psppire_dialog_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireDialogAction *act = PSPPIRE_DIALOG_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_MANAGER:
+ {
+
+ GObject *p = g_value_get_object (value);
+ act->uim = GTK_UI_MANAGER (p);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+
+static void
+psppire_dialog_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireDialogAction *dialog_action = PSPPIRE_DIALOG_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_MANAGER:
+ g_value_take_object (value, dialog_action->uim);
+ break;
+ case PROP_TOPLEVEL:
+ g_value_take_object (value, dialog_action->toplevel);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+
+GType
+psppire_dialog_action_get_type (void)
+{
+ static GType pda_type = 0;
+
+ if (!pda_type)
+ {
+ static const GTypeInfo pda_info =
+ {
+ sizeof (PsppireDialogActionClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) psppire_dialog_action_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (PsppireDialogAction),
+ 0,
+ (GInstanceInitFunc) psppire_dialog_action_init,
+ };
+
+ pda_type = g_type_register_static (GTK_TYPE_ACTION,
+ "PsppireDialogAction",
+ &pda_info, G_TYPE_FLAG_ABSTRACT);
+ }
+
+ return pda_type;
+}
+
+
+
+static void
+psppire_dialog_action_dispose (GObject *object)
+{
+}
+
+static void
+psppire_dialog_action_finalize (GObject *object)
+{
+}
+
+static void
+psppire_dialog_action_activate (PsppireDialogAction *act)
+{
+ gint response;
+
+ PsppireVarStore *vs;
+ PsppireDialogActionClass *class = PSPPIRE_DIALOG_ACTION_GET_CLASS (act);
+
+ GSList *sl = gtk_ui_manager_get_toplevels (act->uim, GTK_UI_MANAGER_MENUBAR | GTK_UI_MANAGER_TOOLBAR);
+ g_return_if_fail (sl);
+
+ act->toplevel = gtk_widget_get_toplevel (GTK_WIDGET (sl->data));
+ g_slist_free (sl);
+
+ vs = PSPPIRE_DATA_WINDOW(act->toplevel)->var_store;
+
+ g_object_get (vs, "dictionary", &act->dict, NULL);
+
+ g_object_set (act->source, "model", act->dict, NULL);
+
+ gtk_window_set_transient_for (GTK_WINDOW (act->dialog), GTK_WINDOW (act->toplevel));
+
+
+ if (GTK_ACTION_CLASS (parent_class)->activate)
+ GTK_ACTION_CLASS (parent_class)->activate ( GTK_ACTION (act));
+
+ response = psppire_dialog_run (PSPPIRE_DIALOG (act->dialog));
+
+ if ( class->generate_syntax )
+ {
+ switch (response)
+ {
+ case GTK_RESPONSE_OK:
+ g_free (execute_syntax_string (PSPPIRE_DATA_WINDOW (act->toplevel),
+ class->generate_syntax (act)));
+ break;
+ case PSPPIRE_RESPONSE_PASTE:
+ g_free (paste_syntax_to_window (class->generate_syntax (act)));
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static void
+psppire_dialog_action_class_init (PsppireDialogActionClass *class)
+{
+ GObjectClass *object_class;
+ GtkActionClass *action_class ;
+
+ GParamSpec *manager_spec =
+ g_param_spec_object ("manager",
+ "Manager",
+ "The GtkUIManager which created this object",
+ GTK_TYPE_UI_MANAGER,
+ G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
+
+ GParamSpec *toplevel_spec =
+ g_param_spec_object ("top-level",
+ "Top Level",
+ "The top level widget to which this dialog action belongs",
+ GTK_TYPE_WINDOW,
+ G_PARAM_READABLE);
+
+
+ parent_class = g_type_class_peek_parent (class);
+ object_class = G_OBJECT_CLASS (class);
+ action_class = GTK_ACTION_CLASS (class);
+
+ object_class->finalize = psppire_dialog_action_finalize;
+ object_class->dispose = psppire_dialog_action_dispose;
+
+ object_class->set_property = psppire_dialog_action_set_property;
+ object_class->get_property = psppire_dialog_action_get_property;
+
+ class->generate_syntax = NULL;
+
+ class->activate = psppire_dialog_action_activate;
+
+ g_object_class_install_property (object_class,
+ PROP_MANAGER,
+ manager_spec);
+
+ g_object_class_install_property (object_class,
+ PROP_TOPLEVEL,
+ toplevel_spec);
+}
+
+
+static void
+psppire_dialog_action_init (PsppireDialogAction *act)
+{
+ act->toplevel = NULL;
+ act->dict = NULL;
+}
diff --git a/src/ui/gui/psppire-dialog-action.h b/src/ui/gui/psppire-dialog-action.h
new file mode 100644
index 0000000..b63e23c
--- /dev/null
+++ b/src/ui/gui/psppire-dialog-action.h
@@ -0,0 +1,85 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+
+#include
+#include
+
+#include "psppire-dict.h"
+#include
+
+#ifndef __PSPPIRE_DIALOG_ACTION_H__
+#define __PSPPIRE_DIALOG_ACTION_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION (psppire_dialog_action_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PSPPIRE_TYPE_DIALOG_ACTION, PsppireDialogAction))
+
+#define PSPPIRE_DIALOG_ACTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PSPPIRE_TYPE_DIALOG_ACTION, \
+ PsppireDialogActionClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION))
+
+#define PSPPIRE_IS_DIALOG_ACTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION))
+
+
+#define PSPPIRE_DIALOG_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PSPPIRE_TYPE_DIALOG_ACTION, \
+ PsppireDialogActionClass))
+
+typedef struct _PsppireDialogAction PsppireDialogAction;
+typedef struct _PsppireDialogActionClass PsppireDialogActionClass;
+
+
+struct _PsppireDialogAction
+{
+ GtkAction parent;
+
+ /*< private >*/
+ gboolean dispose_has_run ;
+ GtkUIManager *uim;
+
+ GtkWidget *source;
+ GtkWidget *dialog;
+
+ GtkWidget *toplevel;
+ PsppireDict *dict;
+};
+
+
+struct _PsppireDialogActionClass
+{
+ GtkActionClass parent_class;
+ void (*activate) (PsppireDialogAction *);
+ char * (*generate_syntax) (PsppireDialogAction *);
+};
+
+
+GType psppire_dialog_action_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_H__ */
--
1.7.2.5