X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fval-labs-dialog.c;h=226021507f45796632a945e37c3ff44bccc661a0;hb=c7b51971e88c4040ead3cebf0417016f4e4578df;hp=56399aa271f3b3b6ee4739c33b3640a008c6472b;hpb=ab97e700f033db654e2f44919c73973d13b0c522;p=pspp diff --git a/src/ui/gui/val-labs-dialog.c b/src/ui/gui/val-labs-dialog.c index 56399aa271..226021507f 100644 --- a/src/ui/gui/val-labs-dialog.c +++ b/src/ui/gui/val-labs-dialog.c @@ -1,5 +1,6 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2005, 2009, 2010, 2011, 2012, 2015 Free Software Foundation + Copyright (C) 2005, 2009, 2010, 2011, 2012, 2015, 2016, + 2020 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 @@ -48,6 +49,8 @@ enum PROP_VALUE_LABELS }; +static void do_change (PsppireValLabsDialog *); + static void psppire_val_labs_dialog_set_property (GObject *object, guint prop_id, @@ -123,6 +126,7 @@ psppire_val_labs_dialog_init (PsppireValLabsDialog *obj) runs after the construction properties have been set. Otherwise PsppireDialog's "orientation" property hasn't been set and therefore we have no box to populate. */ + obj->labs = val_labs_create (0); } @@ -140,10 +144,12 @@ psppire_val_labs_dialog_finalize (GObject *obj) PsppireValLabsDialog * psppire_val_labs_dialog_new (const struct variable *var) { - return PSPPIRE_VAL_LABS_DIALOG ( - g_object_new (PSPPIRE_TYPE_VAL_LABS_DIALOG, - "variable", var, - NULL)); + PsppireValLabsDialog *obj + = PSPPIRE_VAL_LABS_DIALOG (g_object_new (PSPPIRE_TYPE_VAL_LABS_DIALOG, + "variable", var, + NULL)); + + return obj; } struct val_labs * @@ -158,9 +164,16 @@ psppire_val_labs_dialog_run (GtkWindow *parent_window, gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_widget_show (GTK_WIDGET (dialog)); - labs = (psppire_dialog_run (PSPPIRE_DIALOG (dialog)) == GTK_RESPONSE_OK - ? val_labs_clone (psppire_val_labs_dialog_get_value_labels (dialog)) - : NULL); + gint response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + switch (response) + { + case GTK_RESPONSE_OK: + labs = val_labs_clone (psppire_val_labs_dialog_get_value_labels (dialog)); + break; + default: + labs = NULL; + break; + } gtk_widget_destroy (GTK_WIDGET (dialog)); @@ -195,6 +208,15 @@ on_label_entry_change (GtkEntry *entry, gpointer data) value_destroy (&v, val_labs_get_width (dialog->labs)); } +/* This callback occurs when Enter is pressed in the label entry box. */ +static void +on_label_entry_activate (GtkEntry *entry, gpointer data) +{ + PsppireValLabsDialog *dialog = data; + do_change (dialog); +} + +/* Return the value-label pair currently selected in the dialog box */ /* Set the TREEVIEW list cursor to the item which has the value VAL */ static void @@ -221,14 +243,14 @@ select_treeview_from_value (GtkTreeView *treeview, union value *val) v.f = g_value_get_double (&gvalue); - if ( 0 == memcmp (&v, val, sizeof (union value))) + if (0 == memcmp (&v, val, sizeof (union value))) { break; } } path = gtk_tree_model_get_path (model, &iter); - if ( path ) + if (path) { gtk_tree_view_set_cursor (treeview, path, 0, 0); gtk_tree_path_free (path); @@ -257,7 +279,7 @@ on_value_entry_change (GtkEntry *entry, gpointer data) 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); @@ -276,8 +298,15 @@ on_value_entry_change (GtkEntry *entry, gpointer data) value_destroy (&v, val_labs_get_width (dialog->labs)); } +/* This callback occurs when Enter is pressed in the value entry box. */ +static void +on_value_entry_activate (GtkEntry *entry, gpointer data) +{ + PsppireValLabsDialog *dialog = data; + + gtk_widget_grab_focus (dialog->label_entry); +} -/* Return the value-label pair currently selected in the dialog box */ static gboolean get_selected_tuple (PsppireValLabsDialog *dialog, union value *valuep, const char **label) @@ -308,7 +337,7 @@ get_selected_tuple (PsppireValLabsDialog *dialog, if (vl != NULL) *label = val_lab_get_escaped_label (vl); } - + return TRUE; } @@ -320,22 +349,28 @@ static void on_change (GtkWidget *w, gpointer data) { PsppireValLabsDialog *dialog = data; + do_change (dialog); +} +static void +do_change (PsppireValLabsDialog *dialog) +{ const gchar *val_text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry)); union value v; - text_to_value__ (val_text, &dialog->format, dialog->encoding, &v); - - val_labs_replace (dialog->labs, &v, - gtk_entry_get_text (GTK_ENTRY (dialog->label_entry))); + if (text_to_value__ (val_text, &dialog->format, dialog->encoding, &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_widget_set_sensitive (dialog->change_button, FALSE); - repopulate_dialog (dialog); - gtk_widget_grab_focus (dialog->value_entry); + repopulate_dialog (dialog); + gtk_widget_grab_focus (dialog->value_entry); - value_destroy (&v, val_labs_get_width (dialog->labs)); + value_destroy (&v, val_labs_get_width (dialog->labs)); + } } /* Callback which occurs when the "Add" button is clicked */ @@ -348,19 +383,20 @@ on_add (GtkWidget *w, gpointer data) const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry)); - text_to_value__ (text, &dialog->format, dialog->encoding, &v); - - if (val_labs_add (dialog->labs, &v, - gtk_entry_get_text - ( GTK_ENTRY (dialog->label_entry)) ) ) + if (text_to_value__ (text, &dialog->format, dialog->encoding, &v)) { - 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); + } - value_destroy (&v, val_labs_get_width (dialog->labs)); + value_destroy (&v, val_labs_get_width (dialog->labs)); + } } /* Callback which occurs when the "Remove" button is clicked */ @@ -374,7 +410,7 @@ on_remove (GtkWidget *w, gpointer data) if (! get_selected_tuple (dialog, &value, NULL)) return; - + vl = val_labs_lookup (dialog->labs, &value); if (vl != NULL) val_labs_remove (dialog->labs, vl); @@ -401,7 +437,7 @@ on_select_row (GtkTreeView *treeview, gpointer data) if (! get_selected_tuple (dialog, &value, &label)) return; - + text = value_to_text__ (value, &dialog->format, dialog->encoding); g_signal_handler_block (GTK_ENTRY (dialog->value_entry), @@ -449,6 +485,9 @@ psppire_val_labs_dialog_constructor (GType type, type, n_properties, properties); dialog = PSPPIRE_VAL_LABS_DIALOG (obj); + g_object_set (dialog, "help-page", "VALUE-LABELS", + "title", _("Value Labels"), NULL); + content_area = GTK_CONTAINER (PSPPIRE_DIALOG (dialog)); gtk_container_add (GTK_CONTAINER (content_area), get_widget_assert (xml, "val-labs-dialog")); @@ -478,11 +517,15 @@ psppire_val_labs_dialog_constructor (GType type, g_signal_connect (dialog->label_entry, "changed", G_CALLBACK (on_label_entry_change), dialog); + g_signal_connect (dialog->label_entry, "activate", + G_CALLBACK (on_label_entry_activate), dialog); dialog->value_handler_id = g_signal_connect (dialog->value_entry, "changed", G_CALLBACK (on_value_entry_change), dialog); + g_signal_connect (dialog->value_entry, "activate", + G_CALLBACK (on_value_entry_activate), dialog); g_signal_connect (dialog->change_button, "clicked", @@ -498,7 +541,9 @@ psppire_val_labs_dialog_constructor (GType type, g_signal_connect (dialog->add_button, "clicked", G_CALLBACK (on_add), dialog); - dialog->labs = NULL; + /* dialog->labs must not be set here, because as a member of a singleton + class its value persists "between" objects. */ + /* dialog->labs = NULL; */ g_object_unref (xml); @@ -561,7 +606,6 @@ repopulate_dialog (PsppireValLabsDialog *dialog) GTK_TREE_MODEL (list_store)); g_object_unref (list_store); - } void