Change the Register description layout cell type.

Currently the description cell type is QUICKFILL_CELL_TYPE and
commit changes it to COMBO_CELL_TYPE. Doing this allows the user to
select a transaction description from a list or do a similar search to
that of the transfer cell.
This commit is contained in:
Robert Fewell 2022-10-10 11:17:02 +01:00
parent e366528770
commit 46c2e44988
5 changed files with 97 additions and 5 deletions

View File

@ -675,7 +675,7 @@ gnc_split_register_layout_add_cells (SplitRegister* reg,
gnc_register_add_cell (layout,
DESC_CELL,
QUICKFILL_CELL_TYPE_NAME,
COMBO_CELL_TYPE_NAME,
C_ ("sample", "Description of a transaction"),
CELL_ALIGN_LEFT,
TRUE,

View File

@ -50,6 +50,7 @@ static QofLogModule log_module = GNC_MOD_LEDGER;
static void gnc_split_register_load_xfer_cells (SplitRegister* reg,
Account* base_account);
static void gnc_split_register_load_desc_cells (SplitRegister* reg);
static void
gnc_split_register_load_recn_cells (SplitRegister* reg)
{
@ -239,10 +240,6 @@ _find_split_with_parent_txn (gconstpointer a, gconstpointer b)
static void add_quickfill_completions (TableLayout* layout, Transaction* trans,
Split* split, gboolean has_last_num)
{
gnc_quickfill_cell_add_completion (
(QuickFillCell*) gnc_table_layout_get_cell (layout, DESC_CELL),
xaccTransGetDescription (trans));
gnc_quickfill_cell_add_completion (
(QuickFillCell*) gnc_table_layout_get_cell (layout, NOTES_CELL),
xaccTransGetNotes (trans));
@ -528,6 +525,7 @@ gnc_split_register_load (SplitRegister* reg, GList* slist,
/* load up account names into the transfer combobox menus */
gnc_split_register_load_xfer_cells (reg, default_account);
gnc_split_register_load_desc_cells (reg);
gnc_split_register_load_doclink_cells (reg);
gnc_split_register_load_recn_cells (reg);
gnc_split_register_load_type_cells (reg);
@ -662,6 +660,10 @@ gnc_split_register_load (SplitRegister* reg, GList* slist,
if (info->first_pass)
add_quickfill_completions (reg->table->layout, trans, split, has_last_num);
gnc_combo_cell_add_menu_item_unique (
(ComboCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL),
xaccTransGetDescription (trans));
if (trans == find_trans)
new_trans_row = vcell_loc.virt_row;
@ -851,4 +853,15 @@ gnc_split_register_load_xfer_cells (SplitRegister* reg, Account* base_account)
gnc_combo_cell_use_list_store_cache (cell, store);
}
static void
gnc_split_register_load_desc_cells (SplitRegister* reg)
{
ComboCell* cell;
GtkListStore* store = gtk_list_store_new (1, G_TYPE_STRING);
cell = (ComboCell*)
gnc_table_layout_get_cell (reg->table->layout, DESC_CELL);
gnc_combo_cell_use_list_store_cache (cell, store);
}
/* ====================== END OF FILE ================================== */

View File

@ -2666,6 +2666,11 @@ gnc_split_register_config_cells (SplitRegister* reg)
((ComboCell*)
gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL), TRUE);
/* the description cell */
gnc_combo_cell_set_autosize
((ComboCell*)
gnc_table_layout_get_cell (reg->table->layout, DESC_CELL), TRUE);
/* Use GNC_COMMODITY_MAX_FRACTION for prices and "exchange rates" */
gnc_price_cell_set_fraction
((PriceCell*)
@ -2693,6 +2698,11 @@ gnc_split_register_config_cells (SplitRegister* reg)
((ComboCell*)
gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL), FALSE);
/* The description cell should accept strings not in the list */
gnc_combo_cell_set_strict
((ComboCell*)
gnc_table_layout_get_cell (reg->table->layout, DESC_CELL), FALSE);
/* number format for share quantities in stock ledgers */
switch (reg->type)
{

View File

@ -63,6 +63,10 @@ void gnc_combo_cell_clear_menu (ComboCell* cell);
void gnc_combo_cell_add_menu_item (ComboCell* cell,
const char* menustr);
/** Add a unique menu item to the list. */
void gnc_combo_cell_add_menu_item_unique (ComboCell* cell,
const char* menustr);
/** Add a 'account name' menu item to the list. When testing for
* equality with the currently selected item, this function will
* ignore the characters normally used to separate account names. */

View File

@ -73,6 +73,8 @@ typedef struct _PopBox
gunichar complete_char; /* char to be used for auto-completion */
GList* ignore_strings;
GHashTable *item_hash;
} PopBox;
@ -163,6 +165,8 @@ gnc_combo_cell_init (ComboCell* cell)
box->complete_char = '\0';
box->ignore_strings = NULL;
box->item_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
static void
@ -333,6 +337,9 @@ gnc_combo_cell_destroy (BasicCell* bcell)
box->qf = NULL;
}
if (box->item_hash)
g_hash_table_destroy (box->item_hash);
g_list_free_full (box->ignore_strings, g_free);
box->ignore_strings = NULL;
@ -458,6 +465,64 @@ gnc_combo_cell_add_menu_item (ComboCell* cell, const char* menustr)
}
}
void
gnc_combo_cell_add_menu_item_unique (ComboCell* cell, const char* menustr)
{
PopBox* box;
if (cell == NULL)
return;
if (menustr == NULL)
return;
box = cell->cell.gui_private;
if (box->item_list != NULL)
{
block_list_signals (cell);
/* check if menustr has already been added. */
if (g_hash_table_lookup_extended (box->item_hash, menustr, NULL, NULL))
return;
g_hash_table_insert (box->item_hash, g_strdup (menustr), NULL);
gnc_item_list_append (box->item_list, menustr);
if (cell->cell.value &&
(strcmp (menustr, cell->cell.value) == 0))
gnc_item_list_select (box->item_list, menustr);
unblock_list_signals (cell);
}
else
{
GtkTreeIter iter;
// add a blank entry as the first entry in store
if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL(cell->shared_store), NULL) == 0)
{
gtk_list_store_append (cell->shared_store, &iter);
gtk_list_store_set (cell->shared_store, &iter, 0, "", -1);
g_hash_table_insert (box->item_hash, g_strdup (""), NULL);
}
/* check if menustr has already been added. */
if (g_hash_table_lookup_extended (box->item_hash, menustr, NULL, NULL))
return;
g_hash_table_insert (box->item_hash, g_strdup (menustr), NULL);
gtk_list_store_append (cell->shared_store, &iter);
gtk_list_store_set (cell->shared_store, &iter, 0, menustr, -1);
}
/* If we're going to be using a pre-fab quickfill,
* then don't fill it in here */
if (FALSE == box->use_quickfill_cache)
{
gnc_quickfill_insert (box->qf, menustr, QUICKFILL_ALPHA);
}
}
void
gnc_combo_cell_add_account_menu_item (ComboCell* cell, char* menustr)
{