1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "psppire-dialog-action.h"
21 #include "psppire-dialog.h"
24 #include "psppire-data-window.h"
26 static void psppire_dialog_action_init (PsppireDialogAction *act);
27 static void psppire_dialog_action_class_init (PsppireDialogActionClass *class);
29 G_DEFINE_ABSTRACT_TYPE (PsppireDialogAction, psppire_dialog_action, GTK_TYPE_ACTION);
40 psppire_dialog_action_set_property (GObject *object,
45 PsppireDialogAction *act = PSPPIRE_DIALOG_ACTION (object);
52 GObject *p = g_value_get_object (value);
53 act->uim = GTK_UI_MANAGER (p);
57 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
64 psppire_dialog_action_get_property (GObject *object,
69 PsppireDialogAction *dialog_action = PSPPIRE_DIALOG_ACTION (object);
74 g_value_take_object (value, dialog_action->uim);
77 g_value_take_object (value, dialog_action->toplevel);
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
87 psppire_dialog_action_activate (PsppireDialogAction *act)
91 PsppireDialogActionClass *class = PSPPIRE_DIALOG_ACTION_GET_CLASS (act);
93 GSList *sl = gtk_ui_manager_get_toplevels (act->uim, GTK_UI_MANAGER_MENUBAR | GTK_UI_MANAGER_TOOLBAR);
94 g_return_if_fail (sl);
96 act->toplevel = gtk_widget_get_toplevel (GTK_WIDGET (sl->data));
99 act->dict = PSPPIRE_DATA_WINDOW(act->toplevel)->dict;
101 g_object_set (act->source, "model", act->dict, NULL);
103 gtk_window_set_transient_for (GTK_WINDOW (act->dialog), GTK_WINDOW (act->toplevel));
106 if (GTK_ACTION_CLASS (psppire_dialog_action_parent_class)->activate)
107 GTK_ACTION_CLASS (psppire_dialog_action_parent_class)->activate ( GTK_ACTION (act));
109 gtk_widget_grab_focus (act->source);
111 response = psppire_dialog_run (PSPPIRE_DIALOG (act->dialog));
113 if ( class->generate_syntax )
117 case GTK_RESPONSE_OK:
118 g_free (execute_syntax_string (PSPPIRE_DATA_WINDOW (act->toplevel),
119 class->generate_syntax (act)));
121 case PSPPIRE_RESPONSE_PASTE:
122 g_free (paste_syntax_to_window (class->generate_syntax (act)));
129 gtk_widget_destroy (act->dialog);
133 psppire_dialog_action_class_init (PsppireDialogActionClass *class)
135 GObjectClass *object_class = G_OBJECT_CLASS (class);
137 GParamSpec *manager_spec =
138 g_param_spec_object ("manager",
140 "The GtkUIManager which created this object",
144 GParamSpec *toplevel_spec =
145 g_param_spec_object ("top-level",
147 "The top level widget to which this dialog action belongs",
151 object_class->set_property = psppire_dialog_action_set_property;
152 object_class->get_property = psppire_dialog_action_get_property;
154 class->generate_syntax = NULL;
156 class->activate = psppire_dialog_action_activate;
158 g_object_class_install_property (object_class,
162 g_object_class_install_property (object_class,
169 psppire_dialog_action_init (PsppireDialogAction *act)
171 act->toplevel = NULL;
177 psppire_dialog_action_set_valid_predicate (PsppireDialogAction *act,
178 ContentsAreValid dialog_state_valid)
180 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (act->dialog),
181 dialog_state_valid, act);
185 psppire_dialog_action_set_refresh (PsppireDialogAction *pda,
186 PsppireDialogActionRefresh refresh)
188 g_signal_connect_swapped (pda->dialog, "refresh", G_CALLBACK (refresh), pda);