From 3012f7b1f28abda4cb15c50d061af165889bc08b Mon Sep 17 00:00:00 2001 From: Not Zed Date: Mon, 9 Oct 2000 12:24:54 +0000 Subject: Removed the assertion that there must be at least 1 column. No way to 2000-10-06 Not Zed * e-table-item.c (eti_header_structure_changed): Removed the assertion that there must be at least 1 column. No way to remove all columns otherwise (which the header allows). * e-table.c (et_xml_config_header): Reconfigure header based on xml nodes for header. (et_real_set_specification): Just configure the header only, dont try to recreate everything. 2000-10-05 Not Zed * e-table-scrolled.c (e_table_scrolled_set_specification): Set the spec on a scrolled etable. (e_table_scrolled_load_specification): Likewise for load. * e-table.c (et_real_set_specification): Allow you to set the specification after the widget was created. (et_real_construct): Changed to use et_real_set_specification to set the spec. (e_table_load_specification): New frunction, load the speficication from a specific file. (e_table_set_specification): NEw function to set the specification from a string. svn path=/trunk/; revision=5795 --- widgets/table/e-table.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) (limited to 'widgets/table/e-table.c') diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index 294cfa9968..a9598c214f 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -624,6 +624,32 @@ et_xml_to_header (ETable *e_table, ETableHeader *full_header, xmlNode *xmlColumn return nh; } +static void +et_xml_config_header (ETable *e_table, xmlNode *xmlColumns) +{ + xmlNode *column; + const int max_cols = e_table_header_count(e_table->full_header); + int i; + + for (i=e_table_header_count(e_table->header)-1;i>=0;i--) { + e_table_header_remove(e_table->header, i); + } + + for (column = xmlColumns->childs; column; column = column->next) { + char *content; + int col; + + content = xmlNodeListGetString (column->doc, column->childs, 1); + col = atoi (content); + xmlFree (content); + + if (col >= max_cols) + continue; + + e_table_header_add_column (e_table->header, e_table_header_get_column (e_table->full_header, col), -1); + } +} + static void et_grouping_xml_to_sort_info (ETable *table, xmlNode *grouping) { @@ -657,6 +683,25 @@ et_grouping_xml_to_sort_info (ETable *table, xmlNode *grouping) GTK_SIGNAL_FUNC (sort_info_changed), table); } +static int +et_real_set_specification (ETable *e_table, xmlDoc *xmlSpec) +{ + xmlNode *xmlRoot; + xmlNode *xmlColumns; + xmlNode *xmlGrouping; + + xmlRoot = xmlDocGetRootElement (xmlSpec); + xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown"); + xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping"); + + if ((xmlColumns == NULL) || (xmlGrouping == NULL)) + return -1; + + et_xml_config_header(e_table, xmlColumns); + + return 0; +} + static ETable * et_real_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, xmlDoc *xmlSpec) @@ -676,7 +721,6 @@ et_real_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, no_header = e_xml_get_integer_prop_by_name(xmlRoot, "no-header"); e_table->use_click_to_add = e_xml_get_integer_prop_by_name(xmlRoot, "click-to-add"); - e_table->full_header = full_header; gtk_object_ref (GTK_OBJECT (full_header)); @@ -901,6 +945,24 @@ e_table_get_specification (ETable *e_table) return buffer; } +int +e_table_set_specification (ETable *e_table, const char *spec) +{ + xmlDoc *xmlSpec; + int ret; + + g_return_val_if_fail(e_table != NULL, -1); + g_return_val_if_fail(E_IS_TABLE(e_table), -1); + g_return_val_if_fail(spec != NULL, -1); + + /* doesn't work yet, sigh */ + xmlSpec = xmlParseMemory ((char *)spec, strlen(spec)); + ret = et_real_set_specification(e_table, xmlSpec); + xmlFreeDoc (xmlSpec); + + return ret; +} + void e_table_save_specification (ETable *e_table, gchar *filename) { @@ -914,6 +976,24 @@ e_table_save_specification (ETable *e_table, gchar *filename) xmlFreeDoc (doc); } +int +e_table_load_specification (ETable *e_table, gchar *filename) +{ + xmlDoc *xmlSpec; + int ret; + + g_return_val_if_fail(e_table != NULL, -1); + g_return_val_if_fail(E_IS_TABLE(e_table), -1); + g_return_val_if_fail(filename != NULL, -1); + + /* doesn't work yet, yay */ + xmlSpec = xmlParseFile (filename); + ret = et_real_set_specification(e_table, xmlSpec); + xmlFreeDoc (xmlSpec); + + return ret; +} + void e_table_set_cursor_row (ETable *e_table, int row) { -- cgit v1.2.3