From 2e93b3da0b04b8f262891ebf38827b2d21f80905 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Wed, 3 Oct 2001 13:47:56 +0000 Subject: Pick which field of the row to select based on priority. 2001-10-03 Christopher James Lahey * e-table-click-to-add.c (set_initial_selection): Pick which field of the row to select based on priority. * e-table-col.c, e-table-col.h: Added the priority field to this class. Adapted the _new functions appropriately. * e-table-column-specification.c, e-table-column-specification.h: Added the priority field to this class. * e-table-utils.c (et_col_spec_to_col): Handle the priority field here. svn path=/trunk/; revision=13370 --- widgets/table/e-table-click-to-add.c | 35 ++++++++++++++++++++++------ widgets/table/e-table-col.c | 7 ++++-- widgets/table/e-table-col.h | 5 ++-- widgets/table/e-table-column-specification.c | 4 ++++ widgets/table/e-table-column-specification.h | 1 + widgets/table/e-table-utils.c | 4 ++-- 6 files changed, 43 insertions(+), 13 deletions(-) (limited to 'widgets') diff --git a/widgets/table/e-table-click-to-add.c b/widgets/table/e-table-click-to-add.c index a7cc26273f..3759b32e3e 100644 --- a/widgets/table/e-table-click-to-add.c +++ b/widgets/table/e-table-click-to-add.c @@ -280,6 +280,30 @@ item_key_press (ETableItem *item, int row, int col, GdkEvent *event, ETableClick return FALSE; } +static void +set_initial_selection (ETableClickToAdd *etcta) +{ + int best_model_col = 0; + int best_priority; + int i; + int count; + + count = e_table_header_count (etcta->eth); + if (count == 0) + return; + best_priority = e_table_header_get_column (etcta->eth, 0)->priority; + best_model_col = e_table_header_get_column (etcta->eth, 0)->col_idx; + for (i = 1; i < count; i++) { + int priority = e_table_header_get_column (etcta->eth, i)->priority; + if (priority > best_priority) { + best_priority = priority; + best_model_col = e_table_header_get_column (etcta->eth, i)->col_idx; + } + + } + e_selection_model_do_something (E_SELECTION_MODEL(etcta->selection), 0, best_model_col, 0); +} + static void finish_editing (ETableClickToAdd *etcta) { @@ -311,7 +335,7 @@ finish_editing (ETableClickToAdd *etcta) gtk_signal_connect(GTK_OBJECT(etcta->row), "key_press", GTK_SIGNAL_FUNC(item_key_press), etcta); - e_table_item_set_cursor(E_TABLE_ITEM(etcta->row), 0, 0); + set_initial_selection (etcta); } } @@ -322,7 +346,6 @@ static int etcta_event (GnomeCanvasItem *item, GdkEvent *e) { ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - int ret_val = TRUE; switch (e->type){ case GDK_BUTTON_PRESS: @@ -357,11 +380,9 @@ etcta_event (GnomeCanvasItem *item, GdkEvent *e) gtk_signal_connect(GTK_OBJECT(etcta->row), "key_press", GTK_SIGNAL_FUNC(item_key_press), etcta); - gnome_canvas_item_i2w (item, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (etcta->row, &e->button.x, &e->button.y); - gtk_signal_emit_by_name(GTK_OBJECT(etcta->row), "event", e, &ret_val); - gnome_canvas_item_i2w (etcta->row, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); + e_canvas_item_grab_focus (GNOME_CANVAS_ITEM(etcta->row), TRUE); + + set_initial_selection (etcta); } break; diff --git a/widgets/table/e-table-col.c b/widgets/table/e-table-col.c index 7a67a7cf55..9efeedcae7 100644 --- a/widgets/table/e-table-col.c +++ b/widgets/table/e-table-col.c @@ -85,6 +85,7 @@ e_table_col_init (ETableCol *etc) etc->sortable = 1; etc->groupable = 1; etc->justification = GTK_JUSTIFY_LEFT; + etc->priority = 0; } E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, e_table_col_init, PARENT_TYPE); @@ -117,7 +118,7 @@ E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, e_table */ ETableCol * e_table_col_new (int col_idx, const char *text, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) + ECell *ecell, GCompareFunc compare, gboolean resizable, int priority) { ETableCol *etc; @@ -138,6 +139,7 @@ e_table_col_new (int col_idx, const char *text, double expansion, int min_width, etc->min_width = min_width; etc->ecell = ecell; etc->compare = compare; + etc->priority = priority; etc->selected = 0; etc->resizable = resizable; @@ -175,7 +177,7 @@ e_table_col_new (int col_idx, const char *text, double expansion, int min_width, */ ETableCol * e_table_col_new_with_pixbuf (int col_idx, const char *text, GdkPixbuf *pixbuf, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) + ECell *ecell, GCompareFunc compare, gboolean resizable, int priority) { ETableCol *etc; @@ -196,6 +198,7 @@ e_table_col_new_with_pixbuf (int col_idx, const char *text, GdkPixbuf *pixbuf, d etc->min_width = min_width; etc->ecell = ecell; etc->compare = compare; + etc->priority = priority; etc->selected = 0; etc->resizable = resizable; diff --git a/widgets/table/e-table-col.h b/widgets/table/e-table-col.h index 8377beb37e..90deb85f3a 100644 --- a/widgets/table/e-table-col.h +++ b/widgets/table/e-table-col.h @@ -39,6 +39,7 @@ typedef struct { unsigned int sortable:1; unsigned int groupable:1; int col_idx; + int priority; GtkJustification justification; @@ -53,12 +54,12 @@ GtkType e_table_col_get_type (void); ETableCol *e_table_col_new (int col_idx, const char *text, double expansion, int min_width, ECell *ecell, GCompareFunc compare, - gboolean resizable); + gboolean resizable, int priority); ETableCol *e_table_col_new_with_pixbuf (int col_idx, const char *text, GdkPixbuf *pixbuf, double expansion, int min_width, ECell *ecell, GCompareFunc compare, - gboolean resizable); + gboolean resizable, int priority); void e_table_col_destroy (ETableCol *etc); diff --git a/widgets/table/e-table-column-specification.c b/widgets/table/e-table-column-specification.c index 68c19188b1..ad1122dec9 100644 --- a/widgets/table/e-table-column-specification.c +++ b/widgets/table/e-table-column-specification.c @@ -60,6 +60,7 @@ etcs_init (ETableColumnSpecification *specification) specification->cell = NULL; specification->compare = NULL; + specification->priority = 0; } E_MAKE_TYPE(e_table_column_specification, "ETableColumnSpecification", ETableColumnSpecification, etcs_class_init, etcs_init, PARENT_TYPE); @@ -88,6 +89,7 @@ e_table_column_specification_load_from_node (ETableColumnSpecification *etcs, etcs->cell = e_xml_get_string_prop_by_name(node, "cell"); etcs->compare = e_xml_get_string_prop_by_name(node, "compare"); + etcs->priority = e_xml_get_integer_prop_by_name_with_default (node, "priority", 0); if (etcs->title == NULL) etcs->title = g_strdup(""); @@ -113,6 +115,8 @@ e_table_column_specification_save_to_node (ETableColumnSpecification *specificat e_xml_set_string_prop_by_name(node, "cell", specification->cell); e_xml_set_string_prop_by_name(node, "compare", specification->compare); + if (specification->priority != 0) + e_xml_set_integer_prop_by_name (node, "priority", specification->priority); return node; } diff --git a/widgets/table/e-table-column-specification.h b/widgets/table/e-table-column-specification.h index 2bcbe75e20..07a8a41e11 100644 --- a/widgets/table/e-table-column-specification.h +++ b/widgets/table/e-table-column-specification.h @@ -29,6 +29,7 @@ typedef struct { char *cell; char *compare; + int priority; } ETableColumnSpecification; typedef struct { diff --git a/widgets/table/e-table-utils.c b/widgets/table/e-table-utils.c index 9c9aea6911..05b4d5a004 100644 --- a/widgets/table/e-table-utils.c +++ b/widgets/table/e-table-utils.c @@ -74,14 +74,14 @@ et_col_spec_to_col (ETableColumnSpecification *col_spec, col_spec->model_col, gettext (col_spec->title), pixbuf, col_spec->expansion, col_spec->minimum_width, - cell, compare, col_spec->resizable); + cell, compare, col_spec->resizable, col_spec->priority); } } if (col == NULL && col_spec->title && *col_spec->title) { col = e_table_col_new ( col_spec->model_col, gettext (col_spec->title), col_spec->expansion, col_spec->minimum_width, - cell, compare, col_spec->resizable); + cell, compare, col_spec->resizable, col_spec->priority); } } return col; -- cgit v1.2.3