[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/4] var-type-dialog: Reduce redundancy further.
From: |
Ben Pfaff |
Subject: |
[PATCH 3/4] var-type-dialog: Reduce redundancy further. |
Date: |
Sun, 29 Jul 2012 23:58:46 -0700 |
set_format_from_treeview() and set_format_type_from_treeview() were
mostly common code.
---
src/ui/gui/var-type-dialog.c | 75 ++++++++++++++++++++---------------------
1 files changed, 37 insertions(+), 38 deletions(-)
diff --git a/src/ui/gui/var-type-dialog.c b/src/ui/gui/var-type-dialog.c
index cd6f690..3449e82 100644
--- a/src/ui/gui/var-type-dialog.c
+++ b/src/ui/gui/var-type-dialog.c
@@ -296,54 +296,53 @@ preview_custom (GtkWidget *w, gpointer data)
msg_enable ();
}
-/* Callback for when a treeview row is changed.
- It sets the fmt_l_spec to reflect the selected format */
-static void
-set_format_from_treeview (GtkTreeView *treeview, gpointer data)
+static gint
+get_index_from_treeview (GtkTreeView *treeview)
{
- struct var_type_dialog *dialog = data;
- GtkTreeIter iter ;
- GValue the_value = {0};
-
- GtkTreeSelection* sel = gtk_tree_view_get_selection (treeview);
-
- GtkTreeModel * model = gtk_tree_view_get_model (treeview);
-
- gtk_tree_selection_get_selected (sel, &model, &iter);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ gint index;
- gtk_tree_model_get_value (model, &iter, 1, &the_value);
+ gtk_tree_selection_get_selected (selection, &model, &iter);
+ path = gtk_tree_model_get_path (model, &iter);
+ if (!path || gtk_tree_path_get_depth (path) < 1)
+ index = 0;
+ else
+ index = gtk_tree_path_get_indices (path)[0];
+ gtk_tree_path_free (path);
- dialog->fmt_l = *(struct fmt_spec *) g_value_get_pointer (&the_value);
+ return index;
+}
- g_value_unset (&the_value);
+/* Callback for when a date treeview row is changed.
+ It sets the fmt_l_spec to reflect the selected format */
+static void
+set_date_format_from_treeview (GtkTreeView *treeview,
+ struct var_type_dialog *dialog)
+{
+ dialog->fmt_l = date_format[get_index_from_treeview (treeview)];
}
+/* Callback for when a dollar treeview row is changed.
+ It sets the fmt_l_spec to reflect the selected format */
+static void
+set_dollar_format_from_treeview (GtkTreeView *treeview,
+ struct var_type_dialog *dialog)
+{
+ dialog->fmt_l = dollar_format[get_index_from_treeview (treeview)];
+}
/* Callback for when a treeview row is changed.
It sets the type of the fmt_l to reflect the selected type */
static void
-set_format_type_from_treeview (GtkTreeView *treeview, gpointer data)
+set_custom_format_from_treeview (GtkTreeView *treeview,
+ struct var_type_dialog *dialog)
{
- static struct fmt_spec custom_format = {0,0,0};
- struct var_type_dialog *dialog = data;
- GtkTreeIter iter ;
- GValue the_value = {0};
-
- GtkTreeSelection* sel = gtk_tree_view_get_selection (treeview);
-
- GtkTreeModel * model = gtk_tree_view_get_model (treeview);
-
- gtk_tree_selection_get_selected (sel, &model, &iter);
-
- gtk_tree_model_get_value (model, &iter, 1, &the_value);
-
- dialog->fmt_l = custom_format;
- dialog->fmt_l.type = g_value_get_int (&the_value);
-
- g_value_unset (&the_value);
+ dialog->fmt_l.type = cc_format[get_index_from_treeview (treeview)];
}
-
/* Create the structure */
struct var_type_dialog *
var_type_dialog_create (GtkWindow *toplevel)
@@ -461,7 +460,7 @@ var_type_dialog_create (GtkWindow *toplevel)
g_object_unref (list_store);
g_signal_connect (dialog->date_format_treeview, "cursor-changed",
- G_CALLBACK (set_format_from_treeview), dialog);
+ G_CALLBACK (set_date_format_from_treeview), dialog);
/* populate the dollar treeview */
@@ -499,7 +498,7 @@ var_type_dialog_create (GtkWindow *toplevel)
g_signal_connect (dialog->dollar_treeview,
"cursor-changed",
- G_CALLBACK (set_format_from_treeview), dialog);
+ G_CALLBACK (set_dollar_format_from_treeview), dialog);
g_signal_connect_swapped (dialog->dollar_treeview,
"cursor-changed",
@@ -540,7 +539,7 @@ var_type_dialog_create (GtkWindow *toplevel)
g_signal_connect (dialog->custom_treeview,
"cursor-changed",
- G_CALLBACK (set_format_type_from_treeview), dialog);
+ G_CALLBACK (set_custom_format_from_treeview), dialog);
g_signal_connect (dialog->custom_treeview,
--
1.7.2.5
- [PATCH 0/4] further improvements to var-type-dialog, Ben Pfaff, 2012/07/30
- [PATCH 4/4] var-type-dialog: Change entries to spin buttons, add validation., Ben Pfaff, 2012/07/30
- [PATCH 3/4] var-type-dialog: Reduce redundancy further.,
Ben Pfaff <=
- [PATCH 2/4] var-type-dialog: Reduce redundancy., Ben Pfaff, 2012/07/30
- [PATCH 1/4] var-type-dialog: Properly adjust formats when switching buttons., Ben Pfaff, 2012/07/30
- Re: [PATCH 0/4] further improvements to var-type-dialog, John Darrington, 2012/07/30