1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Free Software Foundation
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "ui/gui/psppire-dialog-action-var-info.h"
25 #include "data/format.h"
26 #include "data/value-labels.h"
27 #include "data/variable.h"
28 #include "libpspp/i18n.h"
29 #include "output/driver.h"
30 #include "ui/gui/builder-wrapper.h"
31 #include "ui/gui/executor.h"
32 #include "ui/gui/helper.h"
33 #include "ui/gui/psppire-data-window.h"
34 #include "ui/gui/psppire-dialog.h"
35 #include "ui/gui/psppire-dictview.h"
36 #include "ui/gui/psppire-output-view.h"
37 #include "ui/gui/var-display.h"
39 static void psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act);
40 static void psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class);
42 G_DEFINE_TYPE (PsppireDialogActionVarInfo, psppire_dialog_action_var_info, PSPPIRE_TYPE_DIALOG_ACTION);
45 #define _(msgid) gettext (msgid)
46 #define N_(msgid) msgid
49 treeview_item_selected (gpointer data)
51 PsppireDialogAction *pda = data;
52 GtkTreeView *tv = GTK_TREE_VIEW (pda->source);
53 GtkTreeSelection *selection = gtk_tree_view_get_selection (tv);
55 return gtk_tree_selection_count_selected_rows (selection) >= 1;
59 generate_syntax__ (const PsppireDialogAction *act, const char *prefix)
61 struct variable **vars;
68 psppire_dict_view_get_selected_variables (PSPPIRE_DICT_VIEW (act->source),
71 s = g_string_new (prefix);
73 for (i = 0; i < n_vars; i++)
75 const char *name = var_get_name (vars[i]);
76 size_t name_len = strlen (name);
80 if (line_len + 1 + name_len > 69)
82 g_string_append_c (s, '\n');
87 g_string_append_c (s, ' ');
92 g_string_append (s, name);
99 g_string_free (s, FALSE);
104 generate_syntax (const PsppireDialogAction *act)
106 return generate_syntax__ (act, "");
112 populate_output (GtkTreeSelection *selection, gpointer data)
114 PsppireDialogActionVarInfo *act = data;
115 GtkTreeView *treeview = gtk_tree_selection_get_tree_view (selection);
119 struct variable **vars;
121 g_object_get (treeview, "model", &dict,
124 psppire_dict_view_get_selected_variables (PSPPIRE_DICT_VIEW (treeview),
129 PsppireDataWindow *dw;
131 g_object_get (act, "top-level", &dw, NULL);
133 psppire_output_view_clear (act->output);
135 output_engine_push ();
136 psppire_output_view_register_driver (act->output);
137 g_free (execute_syntax_string (
138 dw, generate_syntax__ (&act->parent,
139 "DISPLAY DICTIONARY /VARIABLES=")));
140 output_engine_pop ();
146 jump_to (PsppireDialog *d, gint response, gpointer data)
148 PsppireDataWindow *dw;
149 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (data);
150 struct variable **vars;
153 if (response != PSPPIRE_RESPONSE_GOTO)
156 psppire_dict_view_get_selected_variables (PSPPIRE_DICT_VIEW (pda->source),
160 g_object_get (pda, "top-level", &dw, NULL);
162 psppire_data_editor_goto_variable (dw->data_editor,
163 var_get_dict_index (vars[0]));
169 psppire_dialog_action_var_info_activate (PsppireDialogAction *a, GVariant *param)
171 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
172 PsppireDialogActionVarInfo *act = PSPPIRE_DIALOG_ACTION_VAR_INFO (pda);
174 GtkBuilder *xml = builder_new ("variable-info.ui");
177 psppire_output_view_new (GTK_LAYOUT (get_widget_assert (xml, "layout1")),
180 pda->dialog = get_widget_assert (xml, "variable-info-dialog");
181 pda->source = get_widget_assert (xml, "treeview2");
183 g_object_set (pda->source,
184 "selection-mode", GTK_SELECTION_MULTIPLE,
187 g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (pda->source)),
188 "changed", G_CALLBACK (populate_output),
191 g_signal_connect (pda->dialog, "response", G_CALLBACK (jump_to),
194 psppire_dialog_action_set_valid_predicate (pda,
195 treeview_item_selected);
201 psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class)
203 PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_var_info_activate;
204 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
209 psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act)