[Gnucash-changes] Changes to use shared quick-fill for teh account
transfer combo box.
Linas Vepstas
linas at cvs.gnucash.org
Mon May 31 13:47:20 EDT 2004
Log Message:
-----------
Changes to use shared quick-fill for teh account transfer combo box.
Untested but should work fine.
Modified Files:
--------------
gnucash/src/business/business-ledger:
gncEntryLedgerLoad.c
Revision Data
-------------
Index: gncEntryLedgerLoad.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-ledger/gncEntryLedgerLoad.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -Lsrc/business/business-ledger/gncEntryLedgerLoad.c -Lsrc/business/business-ledger/gncEntryLedgerLoad.c -u -r1.32 -r1.33
--- src/business/business-ledger/gncEntryLedgerLoad.c
+++ src/business/business-ledger/gncEntryLedgerLoad.c
@@ -29,13 +29,15 @@
#include <libguile.h>
#include "Account.h"
-#include "gnc-ui-util.h"
-#include "recncell.h"
+#include "account-quickfill.h"
#include "combocell.h"
-#include "messages.h"
#include "global-options.h"
-#include "business-options.h"
#include "gnc-component-manager.h"
+#include "gnc-ui-util.h"
+#include "messages.h"
+#include "recncell.h"
+
+#include "business-options.h"
#include "gncEntry.h"
#include "gncEntryLedger.h"
@@ -122,83 +124,114 @@
gnc_combo_cell_add_menu_item (cell, _("Charge"));
}
-static void load_xfer_cell (ComboCell * cell, AccountGroup * grp,
- GncEntryLedgerType ledger_type)
-{
- GList *list;
- GList *node;
-
- if (!grp) return;
-
- /* Build the xfer menu out of account names. */
+/* ==================================================================== */
+/* Return TRUE if we don't want to add this account to the xfer menu */
- list = xaccGroupGetSubAccounts (grp);
-
- for (node = list; node; node = node->next) {
- Account *account = node->data;
- char *name;
- GNCAccountType type;
+static gboolean
+skip_acct_cb (Account *account, gpointer user_data)
+{
+ GncEntryLedgerType ledger_type = (GncEntryLedgerType) user_data;
+ GNCAccountType type;
- /* Don't add placeholder accounts */
- if (xaccAccountGetPlaceholder (account))
- continue;
+ /* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
+ type = xaccAccountGetType (account);
+ if (type == PAYABLE || type == RECEIVABLE ||
+ type == CASH || type == BANK || type == EQUITY)
+ {
+ return TRUE;
+ }
- /* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
- type = xaccAccountGetType (account);
- if (type == PAYABLE || type == RECEIVABLE ||
- type == CASH || type == BANK || type == EQUITY)
- continue;
+ /* Don't add placeholder accounts */
+ if (xaccAccountGetPlaceholder (account))
+ {
+ return TRUE;
+ }
- /* If this is an ORDER or INVOICE, then leave out the expenses.
- * if it's a BILL, then leave out the incomes
- */
- switch (ledger_type) {
+ /* If this is an ORDER or INVOICE, then leave out the expenses.
+ * if it's a BILL, then leave out the incomes
+ */
+ switch (ledger_type)
+ {
case GNCENTRY_ORDER_ENTRY:
case GNCENTRY_ORDER_VIEWER:
case GNCENTRY_INVOICE_ENTRY:
case GNCENTRY_INVOICE_VIEWER:
- if (type == EXPENSE) continue;
- break;
+ if (type == EXPENSE) return TRUE;
+ return FALSE;
case GNCENTRY_BILL_ENTRY:
case GNCENTRY_BILL_VIEWER:
case GNCENTRY_EXPVOUCHER_ENTRY:
case GNCENTRY_EXPVOUCHER_VIEWER:
case GNCENTRY_NUM_REGISTER_TYPES:
- if (type == INCOME) continue;
- break;
- }
+ if (type == INCOME) return TRUE;
+ return FALSE;
+ }
+ return FALSE;
+}
- name = xaccAccountGetFullName (account, gnc_get_account_separator ());
- if (name != NULL)
- gnc_combo_cell_add_menu_item (cell, name);
+/* ===================================================================== */
+/* Splat the account name into the transfer cell combobox menu */
- g_free(name);
- }
+typedef struct {
+ ComboCell *cell;
+ GncEntryLedgerType ledger_type;
+} BCE;
- g_list_free (list);
+static gpointer
+load_xfer_cell_cb (Account *account, gpointer data)
+{
+ BCE *bce = data;
+ char *name;
+
+ if (skip_acct_cb (account, (gpointer) bce->ledger_type)) return NULL;
+
+ name = xaccAccountGetFullName (account, gnc_get_account_separator ());
+ if (NULL == name) return NULL;
+ gnc_combo_cell_add_menu_item (bce->cell, name);
+ g_free(name);
+
+ return NULL;
}
-static void load_xfer_type_cells (GncEntryLedger *ledger)
+#define BKEY "Business entry quickfill"
+
+static void
+load_xfer_type_cells (GncEntryLedger *ledger)
{
+ BCE bce;
AccountGroup *group;
ComboCell *cell;
+ QuickFill *qf;
group = gnc_book_get_group (ledger->book);
- if (group == NULL)
- return;
+ if (group == NULL) return;
+
+ /* Use a common, shared quickfill */
+ qf = gnc_get_shared_account_name_quickfill (group, BKEY,
+ skip_acct_cb, (gpointer) ledger->type);
cell = (ComboCell *)
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_IACCT_CELL);
gnc_combo_cell_clear_menu (cell);
- load_xfer_cell (cell, group, ledger->type);
+ gnc_combo_cell_use_quickfill_cache (cell, qf);
+
+ bce.cell = cell;
+ bce.ledger_type = ledger->type;
+ xaccGroupForEachAccount (group, load_xfer_cell_cb, &bce, TRUE);
cell = (ComboCell *)
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_BACCT_CELL);
gnc_combo_cell_clear_menu (cell);
- load_xfer_cell (cell, group, ledger->type);
+ gnc_combo_cell_use_quickfill_cache (cell, qf);
+
+ bce.cell = cell;
+ bce.ledger_type = ledger->type;
+ xaccGroupForEachAccount (group, load_xfer_cell_cb, &bce, TRUE);
}
+/* ===================================================================== */
+
static void load_taxtable_type_cells (GncEntryLedger *ledger)
{
GList *list;
@@ -240,6 +273,10 @@
/* XXX (FIXME): This should be in a config file! */
/* Copy GncEntry information from the list to the rows of the Ledger. */
+/* XXX This code is a cut-n-paste job from the SplitRegister code;
+ * the split-regsiter should be generalized to the point where a cut-n-paste
+ * like this isn't required, and this should be trashed.
+ */
void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
{
static SCM id_book = SCM_UNDEFINED;
@@ -506,3 +543,5 @@
/* enable callback for cursor user-driven moves */
gnc_table_control_allow_move (table->control, TRUE);
}
+
+/* =========================== END OF FILE ========================== */
More information about the gnucash-changes
mailing list