projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
gui: Fix temporary filtering by a variable's value.
[pspp]
/
src
/
ui
/
gui
/
val-labs-dialog.c
diff --git
a/src/ui/gui/val-labs-dialog.c
b/src/ui/gui/val-labs-dialog.c
index 42dd0b349c530c3f7a3d3daa5e970b78d541c0b1..950a59e6b4ef860ee44ce1240920bda3e4d32c85 100644
(file)
--- a/
src/ui/gui/val-labs-dialog.c
+++ b/
src/ui/gui/val-labs-dialog.c
@@
-1,5
+1,5
@@
/* PSPPIRE - a graphical user interface for PSPP.
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2005, 2009 Free Software Foundation
+ Copyright (C) 2005, 2009
, 2010, 2011
Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-30,11
+30,16
@@
#include "psppire-var-store.h"
#include <libpspp/i18n.h>
#include "psppire-var-store.h"
#include <libpspp/i18n.h>
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
struct val_labs_dialog
{
GtkWidget *window;
struct val_labs_dialog
{
GtkWidget *window;
- PsppireSheet *vs;
+ PsppireVarStore *var_store;
+ PsppireDict *dict;
/* The variable to be updated */
struct variable *pv;
/* The variable to be updated */
struct variable *pv;
@@
-71,11
+76,12
@@
on_label_entry_change (GtkEntry *entry, gpointer data)
text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value (text, &v,
- *var_get_write_format (dialog->pv));
-
+ text_to_value (text,
+ dialog->dict,
+ dialog->pv,
+ &v);
- if (
val_labs_find (dialog->labs, v)
)
+ if (
val_labs_find (dialog->labs, &v)
)
{
gtk_widget_set_sensitive (dialog->change_button, TRUE);
gtk_widget_set_sensitive (dialog->add_button, FALSE);
{
gtk_widget_set_sensitive (dialog->change_button, TRUE);
gtk_widget_set_sensitive (dialog->add_button, FALSE);
@@
-85,6
+91,8
@@
on_label_entry_change (GtkEntry *entry, gpointer data)
gtk_widget_set_sensitive (dialog->change_button, FALSE);
gtk_widget_set_sensitive (dialog->add_button, TRUE);
}
gtk_widget_set_sensitive (dialog->change_button, FALSE);
gtk_widget_set_sensitive (dialog->add_button, TRUE);
}
+
+ value_destroy (&v, var_get_width (dialog->pv));
}
}
@@
-134,15
+142,17
@@
select_treeview_from_value (GtkTreeView *treeview, union value *val)
static void
on_value_entry_change (GtkEntry *entry, gpointer data)
{
static void
on_value_entry_change (GtkEntry *entry, gpointer data)
{
- char *s;
+ c
onst c
har *s;
struct val_labs_dialog *dialog = data;
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
union value v;
struct val_labs_dialog *dialog = data;
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
union value v;
- text_to_value (text, &v,
- *var_get_write_format (dialog->pv));
+ text_to_value (text,
+ dialog->dict,
+ dialog->pv,
+ &v);
g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
@@
-151,7
+161,7
@@
on_value_entry_change (GtkEntry *entry, gpointer data)
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry),"");
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry),"");
- if ( (s = val_labs_find (dialog->labs, v)) )
+ if ( (s = val_labs_find (dialog->labs,
&
v)) )
{
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry), s);
gtk_widget_set_sensitive (dialog->add_button, FALSE);
{
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry), s);
gtk_widget_set_sensitive (dialog->add_button, FALSE);
@@
-166,6
+176,8
@@
on_value_entry_change (GtkEntry *entry, gpointer data)
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
+
+ value_destroy (&v, var_get_width (dialog->pv));
}
}
@@
-180,7
+192,7
@@
val_labs_ok (GtkWidget *w, gpointer data)
val_labs_destroy (dialog->labs);
val_labs_destroy (dialog->labs);
- dialog->labs =
0
;
+ dialog->labs =
NULL
;
gtk_widget_hide (dialog->window);
gtk_widget_hide (dialog->window);
@@
-194,7
+206,7
@@
val_labs_cancel (struct val_labs_dialog *dialog)
{
val_labs_destroy (dialog->labs);
{
val_labs_destroy (dialog->labs);
- dialog->labs =
0
;
+ dialog->labs =
NULL
;
gtk_widget_hide (dialog->window);
}
gtk_widget_hide (dialog->window);
}
@@
-202,14
+214,12
@@
val_labs_cancel (struct val_labs_dialog *dialog)
/* Callback for when the Value Labels dialog is closed using
the Cancel button.*/
/* Callback for when the Value Labels dialog is closed using
the Cancel button.*/
-static
gint
+static
void
on_cancel (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
val_labs_cancel (dialog);
on_cancel (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
val_labs_cancel (dialog);
-
- return FALSE;
}
}
@@
-227,14
+237,15
@@
on_delete (GtkWidget *w, GdkEvent *e, gpointer data)
/* Return the value-label pair currently selected in the dialog box */
/* Return the value-label pair currently selected in the dialog box */
-static struct val_lab *
-get_selected_tuple (struct val_labs_dialog *dialog)
+static void
+get_selected_tuple (struct val_labs_dialog *dialog,
+ union value *valuep, const char **label)
{
GtkTreeView *treeview = GTK_TREE_VIEW (dialog->treeview);
{
GtkTreeView *treeview = GTK_TREE_VIEW (dialog->treeview);
- static struct val_lab vl;
GtkTreeIter iter ;
GValue the_value = {0};
GtkTreeIter iter ;
GValue the_value = {0};
+ union value value;
GtkTreeSelection* sel = gtk_tree_view_get_selection (treeview);
GtkTreeSelection* sel = gtk_tree_view_get_selection (treeview);
@@
-244,19
+255,24
@@
get_selected_tuple (struct val_labs_dialog *dialog)
gtk_tree_model_get_value (model, &iter, 1, &the_value);
gtk_tree_model_get_value (model, &iter, 1, &the_value);
- v
l.v
alue.f = g_value_get_double (&the_value);
+ value.f = g_value_get_double (&the_value);
g_value_unset (&the_value);
g_value_unset (&the_value);
- vl.label = val_labs_find (dialog->labs, vl.value);
-
- return &vl;
+ if (valuep != NULL)
+ *valuep = value;
+ if (label != NULL)
+ {
+ struct val_lab *vl = val_labs_lookup (dialog->labs, &value);
+ if (vl != NULL)
+ *label = val_lab_get_escaped_label (vl);
+ }
}
static void repopulate_dialog (struct val_labs_dialog *dialog);
/* Callback which occurs when the "Change" button is clicked */
}
static void repopulate_dialog (struct val_labs_dialog *dialog);
/* Callback which occurs when the "Change" button is clicked */
-static
gint
+static
void
on_change (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
on_change (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
@@
-265,10
+281,12
@@
on_change (GtkWidget *w, gpointer data)
union value v;
union value v;
- text_to_value (val_text, &v,
- *var_get_write_format (dialog->pv));
+ text_to_value (val_text,
+ dialog->dict,
+ dialog->pv,
+ &v);
- val_labs_replace (dialog->labs, v,
+ val_labs_replace (dialog->labs,
&
v,
gtk_entry_get_text (GTK_ENTRY (dialog->label_entry)));
gtk_widget_set_sensitive (dialog->change_button, FALSE);
gtk_entry_get_text (GTK_ENTRY (dialog->label_entry)));
gtk_widget_set_sensitive (dialog->change_button, FALSE);
@@
-276,11
+294,11
@@
on_change (GtkWidget *w, gpointer data)
repopulate_dialog (dialog);
gtk_widget_grab_focus (dialog->value_entry);
repopulate_dialog (dialog);
gtk_widget_grab_focus (dialog->value_entry);
-
return FALSE
;
+
value_destroy (&v, var_get_width (dialog->pv))
;
}
/* Callback which occurs when the "Add" button is clicked */
}
/* Callback which occurs when the "Add" button is clicked */
-static
gint
+static
void
on_add (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
on_add (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
@@
-289,39
+307,42
@@
on_add (GtkWidget *w, gpointer data)
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value (text, &v,
- *var_get_write_format (dialog->pv));
-
+ text_to_value (text,
+ dialog->dict,
+ dialog->pv,
+ &v);
- if ( ! val_labs_add (dialog->labs, v,
- gtk_entry_get_text
- ( GTK_ENTRY (dialog->label_entry)) ) )
- return FALSE;
-
- gtk_widget_set_sensitive (dialog->add_button, FALSE);
+ if (val_labs_add (dialog->labs, &v,
+ gtk_entry_get_text
+ ( GTK_ENTRY (dialog->label_entry)) ) )
+ {
+ gtk_widget_set_sensitive (dialog->add_button, FALSE);
- repopulate_dialog (dialog);
- gtk_widget_grab_focus (dialog->value_entry);
+ repopulate_dialog (dialog);
+ gtk_widget_grab_focus (dialog->value_entry);
+ }
-
return FALSE
;
+
value_destroy (&v, var_get_width (dialog->pv))
;
}
/* Callback which occurs when the "Remove" button is clicked */
}
/* Callback which occurs when the "Remove" button is clicked */
-static
gint
+static
void
on_remove (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
on_remove (GtkWidget *w, gpointer data)
{
struct val_labs_dialog *dialog = data;
- struct val_lab *vl = get_selected_tuple (dialog);
+ union value value;
+ struct val_lab *vl;
- val_labs_remove (dialog->labs, vl->value);
+ get_selected_tuple (dialog, &value, NULL);
+ vl = val_labs_lookup (dialog->labs, &value);
+ if (vl != NULL)
+ val_labs_remove (dialog->labs, vl);
repopulate_dialog (dialog);
gtk_widget_grab_focus (dialog->value_entry);
gtk_widget_set_sensitive (dialog->remove_button, FALSE);
repopulate_dialog (dialog);
gtk_widget_grab_focus (dialog->value_entry);
gtk_widget_set_sensitive (dialog->remove_button, FALSE);
-
- return FALSE;
}
}
@@
-331,16
+352,15
@@
on_remove (GtkWidget *w, gpointer data)
static void
on_select_row (GtkTreeView *treeview, gpointer data)
{
static void
on_select_row (GtkTreeView *treeview, gpointer data)
{
- gchar *labeltext;
struct val_labs_dialog *dialog = data;
struct val_labs_dialog *dialog = data;
- struct val_lab * vl = get_selected_tuple (dialog);
+ union value value;
+ const char *label = NULL;
- gchar *const text = value_to_text (vl->value,
- *var_get_write_format (dialog->pv));
+ gchar *text;
- PsppireVarStore *var_store =
-
PSPPIRE_VAR_STORE (psppire_sheet_get_model (dialog->vs
));
+ get_selected_tuple (dialog, &value, &label);
+
text = value_to_text (value, dialog->dict, *var_get_write_format (dialog->pv
));
g_signal_handler_block (GTK_ENTRY (dialog->value_entry),
dialog->value_handler_id);
g_signal_handler_block (GTK_ENTRY (dialog->value_entry),
dialog->value_handler_id);
@@
-355,12
+375,8
@@
on_select_row (GtkTreeView *treeview, gpointer data)
dialog->change_handler_id);
dialog->change_handler_id);
- labeltext = recode_string (UTF8, psppire_dict_encoding (var_store->dict),
- vl->label, -1);
-
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry),
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry),
- labeltext);
- g_free (labeltext);
+ label);
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
@@
-373,7
+389,7
@@
on_select_row (GtkTreeView *treeview, gpointer data)
/* Create a new dialog box
(there should normally be only one)*/
struct val_labs_dialog *
/* Create a new dialog box
(there should normally be only one)*/
struct val_labs_dialog *
-val_labs_dialog_create (GtkWindow *toplevel, Psppire
Sheet *sheet
)
+val_labs_dialog_create (GtkWindow *toplevel, Psppire
VarStore *var_store
)
{
GtkTreeViewColumn *column;
{
GtkTreeViewColumn *column;
@@
-383,10
+399,11
@@
val_labs_dialog_create (GtkWindow *toplevel, PsppireSheet *sheet)
struct val_labs_dialog *dialog = g_malloc (sizeof (*dialog));
struct val_labs_dialog *dialog = g_malloc (sizeof (*dialog));
+ dialog->var_store = var_store;
+ g_object_get (var_store, "dictionary", &dialog->dict, NULL);
dialog->window = get_widget_assert (xml,"val_labs_dialog");
dialog->value_entry = get_widget_assert (xml,"value_entry");
dialog->label_entry = get_widget_assert (xml,"label_entry");
dialog->window = get_widget_assert (xml,"val_labs_dialog");
dialog->value_entry = get_widget_assert (xml,"value_entry");
dialog->label_entry = get_widget_assert (xml,"label_entry");
- dialog->vs = sheet;
gtk_window_set_transient_for
(GTK_WINDOW (dialog->window), toplevel);
gtk_window_set_transient_for
(GTK_WINDOW (dialog->window), toplevel);
@@
-411,40
+428,40
@@
val_labs_dialog_create (GtkWindow *toplevel, PsppireSheet *sheet)
g_signal_connect (get_widget_assert (xml, "val_labs_cancel"),
"clicked",
g_signal_connect (get_widget_assert (xml, "val_labs_cancel"),
"clicked",
- G
TK_SIGNAL_FUNC
(on_cancel), dialog);
+ G
_CALLBACK
(on_cancel), dialog);
g_signal_connect (dialog->window, "delete-event",
g_signal_connect (dialog->window, "delete-event",
- G
TK_SIGNAL_FUNC
(on_delete), dialog);
+ G
_CALLBACK
(on_delete), dialog);
g_signal_connect (get_widget_assert (xml, "val_labs_ok"),
"clicked",
g_signal_connect (get_widget_assert (xml, "val_labs_ok"),
"clicked",
- G
TK_SIGNAL_FUNC
(val_labs_ok), dialog);
+ G
_CALLBACK
(val_labs_ok), dialog);
dialog->change_handler_id =
g_signal_connect (dialog->label_entry,
"changed",
dialog->change_handler_id =
g_signal_connect (dialog->label_entry,
"changed",
- G
TK_SIGNAL_FUNC
(on_label_entry_change), dialog);
+ G
_CALLBACK
(on_label_entry_change), dialog);
dialog->value_handler_id =
g_signal_connect (dialog->value_entry,
"changed",
dialog->value_handler_id =
g_signal_connect (dialog->value_entry,
"changed",
- G
TK_SIGNAL_FUNC
(on_value_entry_change), dialog);
+ G
_CALLBACK
(on_value_entry_change), dialog);
g_signal_connect (dialog->change_button,
"clicked",
g_signal_connect (dialog->change_button,
"clicked",
- G
TK_SIGNAL_FUNC
(on_change), dialog);
+ G
_CALLBACK
(on_change), dialog);
g_signal_connect (dialog->treeview, "cursor-changed",
g_signal_connect (dialog->treeview, "cursor-changed",
- G
TK_SIGNAL_FUNC
(on_select_row), dialog);
+ G
_CALLBACK
(on_select_row), dialog);
g_signal_connect (dialog->remove_button, "clicked",
g_signal_connect (dialog->remove_button, "clicked",
- G
TK_SIGNAL_FUNC
(on_remove), dialog);
+ G
_CALLBACK
(on_remove), dialog);
g_signal_connect (dialog->add_button, "clicked",
g_signal_connect (dialog->add_button, "clicked",
- G
TK_SIGNAL_FUNC
(on_add), dialog);
+ G
_CALLBACK
(on_add), dialog);
- dialog->labs =
0
;
+ dialog->labs =
NULL
;
g_object_unref (xml);
g_object_unref (xml);
@@
-466,14
+483,12
@@
val_labs_dialog_set_target_variable (struct val_labs_dialog *dialog,
static void
repopulate_dialog (struct val_labs_dialog *dialog)
{
static void
repopulate_dialog (struct val_labs_dialog *dialog)
{
- struct val_labs_iterator *vli = 0;
- struct val_lab *vl;
+ const struct val_lab **labels;
+ size_t n_labels;
+ size_t i;
GtkTreeIter iter;
GtkTreeIter iter;
- PsppireVarStore *var_store =
- PSPPIRE_VAR_STORE (psppire_sheet_get_model (dialog->vs));
-
GtkListStore *list_store = gtk_list_store_new (2,
G_TYPE_STRING,
G_TYPE_DOUBLE);
GtkListStore *list_store = gtk_list_store_new (2,
G_TYPE_STRING,
G_TYPE_DOUBLE);
@@
-491,23
+506,18
@@
repopulate_dialog (struct val_labs_dialog *dialog)
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
-
- for (vl = val_labs_first_sorted (dialog->labs, &vli);
- vl;
- vl = val_labs_next (dialog->labs, &vli))
+ labels = val_labs_sorted (dialog->labs);
+ n_labels = val_labs_count (dialog->labs);
+ for (i = 0; i < n_labels; i++)
{
{
+ const struct val_lab *vl = labels[i];
gchar *const vstr =
gchar *const vstr =
- value_to_text (vl->value,
+ value_to_text (vl->value,
dialog->dict,
*var_get_write_format (dialog->pv));
*var_get_write_format (dialog->pv));
- gchar *labeltext =
- recode_string (UTF8,
- psppire_dict_encoding (var_store->dict),
- vl->label, -1);
-
- gchar *const text = g_strdup_printf ("%s = \"%s\"",
- vstr, labeltext);
+ gchar *const text = g_strdup_printf (_("%s = `%s'"), vstr,
+ val_lab_get_escaped_label (vl));
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
@@
-515,10
+525,10
@@
repopulate_dialog (struct val_labs_dialog *dialog)
1, vl->value.f,
-1);
1, vl->value.f,
-1);
- g_free (labeltext);
g_free (text);
g_free (vstr);
}
g_free (text);
g_free (vstr);
}
+ free (labels);
gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
GTK_TREE_MODEL (list_store));
gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
GTK_TREE_MODEL (list_store));