diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-10-14 02:53:51 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-10-14 02:53:51 +0800 |
commit | c144d2091888813efe3b7ae4414b356fd080b610 (patch) | |
tree | 727511bf87a68e794081e42191009a5a67b440ea /widgets/table/e-table-config.c | |
parent | 9704f5dbf64e9f34d4ef7b4c0844b82319d4a2cf (diff) | |
download | gsoc2013-evolution-c144d2091888813efe3b7ae4414b356fd080b610.tar.gz gsoc2013-evolution-c144d2091888813efe3b7ae4414b356fd080b610.tar.zst gsoc2013-evolution-c144d2091888813efe3b7ae4414b356fd080b610.zip |
Added e-table-config-field.lo.
2000-10-13 Christopher James Lahey <clahey@helixcode.com>
* gal/Makefile.am: Added e-table-config-field.lo.
* tests/test-tree-2.c: Changed this to use cursor-mode in the xml
instead of the no longer existing gtk argument.
From gal/e-table/ChangeLog:
2000-10-13 Christopher James Lahey <clahey@helixcode.com>
* Makefile.am: Added e-table-config-field.c and
e-table-config-field.h.
* e-table-column-specification.c: Cleaned this up a bit. Made it
leak less memory.
* e-table-config-field.c, e-table-config-field.h: New files.
This is the configuration widgets for sorting or grouping.
* e-table-config.c, e-table-config.h: Nuked these and replaced
them with a widget that handles all the ETable configuration.
* e-table-config.glade, e-table-config.glade.h: Updated this a bit
to match what's actually being used better. This isn't used in
actual code.
* e-table-header-item.c, e-table-header-item.h: Added a pointer to
the table in the header item structure so that we can launch the
configuration from the header item right click menu. Made the
header item launch the ETable configuration dialog.
* e-table.c, e-table.h: Keep the spec given to us around. Added a
get_state_object function which returns an ETableState *. Set the
"table" argument on the header item.
svn path=/trunk/; revision=5901
Diffstat (limited to 'widgets/table/e-table-config.c')
-rw-r--r-- | widgets/table/e-table-config.c | 440 |
1 files changed, 251 insertions, 189 deletions
diff --git a/widgets/table/e-table-config.c b/widgets/table/e-table-config.c index a2831da73a..679c2d5b63 100644 --- a/widgets/table/e-table-config.c +++ b/widgets/table/e-table-config.c @@ -1,250 +1,312 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * E-table.c: A graphical view of a Table. + * E-table-config.c: The ETable config dialog. * * Author: - * Miguel de Icaza (miguel@gnu.org) + * Chris Lahey <clahey@helixcode.com> * - * Copyright 1999, Helix Code, Inc + * (C) 2000 Helix Code, Inc. */ + #include <config.h> +#include <stdlib.h> #include <gnome.h> -#include <glade/glade.h> -#include <gnome-xml/xmlmemory.h> -#include "gal/util/e-util.h" -#include "gal/util/e-xml-utils.h" -#include "gal/widgets/e-canvas.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" #include "e-table-config.h" +#include "e-table-config-field.h" +#include "gal/util/e-util.h" -typedef struct { - GladeXML *gui; - char *old_spec; -} ConfigData; - -static void -load_data (GladeXML *xml, char *label_widget, const char *content) -{ - GtkLabel *label = GTK_LABEL (glade_xml_get_widget (xml, label_widget)); +#define PARENT_TYPE (gnome_dialog_get_type()) - gtk_label_set_text (label, content); -} +static GnomeDialogClass *etco_parent_class; -static char * -get_fields (ETable *etable, xmlNode *xmlRoot) +static void +etco_destroy (GtkObject *object) { - xmlNode *xmlColumns; - xmlNode *column; - GString *res; - char *s; - - res = g_string_new (""); - xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown"); - - for (column = xmlColumns->childs; column; column = column->next){ - ETableCol *ecol; - char *content; - int col; - - content = xmlNodeListGetString (column->doc, column->childs, 1); - col = atoi (content); - xmlFree (content); - - ecol = e_table_header_get_column (etable->header, col); - - g_string_append (res, ecol->text); - if (column->next) - g_string_append (res, ", "); + ETableConfig *etco = E_TABLE_CONFIG (object); + + if (etco->state) { + if (etco->sorting_changed_id) + gtk_signal_disconnect(GTK_OBJECT(etco->state->sort_info), etco->sorting_changed_id); + if (etco->grouping_changed_id) + gtk_signal_disconnect(GTK_OBJECT(etco->state->sort_info), etco->grouping_changed_id); + gtk_object_unref(GTK_OBJECT(etco->state)); } - s = res->str; - g_string_free (res, FALSE); - - return s; -} - -static char * -get_grouping (ETable *etable, xmlNode *xmlRoot) -{ - xmlNode *xmlGrouping; - GString *res; - char *s; - - res = g_string_new (""); - xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping"); - s = res->str; - g_string_free (res, FALSE); + gtk_object_unref(GTK_OBJECT(etco->spec)); - return s; -} - -static char * -get_sort (ETable *etable) -{ - return g_strdup ("None"); -} - -static char * -get_filter (ETable *etable) -{ - return g_strdup ("None"); + GTK_OBJECT_CLASS (etco_parent_class)->destroy (object); } -/* - * Loads a user-readable definition of the various e-table parameters - * into the dialog for configuring it - */ static void -load_label_data (GladeXML *gui, ETable *etable) +etco_class_init (GtkObjectClass *klass) { - /* FIXME: Set this to the right value. */ - xmlNode *xmlRoot = NULL; - char *s; + etco_parent_class = gtk_type_class (PARENT_TYPE); -/* xmlRoot = xmlDocGetRootElement (etable->specification); */ - - s = get_fields (etable, xmlRoot); - load_data (gui, "label1", s); - g_free (s); - - s = get_grouping (etable, xmlRoot); - load_data (gui, "label2", s); - g_free (s); - - s = get_sort (etable); - load_data (gui, "label3", s); - g_free (s); - - s = get_filter (etable); - load_data (gui, "label4", s); - g_free (s); + klass->destroy = etco_destroy; } static void -cb_button_fields (GtkWidget *widget, ETable *etable) +etco_clear_sort(GtkWidget *widget, ETableConfig *etco) { + etco->sort_dialog = NULL; + gtk_object_unref(GTK_OBJECT(etco)); } static void -cb_button_grouping (GtkWidget *widget, ETable *etable) +etco_clear_group(GtkWidget *widget, ETableConfig *etco) { + etco->group_dialog = NULL; + gtk_object_unref(GTK_OBJECT(etco)); } static void -cb_button_sort (GtkWidget *widget, ETable *etable) +etco_sort_config_show(GtkWidget *widget, ETableConfig *etco) { + if (etco->sort_dialog) + gdk_window_raise(GTK_WIDGET(etco->sort_dialog)->window); + else { + GtkWidget *etcf; + etco->sort_dialog = gnome_dialog_new(_("Sort"), + GNOME_STOCK_BUTTON_OK, + NULL); + etcf = GTK_WIDGET(e_table_config_field_new(etco->spec, + etco->state->sort_info, + FALSE)); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(etco->sort_dialog)->vbox), etcf, FALSE, FALSE, 0); + gnome_dialog_set_parent(GNOME_DIALOG(etco->sort_dialog), + GTK_WINDOW(etco)); + + gtk_signal_connect(GTK_OBJECT(etco->sort_dialog), "destroy", + GTK_SIGNAL_FUNC(etco_clear_sort), etco); + gtk_object_ref(GTK_OBJECT(etco)); + + gtk_signal_connect(GTK_OBJECT(etco->sort_dialog), "clicked", + GTK_SIGNAL_FUNC(gnome_dialog_close), etco); + + gtk_widget_show(GTK_WIDGET(etcf)); + gtk_widget_show(GTK_WIDGET(etco->sort_dialog)); + } } static void -cb_button_filter (GtkWidget *widget, ETable *etable) +etco_group_config_show(GtkWidget *widget, ETableConfig *etco) { + if (etco->group_dialog) + gdk_window_raise(GTK_WIDGET(etco->group_dialog)->window); + else { + GtkWidget *etcf; + etco->group_dialog = gnome_dialog_new(_("Group"), + GNOME_STOCK_BUTTON_OK, + NULL); + etcf = GTK_WIDGET(e_table_config_field_new(etco->spec, + etco->state->sort_info, + TRUE)); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(etco->group_dialog)->vbox), etcf, FALSE, FALSE, 0); + gnome_dialog_set_parent(GNOME_DIALOG(etco->group_dialog), + GTK_WINDOW(etco)); + + gtk_signal_connect(GTK_OBJECT(etco->group_dialog), "destroy", + GTK_SIGNAL_FUNC(etco_clear_group), etco); + gtk_signal_connect(GTK_OBJECT(etco->group_dialog), "clicked", + GTK_SIGNAL_FUNC(gnome_dialog_close), etco); + gtk_object_ref(GTK_OBJECT(etco)); + + gtk_widget_show(GTK_WIDGET(etcf)); + gtk_widget_show(GTK_WIDGET(etco->group_dialog)); + } } -GnomeDialog * -e_table_gui_config (ETable *etable) +static void +etco_sort_info_update(ETableSortInfo *info, ETableConfig *etco) { - GladeXML *gui; - GnomeDialog *dialog; - ConfigData *config_data; - - g_return_val_if_fail(etable != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE(etable), NULL); - - glade_gnome_init (); - gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-config.glade", NULL); - if (!gui) - return NULL; - - dialog = GNOME_DIALOG (glade_xml_get_widget (gui, "e-table-config")); - - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-fields")), - "clicked", GTK_SIGNAL_FUNC (cb_button_fields), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-grouping")), - "clicked", GTK_SIGNAL_FUNC (cb_button_grouping), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-sort")), - "clicked", GTK_SIGNAL_FUNC (cb_button_sort), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-filter")), - "clicked", GTK_SIGNAL_FUNC (cb_button_filter), etable); - - load_label_data (gui, etable); - - config_data = g_new (ConfigData, 1); - config_data->gui = gui; - config_data->old_spec = e_table_get_state (etable); - - gtk_object_set_data ( - GTK_OBJECT (dialog), "config-data", - config_data); - - return dialog; + int count; + int i; + gchar **strings; + gchar *substrings[3]; + int stringcount = 0; + gchar *string; + + count = e_table_sort_info_sorting_get_count(info); + strings = g_new(gchar *, count + 1); + + for (i = 0; i < count; i++) { + ETableSortColumn col = e_table_sort_info_sorting_get_nth(info, i); + ETableColumnSpecification **column; + + substrings[0] = NULL; + + for (column = etco->spec->columns; *column; column++) { + if (col.column == (*column)->model_col) { + substrings[0] = (*column)->title_; + break; + } + } + + if (substrings[0]) { + substrings[1] = col.ascending ? _("(Ascending)") : _("(Descending)"); + substrings[2] = NULL; + strings[stringcount++] = g_strjoinv(" ", substrings); + } + } + strings[stringcount] = NULL; + string = g_strjoinv(", ", strings); + + for (i = 0; strings[i]; i++) { + g_free(strings[i]); + } + gtk_label_set_text(GTK_LABEL(etco->sort_label), string); + g_free(string); + } static void -e_table_gui_destroy_config_data (GtkWidget *widget) +etco_group_info_update(ETableSortInfo *info, ETableConfig *etco) { - ConfigData *cd = gtk_object_get_data (GTK_OBJECT (widget), "config-data"); + int count; + int i; + gchar **strings; + gchar *substrings[3]; + int stringcount = 0; + gchar *string; + + count = e_table_sort_info_grouping_get_count(info); + strings = g_new(gchar *, count + 1); + + for (i = 0; i < count; i++) { + ETableSortColumn col = e_table_sort_info_grouping_get_nth(info, i); + ETableColumnSpecification **column; + + substrings[0] = NULL; + + for (column = etco->spec->columns; *column; column++) { + if (col.column == (*column)->model_col) { + substrings[0] = (*column)->title_; + break; + } + } + + if (substrings[0]) { + substrings[1] = col.ascending ? _("(Ascending)") : _("(Descending)"); + substrings[2] = NULL; + strings[stringcount++] = g_strjoinv(" ", substrings); + } + } + strings[stringcount] = NULL; + string = g_strjoinv(", ", strings); + + for (i = 0; strings[i]; i++) { + g_free(strings[i]); + } + gtk_label_set_text(GTK_LABEL(etco->group_label), string); + g_free(string); - g_free (cd->old_spec); - gtk_object_destroy (GTK_OBJECT (cd->gui)); - g_free (cd); } -void -e_table_gui_config_accept (GtkWidget *widget, ETable *etable) +static void +etco_init (ETableConfig *etco) { - g_return_if_fail(etable != NULL); - g_return_if_fail(E_IS_TABLE(etable)); - g_return_if_fail(widget != NULL); - g_return_if_fail(GTK_IS_WIDGET(widget)); - - e_table_gui_destroy_config_data (widget); + GtkWidget *frame; + GtkWidget *table; + GtkWidget *sort_button; + GtkWidget *group_button; + + gtk_window_set_title(GTK_WINDOW(etco), _("View Summary")); + gnome_dialog_append_buttons(GNOME_DIALOG(etco), + GNOME_STOCK_BUTTON_OK, + NULL); + gnome_dialog_set_default(GNOME_DIALOG(etco), 0); + + frame = gtk_frame_new(_("Description")); + gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(etco)->vbox), frame, FALSE, FALSE, 0); + + table = gtk_table_new(2, 2, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(table), 6); + gtk_table_set_col_spacings(GTK_TABLE(table), 6); + gtk_container_add(GTK_CONTAINER(frame), table); + gtk_container_set_border_width(GTK_CONTAINER(table), 6); + + sort_button = gtk_button_new_with_label(_("Sort...")); + gtk_table_attach(GTK_TABLE(table), + sort_button, + 0, 1, 0, 1, + GTK_FILL, + GTK_FILL, + 0, 0); + + group_button = gtk_button_new_with_label(_("Group By...")); + gtk_table_attach(GTK_TABLE(table), + group_button, + 0, 1, 1, 2, + GTK_FILL, + GTK_FILL, + 0, 0); + + etco->sort_label = gtk_label_new(""); + gtk_table_attach(GTK_TABLE(table), + etco->sort_label, + 1, 2, 0, 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL, + 0, 0); + + etco->group_label = gtk_label_new(""); + gtk_table_attach(GTK_TABLE(table), + etco->group_label, + 1, 2, 1, 2, + GTK_FILL | GTK_EXPAND, + GTK_FILL, + 0, 0); + + gtk_signal_connect(GTK_OBJECT(sort_button), "clicked", + GTK_SIGNAL_FUNC(etco_sort_config_show), etco); + gtk_signal_connect(GTK_OBJECT(group_button), "clicked", + GTK_SIGNAL_FUNC(etco_group_config_show), etco); + + gtk_widget_show(etco->group_label); + gtk_widget_show(etco->sort_label); + gtk_widget_show(group_button); + gtk_widget_show(sort_button); + gtk_widget_show(table); + gtk_widget_show(frame); + + etco->sorting_changed_id = 0; + etco->grouping_changed_id = 0; } -void -e_table_gui_config_cancel (GtkWidget *widget, ETable *etable) +E_MAKE_TYPE(e_table_config, "ETableConfig", ETableConfig, etco_class_init, etco_init, PARENT_TYPE); + +GtkWidget * +e_table_config_new (ETableSpecification *spec, + ETableState *state) { - g_return_if_fail(etable != NULL); - g_return_if_fail(E_IS_TABLE(etable)); - g_return_if_fail(widget != NULL); - g_return_if_fail(GTK_IS_WIDGET(widget)); + ETableConfig *etco = gtk_type_new (E_TABLE_CONFIG_TYPE); - e_table_gui_destroy_config_data (widget); + e_table_config_construct(etco, spec, state); + + return GTK_WIDGET(etco); } -void -e_table_do_gui_config (GtkWidget *parent, ETable *etable) +GtkWidget * +e_table_config_construct (ETableConfig *etco, + ETableSpecification *spec, + ETableState *state) { - GnomeDialog *dialog; - int r; - - g_return_if_fail(etable != NULL); - g_return_if_fail(E_IS_TABLE(etable)); - g_return_if_fail(parent == NULL || GTK_IS_WINDOW(parent)); + etco->spec = spec; + etco->state = state; - dialog = GNOME_DIALOG (e_table_gui_config (etable)); - if (!dialog) - return; + if (etco->spec) + gtk_object_ref(GTK_OBJECT(etco->spec)); + if (etco->state) + gtk_object_ref(GTK_OBJECT(etco->state)); - if (parent) - gnome_dialog_set_parent (dialog, GTK_WINDOW (parent)); - - r = gnome_dialog_run (GNOME_DIALOG (dialog)); + etco->sorting_changed_id = gtk_signal_connect(GTK_OBJECT(etco->state->sort_info), "sort_info_changed", + GTK_SIGNAL_FUNC(etco_sort_info_update), etco); + etco->grouping_changed_id = gtk_signal_connect(GTK_OBJECT(etco->state->sort_info), "group_info_changed", + GTK_SIGNAL_FUNC(etco_group_info_update), etco); - if (r == -1 || r == 1) - e_table_gui_config_cancel (GTK_WIDGET (dialog), etable); - else - e_table_gui_config_accept (GTK_WIDGET (dialog), etable); + etco_sort_info_update(etco->state->sort_info, etco); + etco_group_info_update(etco->state->sort_info, etco); - if (r != -1) - gtk_object_destroy (GTK_OBJECT (dialog)); + return GTK_WIDGET(etco); } - |