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/>. */
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.
37 generate_syntax (PsppireDialogAction
*act
)
40 PsppireDialogActionFlip
*rd
= PSPPIRE_DIALOG_ACTION_FLIP (act
);
42 GString
*string
= g_string_new ("FLIP");
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
));
52 g_string_append_printf (string
, " /NEWNAME = %s", text
);
54 g_string_append (string
, ".\n");
58 g_string_free (string
, FALSE
);
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
);
76 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (act
->entry
))))
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
), "");
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
);
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
);
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
;
128 psppire_dialog_action_flip_init (PsppireDialogActionFlip
*act
)