Change some instances of GtkAction to PsppireDialogAction
[pspp.git] / src / ui / gui / psppire-dialog-action-flip.c
blob194864595916d52b7ebf586a72d409c3852bec09
1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2013 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/>. */
18 #include <config.h>
20 #include "psppire-dialog-action-flip.h"
22 #include "psppire-var-view.h"
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
27 static void psppire_dialog_action_flip_init (PsppireDialogActionFlip *act);
28 static void psppire_dialog_action_flip_class_init (PsppireDialogActionFlipClass *class);
30 G_DEFINE_TYPE (PsppireDialogActionFlip, psppire_dialog_action_flip, PSPPIRE_TYPE_DIALOG_ACTION);
34 FLIP /VARIABLES=var_list /NEWNAMES=var_name.
36 static char *
37 generate_syntax (PsppireDialogAction *act)
39 const gchar *text;
40 PsppireDialogActionFlip *rd = PSPPIRE_DIALOG_ACTION_FLIP (act);
42 GString *string = g_string_new ("FLIP");
43 gchar *syntax ;
45 g_string_append (string, " /VARIABLES = ");
47 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->dest), 0, string);
49 text = gtk_entry_get_text (GTK_ENTRY (rd->entry));
51 if ( text)
52 g_string_append_printf (string, " /NEWNAME = %s", text);
54 g_string_append (string, ".\n");
56 syntax = string->str;
58 g_string_free (string, FALSE);
60 return syntax;
64 static gboolean
65 dialog_state_valid (gpointer a)
67 PsppireDialogActionFlip *act = PSPPIRE_DIALOG_ACTION_FLIP (a);
69 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (act->dest));
71 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
73 if ( n_rows == 0 )
74 return FALSE;
76 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (act->entry))))
77 return FALSE;
79 return TRUE;
82 static void
83 refresh (PsppireDialogAction *rd_)
85 PsppireDialogActionFlip *rd = PSPPIRE_DIALOG_ACTION_FLIP (rd_);
86 GtkTreeModel *dmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->dest));
88 gtk_list_store_clear (GTK_LIST_STORE (dmodel));
89 gtk_entry_set_text (GTK_ENTRY (rd->entry), "");
92 static void
93 psppire_dialog_action_flip_activate (PsppireDialogAction *a)
95 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
96 PsppireDialogActionFlip *act = PSPPIRE_DIALOG_ACTION_FLIP (a);
98 GHashTable *thing = psppire_dialog_action_get_hash_table (pda);
99 GtkBuilder *xml = g_hash_table_lookup (thing, a);
100 if (!xml)
102 xml = builder_new ("transpose.ui");
103 g_hash_table_insert (thing, a, xml);
106 pda->dialog = get_widget_assert (xml, "transpose-dialog");
107 pda->source = get_widget_assert (xml, "source-treeview");
109 act->dest = get_widget_assert (xml, "variables-treeview");
110 act->entry = get_widget_assert (xml, "new-name-entry");
112 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
113 psppire_dialog_action_set_refresh (pda, refresh);
115 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_flip_parent_class)->activate)
116 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_flip_parent_class)->activate (pda);
119 static void
120 psppire_dialog_action_flip_class_init (PsppireDialogActionFlipClass *class)
122 psppire_dialog_action_set_activation (class, psppire_dialog_action_flip_activate);
123 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
127 static void
128 psppire_dialog_action_flip_init (PsppireDialogActionFlip *act)