From fb02a024eb794e180bdd1e2c72417c0f6e894b43 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Fri, 24 May 2002 06:21:05 +0000 Subject: [PATCH] Sorting in the reconciliation window is now done by clicking on the column titles. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6906 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 ++ src/gnome/reconcile-list.c | 88 +++++++++++++-- src/gnome/reconcile-list.h | 8 ++ src/gnome/window-reconcile.c | 201 ----------------------------------- 4 files changed, 96 insertions(+), 208 deletions(-) diff --git a/ChangeLog b/ChangeLog index 445795d52e..709fb58036 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2002-05-23 David Hampton + * src/gnome/reconcile-list.c: Encapsulate all list sorting logic + within the GNCReconcileList object. Reconciliation lists are now + sorted by clicking on the column titles, and sorts can be both + increasing and decreasing. + + * src/gnome/window-reconcile.c: Remove all list sorting logic. + * src/gnome-utils/gnc-amount-edit.c: Reparent the amount editor widget so it is based upon a GtkEntry. This allows trivial GtkEntry <-> GncAmountEdit conversions. diff --git a/src/gnome/reconcile-list.c b/src/gnome/reconcile-list.c index 5765df92cb..18b65dc9db 100644 --- a/src/gnome/reconcile-list.c +++ b/src/gnome/reconcile-list.c @@ -58,6 +58,8 @@ static void gnc_reconcile_list_unselect_row(GtkCList *clist, gint row, gint column, GdkEvent *event); static void gnc_reconcile_list_destroy(GtkObject *object); static void gnc_reconcile_list_fill(GNCReconcileList *list); +static void gnc_reconcile_click_column_cb(GtkWidget *w, gint column, + gpointer data); GtkType @@ -156,6 +158,28 @@ update_toggle (GtkCList *list, gint row) gnc_clist_set_check (list, row, 4, reconciled); } +static GtkWidget * +gnc_reconcile_list_column_title (GtkCList *clist, gint column, + const gchar *title) +{ + GtkWidget *hbox, *label, *arrow; + + hbox = gtk_hbox_new(FALSE, 2); + gtk_widget_show(hbox); + gtk_clist_set_column_widget(clist, column, hbox); + + label = gtk_label_new(title); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_ETCHED_IN); + gtk_widget_show(arrow); + gtk_widget_set_sensitive(arrow, column == 0); + gtk_box_pack_end(GTK_BOX(hbox), arrow, FALSE, FALSE, 0); + + return(arrow); +} + static void gnc_reconcile_list_init (GNCReconcileList *list) { @@ -186,9 +210,22 @@ gnc_reconcile_list_init (GNCReconcileList *list) gtk_clist_construct (clist, list->num_columns, titles); gtk_clist_set_shadow_type (clist, GTK_SHADOW_IN); + + list->date_arrow = gnc_reconcile_list_column_title(clist, 0, titles[0]); + list->num_arrow = gnc_reconcile_list_column_title(clist, 1, titles[1]); + list->desc_arrow = gnc_reconcile_list_column_title(clist, 2, titles[2]); + list->amount_arrow = gnc_reconcile_list_column_title(clist, 3, titles[3]); + + gtk_clist_set_column_justification (clist, 1, GTK_JUSTIFY_CENTER); gtk_clist_set_column_justification (clist, 3, GTK_JUSTIFY_RIGHT); gtk_clist_set_column_justification (clist, 4, GTK_JUSTIFY_CENTER); - gtk_clist_column_titles_passive (clist); + gtk_clist_column_title_passive (clist, 4); + + gtk_signal_connect (GTK_OBJECT (clist), "click_column", + GTK_SIGNAL_FUNC(gnc_reconcile_click_column_cb), NULL); + + list->key = BY_STANDARD; + list->increasing = TRUE; style = gtk_widget_get_style (GTK_WIDGET(list)); @@ -721,21 +758,58 @@ gnc_reconcile_list_changed (GNCReconcileList *list) void gnc_reconcile_list_set_sort_order (GNCReconcileList *list, sort_type_t key) { + GtkWidget *arrow; + g_return_if_fail (list != NULL); g_return_if_fail (IS_GNC_RECONCILE_LIST(list)); g_return_if_fail (list->query != NULL); + list->increasing = (list->key == key) ? !list->increasing : TRUE; + list->key = key; + + gtk_widget_set_sensitive(list->date_arrow, FALSE); + gtk_widget_set_sensitive(list->num_arrow, FALSE); + gtk_widget_set_sensitive(list->amount_arrow, FALSE); + gtk_widget_set_sensitive(list->desc_arrow, FALSE); + switch (key) { + default: + case BY_STANDARD: arrow = list->date_arrow; break; + case BY_NUM: arrow = list->num_arrow; break; + case BY_AMOUNT: arrow = list->amount_arrow; break; + case BY_DESC: arrow = list->desc_arrow; break; + } + + gtk_arrow_set(GTK_ARROW(arrow), + list->increasing ? GTK_ARROW_DOWN : GTK_ARROW_UP, + GTK_SHADOW_ETCHED_IN); + gtk_widget_set_sensitive(arrow, TRUE); + xaccQuerySetSortOrder (list->query, key, (key == BY_STANDARD) ? BY_NONE : BY_STANDARD, BY_NONE); - if (list->list_type == RECLIST_DEBIT) - return; - xaccQuerySetSortIncreasing (list->query, - !(key == BY_AMOUNT), - !(key == BY_AMOUNT), - !(key == BY_AMOUNT)); + list->increasing, + list->increasing, + list->increasing); + + gnc_reconcile_list_refresh(list); +} + +static void +gnc_reconcile_click_column_cb(GtkWidget *w, gint column, gpointer data) +{ + GNCReconcileList *list = GNC_RECONCILE_LIST(w); + sort_type_t type; + + switch (column) { + case 0: type = BY_STANDARD; break; + case 1: type = BY_NUM; break; + case 2: type = BY_DESC; break; + case 3: type = BY_AMOUNT; break; + default: return; + } + gnc_reconcile_list_set_sort_order(list, type); } static void diff --git a/src/gnome/reconcile-list.h b/src/gnome/reconcile-list.h index 59be4f230c..7c76421416 100644 --- a/src/gnome/reconcile-list.h +++ b/src/gnome/reconcile-list.h @@ -69,6 +69,14 @@ struct _GNCReconcileList Query *query; GNCReconcileList *sibling; + + /* Sorting info */ + sort_type_t key; + gboolean increasing; + GtkWidget *date_arrow; + GtkWidget *num_arrow; + GtkWidget *amount_arrow; + GtkWidget *desc_arrow; }; struct _GNCReconcileListClass diff --git a/src/gnome/window-reconcile.c b/src/gnome/window-reconcile.c index d9328a4466..96533bc07f 100644 --- a/src/gnome/window-reconcile.c +++ b/src/gnome/window-reconcile.c @@ -69,9 +69,6 @@ struct _RecnWindow gint component_id; /* id of component */ - sort_type_t debit_sort; /* Sorting style of the debit list */ - sort_type_t credit_sort; /* Sorting style of the credit list */ - GtkWidget *window; /* The reconcile window */ GtkWidget *toolbar; /* Toolbar widget */ @@ -96,12 +93,6 @@ struct _RecnWindow GtkWidget *edit_item; /* Edit transaction menu item */ GtkWidget *delete_item; /* Delete transaction menu item */ - GtkWidget *sort_debits_formal; /* Sort debits menu formal */ - GtkWidget *sort_credits_formal; /* Sort credits menu formal */ - - GtkWidget *sort_debits_informal; /* Sort debits menu informal */ - GtkWidget *sort_credits_informal; /* Sort credits menu informal */ - GtkWidget *edit_popup; /* Edit transaction popup menu item */ GtkWidget *delete_popup; /* Delete transaction popup menu item */ @@ -919,21 +910,6 @@ gnc_reconcile_window_set_titles(RecnWindow *recnData) if (!formal) g_free(title); - - if (formal) - { - gtk_widget_show(recnData->sort_debits_formal); - gtk_widget_show(recnData->sort_credits_formal); - gtk_widget_hide(recnData->sort_debits_informal); - gtk_widget_hide(recnData->sort_credits_informal); - } - else - { - gtk_widget_hide(recnData->sort_debits_formal); - gtk_widget_hide(recnData->sort_credits_formal); - gtk_widget_show(recnData->sort_debits_informal); - gtk_widget_show(recnData->sort_credits_informal); - } } static void @@ -1203,114 +1179,6 @@ gnc_recn_open_cb(GtkWidget *widget, gpointer data) gnc_register_raise (regData); } -static void -gnc_reconcile_sort(RecnWindow *recnData, GNCReconcileListType list_type, - sort_type_t sort_code) -{ - GNCReconcileList *list; - sort_type_t *old_type_p; - - if (list_type == RECLIST_DEBIT) - { - list = GNC_RECONCILE_LIST(recnData->debit); - old_type_p = &recnData->debit_sort; - } - else - { - list = GNC_RECONCILE_LIST(recnData->credit); - old_type_p = &recnData->credit_sort; - } - - if (sort_code == *old_type_p) - return; - - switch(sort_code) - { - default: - case BY_STANDARD: - gnc_reconcile_list_set_sort_order(list, BY_STANDARD); - break; - case BY_NUM: - gnc_reconcile_list_set_sort_order(list, BY_NUM); - break; - case BY_AMOUNT: - gnc_reconcile_list_set_sort_order(list, BY_AMOUNT); - break; - case BY_DESC: - gnc_reconcile_list_set_sort_order(list, BY_DESC); - break; - } - - *old_type_p = sort_code; - - gnc_reconcile_list_refresh(GNC_RECONCILE_LIST(recnData->debit)); - gnc_reconcile_list_refresh(GNC_RECONCILE_LIST(recnData->credit)); -} - -static void -sort_debit_standard_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_DEBIT, BY_STANDARD); -} - -static void -sort_debit_num_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_DEBIT, BY_NUM); -} - -static void -sort_debit_desc_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_DEBIT, BY_DESC); -} - -static void -sort_debit_amount_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_DEBIT, BY_AMOUNT); -} - -static void -sort_credit_standard_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_CREDIT, BY_STANDARD); -} - -static void -sort_credit_num_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_CREDIT, BY_NUM); -} - -static void -sort_credit_desc_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_CREDIT, BY_DESC); -} - -static void -sort_credit_amount_cb(GtkWidget *w, gpointer data) -{ - RecnWindow *recnData = data; - - gnc_reconcile_sort(recnData, RECLIST_CREDIT, BY_AMOUNT); -} - static GtkWidget * gnc_recn_create_menu_bar(RecnWindow *recnData, GtkWidget *statusbar) { @@ -1356,61 +1224,6 @@ gnc_recn_create_menu_bar(RecnWindow *recnData, GtkWidget *statusbar) GNOMEUIINFO_END }; - static GnomeUIInfo sort_debit_list[] = - { - GNOMEUIINFO_RADIOITEM_DATA(N_("Standard order"), - N_("Keep normal account order"), - sort_debit_standard_cb, NULL, NULL), - GNOMEUIINFO_RADIOITEM_DATA(N_("Sort by Num"), - N_("Sort by Num"), - sort_debit_num_cb, NULL, NULL), - GNOMEUIINFO_RADIOITEM_DATA(N_("Sort by Description"), - N_("Sort by Description"), - sort_debit_desc_cb, NULL, NULL), - GNOMEUIINFO_RADIOITEM_DATA(N_("Sort by Amount"), - N_("Sort by Amount"), - sort_debit_amount_cb, NULL, NULL), - GNOMEUIINFO_END - }; - - static GnomeUIInfo sort_debit_menu[] = - { - GNOMEUIINFO_RADIOLIST(sort_debit_list), - GNOMEUIINFO_END - }; - - static GnomeUIInfo sort_credit_list[] = - { - GNOMEUIINFO_RADIOITEM_DATA(N_("Standard order"), - N_("Keep normal account order"), - sort_credit_standard_cb, NULL, NULL), - GNOMEUIINFO_RADIOITEM_DATA(N_("Sort by Num"), - N_("Sort by Num"), - sort_credit_num_cb, NULL, NULL), - GNOMEUIINFO_RADIOITEM_DATA(N_("Sort by Description"), - N_("Sort by Description"), - sort_credit_desc_cb, NULL, NULL), - GNOMEUIINFO_RADIOITEM_DATA(N_("Sort by Amount"), - N_("Sort by Amount"), - sort_credit_amount_cb, NULL, NULL), - GNOMEUIINFO_END - }; - - static GnomeUIInfo sort_credit_menu[] = - { - GNOMEUIINFO_RADIOLIST(sort_credit_list), - GNOMEUIINFO_END - }; - - static GnomeUIInfo sort_menu[] = - { - GNOMEUIINFO_SUBTREE(N_("Debits"), sort_debit_menu), - GNOMEUIINFO_SUBTREE(N_("Credits"), sort_credit_menu), - GNOMEUIINFO_SUBTREE(NULL, sort_debit_menu), - GNOMEUIINFO_SUBTREE(NULL, sort_credit_menu), - GNOMEUIINFO_END - }; - static GnomeUIInfo account_menu[] = { { @@ -1489,7 +1302,6 @@ gnc_recn_create_menu_bar(RecnWindow *recnData, GtkWidget *statusbar) static GnomeUIInfo reconcile_window_menu[] = { GNOMEUIINFO_SUBTREE(N_("_Reconcile"), reconcile_menu), - GNOMEUIINFO_SUBTREE(N_("Sort _Order"), sort_menu), GNOMEUIINFO_SUBTREE(N_("_Account"), account_menu), GNOMEUIINFO_SUBTREE(N_("_Transaction"), transaction_menu), GNOMEUIINFO_MENU_HELP_TREE(help_menu), @@ -1498,9 +1310,6 @@ gnc_recn_create_menu_bar(RecnWindow *recnData, GtkWidget *statusbar) gnc_fill_menu_with_data(reconcile_window_menu, recnData); - sort_menu[2].label = gnc_get_debit_string(NO_TYPE); - sort_menu[3].label = gnc_get_credit_string(NO_TYPE); - menubar = gtk_menu_bar_new(); accel_group = gtk_accel_group_new(); @@ -1515,14 +1324,6 @@ gnc_recn_create_menu_bar(RecnWindow *recnData, GtkWidget *statusbar) recnData->edit_item = transaction_menu[1].widget; recnData->delete_item = transaction_menu[2].widget; - recnData->sort_debits_formal = sort_menu[0].widget; - recnData->sort_credits_formal = sort_menu[1].widget; - recnData->sort_debits_informal = sort_menu[2].widget; - recnData->sort_credits_informal = sort_menu[3].widget; - - g_free(sort_menu[2].label); - g_free(sort_menu[3].label); - return menubar; } @@ -1845,8 +1646,6 @@ recnWindow (GtkWidget *parent, Account *account) recnData->statement_date = statement_date; recnData->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); recnData->delete_refresh = FALSE; - recnData->debit_sort = BY_STANDARD; - recnData->credit_sort = BY_STANDARD; gnc_recn_set_window_name(recnData);