From cca1d258d390a6e945b2908539e2e73064a890d6 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Thu, 18 Jan 2001 06:47:07 +0000 Subject: New function. (update_sort_config_dialog): Massive update to this 2001-01-18 Miguel de Icaza * e-table-config.c (find_model_column_by_name): New function. (update_sort_config_dialog): Massive update to this function, it is almost complete now, it just needs a few cosmetic touchups. (config_sort_config_show): Get the main interaction working as well. (config_group_info_update): Beautify. (entry_changed): Do all the magic for the GUI for entries. (ascending_toggled): Implement callback. (configure_sort_dialog): Do also descending. (configure_sort_dialog): Hook up changed/toggled. * e-table-config.h: Put all the configuration stuff for sorting into its own structure to pass around funny functions. svn path=/trunk/; revision=7617 --- widgets/table/e-table-config.c | 230 +++++++++++++++++++++++++++++++--- widgets/table/e-table-config.glade | 5 +- widgets/table/e-table-config.glade.h | 2 +- widgets/table/e-table-config.h | 18 ++- widgets/table/e-table-specification.c | 1 - 5 files changed, 230 insertions(+), 26 deletions(-) (limited to 'widgets/table') diff --git a/widgets/table/e-table-config.c b/widgets/table/e-table-config.c index 23c85fa333..c1f0cce3f5 100644 --- a/widgets/table/e-table-config.c +++ b/widgets/table/e-table-config.c @@ -5,7 +5,11 @@ * Authors: * Chris Lahey (clahey@ximian.com) * Miguel de Icaza (miguel@ximian.com) - + * + * FIXME: + * Sort Dialog: when text is selected, the toggle button switches state. + * Make Clear all work. + * * (C) 2000, 2001 Ximian, Inc. */ @@ -71,31 +75,93 @@ find_column_in_spec (ETableSpecification *spec, int model_col) return NULL; } -static void -config_sort_config_show (GtkWidget *widget, ETableConfig *config) +static int +find_model_column_by_name (ETableSpecification *spec, const char *s) { - GnomeDialog *dialog = GNOME_DIALOG (config->dialog_sort); - int button, count, i; + ETableColumnSpecification **column; - /* - * Make the dialog reflect the current state - */ - count = e_table_sort_info_sorting_get_count (config->state->sort_info); + for (column = spec->columns; *column; column++){ + + if (strcasecmp ((*column)->title, s) == 0) + return (*column)->model_col; + } + return -1; +} + +static void +update_sort_config_dialog (ETableConfig *config) +{ + int count, i; + + count = e_table_sort_info_sorting_get_count (config->temp_state->sort_info); for (i = 0; i < 4; i++){ gboolean sensitive = (i <= count); - gtk_widget_set_sensitive (config->frames [i], sensitive); + gtk_widget_set_sensitive (config->sort [i].frames, sensitive); /* * Sorting is set, auto select the text */ - if ((i + 1) >= count){ + gtk_signal_handler_block ( + GTK_OBJECT (config->sort [i].radio_ascending), + config->sort [i].toggled_id); + + if (i < count){ + GtkToggleButton *a, *d; + ETableSortColumn col = + e_table_sort_info_sorting_get_nth ( + config->temp_state->sort_info, + i); + + ETableColumnSpecification *column = + find_column_in_spec (config->temp_spec, col.column); + + if (!column){ + /* + * This is a bug in the programmer + * stuff, but by the time we arrive + * here, the user has been given a + * warning + */ + continue; + } + + /* + * Change the text + */ + gtk_signal_handler_block ( + GTK_OBJECT (config->sort [i].combo->entry), + config->sort [i].changed_id); + gtk_combo_text_set_text ( + config->sort [i].combo, gettext ( + column->title)); + gtk_signal_handler_unblock ( + GTK_OBJECT (config->sort [i].combo->entry), + config->sort [i].changed_id); + + /* + * Update radio buttons + */ + a = GTK_TOGGLE_BUTTON ( + config->sort [i].radio_ascending); + d = GTK_TOGGLE_BUTTON ( + config->sort [i].radio_descending); + gtk_toggle_button_set_active (col.ascending ? a:d, 1); + } else { + GtkToggleButton *t; + + t = GTK_TOGGLE_BUTTON ( + config->sort [i].radio_ascending); + + gtk_toggle_button_set_active (t, 1); } + gtk_signal_handler_unblock ( + GTK_OBJECT (config->sort [i].radio_ascending), + config->sort [i].toggled_id); } - - button = gnome_dialog_run (dialog); + } static void @@ -129,6 +195,9 @@ config_sort_info_update (ETableConfig *config) res, col.ascending ? _("(Ascending)") : _("(Descending)")); + + if ((i + 1) != count) + g_string_append (res, ", "); } if (res->str [0] == 0) @@ -139,6 +208,50 @@ config_sort_info_update (ETableConfig *config) g_string_free (res, TRUE); } + +static void +config_sort_config_show (GtkWidget *widget, ETableConfig *config) +{ + GnomeDialog *dialog = GNOME_DIALOG (config->dialog_sort); + int button, running = 1; + + config->temp_spec = e_table_specification_duplicate (config->spec); + config->temp_state = e_table_state_duplicate (config->state); + + update_sort_config_dialog (config); + gtk_widget_grab_focus (GTK_WIDGET (config->sort [0].combo)); + + do { + button = gnome_dialog_run (dialog); + switch (button){ + case 0: + e_table_sort_info_sorting_truncate ( + config->state->sort_info, 0); + update_sort_config_dialog (config); + continue; + case 1: + gtk_object_unref (GTK_OBJECT (config->spec)); + gtk_object_unref (GTK_OBJECT (config->state)); + config->spec = config->temp_spec; + config->state = config->temp_state; + running = 0; + break; + + case 2: + gtk_object_unref (GTK_OBJECT (config->temp_state)); + gtk_object_unref (GTK_OBJECT (config->temp_spec)); + config->temp_state = 0; + config->temp_spec = 0; + running = 0; + break; + } + + } while (running); + gnome_dialog_close (GNOME_DIALOG (dialog)); + + config_sort_info_update (config); +} + static void config_group_info_update (ETableConfig *config) { @@ -165,6 +278,9 @@ config_group_info_update (ETableConfig *config) res, col.ascending ? _("(Ascending)") : _("(Descending)")); + + if ((i+1) != count) + g_string_append (res, ", "); } if (res->str [0] == 0) g_string_append (res, _("No grouping")); @@ -242,6 +358,56 @@ configure_dialog (GladeXML *gui, const char *widget_name, ETableConfig *config) return w; } +static void +entry_changed (GtkEntry *entry, ETableConfigSortWidgets *sort) +{ + ETableConfig *config = sort->e_table_config; + ETableSortInfo *sort_info = config->temp_state->sort_info; + ETableConfigSortWidgets *base = &config->sort[0]; + int idx = sort - base; + + char *s = gtk_entry_get_text (entry); + + if (s [0] == 0){ + printf ("Entry %d is empty!\n", idx); + e_table_sort_info_sorting_truncate (sort_info, idx); + update_sort_config_dialog (config); + return; + } + + if (g_hash_table_lookup (sort->combo->elements, s)){ + ETableSortColumn c; + int col; + + col = find_model_column_by_name (config->temp_spec, s); + if (col == -1){ + g_warning ("This should not happen"); + return; + } + + c.ascending = 1; + c.column = col; + e_table_sort_info_sorting_set_nth (sort_info, idx, c); + + update_sort_config_dialog (config); + return; + } +} + +static void +ascending_toggled (GtkToggleButton *t, ETableConfigSortWidgets *sort) +{ + ETableConfig *config = sort->e_table_config; + ETableSortInfo *si = config->temp_state->sort_info; + ETableConfigSortWidgets *base = &config->sort[0]; + int idx = sort - base; + ETableSortColumn c; + + c = e_table_sort_info_sorting_get_nth (si, idx); + c.ascending = t->active; + e_table_sort_info_sorting_set_nth (si, idx, c); +} + static void configure_sort_dialog (ETableConfig *config, GladeXML *gui) { @@ -249,16 +415,31 @@ configure_sort_dialog (ETableConfig *config, GladeXML *gui) int i; for (i = 0; i < 4; i++){ - char buffer [30]; + char buffer [80]; snprintf (buffer, sizeof (buffer), "sort-combo-%d", i + 1); - config->sort_combos [i] = GTK_COMBO_TEXT ( + config->sort [i].combo = GTK_COMBO_TEXT ( glade_xml_get_widget (gui, buffer)); - gtk_combo_text_add_item (config->sort_combos [i], "", ""); + + gtk_combo_text_add_item (config->sort [i].combo, "", ""); snprintf (buffer, sizeof (buffer), "frame-sort-%d", i + 1); - config->frames [i] = + config->sort [i].frames = glade_xml_get_widget (gui, buffer); + + snprintf ( + buffer, sizeof (buffer), + "radiobutton-ascending-sort-%d", i+1); + config->sort [i].radio_ascending = glade_xml_get_widget ( + gui, buffer); + + snprintf ( + buffer, sizeof (buffer), + "radiobutton-descending-sort-%d", i+1); + config->sort [i].radio_descending = glade_xml_get_widget ( + gui, buffer); + + config->sort [i].e_table_config = config; } for (column = config->spec->columns; *column; column++){ @@ -266,10 +447,23 @@ configure_sort_dialog (ETableConfig *config, GladeXML *gui) for (i = 0; i < 4; i++){ gtk_combo_text_add_item ( - config->sort_combos [i], + config->sort [i].combo, gettext (label), label); } } + + /* + * After we have runtime modified things, signal connect + */ + for (i = 0; i < 4; i++){ + config->sort [i].changed_id = gtk_signal_connect ( + GTK_OBJECT (config->sort [i].combo->entry), + "changed", entry_changed, &config->sort [i]); + + config->sort [i].toggled_id = gtk_signal_connect ( + GTK_OBJECT (config->sort [i].radio_ascending), + "toggled", ascending_toggled, &config->sort [i]); + } } static void diff --git a/widgets/table/e-table-config.glade b/widgets/table/e-table-config.glade index a6920ee81c..dff98e5d0b 100644 --- a/widgets/table/e-table-config.glade +++ b/widgets/table/e-table-config.glade @@ -1523,6 +1523,8 @@ Custom sort-combo-1 + True + True e_table_proxy_gtk_combo_text_new 0 0 @@ -1597,13 +1599,14 @@ button43 True True - + GtkButton button44 True + True True GNOME_STOCK_BUTTON_OK diff --git a/widgets/table/e-table-config.glade.h b/widgets/table/e-table-config.glade.h index 1bc023a51b..933fce6143 100644 --- a/widgets/table/e-table-config.glade.h +++ b/widgets/table/e-table-config.glade.h @@ -44,7 +44,7 @@ gchar *s = N_("Descending"); gchar *s = N_("Sort Items By"); gchar *s = N_("Ascending"); gchar *s = N_("Descending"); -gchar *s = N_("_Clear All"); +gchar *s = N_("Clear All"); gchar *s = N_("Description"); gchar *s = N_("_Fields..."); gchar *s = N_("_Sort..."); diff --git a/widgets/table/e-table-config.h b/widgets/table/e-table-config.h index fcf6eff9cc..06252ab2bc 100644 --- a/widgets/table/e-table-config.h +++ b/widgets/table/e-table-config.h @@ -13,6 +13,15 @@ #define E_IS_TABLE_CONFIG(o) (GTK_CHECK_TYPE ((o), E_TABLE_CONFIG_TYPE)) #define E_IS_TABLE_CONFIG_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_CONFIG_TYPE)) +typedef struct { + GtkComboText *combo; + GtkWidget *frames; + GtkWidget *radio_ascending; + GtkWidget *radio_descending; + guint changed_id, toggled_id; + void *e_table_config; +} ETableConfigSortWidgets; + typedef struct { GtkObject parent; @@ -27,15 +36,14 @@ typedef struct { /* * The state we manipulate */ - ETableSpecification *source_spec, *spec; - ETableState *source_state, *state; + ETableSpecification *source_spec, *spec, *temp_spec; + ETableState *source_state, *state, *temp_state; GtkWidget *sort_label; GtkWidget *group_label; GtkWidget *fields_label; - - GtkComboText *sort_combos [4]; - GtkWidget *frames [4]; + + ETableConfigSortWidgets sort [4]; } ETableConfig; typedef struct { diff --git a/widgets/table/e-table-specification.c b/widgets/table/e-table-specification.c index b9a3c4ee98..7f78fac681 100644 --- a/widgets/table/e-table-specification.c +++ b/widgets/table/e-table-specification.c @@ -348,7 +348,6 @@ e_table_specification_duplicate (ETableSpecification *spec) new_spec = e_table_specification_new (); spec_str = e_table_specification_save_to_string (spec); - printf ("This is the spec: \n%s\n", spec_str); e_table_specification_load_from_string (new_spec, spec_str); g_free (spec_str); -- cgit