diff options
Diffstat (limited to 'widgets/table/e-table-selection-model.c')
-rw-r--r-- | widgets/table/e-table-selection-model.c | 129 |
1 files changed, 117 insertions, 12 deletions
diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c index a2a0f99aa9..faeb1fad31 100644 --- a/widgets/table/e-table-selection-model.c +++ b/widgets/table/e-table-selection-model.c @@ -26,35 +26,125 @@ enum { ARG_MODEL, }; +#if 0 +static void +save_to_hash(int model_row, gpointer closure) +{ + ETableSelectionModel *etsm = closure; + gchar *key = e_table_model_get_save_id(etsm->model, model_row); + + g_hash_table_insert(etsm->hash, key, key); +} +#endif + +static void +free_key(gpointer key, gpointer value, gpointer closure) +{ + g_free(key); +} + +static void +free_hash(ETableSelectionModel *etsm) +{ + if (etsm->hash) { + g_hash_table_foreach(etsm->hash, free_key, NULL); + g_hash_table_destroy(etsm->hash); + etsm->hash = NULL; + } + g_free(etsm->cursor_id); + etsm->cursor_id = NULL; +} + +static void +model_pre_change (ETableModel *etm, ETableSelectionModel *etsm) +{ + free_hash(etsm); + +#if 0 + if (etsm->model && e_table_model_has_save_id(etsm->model)) { + gint cursor_row; + etsm->hash = g_hash_table_new(g_str_hash, g_str_equal); + e_selection_model_foreach(E_SELECTION_MODEL(etsm), save_to_hash, etsm); + gtk_object_get(GTK_OBJECT(etsm), + "cursor_row", &cursor_row, + NULL); + if (cursor_row != -1) { + etsm->cursor_id = e_table_model_get_save_id(etm, cursor_row); + } + } +#endif +} + static void model_changed(ETableModel *etm, ETableSelectionModel *etsm) { e_selection_model_clear(E_SELECTION_MODEL(etsm)); + +#if 0 + if (etm && e_table_model_has_save_id(etm)) { + int row_count = e_table_model_row_count(etm); + int i; + if (e_selection_model_confirm_row_count(E_SELECTION_MODEL(etsm))) { + for (i = 0; i < row_count; i++) { + char *save_id = e_table_model_get_save_id(etm, i); + if (g_hash_table_lookup(etsm->hash, save_id)) + e_selection_model_change_one_row(E_SELECTION_MODEL(etsm), i, TRUE); + if (etsm->cursor_id && !strcmp(etsm->cursor_id, save_id)) { + e_selection_model_change_cursor(E_SELECTION_MODEL(etsm), i); + g_free(etsm->cursor_id); + etsm->cursor_id = NULL; + } + g_free(save_id); + } + } + } +#endif + + if (etsm->hash) + free_hash(etsm); +} + +static void +model_row_changed(ETableModel *etm, int row, ETableSelectionModel *etsm) +{ + if (etsm->hash) + free_hash(etsm); +} + +static void +model_cell_changed(ETableModel *etm, int col, int row, ETableSelectionModel *etsm) +{ + if (etsm->hash) + free_hash(etsm); } #if 1 static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) +model_rows_inserted(ETableModel *etm, int row, int count, ETableSelectionModel *etsm) { - e_selection_model_insert_row(E_SELECTION_MODEL(etsm), row); + e_selection_model_insert_rows(E_SELECTION_MODEL(etsm), row, count); + if (etsm->hash) + free_hash(etsm); } static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) +model_rows_deleted(ETableModel *etm, int row, int count, ETableSelectionModel *etsm) { - e_selection_model_delete_row(E_SELECTION_MODEL(etsm), row); + e_selection_model_delete_rows(E_SELECTION_MODEL(etsm), row, count); + if (etsm->hash) + free_hash(etsm); } #else static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) +model_rows_inserted(ETableModel *etm, int row, int count, ETableSelectionModel *etsm) { model_changed(etm, etsm); } static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) +model_rows_deleted(ETableModel *etm, int row, int count, ETableSelectionModel *etsm) { model_changed(etm, etsm); } @@ -66,12 +156,18 @@ add_model(ETableSelectionModel *etsm, ETableModel *model) etsm->model = model; if (model) { gtk_object_ref(GTK_OBJECT(model)); + etsm->model_pre_change_id = gtk_signal_connect(GTK_OBJECT(model), "model_pre_change", + GTK_SIGNAL_FUNC(model_pre_change), etsm); etsm->model_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_changed", GTK_SIGNAL_FUNC(model_changed), etsm); - etsm->model_row_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_inserted", - GTK_SIGNAL_FUNC(model_row_inserted), etsm); - etsm->model_row_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_deleted", - GTK_SIGNAL_FUNC(model_row_deleted), etsm); + etsm->model_row_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_changed", + GTK_SIGNAL_FUNC(model_row_changed), etsm); + etsm->model_cell_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_cell_changed", + GTK_SIGNAL_FUNC(model_cell_changed), etsm); + etsm->model_rows_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_rows_inserted", + GTK_SIGNAL_FUNC(model_rows_inserted), etsm); + etsm->model_rows_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_rows_deleted", + GTK_SIGNAL_FUNC(model_rows_deleted), etsm); } } @@ -80,11 +176,17 @@ drop_model(ETableSelectionModel *etsm) { if (etsm->model) { gtk_signal_disconnect(GTK_OBJECT(etsm->model), + etsm->model_pre_change_id); + gtk_signal_disconnect(GTK_OBJECT(etsm->model), etsm->model_changed_id); gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_inserted_id); + etsm->model_row_changed_id); + gtk_signal_disconnect(GTK_OBJECT(etsm->model), + etsm->model_cell_changed_id); + gtk_signal_disconnect(GTK_OBJECT(etsm->model), + etsm->model_rows_inserted_id); gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_deleted_id); + etsm->model_rows_deleted_id); gtk_object_unref(GTK_OBJECT(etsm->model)); } etsm->model = NULL; @@ -98,6 +200,7 @@ etsm_destroy (GtkObject *object) etsm = E_TABLE_SELECTION_MODEL (object); drop_model(etsm); + free_hash(etsm); if (GTK_OBJECT_CLASS(parent_class)->destroy) GTK_OBJECT_CLASS(parent_class)->destroy (object); @@ -132,6 +235,8 @@ static void e_table_selection_model_init (ETableSelectionModel *selection) { selection->model = NULL; + selection->hash = NULL; + selection->cursor_id = NULL; } static void |