Skip to content

Commit

Permalink
Use new completion cell for register description field
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob-IT committed May 29, 2023
1 parent f46a958 commit 3c81b4c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 123 deletions.
2 changes: 1 addition & 1 deletion gnucash/register/ledger-core/split-register-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ gnc_split_register_layout_add_cells (SplitRegister* reg,

gnc_register_add_cell (layout,
DESC_CELL,
COMBO_CELL_TYPE_NAME,
COMPLETION_CELL_TYPE_NAME,
C_ ("sample", "Description of a transaction"),
CELL_ALIGN_LEFT,
TRUE,
Expand Down
44 changes: 27 additions & 17 deletions gnucash/register/ledger-core/split-register-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "Transaction.h"
#include "account-quickfill.h"
#include "combocell.h"
#include "completioncell.h"
#include "gnc-component-manager.h"
#include "qof.h"
#include "gnc-ui-util.h"
Expand All @@ -54,7 +55,6 @@ 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)
{
Expand Down Expand Up @@ -113,6 +113,21 @@ gnc_split_register_load_type_cells (SplitRegister* reg)
gnc_recn_cell_set_read_only (cell, TRUE);
}

static void
gnc_split_register_load_desc_cells (SplitRegister* reg)
{
CompletionCell *cell;

if (!reg) return;

cell = (CompletionCell *)
gnc_table_layout_get_cell (reg->table->layout, DESC_CELL);

if (!cell) return;

gnc_completion_cell_set_sort_enabled (cell, TRUE);
}

/** Add a transaction to the register.
*
* Virtual cells are set up to hold the data, beginning at @a vcell_loc and
Expand Down Expand Up @@ -609,6 +624,13 @@ gnc_split_register_load (SplitRegister* reg, GList* slist,
added_blank_trans = TRUE;
}

gnc_completion_cell_clear_menu (
(CompletionCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL));

gnc_completion_cell_reverse_sort (
(CompletionCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL),
table->model->reverse_sort);

/* populate the table */
for (node = slist; node; node = node->next)
{
Expand Down Expand Up @@ -729,9 +751,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));
gnc_completion_cell_add_menu_item (
(CompletionCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL),
xaccTransGetDescription (trans));


if (trans == find_trans)
new_trans_row = vcell_loc.virt_row;
Expand Down Expand Up @@ -936,17 +959,4 @@ 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_type_ahead_only (cell);

gnc_combo_cell_use_list_store_cache (cell, store);
}
/* ====================== END OF FILE ================================== */
17 changes: 9 additions & 8 deletions gnucash/register/ledger-core/split-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <glib/gi18n.h>

#include "combocell.h"
#include "completioncell.h"
#include "datecell.h"
#include "dialog-utils.h"
#include "gnc-component-manager.h"
Expand Down Expand Up @@ -2665,10 +2666,10 @@ 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);
/* the description cell */
gnc_completion_cell_set_autosize
((CompletionCell*)
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
Expand Down Expand Up @@ -2697,10 +2698,10 @@ 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);
/* The description cell should accept strings not in the list */
gnc_completion_cell_set_strict
((CompletionCell*)
gnc_table_layout_get_cell (reg->table->layout, DESC_CELL), FALSE);

/* number format for share quantities in stock ledgers */
switch (reg->type)
Expand Down
8 changes: 0 additions & 8 deletions gnucash/register/register-core/combocell.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ 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. */
Expand Down Expand Up @@ -108,9 +104,5 @@ void gnc_combo_cell_use_quickfill_cache (ComboCell* cell,
QuickFill* shared_qf);
void gnc_combo_cell_use_list_store_cache (ComboCell* cell, gpointer data);

/** Set the combocell to use only type ahead search. This will make the
* search to be more like a modified entry completion. */
void gnc_combo_cell_use_type_ahead_only (ComboCell* cell);

/** @} */
#endif
90 changes: 1 addition & 89 deletions gnucash/register/register-gnome/combocell-gnome.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ typedef struct _PopBox

GList* ignore_strings;

GHashTable *item_hash;

gboolean use_type_ahead_only;
} PopBox;


Expand Down Expand Up @@ -168,10 +165,6 @@ 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);

box->use_type_ahead_only = FALSE;
}

static void
Expand Down Expand Up @@ -340,9 +333,6 @@ 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;

Expand Down Expand Up @@ -468,70 +458,6 @@ 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);

gchar *menustr_temp = g_strdup (menustr);
gnc_utf8_strip_invalid_and_controls (menustr_temp);
gnc_item_list_append (box->item_list, menustr_temp);
if (cell->cell.value &&
(strcmp (menustr_temp, cell->cell.value) == 0))
gnc_item_list_select (box->item_list, menustr_temp);
g_free (menustr_temp);
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);

gchar *menustr_temp = g_strdup (menustr);
gnc_utf8_strip_invalid_and_controls (menustr_temp);
gtk_list_store_append (cell->shared_store, &iter);
gtk_list_store_set (cell->shared_store, &iter, 0, menustr_temp, -1);
g_free (menustr_temp);
}

/* 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)
{
Expand Down Expand Up @@ -713,8 +639,7 @@ gnc_combo_cell_modify_verify (BasicCell* _cell,
return;
}

if (!box->use_type_ahead_only) // Do we only want to use type-ahead
match_str = quickfill_match (box->qf, newval);
match_str = quickfill_match (box->qf, newval);

if (match_str != NULL) // Do we have a quickfill match
{
Expand Down Expand Up @@ -937,19 +862,6 @@ gnc_combo_cell_direct_update (BasicCell* bcell,
return TRUE;
}

void
gnc_combo_cell_use_type_ahead_only (ComboCell* cell)
{
PopBox* box;

if (cell == NULL) return;

box = cell->cell.gui_private;

box->use_type_ahead_only = TRUE;

}

static void
gnc_combo_cell_gui_realize (BasicCell* bcell, gpointer data)
{
Expand Down
2 changes: 2 additions & 0 deletions gnucash/register/register-gnome/gnucash-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "gnc-state.h"

#include "combocell.h"
#include "completioncell.h"
#include "datecell.h"
#include "formulacell-gnome.h"
#include "pricecell-gnome.h"
Expand Down Expand Up @@ -100,6 +101,7 @@ void
gnucash_register_add_cell_types (void)
{
gnc_register_add_cell_type (COMBO_CELL_TYPE_NAME, gnc_combo_cell_new);
gnc_register_add_cell_type (COMPLETION_CELL_TYPE_NAME, gnc_completion_cell_new);
gnc_register_add_cell_type (DATE_CELL_TYPE_NAME, gnc_date_cell_new);
gnc_register_add_cell_type (PRICE_CELL_TYPE_NAME,
gnc_price_cell_gnome_new);
Expand Down

0 comments on commit 3c81b4c

Please sign in to comment.