[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] var-type-dialog: Properly adjust formats when switching butt
From: |
Ben Pfaff |
Subject: |
[PATCH 1/4] var-type-dialog: Properly adjust formats when switching buttons. |
Date: |
Sun, 29 Jul 2012 23:58:44 -0700 |
The var-type-dialog based the default new format on the variable's
existing format when a button was clicked, and attempted to adjust
the width and decimals into valid range, but the adjustment wasn't
always correct, so in some cases it could pick an invalid format.
This commit uses fmt_fix_output() instead, which will always choose
a valid output format.
---
src/ui/gui/var-type-dialog.c | 72 ++++++++++++++++++++++--------------------
1 files changed, 38 insertions(+), 34 deletions(-)
diff --git a/src/ui/gui/var-type-dialog.c b/src/ui/gui/var-type-dialog.c
index 1e86049..6db0e72 100644
--- a/src/ui/gui/var-type-dialog.c
+++ b/src/ui/gui/var-type-dialog.c
@@ -80,6 +80,7 @@ static const int cc_format[] =
};
+static void select_treeview_at_index (GtkTreeView *, int index);
static void select_treeview_from_format
(GtkTreeView *treeview, const struct fmt_spec *fmt);
@@ -109,29 +110,6 @@ on_toggle_1 (GtkToggleButton *togglebutton, gpointer
dialog_)
static void update_width_decimals (const struct var_type_dialog *dialog);
-#define force_max(x, val) if (x > val) x = val
-
-/*
- Set the local format from the variable
- and force them to have sensible values */
-static void
-set_local_width_decimals (struct var_type_dialog *dialog)
-{
- dialog->fmt_l = * var_get_print_format (dialog->pv);
-
- switch (dialog->active_button)
- {
- case BUTTON_STRING:
- force_max ( dialog->fmt_l.w, 255);
- break;
- default:
- force_max ( dialog->fmt_l.w, 40);
- force_max ( dialog->fmt_l.d, 16);
- break;
- }
-}
-
-
/* callback for when any of the radio buttons are toggled */
static void
on_toggle_2 (GtkToggleButton *togglebutton, gpointer user_data)
@@ -158,40 +136,56 @@ on_toggle_2 (GtkToggleButton *togglebutton, gpointer
user_data)
return ;
}
- set_local_width_decimals (dialog);
- update_width_decimals (dialog);
+ dialog->fmt_l = *var_get_print_format (dialog->pv);
switch (dialog->active_button)
{
+ case BUTTON_NUMERIC:
+ gtk_widget_show_all (dialog->width_decimals);
+ dialog->fmt_l.type = FMT_F;
+ break;
+ case BUTTON_COMMA:
+ gtk_widget_show_all (dialog->width_decimals);
+ dialog->fmt_l.type = FMT_COMMA;
+ break;
+ case BUTTON_DOT:
+ gtk_widget_show_all (dialog->width_decimals);
+ dialog->fmt_l.type = FMT_DOT;
+ break;
+ case BUTTON_SCIENTIFIC:
+ gtk_widget_show_all (dialog->width_decimals);
+ dialog->fmt_l.type = FMT_E;
+ break;
case BUTTON_STRING:
+ dialog->fmt_l.type = FMT_A;
gtk_widget_show (dialog->entry_width);
gtk_widget_show (dialog->width_decimals);
gtk_widget_hide (dialog->label_decimals);
gtk_widget_hide (dialog->entry_decimals);
break;
case BUTTON_DATE:
- select_treeview_from_format (dialog->date_format_treeview,
- &date_format[0]);
+ select_treeview_at_index (dialog->date_format_treeview, 0);
+ dialog->fmt_l = date_format[0];
gtk_widget_hide (dialog->width_decimals);
gtk_widget_show (dialog->date_format_list);
break;
case BUTTON_DOLLAR:
- select_treeview_from_format (dialog->dollar_treeview,
- &dollar_format[0]);
+ select_treeview_at_index (dialog->dollar_treeview, 0);
+ dialog->fmt_l = dollar_format[0];
gtk_widget_show (dialog->dollar_window);
gtk_widget_show_all (dialog->width_decimals);
break;
case BUTTON_CUSTOM:
- select_treeview_from_format_type (dialog->custom_treeview,
- cc_format[0]);
+ select_treeview_at_index (dialog->custom_treeview, 0);
+ dialog->fmt_l.type = cc_format[0];
gtk_widget_show (dialog->width_decimals);
gtk_widget_show (dialog->custom_currency_hbox);
break;
- default:
- gtk_widget_show_all (dialog->width_decimals);
- break;
}
+
+ fmt_fix_output (&dialog->fmt_l);
+ update_width_decimals (dialog);
}
@@ -561,6 +555,16 @@ var_type_dialog_set_active_button (struct var_type_dialog
*dialog, gint b)
+static void
+select_treeview_at_index (GtkTreeView *treeview, int index)
+{
+ GtkTreePath *path;
+
+ path = gtk_tree_path_new_from_indices (index, -1);
+ gtk_tree_view_set_cursor (treeview, path, 0, 0);
+ gtk_tree_path_free (path);
+}
+
/* Set the TREEVIEW list cursor to the item described by FMT */
static void
select_treeview_from_format (GtkTreeView *treeview, const struct fmt_spec *fmt)
--
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, 2012/07/30
- [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 <=
- Re: [PATCH 0/4] further improvements to var-type-dialog, John Darrington, 2012/07/30