X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-dictview.c;h=8a976c04241927ab7f1344476789a8d5d4b05fe2;hb=e7913c62251710319b06c50702c5db9afb612be5;hp=d51a22381b26efe01970dd9368eb8d0cb4303f97;hpb=dcd593ebc418681f2a7f14795b13f94eaa95ccaf;p=pspp diff --git a/src/ui/gui/psppire-dictview.c b/src/ui/gui/psppire-dictview.c index d51a22381b..8a976c0424 100644 --- a/src/ui/gui/psppire-dictview.c +++ b/src/ui/gui/psppire-dictview.c @@ -27,44 +27,18 @@ #include #include "helper.h" +#include "psppire-dialog.h" +#include "psppire-var-info.h" +#include "psppire-buttonbox.h" + #include #define _(msgid) gettext (msgid) #define N_(msgid) msgid -static void psppire_dict_view_base_finalize (PsppireDictViewClass *, gpointer); -static void psppire_dict_view_base_init (PsppireDictViewClass *class); static void psppire_dict_view_class_init (PsppireDictViewClass *class); static void psppire_dict_view_init (PsppireDictView *dict_view); -GType -psppire_dict_view_get_type (void) -{ - static GType psppire_dict_view_type = 0; - - if (!psppire_dict_view_type) - { - static const GTypeInfo psppire_dict_view_info = - { - sizeof (PsppireDictViewClass), - (GBaseInitFunc) (void (*)(void)) psppire_dict_view_base_init, - (GBaseFinalizeFunc) (void (*)(void)) psppire_dict_view_base_finalize, - (GClassInitFunc) (void (*)(void)) psppire_dict_view_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (PsppireDictView), - 0, - (GInstanceInitFunc) (void (*)(void)) psppire_dict_view_init, - NULL /* value_table */ - }; - - psppire_dict_view_type = - g_type_register_static (GTK_TYPE_TREE_VIEW, "PsppireDictView", - &psppire_dict_view_info, 0); - } - - return psppire_dict_view_type; -} - +G_DEFINE_TYPE (PsppireDictView, psppire_dict_view, GTK_TYPE_TREE_VIEW) static void psppire_dict_view_finalize (GObject *object) @@ -291,6 +265,7 @@ psppire_dict_view_get_property (GObject *object, g_value_set_enum (value, gtk_tree_selection_get_mode (selection)); } + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -304,6 +279,8 @@ psppire_dict_view_class_init (PsppireDictViewClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + object_class->finalize = psppire_dict_view_finalize; + GParamSpec *predicate_spec = g_param_spec_pointer ("predicate", "Predicate", @@ -335,24 +312,6 @@ psppire_dict_view_class_init (PsppireDictViewClass *class) selection_mode_spec); } - -static void -psppire_dict_view_base_init (PsppireDictViewClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->finalize = psppire_dict_view_finalize; -} - - - -static void -psppire_dict_view_base_finalize (PsppireDictViewClass *class, - gpointer class_data) -{ - -} - static gboolean use_labels (PsppireDictView *dv) { @@ -534,12 +493,50 @@ set_tooltip_for_variable (GtkTreeView *treeview, return TRUE; } +static struct variable * +psppire_dict_view_iter_to_var (PsppireDictView *dict_view, + GtkTreeIter *top_iter) +{ + GtkTreeView *treeview = GTK_TREE_VIEW (dict_view); + GtkTreeModel *top_model = gtk_tree_view_get_model (treeview); + + struct variable *var; + GtkTreeModel *model; + GtkTreeIter iter; + + get_base_model (top_model, top_iter, &model, &iter); + g_assert (PSPPIRE_IS_DICT (model)); + + gtk_tree_model_get (model, + &iter, DICT_TVM_COL_VAR, &var, -1); + + return var; +} + static gboolean show_menu (PsppireDictView *dv, GdkEvent *event, gpointer data) { - if (((GdkEventButton *) event)->button != 3) + GdkEventButton *button_event = (GdkEventButton *) event; + if (button_event->button != 3) return FALSE; + dv->var_under_cursor = NULL; + GtkTreePath *path = NULL; + gboolean is_row = + gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (dv), + button_event->x, button_event->y, + &path, NULL, NULL, NULL); + if (is_row) + { + GtkTreeIter iter; + GtkTreeModel *top_model = gtk_tree_view_get_model (GTK_TREE_VIEW (dv)); + gtk_tree_model_get_iter (top_model, &iter, path); + dv->var_under_cursor = psppire_dict_view_iter_to_var (dv, &iter); + } + gtk_tree_path_free (path); + + gtk_widget_set_sensitive (GTK_WIDGET (dv->var_info_check), is_row); + gtk_menu_popup_at_pointer (GTK_MENU (dv->menu), event); return TRUE; @@ -610,7 +607,51 @@ set_sort_criteria_unsorted (GtkCheckMenuItem *checkbox, gpointer data) set_sort_criteria (checkbox, dv, unsorted); } +static void +check_item_set_inactive (GtkCheckMenuItem *cmi) +{ + gtk_check_menu_item_set_active (cmi, FALSE); +} + +static void +pop_up_down_variable_information (GtkCheckMenuItem *cmi, PsppireDictView *dv) +{ + gboolean active; + g_object_get (cmi, "active", &active, NULL); + + g_return_if_fail (dv->var_under_cursor); + + if (!active) + return; + + GtkWidget *dialog = psppire_dialog_new (); + g_object_set (dialog, + "title", _("Variable Details"), + "help-page", "Manipulating-Variables", + NULL); + GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); + gtk_container_add (GTK_CONTAINER (dialog), box); + + GtkWidget *var_info = psppire_var_info_new (); + g_object_set (var_info, "variable", dv->var_under_cursor, NULL); + gtk_box_pack_start (GTK_BOX (box), var_info, TRUE, TRUE, 5); + + GtkWidget *button_box = psppire_button_box_new (); + g_object_set (button_box, + "buttons", PSPPIRE_BUTTON_CLOSE_MASK | PSPPIRE_BUTTON_HELP_MASK, + NULL); + g_object_set (button_box, "layout-style", GTK_BUTTONBOX_SPREAD, NULL); + gtk_box_pack_start (GTK_BOX (box), button_box, FALSE, TRUE, 5); + + g_signal_connect_swapped (dialog, "unmap", + G_CALLBACK (check_item_set_inactive), cmi); + + gtk_widget_show_all (box); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + psppire_dialog_run (PSPPIRE_DIALOG (dialog)); +} static void psppire_dict_view_init (PsppireDictView *dict_view) @@ -621,6 +662,7 @@ psppire_dict_view_init (PsppireDictView *dict_view) dict_view->prefer_labels_override = FALSE; dict_view->sorted_model = NULL; + dict_view->var_under_cursor = NULL; gtk_tree_view_column_set_title (col, _("Variable")); @@ -693,6 +735,14 @@ psppire_dict_view_init (PsppireDictView *dict_view) group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item)); gtk_menu_shell_append (GTK_MENU_SHELL (dict_view->menu), item); g_signal_connect (item, "toggled", G_CALLBACK (set_sort_criteria_label), dict_view); + + item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (dict_view->menu), item); + + item = gtk_check_menu_item_new_with_label (_("Variable Information")); + dict_view->var_info_check = item; + gtk_menu_shell_append (GTK_MENU_SHELL (dict_view->menu), item); + g_signal_connect (item, "toggled", G_CALLBACK (pop_up_down_variable_information), dict_view); } gtk_widget_show_all (dict_view->menu); @@ -701,34 +751,6 @@ psppire_dict_view_init (PsppireDictView *dict_view) G_CALLBACK (show_menu), NULL); } - -GtkWidget* -psppire_dict_view_new (void) -{ - return GTK_WIDGET (g_object_new (psppire_dict_view_get_type (), NULL)); -} - -static struct variable * -psppire_dict_view_iter_to_var (PsppireDictView *dict_view, - GtkTreeIter *top_iter) -{ - GtkTreeView *treeview = GTK_TREE_VIEW (dict_view); - GtkTreeModel *top_model = gtk_tree_view_get_model (treeview); - - struct variable *var; - GtkTreeModel *model; - GtkTreeIter iter; - - get_base_model (top_model, top_iter, &model, &iter); - - g_assert (PSPPIRE_IS_DICT (model)); - - gtk_tree_model_get (model, - &iter, DICT_TVM_COL_VAR, &var, -1); - - return var; -} - struct get_vars_aux { PsppireDictView *dict_view;