1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2016,
3 2020 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),
127 g_return_if_fail (n_vars <= 1);
129 g_object_set (act->var_info, "variable", n_vars > 0 ? vars[0] : NULL, NULL);
134 jump_to (PsppireDialog *d, gint response, gpointer data)
136 PsppireDataWindow *dw;
137 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (data);
138 struct variable **vars;
141 if (response != PSPPIRE_RESPONSE_GOTO)
144 psppire_dict_view_get_selected_variables (PSPPIRE_DICT_VIEW (pda->source),
148 g_object_get (pda, "top-level", &dw, NULL);
150 psppire_data_editor_goto_variable (dw->data_editor,
151 var_get_dict_index (vars[0]));
157 psppire_dialog_action_var_info_activate (PsppireDialogAction *a, GVariant *param)
159 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
160 PsppireDialogActionVarInfo *act = PSPPIRE_DIALOG_ACTION_VAR_INFO (pda);
162 GtkBuilder *xml = builder_new ("variable-info.ui");
164 act->var_info = get_widget_assert (xml, "var-info0");
166 pda->dialog = get_widget_assert (xml, "variable-info-dialog");
167 pda->source = get_widget_assert (xml, "treeview2");
169 g_object_set (pda->source,
170 "selection-mode", GTK_SELECTION_MULTIPLE,
173 g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (pda->source)),
174 "changed", G_CALLBACK (populate_output),
177 g_signal_connect (pda->dialog, "response", G_CALLBACK (jump_to),
180 psppire_dialog_action_set_valid_predicate (pda,
181 treeview_item_selected);
187 psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class)
189 PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_var_info_activate;
190 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
195 psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act)