mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Jean Laroche's 'fix_autocompletion_master' into master.
This commit is contained in:
commit
f74d7c52da
@ -30,8 +30,10 @@
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
static QofLogModule log_module = GNC_MOD_REGISTER;
|
||||
|
||||
static void shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer qfb);
|
||||
static void listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
static void shared_quickfill_pref_changed (gpointer prefs, gchar* pref,
|
||||
gpointer qfb);
|
||||
static void listen_for_account_events (QofInstance* entity,
|
||||
QofEventId event_type,
|
||||
gpointer user_data, gpointer event_data);
|
||||
|
||||
/* Column indices for the list store */
|
||||
@ -51,20 +53,23 @@ static void listen_for_account_events (QofInstance *entity, QofEventId event_typ
|
||||
|
||||
typedef struct
|
||||
{
|
||||
QuickFill *qf;
|
||||
QuickFill* qf;
|
||||
gboolean load_list_store;
|
||||
GtkListStore *list_store;
|
||||
QofBook *book;
|
||||
Account *root;
|
||||
GtkListStore* list_store;
|
||||
/* For the type-ahead search, we need two lists, list_store contains the accounts that
|
||||
match the search. list_store_full contain the original full list of accounts. */
|
||||
GtkListStore* list_store_full;
|
||||
QofBook* book;
|
||||
Account* root;
|
||||
gint listener;
|
||||
AccountBoolCB dont_add_cb;
|
||||
gpointer dont_add_data;
|
||||
} QFB;
|
||||
|
||||
static void
|
||||
shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
|
||||
shared_quickfill_destroy (QofBook* book, gpointer key, gpointer user_data)
|
||||
{
|
||||
QFB *qfb = user_data;
|
||||
QFB* qfb = user_data;
|
||||
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
|
||||
GNC_PREF_ACCOUNT_SEPARATOR,
|
||||
shared_quickfill_pref_changed,
|
||||
@ -75,6 +80,7 @@ shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
|
||||
qfb);
|
||||
gnc_quickfill_destroy (qfb->qf);
|
||||
g_object_unref (qfb->list_store);
|
||||
g_object_unref (qfb->list_store_full);
|
||||
qof_event_unregister_handler (qfb->listener);
|
||||
g_free (qfb);
|
||||
}
|
||||
@ -82,20 +88,20 @@ shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
|
||||
|
||||
typedef struct find_data
|
||||
{
|
||||
GList *accounts;
|
||||
GList *refs;
|
||||
GList* accounts;
|
||||
GList* refs;
|
||||
} find_data;
|
||||
|
||||
static gboolean
|
||||
shared_quickfill_find_accounts (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
shared_quickfill_find_accounts (GtkTreeModel* model,
|
||||
GtkTreePath* path,
|
||||
GtkTreeIter* iter,
|
||||
gpointer user_data)
|
||||
{
|
||||
Account *account = NULL;
|
||||
find_data *data = user_data;
|
||||
Account* account = NULL;
|
||||
find_data* data = user_data;
|
||||
GtkTreeRowReference* ref;
|
||||
GList *tmp;
|
||||
GList* tmp;
|
||||
|
||||
gtk_tree_model_get (model, iter, ACCOUNT_POINTER, &account, -1);
|
||||
for (tmp = data->accounts; tmp; tmp = g_list_next (tmp))
|
||||
@ -114,10 +120,10 @@ shared_quickfill_find_accounts (GtkTreeModel *model,
|
||||
|
||||
/* Splat the account name into the shared quickfill object */
|
||||
static void
|
||||
load_shared_qf_cb (Account *account, gpointer data)
|
||||
load_shared_qf_cb (Account* account, gpointer data)
|
||||
{
|
||||
QFB *qfb = data;
|
||||
char *name;
|
||||
QFB* qfb = data;
|
||||
char* name;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (qfb->dont_add_cb)
|
||||
@ -138,19 +144,25 @@ load_shared_qf_cb (Account *account, gpointer data)
|
||||
ACCOUNT_NAME, name,
|
||||
ACCOUNT_POINTER, account,
|
||||
-1);
|
||||
gtk_list_store_append (qfb->list_store_full, &iter);
|
||||
gtk_list_store_set (qfb->list_store_full, &iter,
|
||||
ACCOUNT_NAME, name,
|
||||
ACCOUNT_POINTER, account,
|
||||
-1);
|
||||
}
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer user_data)
|
||||
shared_quickfill_pref_changed (gpointer prefs, gchar* pref, gpointer user_data)
|
||||
{
|
||||
QFB *qfb = user_data;
|
||||
QFB* qfb = user_data;
|
||||
|
||||
/* Reload the quickfill */
|
||||
gnc_quickfill_purge (qfb->qf);
|
||||
gtk_list_store_clear (qfb->list_store);
|
||||
gtk_list_store_clear (qfb->list_store_full);
|
||||
qfb->load_list_store = TRUE;
|
||||
gnc_account_foreach_descendant (qfb->root, load_shared_qf_cb, qfb);
|
||||
qfb->load_list_store = FALSE;
|
||||
@ -160,22 +172,24 @@ shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer user_data)
|
||||
/* Build the quickfill list out of account names.
|
||||
* Essentially same loop as in gnc_load_xfer_cell() above.
|
||||
*/
|
||||
static QFB *
|
||||
build_shared_quickfill (QofBook *book, Account *root, const char * key,
|
||||
static QFB*
|
||||
build_shared_quickfill (QofBook* book, Account* root, const char* key,
|
||||
AccountBoolCB cb, gpointer data)
|
||||
{
|
||||
QFB *qfb;
|
||||
QFB* qfb;
|
||||
|
||||
qfb = g_new0 (QFB, 1);
|
||||
qfb->qf = gnc_quickfill_new ();
|
||||
qfb->qf = gnc_quickfill_new();
|
||||
qfb->book = book;
|
||||
qfb->root = root;
|
||||
qfb->listener = 0;
|
||||
qfb->dont_add_cb = cb;
|
||||
qfb->dont_add_data = data;
|
||||
qfb->load_list_store = TRUE;
|
||||
qfb->list_store = gtk_list_store_new (NUM_ACCOUNT_COLUMNS,
|
||||
G_TYPE_STRING, G_TYPE_POINTER);
|
||||
qfb->list_store = gtk_list_store_new (NUM_ACCOUNT_COLUMNS,
|
||||
G_TYPE_STRING, G_TYPE_POINTER);
|
||||
qfb->list_store_full = gtk_list_store_new (NUM_ACCOUNT_COLUMNS,
|
||||
G_TYPE_STRING, G_TYPE_POINTER);
|
||||
|
||||
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
|
||||
GNC_PREF_ACCOUNT_SEPARATOR,
|
||||
@ -197,12 +211,12 @@ build_shared_quickfill (QofBook *book, Account *root, const char * key,
|
||||
return qfb;
|
||||
}
|
||||
|
||||
QuickFill *
|
||||
gnc_get_shared_account_name_quickfill (Account *root, const char * key,
|
||||
QuickFill*
|
||||
gnc_get_shared_account_name_quickfill (Account* root, const char* key,
|
||||
AccountBoolCB cb, gpointer cb_data)
|
||||
{
|
||||
QFB *qfb;
|
||||
QofBook *book;
|
||||
QFB* qfb;
|
||||
QofBook* book;
|
||||
|
||||
book = gnc_account_get_book (root);
|
||||
qfb = qof_book_get_data (book, key);
|
||||
@ -214,12 +228,12 @@ gnc_get_shared_account_name_quickfill (Account *root, const char * key,
|
||||
return qfb->qf;
|
||||
}
|
||||
|
||||
GtkListStore *
|
||||
gnc_get_shared_account_name_list_store (Account *root, const char * key,
|
||||
GtkListStore*
|
||||
gnc_get_shared_account_name_list_store (Account* root, const char* key,
|
||||
AccountBoolCB cb, gpointer cb_data)
|
||||
{
|
||||
QFB *qfb;
|
||||
QofBook *book;
|
||||
QFB* qfb;
|
||||
QofBook* book;
|
||||
|
||||
book = gnc_account_get_book (root);
|
||||
qfb = qof_book_get_data (book, key);
|
||||
@ -231,58 +245,76 @@ gnc_get_shared_account_name_list_store (Account *root, const char * key,
|
||||
return qfb->list_store;
|
||||
}
|
||||
|
||||
GtkListStore*
|
||||
gnc_get_shared_account_name_list_store_full (Account* root, const char* key,
|
||||
AccountBoolCB cb, gpointer cb_data)
|
||||
{
|
||||
QFB* qfb;
|
||||
QofBook* book;
|
||||
|
||||
book = gnc_account_get_book (root);
|
||||
qfb = qof_book_get_data (book, key);
|
||||
|
||||
if (qfb)
|
||||
return qfb->list_store_full;
|
||||
|
||||
qfb = build_shared_quickfill (book, root, key, cb, cb_data);
|
||||
return qfb->list_store_full;
|
||||
}
|
||||
|
||||
/* Since we are maintaining a 'global' quickfill list, we need to
|
||||
* update it whenever the user creates a new account. So listen
|
||||
* for account modification events, and add new accounts.
|
||||
*/
|
||||
static void
|
||||
listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
listen_for_account_events (QofInstance* entity, QofEventId event_type,
|
||||
gpointer user_data, gpointer event_data)
|
||||
{
|
||||
QFB *qfb = user_data;
|
||||
QuickFill *qf = qfb->qf;
|
||||
QuickFill *match;
|
||||
char * name;
|
||||
const char *match_str;
|
||||
Account *account;
|
||||
QFB* qfb = user_data;
|
||||
QuickFill* qf = qfb->qf;
|
||||
QuickFill* match;
|
||||
char* name;
|
||||
const char* match_str;
|
||||
Account* account;
|
||||
GtkTreeIter iter;
|
||||
find_data data = { 0 };
|
||||
GtkTreePath *path;
|
||||
GList *tmp;
|
||||
GtkTreePath* path;
|
||||
GList* tmp;
|
||||
gboolean valid;
|
||||
|
||||
if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_ADD | QOF_EVENT_REMOVE)))
|
||||
return;
|
||||
|
||||
if (!GNC_IS_ACCOUNT(entity))
|
||||
if (!GNC_IS_ACCOUNT (entity))
|
||||
return;
|
||||
account = GNC_ACCOUNT(entity);
|
||||
account = GNC_ACCOUNT (entity);
|
||||
|
||||
ENTER("entity %p, event type %x, user data %p, ecent data %p",
|
||||
entity, event_type, user_data, event_data);
|
||||
ENTER ("entity %p, event type %x, user data %p, ecent data %p",
|
||||
entity, event_type, user_data, event_data);
|
||||
|
||||
if (gnc_account_get_root(account) != qfb->root)
|
||||
if (gnc_account_get_root (account) != qfb->root)
|
||||
{
|
||||
LEAVE("root account mismatch");
|
||||
LEAVE ("root account mismatch");
|
||||
return;
|
||||
}
|
||||
|
||||
name = gnc_get_account_name_for_register (account);
|
||||
if (NULL == name)
|
||||
{
|
||||
LEAVE("account has no name");
|
||||
LEAVE ("account has no name");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event_type)
|
||||
{
|
||||
case QOF_EVENT_MODIFY:
|
||||
DEBUG("modify %s", name);
|
||||
DEBUG ("modify %s", name);
|
||||
|
||||
/* Find the account (and all its descendants) in the model. The
|
||||
* full name of all these accounts has changed. */
|
||||
data.accounts = gnc_account_get_descendants (account);
|
||||
data.accounts = g_list_prepend (data.accounts, account);
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL(qfb->list_store),
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (qfb->list_store_full),
|
||||
shared_quickfill_find_accounts, &data);
|
||||
|
||||
/* Update the existing items in the list store. Its possible
|
||||
@ -291,17 +323,17 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
* store. Otherwise its a simple update of the name string. */
|
||||
for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
|
||||
{
|
||||
gchar *old_name, *new_name;
|
||||
gchar* old_name, *new_name;
|
||||
path = gtk_tree_row_reference_get_path (tmp->data);
|
||||
gtk_tree_row_reference_free (tmp->data);
|
||||
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL(qfb->list_store),
|
||||
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (qfb->list_store_full),
|
||||
&iter, path))
|
||||
{
|
||||
gtk_tree_path_free (path);
|
||||
continue;
|
||||
}
|
||||
gtk_tree_path_free (path);
|
||||
gtk_tree_model_get (GTK_TREE_MODEL(qfb->list_store), &iter,
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (qfb->list_store_full), &iter,
|
||||
ACCOUNT_POINTER, &account,
|
||||
ACCOUNT_NAME, &old_name,
|
||||
-1);
|
||||
@ -314,15 +346,15 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
gnc_quickfill_remove (qf, old_name, QUICKFILL_ALPHA);
|
||||
|
||||
if (qfb->dont_add_cb &&
|
||||
qfb->dont_add_cb (account, qfb->dont_add_data))
|
||||
qfb->dont_add_cb (account, qfb->dont_add_data))
|
||||
{
|
||||
gnc_quickfill_remove (qf, new_name, QUICKFILL_ALPHA);
|
||||
gtk_list_store_remove (qfb->list_store, &iter);
|
||||
gtk_list_store_remove (qfb->list_store_full, &iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
gnc_quickfill_insert (qf, new_name, QUICKFILL_ALPHA);
|
||||
gtk_list_store_set (qfb->list_store, &iter,
|
||||
gtk_list_store_set (qfb->list_store_full, &iter,
|
||||
ACCOUNT_NAME, new_name,
|
||||
-1);
|
||||
}
|
||||
@ -344,8 +376,8 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
}
|
||||
}
|
||||
gnc_quickfill_insert (qf, name, QUICKFILL_ALPHA);
|
||||
gtk_list_store_append (qfb->list_store, &iter);
|
||||
gtk_list_store_set (qfb->list_store, &iter,
|
||||
gtk_list_store_append (qfb->list_store_full, &iter);
|
||||
gtk_list_store_set (qfb->list_store_full, &iter,
|
||||
ACCOUNT_NAME, name,
|
||||
ACCOUNT_POINTER, account,
|
||||
-1);
|
||||
@ -353,14 +385,14 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
break;
|
||||
|
||||
case QOF_EVENT_REMOVE:
|
||||
DEBUG("remove %s", name);
|
||||
DEBUG ("remove %s", name);
|
||||
|
||||
/* Remove from qf */
|
||||
gnc_quickfill_remove (qfb->qf, name, QUICKFILL_ALPHA);
|
||||
|
||||
/* Does the account exist in the model? */
|
||||
data.accounts = g_list_append (NULL, account);
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL(qfb->list_store),
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (qfb->list_store_full),
|
||||
shared_quickfill_find_accounts, &data);
|
||||
|
||||
/* Remove from list store */
|
||||
@ -368,20 +400,20 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
{
|
||||
path = gtk_tree_row_reference_get_path (tmp->data);
|
||||
gtk_tree_row_reference_free (tmp->data);
|
||||
if (gtk_tree_model_get_iter (GTK_TREE_MODEL(qfb->list_store),
|
||||
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (qfb->list_store_full),
|
||||
&iter, path))
|
||||
{
|
||||
gtk_list_store_remove (qfb->list_store, &iter);
|
||||
gtk_list_store_remove (qfb->list_store_full, &iter);
|
||||
}
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
break;
|
||||
|
||||
case QOF_EVENT_ADD:
|
||||
DEBUG("add %s", name);
|
||||
DEBUG ("add %s", name);
|
||||
|
||||
if (qfb->dont_add_cb &&
|
||||
qfb->dont_add_cb (account, qfb->dont_add_data))
|
||||
qfb->dont_add_cb (account, qfb->dont_add_data))
|
||||
break;
|
||||
|
||||
match = gnc_quickfill_get_string_match (qf, name);
|
||||
@ -397,24 +429,43 @@ listen_for_account_events (QofInstance *entity, QofEventId event_type,
|
||||
|
||||
PINFO ("insert new account %s into qf=%p", name, qf);
|
||||
gnc_quickfill_insert (qf, name, QUICKFILL_ALPHA);
|
||||
gtk_list_store_append (qfb->list_store, &iter);
|
||||
gtk_list_store_set (qfb->list_store, &iter,
|
||||
gtk_list_store_append (qfb->list_store_full, &iter);
|
||||
gtk_list_store_set (qfb->list_store_full, &iter,
|
||||
ACCOUNT_NAME, name,
|
||||
ACCOUNT_POINTER, account,
|
||||
-1);
|
||||
break;
|
||||
|
||||
default:
|
||||
DEBUG("other %s", name);
|
||||
DEBUG ("other %s", name);
|
||||
break;
|
||||
}
|
||||
/* Now that qfb->list_store_full has been updated, qfb->list_store also needs to be updated in
|
||||
case we're using the regular search. */
|
||||
gtk_list_store_clear (qfb->list_store);
|
||||
|
||||
g_debug ("Replicate shared_store_full\n");
|
||||
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (qfb->list_store_full),
|
||||
&iter);
|
||||
while (valid)
|
||||
{
|
||||
gchar* str_data = NULL;
|
||||
GtkTreeIter iter2;
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (qfb->list_store_full), &iter, 0, &str_data,
|
||||
-1);
|
||||
gtk_list_store_append (qfb->list_store, &iter2);
|
||||
gtk_list_store_set (qfb->list_store, &iter2, 0, str_data, -1);
|
||||
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (qfb->list_store_full),
|
||||
&iter);
|
||||
g_free (str_data);
|
||||
}
|
||||
|
||||
if (data.accounts)
|
||||
g_list_free (data.accounts);
|
||||
if (data.refs)
|
||||
g_list_free (data.refs);
|
||||
g_free (name);
|
||||
LEAVE(" ");
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
/* ====================== END OF FILE ================================== */
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "Account.h"
|
||||
#include "QuickFill.h"
|
||||
|
||||
typedef gboolean (*AccountBoolCB) (Account *, gpointer);
|
||||
typedef gboolean (*AccountBoolCB) (Account*, gpointer);
|
||||
|
||||
/** Create/fetch a quickfill of account names.
|
||||
*
|
||||
@ -68,12 +68,15 @@ typedef gboolean (*AccountBoolCB) (Account *, gpointer);
|
||||
* it). This code does not currently listen to account-destroy
|
||||
* events.
|
||||
*/
|
||||
QuickFill *
|
||||
gnc_get_shared_account_name_quickfill (Account *root, const char * key,
|
||||
QuickFill*
|
||||
gnc_get_shared_account_name_quickfill (Account* root, const char* key,
|
||||
AccountBoolCB skip_cb, gpointer cb_data);
|
||||
GtkListStore *
|
||||
gnc_get_shared_account_name_list_store (Account *root, const char * key,
|
||||
GtkListStore*
|
||||
gnc_get_shared_account_name_list_store (Account* root, const char* key,
|
||||
AccountBoolCB cb, gpointer cb_data);
|
||||
GtkListStore*
|
||||
gnc_get_shared_account_name_list_store_full (Account* root, const char* key,
|
||||
AccountBoolCB cb, gpointer cb_data);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -45,43 +45,43 @@
|
||||
static const QofLogModule log_module = "Business Entry Ledger";
|
||||
|
||||
/* XXX: This should go elsewhere */
|
||||
const char * gnc_entry_ledger_type_string_getter (char flag)
|
||||
const char* gnc_entry_ledger_type_string_getter (char flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
case '1':
|
||||
return _("$");
|
||||
return _ ("$");
|
||||
case '2':
|
||||
return _("%");
|
||||
return _ ("%");
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return "?";
|
||||
}
|
||||
|
||||
const char * gnc_entry_ledger_how_string_getter (char flag)
|
||||
const char* gnc_entry_ledger_how_string_getter (char flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
case '1':
|
||||
return _("<");
|
||||
return _ ("<");
|
||||
case '2':
|
||||
return _("=");
|
||||
return _ ("=");
|
||||
case '3':
|
||||
return _(">");
|
||||
return _ (">");
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return "?";
|
||||
return "?";
|
||||
}
|
||||
|
||||
static void load_discount_type_cells (GncEntryLedger *ledger)
|
||||
static void load_discount_type_cells (GncEntryLedger* ledger)
|
||||
{
|
||||
RecnCell *cell;
|
||||
RecnCell* cell;
|
||||
|
||||
if (!ledger) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
cell = (RecnCell*)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISTYPE_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
@ -91,13 +91,13 @@ static void load_discount_type_cells (GncEntryLedger *ledger)
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
|
||||
}
|
||||
|
||||
static void load_discount_how_cells (GncEntryLedger *ledger)
|
||||
static void load_discount_how_cells (GncEntryLedger* ledger)
|
||||
{
|
||||
RecnCell *cell;
|
||||
RecnCell* cell;
|
||||
|
||||
if (!ledger) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
cell = (RecnCell*)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISHOW_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
@ -107,14 +107,14 @@ static void load_discount_how_cells (GncEntryLedger *ledger)
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_how_string_getter);
|
||||
}
|
||||
|
||||
static void load_payment_type_cells (GncEntryLedger *ledger)
|
||||
static void load_payment_type_cells (GncEntryLedger* ledger)
|
||||
{
|
||||
ComboCell *cell;
|
||||
const GncOwner *owner;
|
||||
GncEmployee *employee;
|
||||
ComboCell* cell;
|
||||
const GncOwner* owner;
|
||||
GncEmployee* employee;
|
||||
|
||||
cell = (ComboCell *) gnc_table_layout_get_cell (ledger->table->layout,
|
||||
ENTRY_PAYMENT_CELL);
|
||||
cell = (ComboCell*) gnc_table_layout_get_cell (ledger->table->layout,
|
||||
ENTRY_PAYMENT_CELL);
|
||||
if (!cell) return;
|
||||
|
||||
if (!ledger->invoice) return;
|
||||
@ -127,25 +127,25 @@ static void load_payment_type_cells (GncEntryLedger *ledger)
|
||||
g_return_if_fail (employee);
|
||||
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
gnc_combo_cell_add_menu_item (cell, _("Cash"));
|
||||
gnc_combo_cell_add_menu_item (cell, _ ("Cash"));
|
||||
|
||||
if (gncEmployeeGetCCard (employee))
|
||||
gnc_combo_cell_add_menu_item (cell, _("Charge"));
|
||||
gnc_combo_cell_add_menu_item (cell, _ ("Charge"));
|
||||
}
|
||||
|
||||
/* ==================================================================== */
|
||||
/* Return TRUE if we don't want to add this account to the xfer menu */
|
||||
|
||||
static gboolean
|
||||
skip_expense_acct_cb (Account *account, gpointer user_data)
|
||||
skip_expense_acct_cb (Account* account, gpointer user_data)
|
||||
{
|
||||
GNCAccountType type;
|
||||
|
||||
/* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
|
||||
type = xaccAccountGetType (account);
|
||||
if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@ -160,15 +160,15 @@ skip_expense_acct_cb (Account *account, gpointer user_data)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
skip_income_acct_cb (Account *account, gpointer user_data)
|
||||
skip_income_acct_cb (Account* account, gpointer user_data)
|
||||
{
|
||||
GNCAccountType type;
|
||||
|
||||
/* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
|
||||
type = xaccAccountGetType (account);
|
||||
if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@ -189,12 +189,13 @@ skip_income_acct_cb (Account *account, gpointer user_data)
|
||||
#define IKEY "Income Business entry quickfill"
|
||||
|
||||
static void
|
||||
load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
load_xfer_type_cells (GncEntryLedger* ledger)
|
||||
{
|
||||
Account *root;
|
||||
ComboCell *cell;
|
||||
QuickFill *qf = NULL;
|
||||
GtkListStore *store = NULL;
|
||||
Account* root;
|
||||
ComboCell* cell;
|
||||
QuickFill* qf = NULL;
|
||||
GtkListStore* store = NULL;
|
||||
GtkListStore* store_full = NULL;
|
||||
|
||||
root = gnc_book_get_root_account (ledger->book);
|
||||
if (root == NULL) return;
|
||||
@ -212,9 +213,11 @@ load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
|
||||
case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
|
||||
qf = gnc_get_shared_account_name_quickfill (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
skip_expense_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
skip_expense_acct_cb, NULL);
|
||||
store_full = gnc_get_shared_account_name_list_store_full (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
break;
|
||||
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
@ -227,49 +230,51 @@ load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
|
||||
case GNCENTRY_NUM_REGISTER_TYPES:
|
||||
qf = gnc_get_shared_account_name_quickfill (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
skip_income_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
skip_income_acct_cb, NULL);
|
||||
store_full = gnc_get_shared_account_name_list_store_full (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
break;
|
||||
default:
|
||||
PWARN ("Bad GncEntryLedgerType");
|
||||
break;
|
||||
PWARN ("Bad GncEntryLedgerType");
|
||||
break;
|
||||
}
|
||||
|
||||
cell = (ComboCell *)
|
||||
cell = (ComboCell*)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_IACCT_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store, store_full);
|
||||
|
||||
cell = (ComboCell *)
|
||||
cell = (ComboCell*)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_BACCT_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store, store_full);
|
||||
}
|
||||
|
||||
/* ===================================================================== */
|
||||
|
||||
static void load_taxtable_type_cells (GncEntryLedger *ledger)
|
||||
static void load_taxtable_type_cells (GncEntryLedger* ledger)
|
||||
{
|
||||
GList *list;
|
||||
ComboCell *cell;
|
||||
GList* list;
|
||||
ComboCell* cell;
|
||||
|
||||
cell = (ComboCell *)
|
||||
cell = (ComboCell*)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAXTABLE_CELL);
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
|
||||
list = gncTaxTableGetTables (ledger->book);
|
||||
for ( ; list ; list = list->next )
|
||||
for (; list ; list = list->next)
|
||||
{
|
||||
GncTaxTable *table = list->data;
|
||||
const char *name = gncTaxTableGetName (table);
|
||||
GncTaxTable* table = list->data;
|
||||
const char* name = gncTaxTableGetName (table);
|
||||
if (name != NULL)
|
||||
gnc_combo_cell_add_menu_item (cell, (char*)name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_entry_ledger_show_entry (GncEntryLedger *ledger,
|
||||
gnc_entry_ledger_show_entry (GncEntryLedger* ledger,
|
||||
VirtualCellLocation start_loc)
|
||||
{
|
||||
VirtualCellLocation end_loc;
|
||||
@ -286,10 +291,10 @@ gnc_entry_ledger_show_entry (GncEntryLedger *ledger,
|
||||
#define DESC_QF_KEY_BILLS "ENTRY_DESC_CELL_QF_BILLS"
|
||||
|
||||
static void
|
||||
load_description_cell (GncEntryLedger *ledger)
|
||||
load_description_cell (GncEntryLedger* ledger)
|
||||
{
|
||||
QuickFill *shared_quickfill;
|
||||
QuickFillCell *cell;
|
||||
QuickFill* shared_quickfill;
|
||||
QuickFillCell* cell;
|
||||
|
||||
switch (ledger->type)
|
||||
{
|
||||
@ -297,19 +302,21 @@ load_description_cell (GncEntryLedger *ledger)
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
|
||||
case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
|
||||
shared_quickfill = gnc_get_shared_entry_desc_quickfill(ledger->book, DESC_QF_KEY_INVOICES, TRUE);
|
||||
shared_quickfill = gnc_get_shared_entry_desc_quickfill (ledger->book,
|
||||
DESC_QF_KEY_INVOICES, TRUE);
|
||||
break;
|
||||
default:
|
||||
shared_quickfill = gnc_get_shared_entry_desc_quickfill(ledger->book, DESC_QF_KEY_BILLS, FALSE);
|
||||
shared_quickfill = gnc_get_shared_entry_desc_quickfill (ledger->book,
|
||||
DESC_QF_KEY_BILLS, FALSE);
|
||||
break;
|
||||
};
|
||||
|
||||
cell = (QuickFillCell *)
|
||||
cell = (QuickFillCell*)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DESC_CELL);
|
||||
gnc_quickfill_cell_use_quickfill_cache (cell, shared_quickfill);
|
||||
}
|
||||
|
||||
void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger)
|
||||
void gnc_entry_ledger_load_xfer_cells (GncEntryLedger* ledger)
|
||||
{
|
||||
load_xfer_type_cells (ledger);
|
||||
load_taxtable_type_cells (ledger);
|
||||
@ -323,14 +330,14 @@ void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger)
|
||||
* the split-register 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)
|
||||
void gnc_entry_ledger_load (GncEntryLedger* ledger, GList* entry_list)
|
||||
{
|
||||
GncEntry *blank_entry, *find_entry;
|
||||
CursorBuffer *cursor_buffer;
|
||||
Table *table;
|
||||
GncEntry* blank_entry, *find_entry;
|
||||
CursorBuffer* cursor_buffer;
|
||||
Table* table;
|
||||
|
||||
GList *node;
|
||||
CellBlock *cursor_header, *cursor;
|
||||
GList* node;
|
||||
CellBlock* cursor_header, *cursor;
|
||||
VirtualCellLocation vcell_loc;
|
||||
VirtualLocation save_loc;
|
||||
gboolean start_primary_color = TRUE;
|
||||
@ -361,29 +368,30 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
|
||||
case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
|
||||
|
||||
gnc_suspend_gui_refresh ();
|
||||
gnc_suspend_gui_refresh();
|
||||
|
||||
blank_entry = gncEntryCreate (ledger->book);
|
||||
gncEntrySetDateGDate (blank_entry, &ledger->last_date_entered);
|
||||
ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
|
||||
|
||||
gnc_resume_gui_refresh ();
|
||||
gnc_resume_gui_refresh();
|
||||
|
||||
/* The rest of this does not apply to expense vouchers */
|
||||
if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
|
||||
{
|
||||
const GncOwner *owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
|
||||
GncTaxTable *table = NULL;
|
||||
const GncOwner* owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (
|
||||
ledger->invoice));
|
||||
GncTaxTable* table = NULL;
|
||||
GncTaxIncluded taxincluded_p = GNC_TAXINCLUDED_USEGLOBAL;
|
||||
gboolean taxincluded = FALSE;
|
||||
gnc_numeric discount = gnc_numeric_zero ();
|
||||
gnc_numeric price = gnc_numeric_zero ();
|
||||
gnc_numeric discount = gnc_numeric_zero();
|
||||
gnc_numeric price = gnc_numeric_zero();
|
||||
|
||||
/* Determine the Price from Customer's or Vendor's Job */
|
||||
switch (gncOwnerGetType (gncInvoiceGetOwner (ledger->invoice)))
|
||||
{
|
||||
case GNC_OWNER_JOB:
|
||||
price = gncJobGetRate( gncOwnerGetJob (gncInvoiceGetOwner (ledger->invoice)));
|
||||
price = gncJobGetRate (gncOwnerGetJob (gncInvoiceGetOwner (ledger->invoice)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -466,7 +474,7 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
|
||||
break;
|
||||
default:
|
||||
ledger->blank_entry_guid = *guid_null ();
|
||||
ledger->blank_entry_guid = *guid_null();
|
||||
break;
|
||||
}
|
||||
ledger->blank_entry_edited = FALSE;
|
||||
@ -488,16 +496,16 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
}
|
||||
else
|
||||
{
|
||||
find_entry = gnc_entry_ledger_get_current_entry(ledger);
|
||||
find_entry = gnc_entry_ledger_get_current_entry (ledger);
|
||||
/* XXX: get current entry (cursor_hint_xxx) */
|
||||
}
|
||||
|
||||
/* If the current cursor has changed we save the values for later
|
||||
* possible restoration. */
|
||||
if (gnc_table_current_cursor_changed (table, TRUE) &&
|
||||
(find_entry == gnc_entry_ledger_get_current_entry (ledger)))
|
||||
(find_entry == gnc_entry_ledger_get_current_entry (ledger)))
|
||||
{
|
||||
cursor_buffer = gnc_cursor_buffer_new ();
|
||||
cursor_buffer = gnc_cursor_buffer_new();
|
||||
gnc_table_save_current_cursor (table, cursor_buffer);
|
||||
}
|
||||
else
|
||||
@ -535,7 +543,7 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
/* Populate the table */
|
||||
for (node = entry_list; node; node = node->next)
|
||||
{
|
||||
GncEntry *entry = node->data;
|
||||
GncEntry* entry = node->data;
|
||||
|
||||
/* Don't load the blank entry */
|
||||
if (entry == blank_entry)
|
||||
@ -599,14 +607,14 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
|
||||
/* Set completion character */
|
||||
gnc_combo_cell_set_complete_char
|
||||
((ComboCell *)
|
||||
((ComboCell*)
|
||||
gnc_table_layout_get_cell (table->layout, ENTRY_IACCT_CELL),
|
||||
gnc_get_account_separator ());
|
||||
gnc_get_account_separator());
|
||||
|
||||
gnc_combo_cell_set_complete_char
|
||||
((ComboCell *)
|
||||
((ComboCell*)
|
||||
gnc_table_layout_get_cell (table->layout, ENTRY_BACCT_CELL),
|
||||
gnc_get_account_separator ());
|
||||
gnc_get_account_separator());
|
||||
|
||||
/* enable callback for cursor user-driven moves */
|
||||
gnc_table_control_allow_move (table->control, TRUE);
|
||||
|
@ -46,36 +46,36 @@
|
||||
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_xfer_cells (SplitRegister* reg,
|
||||
Account* base_account);
|
||||
|
||||
static void
|
||||
gnc_split_register_load_recn_cells (SplitRegister *reg)
|
||||
gnc_split_register_load_recn_cells (SplitRegister* reg)
|
||||
{
|
||||
RecnCell *cell;
|
||||
const char * s;
|
||||
RecnCell* cell;
|
||||
const char* s;
|
||||
|
||||
if (!reg) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
cell = (RecnCell*)
|
||||
gnc_table_layout_get_cell (reg->table->layout, RECN_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
|
||||
s = gnc_get_reconcile_valid_flags ();
|
||||
s = gnc_get_reconcile_valid_flags();
|
||||
gnc_recn_cell_set_valid_flags (cell, s, *s);
|
||||
gnc_recn_cell_set_flag_order (cell, gnc_get_reconcile_flag_order ());
|
||||
gnc_recn_cell_set_flag_order (cell, gnc_get_reconcile_flag_order());
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_get_reconcile_str);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_split_register_load_associate_cells (SplitRegister *reg)
|
||||
gnc_split_register_load_associate_cells (SplitRegister* reg)
|
||||
{
|
||||
RecnCell *cell;
|
||||
RecnCell* cell;
|
||||
|
||||
if (!reg) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
cell = (RecnCell*)
|
||||
gnc_table_layout_get_cell (reg->table->layout, ASSOC_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
@ -87,13 +87,13 @@ gnc_split_register_load_associate_cells (SplitRegister *reg)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_split_register_load_type_cells (SplitRegister *reg)
|
||||
gnc_split_register_load_type_cells (SplitRegister* reg)
|
||||
{
|
||||
RecnCell *cell;
|
||||
RecnCell* cell;
|
||||
|
||||
if (!reg) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
cell = (RecnCell*)
|
||||
gnc_table_layout_get_cell (reg->table->layout, TYPE_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
@ -166,24 +166,24 @@ gnc_split_register_load_type_cells (SplitRegister *reg)
|
||||
* will be changed to the row below the last row filled.
|
||||
*/
|
||||
static void
|
||||
gnc_split_register_add_transaction (SplitRegister *reg,
|
||||
Transaction *trans,
|
||||
Split *split,
|
||||
CellBlock *lead_cursor,
|
||||
CellBlock *split_cursor,
|
||||
gnc_split_register_add_transaction (SplitRegister* reg,
|
||||
Transaction* trans,
|
||||
Split* split,
|
||||
CellBlock* lead_cursor,
|
||||
CellBlock* split_cursor,
|
||||
gboolean visible_splits,
|
||||
gboolean start_primary_color,
|
||||
gboolean add_empty,
|
||||
Transaction *find_trans,
|
||||
Split *find_split,
|
||||
Transaction* find_trans,
|
||||
Split* find_split,
|
||||
CursorClass find_class,
|
||||
int *new_split_row,
|
||||
VirtualCellLocation *vcell_loc)
|
||||
int* new_split_row,
|
||||
VirtualCellLocation* vcell_loc)
|
||||
{
|
||||
GList *node;
|
||||
GList* node;
|
||||
|
||||
g_return_if_fail(reg);
|
||||
g_return_if_fail(vcell_loc);
|
||||
g_return_if_fail (reg);
|
||||
g_return_if_fail (vcell_loc);
|
||||
|
||||
if (split == find_split)
|
||||
*new_split_row = vcell_loc->virt_row;
|
||||
@ -197,9 +197,9 @@ gnc_split_register_add_transaction (SplitRegister *reg,
|
||||
* split in the transaction. */
|
||||
for (node = xaccTransGetSplitList (trans); node; node = node->next)
|
||||
{
|
||||
Split *secondary = node->data;
|
||||
Split* secondary = node->data;
|
||||
|
||||
if (!xaccTransStillHasSplit(trans, secondary)) continue;
|
||||
if (!xaccTransStillHasSplit (trans, secondary)) continue;
|
||||
if (secondary == find_split && find_class == CURSOR_CLASS_SPLIT)
|
||||
*new_split_row = vcell_loc->virt_row;
|
||||
|
||||
@ -213,81 +213,82 @@ gnc_split_register_add_transaction (SplitRegister *reg,
|
||||
if (add_empty)
|
||||
{
|
||||
if (find_trans == trans && find_split == NULL &&
|
||||
find_class == CURSOR_CLASS_SPLIT)
|
||||
find_class == CURSOR_CLASS_SPLIT)
|
||||
*new_split_row = vcell_loc->virt_row;
|
||||
|
||||
gnc_table_set_vcell(reg->table, split_cursor, xaccSplitGetGUID(NULL),
|
||||
FALSE, TRUE, *vcell_loc);
|
||||
gnc_table_set_vcell (reg->table, split_cursor, xaccSplitGetGUID (NULL),
|
||||
FALSE, TRUE, *vcell_loc);
|
||||
vcell_loc->virt_row++;
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
_find_split_with_parent_txn(gconstpointer a, gconstpointer b)
|
||||
_find_split_with_parent_txn (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
Split *split = (Split*)a;
|
||||
Transaction *txn = (Transaction*)b;
|
||||
Split* split = (Split*)a;
|
||||
Transaction* txn = (Transaction*)b;
|
||||
|
||||
return xaccSplitGetParent(split) == txn ? 0 : 1;
|
||||
return xaccSplitGetParent (split) == txn ? 0 : 1;
|
||||
}
|
||||
|
||||
static void add_quickfill_completions(TableLayout *layout, Transaction *trans,
|
||||
Split *split, gboolean has_last_num)
|
||||
static void add_quickfill_completions (TableLayout* layout, Transaction* trans,
|
||||
Split* split, gboolean has_last_num)
|
||||
{
|
||||
Split *s;
|
||||
Split* s;
|
||||
int i = 0;
|
||||
|
||||
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, DESC_CELL),
|
||||
xaccTransGetDescription (trans));
|
||||
|
||||
gnc_quickfill_cell_add_completion(
|
||||
(QuickFillCell *) gnc_table_layout_get_cell(layout, NOTES_CELL),
|
||||
xaccTransGetNotes(trans));
|
||||
gnc_quickfill_cell_add_completion (
|
||||
(QuickFillCell*) gnc_table_layout_get_cell (layout, NOTES_CELL),
|
||||
xaccTransGetNotes (trans));
|
||||
|
||||
if (!has_last_num)
|
||||
gnc_num_cell_set_last_num(
|
||||
(NumCell *) gnc_table_layout_get_cell(layout, NUM_CELL),
|
||||
gnc_get_num_action(trans, split));
|
||||
gnc_num_cell_set_last_num (
|
||||
(NumCell*) gnc_table_layout_get_cell (layout, NUM_CELL),
|
||||
gnc_get_num_action (trans, split));
|
||||
|
||||
while ((s = xaccTransGetSplit(trans, i)) != NULL)
|
||||
while ((s = xaccTransGetSplit (trans, i)) != NULL)
|
||||
{
|
||||
gnc_quickfill_cell_add_completion(
|
||||
(QuickFillCell *) gnc_table_layout_get_cell(layout, MEMO_CELL),
|
||||
xaccSplitGetMemo(s));
|
||||
gnc_quickfill_cell_add_completion (
|
||||
(QuickFillCell*) gnc_table_layout_get_cell (layout, MEMO_CELL),
|
||||
xaccSplitGetMemo (s));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static Split*
|
||||
create_blank_split (Account *default_account, SRInfo *info)
|
||||
create_blank_split (Account* default_account, SRInfo* info)
|
||||
{
|
||||
Transaction *new_trans;
|
||||
Transaction* new_trans;
|
||||
gboolean currency_from_account = TRUE;
|
||||
Split *blank_split = NULL;
|
||||
Split* blank_split = NULL;
|
||||
/* Determine the proper currency to use for this transaction.
|
||||
* if default_account != NULL and default_account->commodity is
|
||||
* a currency, then use that. Otherwise use the default currency.
|
||||
*/
|
||||
gnc_commodity * currency = gnc_account_or_default_currency(default_account, ¤cy_from_account);
|
||||
gnc_commodity* currency = gnc_account_or_default_currency (default_account,
|
||||
¤cy_from_account);
|
||||
|
||||
if (default_account != NULL && !currency_from_account)
|
||||
{
|
||||
/* If we don't have a currency then pop up a warning dialog */
|
||||
gnc_info_dialog(NULL, "%s",
|
||||
_("Could not determine the account currency. "
|
||||
"Using the default currency provided by your system."));
|
||||
/* If we don't have a currency then pop up a warning dialog */
|
||||
gnc_info_dialog (NULL, "%s",
|
||||
_ ("Could not determine the account currency. "
|
||||
"Using the default currency provided by your system."));
|
||||
}
|
||||
|
||||
gnc_suspend_gui_refresh ();
|
||||
gnc_suspend_gui_refresh();
|
||||
|
||||
new_trans = xaccMallocTransaction (gnc_get_current_book ());
|
||||
new_trans = xaccMallocTransaction (gnc_get_current_book());
|
||||
|
||||
xaccTransBeginEdit (new_trans);
|
||||
xaccTransSetCurrency (new_trans, currency);
|
||||
xaccTransSetDatePostedSecsNormalized(new_trans, info->last_date_entered);
|
||||
blank_split = xaccMallocSplit (gnc_get_current_book ());
|
||||
xaccSplitSetParent(blank_split, new_trans);
|
||||
xaccTransSetDatePostedSecsNormalized (new_trans, info->last_date_entered);
|
||||
blank_split = xaccMallocSplit (gnc_get_current_book());
|
||||
xaccSplitSetParent (blank_split, new_trans);
|
||||
/* We don't want to commit this transaction yet, because the split
|
||||
doesn't even belong to an account yet. But, we don't want to
|
||||
set this transaction as the pending transaction either, because
|
||||
@ -299,34 +300,34 @@ create_blank_split (Account *default_account, SRInfo *info)
|
||||
info->blank_split_guid = *xaccSplitGetGUID (blank_split);
|
||||
info->blank_split_edited = FALSE;
|
||||
info->auto_complete = FALSE;
|
||||
DEBUG("created new blank_split=%p", blank_split);
|
||||
DEBUG ("created new blank_split=%p", blank_split);
|
||||
|
||||
gnc_resume_gui_refresh ();
|
||||
gnc_resume_gui_refresh();
|
||||
return blank_split;
|
||||
}
|
||||
|
||||
static void
|
||||
change_account_separator (SRInfo *info, Table *table, SplitRegister *reg)
|
||||
change_account_separator (SRInfo* info, Table* table, SplitRegister* reg)
|
||||
{
|
||||
info->separator_changed = FALSE;
|
||||
|
||||
/* set the completion character for the xfer cells */
|
||||
gnc_combo_cell_set_complete_char(
|
||||
(ComboCell *) gnc_table_layout_get_cell(table->layout, MXFRM_CELL),
|
||||
gnc_get_account_separator());
|
||||
gnc_combo_cell_set_complete_char (
|
||||
(ComboCell*) gnc_table_layout_get_cell (table->layout, MXFRM_CELL),
|
||||
gnc_get_account_separator());
|
||||
|
||||
gnc_combo_cell_set_complete_char(
|
||||
(ComboCell *) gnc_table_layout_get_cell(table->layout, XFRM_CELL),
|
||||
gnc_get_account_separator());
|
||||
gnc_combo_cell_set_complete_char (
|
||||
(ComboCell*) gnc_table_layout_get_cell (table->layout, XFRM_CELL),
|
||||
gnc_get_account_separator());
|
||||
|
||||
/* set the confirmation callback for the reconcile cell */
|
||||
gnc_recn_cell_set_confirm_cb(
|
||||
(RecnCell *) gnc_table_layout_get_cell(table->layout, RECN_CELL),
|
||||
gnc_split_register_recn_cell_confirm, reg);
|
||||
gnc_recn_cell_set_confirm_cb (
|
||||
(RecnCell*) gnc_table_layout_get_cell (table->layout, RECN_CELL),
|
||||
gnc_split_register_recn_cell_confirm, reg);
|
||||
}
|
||||
|
||||
static void
|
||||
update_info (SRInfo *info, SplitRegister *reg)
|
||||
update_info (SRInfo* info, SplitRegister* reg)
|
||||
{
|
||||
/* Set up the hint transaction, split, transaction split, and column. */
|
||||
info->cursor_hint_trans = gnc_split_register_get_current_trans (reg);
|
||||
@ -343,26 +344,26 @@ update_info (SRInfo *info, SplitRegister *reg)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
Account *default_account)
|
||||
gnc_split_register_load (SplitRegister* reg, GList* slist,
|
||||
Account* default_account)
|
||||
{
|
||||
SRInfo *info;
|
||||
Transaction *pending_trans;
|
||||
CursorBuffer *cursor_buffer;
|
||||
GHashTable *trans_table = NULL;
|
||||
CellBlock *cursor_header;
|
||||
CellBlock *lead_cursor;
|
||||
CellBlock *split_cursor;
|
||||
Transaction *blank_trans;
|
||||
Transaction *find_trans;
|
||||
Transaction *trans;
|
||||
SRInfo* info;
|
||||
Transaction* pending_trans;
|
||||
CursorBuffer* cursor_buffer;
|
||||
GHashTable* trans_table = NULL;
|
||||
CellBlock* cursor_header;
|
||||
CellBlock* lead_cursor;
|
||||
CellBlock* split_cursor;
|
||||
Transaction* blank_trans;
|
||||
Transaction* find_trans;
|
||||
Transaction* trans;
|
||||
CursorClass find_class;
|
||||
Split *find_trans_split;
|
||||
Split *blank_split;
|
||||
Split *find_split;
|
||||
Split *split;
|
||||
Table *table;
|
||||
GList *node;
|
||||
Split* find_trans_split;
|
||||
Split* blank_split;
|
||||
Split* find_split;
|
||||
Split* split;
|
||||
Table* table;
|
||||
GList* node;
|
||||
|
||||
gboolean start_primary_color = TRUE;
|
||||
gboolean found_pending = FALSE;
|
||||
@ -373,9 +374,11 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
gboolean multi_line;
|
||||
gboolean dynamic;
|
||||
gboolean we_own_slist = FALSE;
|
||||
gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
|
||||
gboolean future_after_blank = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
|
||||
GNC_PREF_FUTURE_AFTER_BLANK);
|
||||
gboolean use_autoreadonly = qof_book_uses_autoreadonly (
|
||||
gnc_get_current_book());
|
||||
gboolean future_after_blank = gnc_prefs_get_bool (
|
||||
GNC_PREFS_GROUP_GENERAL_REGISTER,
|
||||
GNC_PREF_FUTURE_AFTER_BLANK);
|
||||
gboolean added_blank_trans = FALSE;
|
||||
|
||||
VirtualCellLocation vcell_loc;
|
||||
@ -386,42 +389,42 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
int new_split_row = -1;
|
||||
time64 present, autoreadonly_time = 0;
|
||||
|
||||
g_return_if_fail(reg);
|
||||
g_return_if_fail (reg);
|
||||
table = reg->table;
|
||||
g_return_if_fail(table);
|
||||
g_return_if_fail (table);
|
||||
info = gnc_split_register_get_info (reg);
|
||||
g_return_if_fail(info);
|
||||
g_return_if_fail (info);
|
||||
|
||||
ENTER("reg=%p, slist=%p, default_account=%p", reg, slist, default_account);
|
||||
ENTER ("reg=%p, slist=%p, default_account=%p", reg, slist, default_account);
|
||||
|
||||
blank_split = xaccSplitLookup (&info->blank_split_guid,
|
||||
gnc_get_current_book ());
|
||||
gnc_get_current_book());
|
||||
|
||||
pending_trans = xaccTransLookup (&info->pending_trans_guid,
|
||||
gnc_get_current_book ());
|
||||
gnc_get_current_book());
|
||||
|
||||
/* Bug 742089: Set the debit and credit cells' print_info to the account */
|
||||
gnc_price_cell_set_print_info
|
||||
((PriceCell *) gnc_table_layout_get_cell (table->layout, DEBT_CELL),
|
||||
((PriceCell*) gnc_table_layout_get_cell (table->layout, DEBT_CELL),
|
||||
gnc_account_print_info (default_account, FALSE));
|
||||
|
||||
gnc_price_cell_set_print_info
|
||||
((PriceCell *) gnc_table_layout_get_cell (table->layout, CRED_CELL),
|
||||
((PriceCell*) gnc_table_layout_get_cell (table->layout, CRED_CELL),
|
||||
gnc_account_print_info (default_account, FALSE));
|
||||
|
||||
/* make sure we have a blank split */
|
||||
if (blank_split == NULL)
|
||||
{
|
||||
/* Wouldn't it be a bug to open the new transaction if there was
|
||||
* already a pending transaction?
|
||||
*/
|
||||
g_assert(pending_trans == NULL);
|
||||
blank_split = create_blank_split (default_account, info);
|
||||
/* Wouldn't it be a bug to open the new transaction if there was
|
||||
* already a pending transaction?
|
||||
*/
|
||||
g_assert (pending_trans == NULL);
|
||||
blank_split = create_blank_split (default_account, info);
|
||||
}
|
||||
blank_trans = xaccSplitGetParent (blank_split);
|
||||
|
||||
DEBUG("blank_split=%p, blank_trans=%p, pending_trans=%p",
|
||||
blank_split, blank_trans, pending_trans);
|
||||
DEBUG ("blank_split=%p, blank_trans=%p, pending_trans=%p",
|
||||
blank_split, blank_trans, pending_trans);
|
||||
|
||||
info->default_account = *xaccAccountGetGUID (default_account);
|
||||
|
||||
@ -454,9 +457,9 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
/* If the current cursor has changed we save the values for later
|
||||
* possible restoration. */
|
||||
if (gnc_table_current_cursor_changed (table, TRUE) &&
|
||||
(find_split == gnc_split_register_get_current_split (reg)))
|
||||
(find_split == gnc_split_register_get_current_split (reg)))
|
||||
{
|
||||
cursor_buffer = gnc_cursor_buffer_new ();
|
||||
cursor_buffer = gnc_cursor_buffer_new();
|
||||
gnc_table_save_current_cursor (table, cursor_buffer);
|
||||
}
|
||||
else
|
||||
@ -470,7 +473,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
{
|
||||
VirtualLocation virt_loc;
|
||||
|
||||
gnc_virtual_location_init(&virt_loc);
|
||||
gnc_virtual_location_init (&virt_loc);
|
||||
gnc_table_move_cursor_gui (table, virt_loc);
|
||||
}
|
||||
|
||||
@ -482,26 +485,26 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* get the current time and reset the dividing row */
|
||||
present = gnc_time64_get_today_end ();
|
||||
present = gnc_time64_get_today_end();
|
||||
if (use_autoreadonly)
|
||||
{
|
||||
GDate *d = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
|
||||
GDate* d = qof_book_get_autoreadonly_gdate (gnc_get_current_book());
|
||||
// "d" is NULL if use_autoreadonly is FALSE
|
||||
autoreadonly_time = d ? gdate_to_time64 (*d) : 0;
|
||||
g_date_free(d);
|
||||
g_date_free (d);
|
||||
}
|
||||
|
||||
if (info->first_pass)
|
||||
{
|
||||
if (default_account)
|
||||
{
|
||||
const char *last_num = xaccAccountGetLastNum (default_account);
|
||||
const char* last_num = xaccAccountGetLastNum (default_account);
|
||||
|
||||
if (last_num)
|
||||
{
|
||||
NumCell *cell;
|
||||
NumCell* cell;
|
||||
|
||||
cell = (NumCell *) gnc_table_layout_get_cell(table->layout, NUM_CELL);
|
||||
cell = (NumCell*) gnc_table_layout_get_cell (table->layout, NUM_CELL);
|
||||
gnc_num_cell_set_last_num (cell, last_num);
|
||||
has_last_num = TRUE;
|
||||
}
|
||||
@ -515,7 +518,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
}
|
||||
|
||||
if (info->separator_changed)
|
||||
change_account_separator (info, table, reg);
|
||||
change_account_separator (info, table, reg);
|
||||
|
||||
table->model->dividing_row_upper = -1;
|
||||
table->model->dividing_row = -1;
|
||||
@ -525,24 +528,24 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
// list we're about to load.
|
||||
if (pending_trans != NULL)
|
||||
{
|
||||
for (node = xaccTransGetSplitList(pending_trans); node; node = node->next)
|
||||
for (node = xaccTransGetSplitList (pending_trans); node; node = node->next)
|
||||
{
|
||||
Split *pending_split = (Split*)node->data;
|
||||
if (!xaccTransStillHasSplit(pending_trans, pending_split)) continue;
|
||||
if (g_list_find(slist, pending_split) != NULL)
|
||||
Split* pending_split = (Split*)node->data;
|
||||
if (!xaccTransStillHasSplit (pending_trans, pending_split)) continue;
|
||||
if (g_list_find (slist, pending_split) != NULL)
|
||||
continue;
|
||||
|
||||
if (g_list_find_custom(slist, pending_trans,
|
||||
_find_split_with_parent_txn) != NULL)
|
||||
if (g_list_find_custom (slist, pending_trans,
|
||||
_find_split_with_parent_txn) != NULL)
|
||||
continue;
|
||||
|
||||
if (!we_own_slist)
|
||||
{
|
||||
// lazy-copy
|
||||
slist = g_list_copy(slist);
|
||||
slist = g_list_copy (slist);
|
||||
we_own_slist = TRUE;
|
||||
}
|
||||
slist = g_list_append(slist, pending_split);
|
||||
slist = g_list_append (slist, pending_split);
|
||||
}
|
||||
}
|
||||
|
||||
@ -555,18 +558,18 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
split = node->data;
|
||||
trans = xaccSplitGetParent (split);
|
||||
|
||||
if (!xaccTransStillHasSplit(trans, split))
|
||||
if (!xaccTransStillHasSplit (trans, split))
|
||||
continue;
|
||||
|
||||
if (pending_trans == trans)
|
||||
found_pending = TRUE;
|
||||
/* If the transaction has only one split, and it's not our
|
||||
* pending_trans, then it's another register's blank split and
|
||||
* we don't want to see it.
|
||||
*/
|
||||
else if (xaccTransCountSplits (trans) == 1 &&
|
||||
xaccSplitGetAccount (split) == NULL)
|
||||
continue;
|
||||
/* If the transaction has only one split, and it's not our
|
||||
* pending_trans, then it's another register's blank split and
|
||||
* we don't want to see it.
|
||||
*/
|
||||
else if (xaccTransCountSplits (trans) == 1 &&
|
||||
xaccSplitGetAccount (split) == NULL)
|
||||
continue;
|
||||
|
||||
|
||||
/* Do not load splits from the blank transaction. */
|
||||
@ -583,8 +586,8 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
}
|
||||
|
||||
if (info->show_present_divider &&
|
||||
use_autoreadonly &&
|
||||
!found_divider_upper)
|
||||
use_autoreadonly &&
|
||||
!found_divider_upper)
|
||||
{
|
||||
if (xaccTransGetDate (trans) >= autoreadonly_time)
|
||||
{
|
||||
@ -598,8 +601,8 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
}
|
||||
|
||||
if (info->show_present_divider &&
|
||||
!found_divider &&
|
||||
(xaccTransGetDate (trans) > present))
|
||||
!found_divider &&
|
||||
(xaccTransGetDate (trans) > present))
|
||||
{
|
||||
table->model->dividing_row = vcell_loc.virt_row;
|
||||
found_divider = TRUE;
|
||||
@ -621,13 +624,13 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
}
|
||||
|
||||
gnc_split_register_add_transaction (reg,
|
||||
blank_trans, blank_split,
|
||||
lead_cursor, split_cursor,
|
||||
multi_line, start_primary_color,
|
||||
info->blank_split_edited,
|
||||
find_trans, find_split,
|
||||
find_class, &new_split_row,
|
||||
&vcell_loc);
|
||||
blank_trans, blank_split,
|
||||
lead_cursor, split_cursor,
|
||||
multi_line, start_primary_color,
|
||||
info->blank_split_edited,
|
||||
find_trans, find_split,
|
||||
find_class, &new_split_row,
|
||||
&vcell_loc);
|
||||
|
||||
table->model->dividing_row_lower = vcell_loc.virt_row;
|
||||
|
||||
@ -641,7 +644,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
/* If this is the first load of the register,
|
||||
* fill up the quickfill cells. */
|
||||
if (info->first_pass)
|
||||
add_quickfill_completions(reg->table->layout, trans, split, has_last_num);
|
||||
add_quickfill_completions (reg->table->layout, trans, split, has_last_num);
|
||||
|
||||
if (trans == find_trans)
|
||||
new_trans_row = vcell_loc.virt_row;
|
||||
@ -669,8 +672,8 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
|
||||
/* No upper divider yet? Store it now */
|
||||
if (info->show_present_divider &&
|
||||
use_autoreadonly &&
|
||||
!found_divider_upper && need_divider_upper)
|
||||
use_autoreadonly &&
|
||||
!found_divider_upper && need_divider_upper)
|
||||
{
|
||||
table->model->dividing_row_upper = vcell_loc.virt_row;
|
||||
}
|
||||
@ -679,7 +682,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
* from the account. */
|
||||
if (!found_pending)
|
||||
{
|
||||
info->pending_trans_guid = *guid_null ();
|
||||
info->pending_trans_guid = *guid_null();
|
||||
if (xaccTransIsOpen (pending_trans))
|
||||
xaccTransCommitEdit (pending_trans);
|
||||
else if (pending_trans)
|
||||
@ -740,12 +743,12 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
|
||||
trans_split_loc = save_loc;
|
||||
|
||||
gnc_split_register_get_trans_split (reg, save_loc.vcell_loc,
|
||||
&trans_split_loc.vcell_loc);
|
||||
gnc_split_register_get_trans_split (reg, save_loc.vcell_loc,
|
||||
&trans_split_loc.vcell_loc);
|
||||
|
||||
if (dynamic || multi_line || info->trans_expanded)
|
||||
{
|
||||
gnc_table_set_virt_cell_cursor(
|
||||
gnc_table_set_virt_cell_cursor (
|
||||
table, trans_split_loc.vcell_loc,
|
||||
gnc_split_register_get_active_cursor (reg));
|
||||
gnc_split_register_set_trans_visible (reg, trans_split_loc.vcell_loc,
|
||||
@ -773,7 +776,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
|
||||
update_info (info, reg);
|
||||
|
||||
gnc_split_register_set_cell_fractions(
|
||||
gnc_split_register_set_cell_fractions (
|
||||
reg, gnc_split_register_get_current_split (reg));
|
||||
|
||||
gnc_table_refresh_gui (table, TRUE);
|
||||
@ -784,9 +787,9 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
gnc_table_control_allow_move (table->control, TRUE);
|
||||
|
||||
if (we_own_slist)
|
||||
g_list_free(slist);
|
||||
g_list_free (slist);
|
||||
|
||||
LEAVE(" ");
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
/* ===================================================================== */
|
||||
@ -794,7 +797,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
#define QKEY "split_reg_shared_quickfill"
|
||||
|
||||
static gboolean
|
||||
skip_cb (Account *account, gpointer x)
|
||||
skip_cb (Account* account, gpointer x)
|
||||
{
|
||||
/* commented out as per Bug#340885 Comments 1 and 2, option (2).
|
||||
if (xaccAccountIsHidden(account))
|
||||
@ -804,15 +807,16 @@ skip_cb (Account *account, gpointer x)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_split_register_load_xfer_cells (SplitRegister *reg, Account *base_account)
|
||||
gnc_split_register_load_xfer_cells (SplitRegister* reg, Account* base_account)
|
||||
{
|
||||
Account *root = NULL;
|
||||
QuickFill *qf;
|
||||
ComboCell *cell;
|
||||
GtkListStore *store;
|
||||
Account* root = NULL;
|
||||
QuickFill* qf;
|
||||
ComboCell* cell;
|
||||
GtkListStore* store;
|
||||
GtkListStore* store_full;
|
||||
|
||||
if (base_account)
|
||||
root = gnc_account_get_root(base_account);
|
||||
root = gnc_account_get_root (base_account);
|
||||
if (root == NULL)
|
||||
root = gnc_get_current_root_account();
|
||||
if (root == NULL)
|
||||
@ -820,16 +824,18 @@ gnc_split_register_load_xfer_cells (SplitRegister *reg, Account *base_account)
|
||||
|
||||
qf = gnc_get_shared_account_name_quickfill (root, QKEY, skip_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, QKEY, skip_cb, NULL);
|
||||
store_full = gnc_get_shared_account_name_list_store_full (root, QKEY, skip_cb,
|
||||
NULL);
|
||||
|
||||
cell = (ComboCell *)
|
||||
cell = (ComboCell*)
|
||||
gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store, store_full);
|
||||
|
||||
cell = (ComboCell *)
|
||||
cell = (ComboCell*)
|
||||
gnc_table_layout_get_cell (reg->table->layout, MXFRM_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store, store_full);
|
||||
}
|
||||
|
||||
/* ====================== END OF FILE ================================== */
|
||||
|
@ -49,44 +49,48 @@ typedef struct
|
||||
{
|
||||
BasicCell cell;
|
||||
gpointer shared_store;
|
||||
gpointer shared_store_full;
|
||||
} ComboCell;
|
||||
|
||||
|
||||
BasicCell * gnc_combo_cell_new (void);
|
||||
void gnc_combo_cell_init (ComboCell *cell);
|
||||
BasicCell* gnc_combo_cell_new (void);
|
||||
void gnc_combo_cell_init (ComboCell* cell);
|
||||
|
||||
void gnc_combo_cell_set_value (ComboCell *cell, const char *value);
|
||||
void gnc_combo_cell_set_value (ComboCell* cell, const char* value);
|
||||
|
||||
void gnc_combo_cell_clear_menu (ComboCell *cell);
|
||||
void gnc_combo_cell_clear_menu (ComboCell* cell);
|
||||
|
||||
/** Add a menu item to the list. */
|
||||
void gnc_combo_cell_add_menu_item (ComboCell *cell, const char * menustr);
|
||||
void gnc_combo_cell_add_menu_item (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. */
|
||||
void gnc_combo_cell_add_account_menu_item (ComboCell *cell, char * menustr);
|
||||
void gnc_combo_cell_add_account_menu_item (ComboCell* cell,
|
||||
char* menustr);
|
||||
|
||||
/** Enable sorting of the menu item's contents. Loading the item is
|
||||
* much faster with sorting disabled. */
|
||||
void gnc_combo_cell_set_sort_enabled (ComboCell *cell, gboolean enabled);
|
||||
void gnc_combo_cell_set_sort_enabled (ComboCell* cell,
|
||||
gboolean enabled);
|
||||
|
||||
/** Determines whether the cell will accept strings not in the
|
||||
* menu. Defaults to strict, i.e., only menu items are accepted. */
|
||||
void gnc_combo_cell_set_strict (ComboCell *cell, gboolean strict);
|
||||
void gnc_combo_cell_set_strict (ComboCell* cell, gboolean strict);
|
||||
|
||||
/** Sets a character used for special completion processing. */
|
||||
void gnc_combo_cell_set_complete_char (ComboCell *cell,
|
||||
gunichar complete_char);
|
||||
void gnc_combo_cell_set_complete_char (ComboCell* cell,
|
||||
gunichar complete_char);
|
||||
|
||||
/** Add a string to a list of strings which, if the cell has that value,
|
||||
* will cause the cell to be uneditable on 'enter'. */
|
||||
void gnc_combo_cell_add_ignore_string (ComboCell *cell,
|
||||
const char *ignore_string);
|
||||
void gnc_combo_cell_add_ignore_string (ComboCell* cell,
|
||||
const char* ignore_string);
|
||||
|
||||
/** Determines whether the popup list autosizes itself or uses
|
||||
* all available space. FALSE by default. */
|
||||
void gnc_combo_cell_set_autosize (ComboCell *cell, gboolean autosize);
|
||||
void gnc_combo_cell_set_autosize (ComboCell* cell, gboolean autosize);
|
||||
|
||||
/** Tell the combocell to use a shared QuickFill object. Using this routine
|
||||
* can dramatically improve performance when creating combocells with a
|
||||
@ -97,9 +101,10 @@ void gnc_combo_cell_set_autosize (ComboCell *cell, gboolean autosize);
|
||||
* nor delete the quickfill; it is the users resonsibility to manage the
|
||||
* quickfill object. The combocell will *not* make a copy of the quickfill.
|
||||
*/
|
||||
void gnc_combo_cell_use_quickfill_cache (ComboCell *cell, QuickFill *shared_qf);
|
||||
|
||||
void gnc_combo_cell_use_list_store_cache (ComboCell * cell, gpointer data);
|
||||
void gnc_combo_cell_use_quickfill_cache (ComboCell* cell,
|
||||
QuickFill* shared_qf);
|
||||
void gnc_combo_cell_use_list_store_cache (ComboCell* cell, gpointer data,
|
||||
gpointer data2);
|
||||
|
||||
/** @} */
|
||||
#endif
|
||||
|
@ -46,15 +46,16 @@
|
||||
#include "gnucash-sheet.h"
|
||||
#include "gnucash-sheetP.h"
|
||||
#include "table-allgui.h"
|
||||
#include "Account.h"
|
||||
|
||||
#define GNC_PREF_AUTO_RAISE_LISTS "auto-raise-lists"
|
||||
|
||||
typedef struct _PopBox
|
||||
{
|
||||
GnucashSheet *sheet;
|
||||
GncItemEdit *item_edit;
|
||||
GncItemList *item_list;
|
||||
GtkListStore *tmp_store;
|
||||
GnucashSheet* sheet;
|
||||
GncItemEdit* item_edit;
|
||||
GncItemList* item_list;
|
||||
GtkListStore* tmp_store;
|
||||
|
||||
gboolean signals_connected; /* list signals connected? */
|
||||
|
||||
@ -62,7 +63,7 @@ typedef struct _PopBox
|
||||
|
||||
gboolean autosize;
|
||||
|
||||
QuickFill *qf;
|
||||
QuickFill* qf;
|
||||
gboolean use_quickfill_cache; /* If TRUE, we don't own the qf */
|
||||
|
||||
gboolean in_list_select;
|
||||
@ -71,26 +72,26 @@ typedef struct _PopBox
|
||||
|
||||
gunichar complete_char; /* char to be used for auto-completion */
|
||||
|
||||
GList *ignore_strings;
|
||||
GList* ignore_strings;
|
||||
} PopBox;
|
||||
|
||||
|
||||
static void gnc_combo_cell_gui_realize (BasicCell *bcell, gpointer w);
|
||||
static void gnc_combo_cell_gui_move (BasicCell *bcell);
|
||||
static void gnc_combo_cell_gui_destroy (BasicCell *bcell);
|
||||
static gboolean gnc_combo_cell_enter (BasicCell *bcell,
|
||||
int *cursor_position,
|
||||
int *start_selection,
|
||||
int *end_selection);
|
||||
static void gnc_combo_cell_leave (BasicCell *bcell);
|
||||
static void gnc_combo_cell_destroy (BasicCell *bcell);
|
||||
static void gnc_combo_cell_gui_realize (BasicCell* bcell, gpointer w);
|
||||
static void gnc_combo_cell_gui_move (BasicCell* bcell);
|
||||
static void gnc_combo_cell_gui_destroy (BasicCell* bcell);
|
||||
static gboolean gnc_combo_cell_enter (BasicCell* bcell,
|
||||
int* cursor_position,
|
||||
int* start_selection,
|
||||
int* end_selection);
|
||||
static void gnc_combo_cell_leave (BasicCell* bcell);
|
||||
static void gnc_combo_cell_destroy (BasicCell* bcell);
|
||||
|
||||
static GOnce auto_pop_init_once = G_ONCE_INIT;
|
||||
static gboolean auto_pop_combos = FALSE;
|
||||
|
||||
|
||||
static void
|
||||
gnc_combo_cell_set_autopop (gpointer prefs, gchar *pref, gpointer user_data)
|
||||
gnc_combo_cell_set_autopop (gpointer prefs, gchar* pref, gpointer user_data)
|
||||
{
|
||||
auto_pop_combos = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER,
|
||||
GNC_PREF_AUTO_RAISE_LISTS);
|
||||
@ -112,12 +113,12 @@ gnc_combo_cell_autopop_init (gpointer unused)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BasicCell *
|
||||
BasicCell*
|
||||
gnc_combo_cell_new (void)
|
||||
{
|
||||
ComboCell * cell;
|
||||
ComboCell* cell;
|
||||
|
||||
g_once(&auto_pop_init_once, gnc_combo_cell_autopop_init, NULL);
|
||||
g_once (&auto_pop_init_once, gnc_combo_cell_autopop_init, NULL);
|
||||
|
||||
cell = g_new0 (ComboCell, 1);
|
||||
|
||||
@ -127,11 +128,11 @@ gnc_combo_cell_new (void)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_init (ComboCell *cell)
|
||||
gnc_combo_cell_init (ComboCell* cell)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
gnc_basic_cell_init (&(cell->cell));
|
||||
gnc_basic_cell_init (& (cell->cell));
|
||||
|
||||
cell->cell.is_popup = TRUE;
|
||||
|
||||
@ -150,9 +151,10 @@ gnc_combo_cell_init (ComboCell *cell)
|
||||
box->list_popped = FALSE;
|
||||
box->autosize = FALSE;
|
||||
|
||||
cell->shared_store_full = NULL;
|
||||
cell->cell.gui_private = box;
|
||||
|
||||
box->qf = gnc_quickfill_new ();
|
||||
box->qf = gnc_quickfill_new();
|
||||
box->use_quickfill_cache = FALSE;
|
||||
|
||||
box->in_list_select = FALSE;
|
||||
@ -165,10 +167,10 @@ gnc_combo_cell_init (ComboCell *cell)
|
||||
}
|
||||
|
||||
static void
|
||||
select_item_cb (GncItemList *item_list, char *item_string, gpointer data)
|
||||
select_item_cb (GncItemList* item_list, char* item_string, gpointer data)
|
||||
{
|
||||
ComboCell *cell = data;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
ComboCell* cell = data;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
box->in_list_select = TRUE;
|
||||
gnucash_sheet_modify_current_cell (box->sheet, item_string);
|
||||
@ -179,10 +181,10 @@ select_item_cb (GncItemList *item_list, char *item_string, gpointer data)
|
||||
}
|
||||
|
||||
static void
|
||||
change_item_cb (GncItemList *item_list, char *item_string, gpointer data)
|
||||
change_item_cb (GncItemList* item_list, char* item_string, gpointer data)
|
||||
{
|
||||
ComboCell *cell = data;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
ComboCell* cell = data;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
box->in_list_select = TRUE;
|
||||
gnucash_sheet_modify_current_cell (box->sheet, item_string);
|
||||
@ -190,20 +192,20 @@ change_item_cb (GncItemList *item_list, char *item_string, gpointer data)
|
||||
}
|
||||
|
||||
static void
|
||||
activate_item_cb (GncItemList *item_list, char *item_string, gpointer data)
|
||||
activate_item_cb (GncItemList* item_list, char* item_string, gpointer data)
|
||||
{
|
||||
ComboCell *cell = data;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
ComboCell* cell = data;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
gnc_item_edit_hide_popup (box->item_edit);
|
||||
box->list_popped = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
key_press_item_cb (GncItemList *item_list, GdkEventKey *event, gpointer data)
|
||||
key_press_item_cb (GncItemList* item_list, GdkEventKey* event, gpointer data)
|
||||
{
|
||||
ComboCell *cell = data;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
ComboCell* cell = data;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
switch (event->keyval)
|
||||
{
|
||||
@ -213,30 +215,31 @@ key_press_item_cb (GncItemList *item_list, GdkEventKey *event, gpointer data)
|
||||
break;
|
||||
|
||||
default:
|
||||
gtk_widget_event (GTK_WIDGET(box->sheet),
|
||||
(GdkEvent *) event);
|
||||
gtk_widget_event (GTK_WIDGET (box->sheet),
|
||||
(GdkEvent*) event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
combo_disconnect_signals (ComboCell *cell)
|
||||
combo_disconnect_signals (ComboCell* cell)
|
||||
{
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
if (!box->signals_connected)
|
||||
return;
|
||||
|
||||
g_signal_handlers_disconnect_matched (G_OBJECT (box->item_list), G_SIGNAL_MATCH_DATA,
|
||||
g_signal_handlers_disconnect_matched (G_OBJECT (box->item_list),
|
||||
G_SIGNAL_MATCH_DATA,
|
||||
0, 0, NULL, NULL, cell);
|
||||
|
||||
box->signals_connected = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
combo_connect_signals (ComboCell *cell)
|
||||
combo_connect_signals (ComboCell* cell)
|
||||
{
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
if (box->signals_connected)
|
||||
return;
|
||||
@ -257,40 +260,42 @@ combo_connect_signals (ComboCell *cell)
|
||||
}
|
||||
|
||||
static void
|
||||
block_list_signals (ComboCell *cell)
|
||||
block_list_signals (ComboCell* cell)
|
||||
{
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
if (!box->signals_connected)
|
||||
return;
|
||||
|
||||
g_signal_handlers_block_matched (G_OBJECT (box->item_list), G_SIGNAL_MATCH_DATA,
|
||||
g_signal_handlers_block_matched (G_OBJECT (box->item_list),
|
||||
G_SIGNAL_MATCH_DATA,
|
||||
0, 0, NULL, NULL, cell);
|
||||
}
|
||||
|
||||
static void
|
||||
unblock_list_signals (ComboCell *cell)
|
||||
unblock_list_signals (ComboCell* cell)
|
||||
{
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
if (!box->signals_connected)
|
||||
return;
|
||||
|
||||
g_signal_handlers_unblock_matched (G_OBJECT (box->item_list), G_SIGNAL_MATCH_DATA,
|
||||
g_signal_handlers_unblock_matched (G_OBJECT (box->item_list),
|
||||
G_SIGNAL_MATCH_DATA,
|
||||
0, 0, NULL, NULL, cell);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_gui_destroy (BasicCell *bcell)
|
||||
gnc_combo_cell_gui_destroy (BasicCell* bcell)
|
||||
{
|
||||
PopBox *box = bcell->gui_private;
|
||||
ComboCell *cell = (ComboCell *) bcell;
|
||||
PopBox* box = bcell->gui_private;
|
||||
ComboCell* cell = (ComboCell*) bcell;
|
||||
|
||||
if (cell->cell.gui_realize == NULL)
|
||||
{
|
||||
if (box != NULL && box->item_list != NULL)
|
||||
{
|
||||
combo_disconnect_signals(cell);
|
||||
combo_disconnect_signals (cell);
|
||||
g_object_unref (box->item_list);
|
||||
box->item_list = NULL;
|
||||
}
|
||||
@ -305,16 +310,16 @@ gnc_combo_cell_gui_destroy (BasicCell *bcell)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_destroy (BasicCell *bcell)
|
||||
gnc_combo_cell_destroy (BasicCell* bcell)
|
||||
{
|
||||
ComboCell *cell = (ComboCell *) bcell;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
ComboCell* cell = (ComboCell*) bcell;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
gnc_combo_cell_gui_destroy (&(cell->cell));
|
||||
gnc_combo_cell_gui_destroy (& (cell->cell));
|
||||
|
||||
if (box != NULL)
|
||||
{
|
||||
GList *node;
|
||||
GList* node;
|
||||
|
||||
/* Don't destroy the qf if its not ours to destroy */
|
||||
if (FALSE == box->use_quickfill_cache)
|
||||
@ -341,9 +346,9 @@ gnc_combo_cell_destroy (BasicCell *bcell)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_set_sort_enabled (ComboCell *cell, gboolean enabled)
|
||||
gnc_combo_cell_set_sort_enabled (ComboCell* cell, gboolean enabled)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -353,14 +358,14 @@ gnc_combo_cell_set_sort_enabled (ComboCell *cell, gboolean enabled)
|
||||
return;
|
||||
|
||||
block_list_signals (cell);
|
||||
gnc_item_list_set_sort_enabled(box->item_list, enabled);
|
||||
gnc_item_list_set_sort_enabled (box->item_list, enabled);
|
||||
unblock_list_signals (cell);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_clear_menu (ComboCell * cell)
|
||||
gnc_combo_cell_clear_menu (ComboCell* cell)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -373,7 +378,7 @@ gnc_combo_cell_clear_menu (ComboCell * cell)
|
||||
if (FALSE == box->use_quickfill_cache)
|
||||
{
|
||||
gnc_quickfill_destroy (box->qf);
|
||||
box->qf = gnc_quickfill_new ();
|
||||
box->qf = gnc_quickfill_new();
|
||||
}
|
||||
|
||||
if (box->item_list != NULL)
|
||||
@ -389,9 +394,9 @@ gnc_combo_cell_clear_menu (ComboCell * cell)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_use_quickfill_cache (ComboCell * cell, QuickFill *shared_qf)
|
||||
gnc_combo_cell_use_quickfill_cache (ComboCell* cell, QuickFill* shared_qf)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL) return;
|
||||
|
||||
@ -407,17 +412,19 @@ gnc_combo_cell_use_quickfill_cache (ComboCell * cell, QuickFill *shared_qf)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_use_list_store_cache (ComboCell * cell, gpointer data)
|
||||
gnc_combo_cell_use_list_store_cache (ComboCell* cell, gpointer data,
|
||||
gpointer data_full)
|
||||
{
|
||||
if (cell == NULL) return;
|
||||
|
||||
cell->shared_store = data;
|
||||
cell->shared_store_full = data_full;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_add_menu_item (ComboCell *cell, const char * menustr)
|
||||
gnc_combo_cell_add_menu_item (ComboCell* cell, const char* menustr)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -432,7 +439,7 @@ gnc_combo_cell_add_menu_item (ComboCell *cell, const char * menustr)
|
||||
|
||||
gnc_item_list_append (box->item_list, menustr);
|
||||
if (cell->cell.value &&
|
||||
(strcmp (menustr, cell->cell.value) == 0))
|
||||
(strcmp (menustr, cell->cell.value) == 0))
|
||||
gnc_item_list_select (box->item_list, menustr);
|
||||
|
||||
unblock_list_signals (cell);
|
||||
@ -441,8 +448,8 @@ gnc_combo_cell_add_menu_item (ComboCell *cell, const char * menustr)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
gtk_list_store_append(box->tmp_store, &iter);
|
||||
gtk_list_store_set(box->tmp_store, &iter, 0, menustr, -1);
|
||||
gtk_list_store_append (box->tmp_store, &iter);
|
||||
gtk_list_store_set (box->tmp_store, &iter, 0, menustr, -1);
|
||||
}
|
||||
|
||||
/* If we're going to be using a pre-fab quickfill,
|
||||
@ -454,10 +461,10 @@ gnc_combo_cell_add_menu_item (ComboCell *cell, const char * menustr)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_add_account_menu_item (ComboCell *cell, char * menustr)
|
||||
gnc_combo_cell_add_account_menu_item (ComboCell* cell, char* menustr)
|
||||
{
|
||||
PopBox *box;
|
||||
gchar *menu_copy, *value_copy;
|
||||
PopBox* box;
|
||||
gchar* menu_copy, *value_copy;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -473,16 +480,16 @@ gnc_combo_cell_add_account_menu_item (ComboCell *cell, char * menustr)
|
||||
gnc_item_list_append (box->item_list, menustr);
|
||||
if (cell->cell.value)
|
||||
{
|
||||
menu_copy = g_strdelimit(g_strdup(menustr), "-:/\\.", ' ');
|
||||
menu_copy = g_strdelimit (g_strdup (menustr), "-:/\\.", ' ');
|
||||
value_copy =
|
||||
g_strdelimit(g_strdup(cell->cell.value), "-:/\\.", ' ');
|
||||
g_strdelimit (g_strdup (cell->cell.value), "-:/\\.", ' ');
|
||||
if (strcmp (menu_copy, value_copy) == 0)
|
||||
{
|
||||
gnc_combo_cell_set_value (cell, menustr);
|
||||
gnc_item_list_select (box->item_list, menustr);
|
||||
}
|
||||
g_free(value_copy);
|
||||
g_free(menu_copy);
|
||||
g_free (value_copy);
|
||||
g_free (menu_copy);
|
||||
}
|
||||
unblock_list_signals (cell);
|
||||
}
|
||||
@ -496,28 +503,88 @@ gnc_combo_cell_add_account_menu_item (ComboCell *cell, char * menustr)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_set_value (ComboCell *cell, const char *str)
|
||||
gnc_combo_cell_set_value (ComboCell* cell, const char* str)
|
||||
{
|
||||
gnc_basic_cell_set_value (&cell->cell, str);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_modify_verify (BasicCell *_cell,
|
||||
const char *change,
|
||||
int change_len,
|
||||
const char *newval,
|
||||
int newval_len,
|
||||
int *cursor_position,
|
||||
int *start_selection,
|
||||
int *end_selection)
|
||||
/* This function looks through full_store for a partial match with newval and returns the first
|
||||
match (which must be subsequently freed). It fills out box->item_list with found matches */
|
||||
static gchar*
|
||||
gnc_combo_cell_type_ahead_search (const gchar* newval,
|
||||
GtkListStore* full_store, PopBox* box)
|
||||
{
|
||||
ComboCell *cell = (ComboCell *) _cell;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
const char *match_str;
|
||||
QuickFill *match;
|
||||
gboolean pop_list;
|
||||
GtkTreeIter iter;
|
||||
gboolean valid;
|
||||
int num_found = 0;
|
||||
gchar* first_found = NULL;
|
||||
gchar* match_str = NULL;
|
||||
GError* gerror = NULL;
|
||||
GMatchInfo* match_info = NULL;
|
||||
GRegex* regex = NULL;
|
||||
gchar* rep_str = NULL;
|
||||
gchar* newval_rep = NULL;
|
||||
GRegex* regex0 = g_regex_new (gnc_get_account_separator_string(), 0, 0,
|
||||
&gerror);
|
||||
|
||||
// Replace ":" in newval with ".*:.*" so we can use regexp to match.
|
||||
newval_rep = g_strconcat (".*", gnc_get_account_separator_string(), ".*",
|
||||
NULL);
|
||||
rep_str = g_regex_replace (regex0, newval, -1, 0, newval_rep, 0, &gerror);
|
||||
// Then compile the regular expression based on rep_str.
|
||||
regex = g_regex_new (rep_str, G_REGEX_CASELESS, 0, &gerror);
|
||||
|
||||
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (full_store), &iter);
|
||||
// Clear result list.
|
||||
gnc_item_list_clear (box->item_list);
|
||||
while (valid)
|
||||
{
|
||||
static const gint MAX_NUM_MATCHES = 30;
|
||||
gchar* str_data = NULL;
|
||||
gchar* normalized_str_data = NULL;
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (full_store), &iter, 0, &str_data, -1);
|
||||
normalized_str_data = g_utf8_normalize (str_data, -1, G_NORMALIZE_ALL);
|
||||
|
||||
if (g_regex_match (regex, normalized_str_data, 0, NULL))
|
||||
{
|
||||
if (!num_found) first_found = g_strdup (str_data);
|
||||
++num_found;
|
||||
/* The pop box can be very slow to display if it has too many items and it's not very useful
|
||||
to have many. So limit that to a reasonable number. */
|
||||
if (num_found < MAX_NUM_MATCHES)
|
||||
gnc_item_list_append (box->item_list, str_data);
|
||||
}
|
||||
g_free (str_data);
|
||||
g_free (normalized_str_data);
|
||||
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (full_store), &iter);
|
||||
}
|
||||
if (num_found)
|
||||
match_str = first_found;
|
||||
g_regex_unref (regex);
|
||||
g_regex_unref (regex0);
|
||||
g_free (rep_str);
|
||||
g_free (newval_rep);
|
||||
return match_str;
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_modify_verify (BasicCell* _cell,
|
||||
const char* change,
|
||||
int change_len,
|
||||
const char* newval,
|
||||
int newval_len,
|
||||
int* cursor_position,
|
||||
int* start_selection,
|
||||
int* end_selection)
|
||||
{
|
||||
ComboCell* cell = (ComboCell*) _cell;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
gchar* match_str = NULL;
|
||||
glong newval_chars;
|
||||
glong change_chars;
|
||||
GtkListStore* full_store;
|
||||
const gchar* box_str = NULL;
|
||||
QuickFill* match = NULL;
|
||||
|
||||
newval_chars = g_utf8_strlen (newval, newval_len);
|
||||
change_chars = g_utf8_strlen (change, change_len);
|
||||
@ -525,53 +592,51 @@ gnc_combo_cell_modify_verify (BasicCell *_cell,
|
||||
if (box->in_list_select)
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (_cell, newval);
|
||||
|
||||
*cursor_position = -1;
|
||||
*start_selection = 0;
|
||||
*end_selection = -1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* If deleting, just accept */
|
||||
if (change == NULL)
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (_cell, newval);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we are inserting in the middle, just accept */
|
||||
if (*cursor_position < _cell->value_chars)
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (_cell, newval);
|
||||
return;
|
||||
}
|
||||
|
||||
// Try the start-of-name match using the quickfill
|
||||
match = gnc_quickfill_get_string_match (box->qf, newval);
|
||||
|
||||
match_str = gnc_quickfill_string (match);
|
||||
|
||||
if ((match == NULL) || (match_str == NULL))
|
||||
match_str = g_strdup (gnc_quickfill_string (match));
|
||||
if (match_str != NULL)
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (_cell, newval);
|
||||
// We have a match, but if we were deleting or inserting in the middle, just accept.
|
||||
if (change == NULL || *cursor_position < _cell->value_chars)
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (_cell, newval);
|
||||
return;
|
||||
}
|
||||
*start_selection = newval_chars;
|
||||
*end_selection = -1;
|
||||
*cursor_position += change_chars;
|
||||
box_str = match_str;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No start-of-name match, try type-ahead search, we match any substring of the account name.
|
||||
full_store = cell->shared_store_full;
|
||||
match_str = gnc_combo_cell_type_ahead_search (newval, full_store, box);
|
||||
*start_selection = newval_chars;
|
||||
*end_selection = -1;
|
||||
*cursor_position = newval_chars;
|
||||
// Do not change the string in the type-in box.
|
||||
box_str = newval;
|
||||
}
|
||||
|
||||
if (match_str == NULL)
|
||||
{
|
||||
// No match. Remove any selection in popup, don't change the type-in box
|
||||
gnc_basic_cell_set_value_internal (_cell, newval);
|
||||
block_list_signals (cell);
|
||||
gnc_item_list_select (box->item_list, NULL);
|
||||
unblock_list_signals (cell);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*start_selection = newval_chars;
|
||||
*end_selection = -1;
|
||||
*cursor_position += change_chars;
|
||||
|
||||
if (!box->list_popped)
|
||||
pop_list = auto_pop_combos;
|
||||
else
|
||||
pop_list = FALSE;
|
||||
|
||||
if (pop_list)
|
||||
if (!box->list_popped && auto_pop_combos)
|
||||
{
|
||||
gnc_item_edit_show_popup (box->item_edit);
|
||||
box->list_popped = TRUE;
|
||||
@ -581,24 +646,25 @@ gnc_combo_cell_modify_verify (BasicCell *_cell,
|
||||
gnc_item_list_select (box->item_list, match_str);
|
||||
unblock_list_signals (cell);
|
||||
|
||||
gnc_basic_cell_set_value_internal (_cell, match_str);
|
||||
gnc_basic_cell_set_value_internal (_cell, box_str);
|
||||
g_free (match_str);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
int *cursor_position,
|
||||
int *start_selection,
|
||||
int *end_selection,
|
||||
void *gui_data)
|
||||
gnc_combo_cell_direct_update (BasicCell* bcell,
|
||||
int* cursor_position,
|
||||
int* start_selection,
|
||||
int* end_selection,
|
||||
void* gui_data)
|
||||
{
|
||||
ComboCell *cell = (ComboCell *) bcell;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
GdkEventKey *event = gui_data;
|
||||
ComboCell* cell = (ComboCell*) bcell;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
GdkEventKey* event = gui_data;
|
||||
gboolean keep_on_going = FALSE;
|
||||
gboolean extra_colon;
|
||||
gunichar unicode_value;
|
||||
QuickFill *match;
|
||||
const char *match_str;
|
||||
QuickFill* match;
|
||||
const char* match_str;
|
||||
int prefix_len;
|
||||
int find_pos;
|
||||
int new_pos;
|
||||
@ -606,11 +672,11 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
if (event->type != GDK_KEY_PRESS)
|
||||
return FALSE;
|
||||
|
||||
unicode_value = gdk_keyval_to_unicode(event->keyval);
|
||||
unicode_value = gdk_keyval_to_unicode (event->keyval);
|
||||
switch (event->keyval)
|
||||
{
|
||||
case GDK_KEY_slash:
|
||||
if (!(event->state & GDK_MOD1_MASK))
|
||||
if (! (event->state & GDK_MOD1_MASK))
|
||||
{
|
||||
if (unicode_value == box->complete_char)
|
||||
break;
|
||||
@ -618,11 +684,11 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
return FALSE;
|
||||
}
|
||||
keep_on_going = TRUE;
|
||||
/* fall through */
|
||||
/* fall through */
|
||||
case GDK_KEY_Tab:
|
||||
case GDK_KEY_ISO_Left_Tab:
|
||||
if (!(event->state & GDK_CONTROL_MASK) &&
|
||||
!keep_on_going)
|
||||
if (! (event->state & GDK_CONTROL_MASK) &&
|
||||
!keep_on_going)
|
||||
return FALSE;
|
||||
|
||||
match = gnc_quickfill_get_string_len_match
|
||||
@ -638,9 +704,9 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
match_str = gnc_quickfill_string (match);
|
||||
|
||||
if ((match_str != NULL) &&
|
||||
(strncmp (match_str, bcell->value,
|
||||
strlen (bcell->value)) == 0) &&
|
||||
(strcmp (match_str, bcell->value) != 0))
|
||||
(strncmp (match_str, bcell->value,
|
||||
strlen (bcell->value)) == 0) &&
|
||||
(strcmp (match_str, bcell->value) != 0))
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (bcell,
|
||||
match_str);
|
||||
@ -668,20 +734,20 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
return FALSE;
|
||||
|
||||
if ((*cursor_position < bcell->value_chars) &&
|
||||
((*end_selection < bcell->value_chars) ||
|
||||
(*cursor_position < *start_selection)))
|
||||
((*end_selection < bcell->value_chars) ||
|
||||
(*cursor_position < *start_selection)))
|
||||
return FALSE;
|
||||
|
||||
if ((*cursor_position == bcell->value_chars) &&
|
||||
(*start_selection != *end_selection) &&
|
||||
(*end_selection < bcell->value_chars))
|
||||
(*start_selection != *end_selection) &&
|
||||
(*end_selection < bcell->value_chars))
|
||||
return FALSE;
|
||||
|
||||
find_pos = -1;
|
||||
if (*start_selection < bcell->value_chars)
|
||||
{
|
||||
int i = *start_selection;
|
||||
const char *c;
|
||||
const char* c;
|
||||
gunichar uc;
|
||||
|
||||
c = g_utf8_offset_to_pointer (bcell->value, i);
|
||||
@ -710,7 +776,7 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
}
|
||||
|
||||
match = gnc_quickfill_get_string_len_match (box->qf,
|
||||
bcell->value, new_pos);
|
||||
bcell->value, new_pos);
|
||||
if (match == NULL)
|
||||
return FALSE;
|
||||
|
||||
@ -727,8 +793,8 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
match_str = gnc_quickfill_string (match);
|
||||
|
||||
if ((match_str != NULL) &&
|
||||
(strncmp (match_str, bcell->value, strlen (bcell->value)) == 0) &&
|
||||
(strcmp (match_str, bcell->value) != 0))
|
||||
(strncmp (match_str, bcell->value, strlen (bcell->value)) == 0) &&
|
||||
(strcmp (match_str, bcell->value) != 0))
|
||||
{
|
||||
gnc_basic_cell_set_value_internal (bcell, match_str);
|
||||
|
||||
@ -745,12 +811,12 @@ gnc_combo_cell_direct_update (BasicCell *bcell,
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_gui_realize (BasicCell *bcell, gpointer data)
|
||||
gnc_combo_cell_gui_realize (BasicCell* bcell, gpointer data)
|
||||
{
|
||||
GnucashSheet *sheet = data;
|
||||
GncItemEdit *item_edit = gnucash_sheet_get_item_edit (sheet);
|
||||
ComboCell *cell = (ComboCell *) bcell;
|
||||
PopBox *box = cell->cell.gui_private;
|
||||
GnucashSheet* sheet = data;
|
||||
GncItemEdit* item_edit = gnucash_sheet_get_item_edit (sheet);
|
||||
ComboCell* cell = (ComboCell*) bcell;
|
||||
PopBox* box = cell->cell.gui_private;
|
||||
|
||||
/* initialize gui-specific, private data */
|
||||
box->sheet = sheet;
|
||||
@ -759,8 +825,8 @@ gnc_combo_cell_gui_realize (BasicCell *bcell, gpointer data)
|
||||
box->item_list = GNC_ITEM_LIST (gnc_item_list_new (cell->shared_store));
|
||||
else
|
||||
box->item_list = GNC_ITEM_LIST (gnc_item_list_new (box->tmp_store));
|
||||
gtk_widget_show_all (GTK_WIDGET(box->item_list));
|
||||
g_object_ref_sink(box->item_list);
|
||||
gtk_widget_show_all (GTK_WIDGET (box->item_list));
|
||||
g_object_ref_sink (box->item_list);
|
||||
|
||||
/* to mark cell as realized, remove the realize method */
|
||||
cell->cell.gui_realize = NULL;
|
||||
@ -773,11 +839,11 @@ gnc_combo_cell_gui_realize (BasicCell *bcell, gpointer data)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_gui_move (BasicCell *bcell)
|
||||
gnc_combo_cell_gui_move (BasicCell* bcell)
|
||||
{
|
||||
PopBox *box = bcell->gui_private;
|
||||
PopBox* box = bcell->gui_private;
|
||||
|
||||
combo_disconnect_signals ((ComboCell *) bcell);
|
||||
combo_disconnect_signals ((ComboCell*) bcell);
|
||||
|
||||
gnc_item_edit_set_popup (box->item_edit, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL);
|
||||
@ -786,24 +852,24 @@ gnc_combo_cell_gui_move (BasicCell *bcell)
|
||||
}
|
||||
|
||||
static int
|
||||
popup_get_height (G_GNUC_UNUSED GtkWidget *widget,
|
||||
popup_get_height (G_GNUC_UNUSED GtkWidget* widget,
|
||||
int space_available,
|
||||
int row_height,
|
||||
gpointer user_data)
|
||||
{
|
||||
PopBox *box = user_data;
|
||||
PopBox* box = user_data;
|
||||
int count, pad = 4;
|
||||
|
||||
count = gnc_item_list_num_entries(box->item_list);
|
||||
return MIN(space_available, (count * (row_height + pad)) + pad);
|
||||
count = gnc_item_list_num_entries (box->item_list);
|
||||
return MIN (space_available, (count * (row_height + pad)) + pad);
|
||||
}
|
||||
|
||||
static int
|
||||
popup_autosize (GtkWidget *widget,
|
||||
popup_autosize (GtkWidget* widget,
|
||||
int max_width,
|
||||
gpointer user_data)
|
||||
{
|
||||
PopBox *box = user_data;
|
||||
PopBox* box = user_data;
|
||||
|
||||
if (!box || !box->autosize)
|
||||
return max_width;
|
||||
@ -812,14 +878,14 @@ popup_autosize (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static void
|
||||
popup_set_focus (GtkWidget *widget,
|
||||
popup_set_focus (GtkWidget* widget,
|
||||
G_GNUC_UNUSED gpointer user_data)
|
||||
{
|
||||
gtk_widget_grab_focus (GTK_WIDGET (GNC_ITEM_LIST (widget)->tree_view));
|
||||
}
|
||||
|
||||
static void
|
||||
popup_post_show (GtkWidget *widget,
|
||||
popup_post_show (GtkWidget* widget,
|
||||
G_GNUC_UNUSED gpointer user_data)
|
||||
{
|
||||
gnc_item_list_autosize (GNC_ITEM_LIST (widget));
|
||||
@ -827,23 +893,24 @@ popup_post_show (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static int
|
||||
popup_get_width (GtkWidget *widget,
|
||||
popup_get_width (GtkWidget* widget,
|
||||
G_GNUC_UNUSED gpointer user_data)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
gtk_widget_get_allocation (GTK_WIDGET (GNC_ITEM_LIST (widget)->tree_view), &alloc);
|
||||
gtk_widget_get_allocation (GTK_WIDGET (GNC_ITEM_LIST (widget)->tree_view),
|
||||
&alloc);
|
||||
return alloc.width;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_combo_cell_enter (BasicCell *bcell,
|
||||
int *cursor_position,
|
||||
int *start_selection,
|
||||
int *end_selection)
|
||||
gnc_combo_cell_enter (BasicCell* bcell,
|
||||
int* cursor_position,
|
||||
int* start_selection,
|
||||
int* end_selection)
|
||||
{
|
||||
ComboCell *cell = (ComboCell *) bcell;
|
||||
PopBox *box = bcell->gui_private;
|
||||
GList *find = NULL;
|
||||
ComboCell* cell = (ComboCell*) bcell;
|
||||
PopBox* box = bcell->gui_private;
|
||||
GList* find = NULL;
|
||||
|
||||
if (bcell->value)
|
||||
find = g_list_find_custom (box->ignore_strings,
|
||||
@ -853,7 +920,7 @@ gnc_combo_cell_enter (BasicCell *bcell,
|
||||
return FALSE;
|
||||
|
||||
gnc_item_edit_set_popup (box->item_edit,
|
||||
GTK_WIDGET(box->item_list),
|
||||
GTK_WIDGET (box->item_list),
|
||||
popup_get_height, popup_autosize,
|
||||
popup_set_focus, popup_post_show,
|
||||
popup_get_width, box);
|
||||
@ -872,11 +939,11 @@ gnc_combo_cell_enter (BasicCell *bcell,
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_combo_cell_leave (BasicCell *bcell)
|
||||
gnc_combo_cell_leave (BasicCell* bcell)
|
||||
{
|
||||
PopBox *box = bcell->gui_private;
|
||||
PopBox* box = bcell->gui_private;
|
||||
|
||||
combo_disconnect_signals ((ComboCell *) bcell);
|
||||
combo_disconnect_signals ((ComboCell*) bcell);
|
||||
|
||||
gnc_item_edit_set_popup (box->item_edit, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL);
|
||||
@ -900,9 +967,9 @@ gnc_combo_cell_leave (BasicCell *bcell)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_set_strict (ComboCell *cell, gboolean strict)
|
||||
gnc_combo_cell_set_strict (ComboCell* cell, gboolean strict)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -913,9 +980,9 @@ gnc_combo_cell_set_strict (ComboCell *cell, gboolean strict)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_set_complete_char (ComboCell *cell, gunichar complete_char)
|
||||
gnc_combo_cell_set_complete_char (ComboCell* cell, gunichar complete_char)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -926,10 +993,10 @@ gnc_combo_cell_set_complete_char (ComboCell *cell, gunichar complete_char)
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_add_ignore_string (ComboCell *cell,
|
||||
const char *ignore_string)
|
||||
gnc_combo_cell_add_ignore_string (ComboCell* cell,
|
||||
const char* ignore_string)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (cell == NULL)
|
||||
return;
|
||||
@ -944,9 +1011,9 @@ gnc_combo_cell_add_ignore_string (ComboCell *cell,
|
||||
}
|
||||
|
||||
void
|
||||
gnc_combo_cell_set_autosize (ComboCell *cell, gboolean autosize)
|
||||
gnc_combo_cell_set_autosize (ComboCell* cell, gboolean autosize)
|
||||
{
|
||||
PopBox *box;
|
||||
PopBox* box;
|
||||
|
||||
if (!cell)
|
||||
return;
|
||||
|
@ -45,31 +45,32 @@ enum
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static GtkEventBoxClass *gnc_item_list_parent_class;
|
||||
static GtkEventBoxClass* gnc_item_list_parent_class;
|
||||
static guint gnc_item_list_signals[LAST_SIGNAL];
|
||||
|
||||
gboolean _gnc_item_find_selection(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
|
||||
gboolean _gnc_item_find_selection (GtkTreeModel* model, GtkTreePath* path,
|
||||
GtkTreeIter* iter, gpointer data);
|
||||
|
||||
gint
|
||||
gnc_item_list_num_entries (GncItemList *item_list)
|
||||
gnc_item_list_num_entries (GncItemList* item_list)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeModel* model;
|
||||
|
||||
g_return_val_if_fail(item_list != NULL, 0);
|
||||
g_return_val_if_fail(IS_GNC_ITEM_LIST(item_list), 0);
|
||||
g_return_val_if_fail (item_list != NULL, 0);
|
||||
g_return_val_if_fail (IS_GNC_ITEM_LIST (item_list), 0);
|
||||
|
||||
model = GTK_TREE_MODEL(item_list->list_store);
|
||||
return gtk_tree_model_iter_n_children(model, NULL);
|
||||
model = GTK_TREE_MODEL (item_list->list_store);
|
||||
return gtk_tree_model_iter_n_children (model, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_item_list_clear (GncItemList *item_list)
|
||||
gnc_item_list_clear (GncItemList* item_list)
|
||||
{
|
||||
GtkTreeSelection* selection;
|
||||
|
||||
g_return_if_fail(IS_GNC_ITEM_LIST(item_list));
|
||||
g_return_if_fail(item_list->list_store != NULL);
|
||||
g_return_if_fail (IS_GNC_ITEM_LIST (item_list));
|
||||
g_return_if_fail (item_list->list_store != NULL);
|
||||
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (item_list->tree_view));
|
||||
|
||||
@ -82,21 +83,20 @@ gnc_item_list_clear (GncItemList *item_list)
|
||||
|
||||
|
||||
void
|
||||
gnc_item_list_append (GncItemList *item_list, const char *string)
|
||||
gnc_item_list_append (GncItemList* item_list, const char* string)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_return_if_fail(IS_GNC_ITEM_LIST(item_list));
|
||||
g_return_if_fail(item_list->list_store != NULL);
|
||||
g_return_if_fail(string != NULL);
|
||||
|
||||
g_return_if_fail (IS_GNC_ITEM_LIST (item_list));
|
||||
g_return_if_fail (item_list->list_store != NULL);
|
||||
g_return_if_fail (string != NULL);
|
||||
gtk_list_store_append (item_list->list_store, &iter);
|
||||
gtk_list_store_set (item_list->list_store, &iter, 0, string, -1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_item_list_set_sort_enabled(GncItemList *item_list, gboolean enabled)
|
||||
gnc_item_list_set_sort_enabled (GncItemList* item_list, gboolean enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
@ -117,99 +117,101 @@ gnc_item_list_set_sort_enabled(GncItemList *item_list, gboolean enabled)
|
||||
|
||||
typedef struct _findSelectionData
|
||||
{
|
||||
GncItemList *item_list;
|
||||
const char *string_to_find;
|
||||
GtkTreePath *found_path;
|
||||
GncItemList* item_list;
|
||||
const char* string_to_find;
|
||||
GtkTreePath* found_path;
|
||||
} FindSelectionData;
|
||||
|
||||
gboolean
|
||||
_gnc_item_find_selection(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
||||
_gnc_item_find_selection (GtkTreeModel* model, GtkTreePath* path,
|
||||
GtkTreeIter* iter, gpointer data)
|
||||
{
|
||||
FindSelectionData *to_find = (FindSelectionData*)data;
|
||||
gchar *iterStr;
|
||||
FindSelectionData* to_find = (FindSelectionData*)data;
|
||||
gchar* iterStr;
|
||||
gboolean found;
|
||||
|
||||
gtk_tree_model_get(model, iter, 0, &iterStr, -1);
|
||||
found = g_strcmp0(to_find->string_to_find, iterStr) == 0;
|
||||
g_free(iterStr);
|
||||
gtk_tree_model_get (model, iter, 0, &iterStr, -1);
|
||||
found = g_strcmp0 (to_find->string_to_find, iterStr) == 0;
|
||||
g_free (iterStr);
|
||||
if (found)
|
||||
{
|
||||
to_find->found_path = gtk_tree_path_copy(path);
|
||||
to_find->found_path = gtk_tree_path_copy (path);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_item_in_list (GncItemList *item_list, const char *string)
|
||||
gnc_item_in_list (GncItemList* item_list, const char* string)
|
||||
{
|
||||
FindSelectionData *to_find_data;
|
||||
FindSelectionData* to_find_data;
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail(item_list != NULL, FALSE);
|
||||
g_return_val_if_fail(IS_GNC_ITEM_LIST(item_list), FALSE);
|
||||
g_return_val_if_fail (item_list != NULL, FALSE);
|
||||
g_return_val_if_fail (IS_GNC_ITEM_LIST (item_list), FALSE);
|
||||
|
||||
to_find_data = (FindSelectionData*)g_new0(FindSelectionData, 1);
|
||||
to_find_data = (FindSelectionData*)g_new0 (FindSelectionData, 1);
|
||||
to_find_data->item_list = item_list;
|
||||
to_find_data->string_to_find = string;
|
||||
|
||||
gtk_tree_model_foreach(GTK_TREE_MODEL(item_list->list_store),
|
||||
_gnc_item_find_selection,
|
||||
to_find_data);
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (item_list->list_store),
|
||||
_gnc_item_find_selection,
|
||||
to_find_data);
|
||||
|
||||
result = (to_find_data->found_path != NULL);
|
||||
g_free(to_find_data);
|
||||
g_free (to_find_data);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_item_list_select (GncItemList *item_list, const char *string)
|
||||
gnc_item_list_select (GncItemList* item_list, const char* string)
|
||||
{
|
||||
GtkTreeSelection *tree_sel = NULL;
|
||||
FindSelectionData *to_find_data;
|
||||
GtkTreeSelection* tree_sel = NULL;
|
||||
FindSelectionData* to_find_data;
|
||||
|
||||
g_return_if_fail(item_list != NULL);
|
||||
g_return_if_fail(IS_GNC_ITEM_LIST(item_list));
|
||||
g_return_if_fail (item_list != NULL);
|
||||
g_return_if_fail (IS_GNC_ITEM_LIST (item_list));
|
||||
|
||||
tree_sel = gtk_tree_view_get_selection(item_list->tree_view);
|
||||
tree_sel = gtk_tree_view_get_selection (item_list->tree_view);
|
||||
|
||||
if (string == NULL)
|
||||
{
|
||||
gtk_tree_selection_unselect_all(tree_sel);
|
||||
gtk_tree_selection_unselect_all (tree_sel);
|
||||
return;
|
||||
}
|
||||
|
||||
to_find_data = (FindSelectionData*)g_new0(FindSelectionData, 1);
|
||||
to_find_data = (FindSelectionData*)g_new0 (FindSelectionData, 1);
|
||||
to_find_data->item_list = item_list;
|
||||
to_find_data->string_to_find = string;
|
||||
|
||||
gtk_tree_model_foreach(GTK_TREE_MODEL(item_list->list_store),
|
||||
_gnc_item_find_selection,
|
||||
to_find_data);
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (item_list->list_store),
|
||||
_gnc_item_find_selection,
|
||||
to_find_data);
|
||||
|
||||
if (to_find_data->found_path != NULL)
|
||||
{
|
||||
gtk_tree_view_set_cursor(item_list->tree_view, to_find_data->found_path, NULL, FALSE);
|
||||
gtk_tree_path_free(to_find_data->found_path);
|
||||
gtk_tree_view_set_cursor (item_list->tree_view, to_find_data->found_path, NULL,
|
||||
FALSE);
|
||||
gtk_tree_path_free (to_find_data->found_path);
|
||||
|
||||
gnc_item_list_show_selected(item_list);
|
||||
gnc_item_list_show_selected (item_list);
|
||||
}
|
||||
|
||||
g_free(to_find_data);
|
||||
g_free (to_find_data);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_item_list_show_selected (GncItemList *item_list)
|
||||
gnc_item_list_show_selected (GncItemList* item_list)
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeSelection* selection;
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeModel *model;
|
||||
GtkTreePath* path;
|
||||
GtkTreeModel* model;
|
||||
|
||||
g_return_if_fail(item_list != NULL);
|
||||
g_return_if_fail(IS_GNC_ITEM_LIST(item_list));
|
||||
g_return_if_fail (item_list != NULL);
|
||||
g_return_if_fail (IS_GNC_ITEM_LIST (item_list));
|
||||
|
||||
selection = gtk_tree_view_get_selection (item_list->tree_view);
|
||||
|
||||
@ -223,17 +225,17 @@ gnc_item_list_show_selected (GncItemList *item_list)
|
||||
}
|
||||
|
||||
int
|
||||
gnc_item_list_autosize (GncItemList *item_list)
|
||||
gnc_item_list_autosize (GncItemList* item_list)
|
||||
{
|
||||
g_return_val_if_fail(item_list != NULL, 0);
|
||||
g_return_val_if_fail(IS_GNC_ITEM_LIST(item_list), 0);
|
||||
g_return_val_if_fail (item_list != NULL, 0);
|
||||
g_return_val_if_fail (IS_GNC_ITEM_LIST (item_list), 0);
|
||||
|
||||
return 100;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnc_item_list_init (GncItemList *item_list)
|
||||
gnc_item_list_init (GncItemList* item_list)
|
||||
{
|
||||
item_list->tree_view = NULL;
|
||||
item_list->list_store = NULL;
|
||||
@ -241,17 +243,17 @@ gnc_item_list_init (GncItemList *item_list)
|
||||
|
||||
|
||||
static gboolean
|
||||
gnc_item_list_button_event(GtkWidget *widget, GdkEventButton *event,
|
||||
gpointer data)
|
||||
gnc_item_list_button_event (GtkWidget* widget, GdkEventButton* event,
|
||||
gpointer data)
|
||||
{
|
||||
GncItemList *item_list;
|
||||
GncItemList* item_list;
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeModel *model;
|
||||
gchar *string;
|
||||
GtkTreePath* path;
|
||||
GtkTreeModel* model;
|
||||
gchar* string;
|
||||
gboolean success;
|
||||
|
||||
g_return_val_if_fail(IS_GNC_ITEM_LIST (data), FALSE);
|
||||
g_return_val_if_fail (IS_GNC_ITEM_LIST (data), FALSE);
|
||||
|
||||
item_list = GNC_ITEM_LIST (data);
|
||||
|
||||
@ -285,7 +287,7 @@ gnc_item_list_button_event(GtkWidget *widget, GdkEventButton *event,
|
||||
gnc_item_list_signals[ACTIVATE_ITEM],
|
||||
0,
|
||||
string);
|
||||
g_free(string);
|
||||
g_free (string);
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
@ -295,13 +297,13 @@ gnc_item_list_button_event(GtkWidget *widget, GdkEventButton *event,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_item_list_key_event (GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
gnc_item_list_key_event (GtkWidget* widget, GdkEventKey* event, gpointer data)
|
||||
{
|
||||
GncItemList *item_list = GNC_ITEM_LIST (data);
|
||||
GtkTreeSelection *selection = NULL;
|
||||
GncItemList* item_list = GNC_ITEM_LIST (data);
|
||||
GtkTreeSelection* selection = NULL;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
gchar *string;
|
||||
GtkTreeModel* model;
|
||||
gchar* string;
|
||||
gboolean retval;
|
||||
|
||||
switch (event->keyval)
|
||||
@ -317,7 +319,9 @@ gnc_item_list_key_event (GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
gnc_item_list_signals[ACTIVATE_ITEM],
|
||||
0,
|
||||
string);
|
||||
g_free(string);
|
||||
g_signal_emit (G_OBJECT (item_list), gnc_item_list_signals[CHANGE_ITEM], 0,
|
||||
string);
|
||||
g_free (string);
|
||||
return TRUE;
|
||||
|
||||
case GDK_KEY_Page_Up:
|
||||
@ -331,16 +335,17 @@ gnc_item_list_key_event (GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
/* These go to the sheet */
|
||||
g_signal_stop_emission_by_name (G_OBJECT (widget), "key_press_event");
|
||||
|
||||
g_signal_emit_by_name (G_OBJECT (item_list), "key_press_event", event, &retval);
|
||||
g_signal_emit_by_name (G_OBJECT (item_list), "key_press_event", event,
|
||||
&retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnc_item_list_class_init (GncItemListClass *item_list_class)
|
||||
gnc_item_list_class_init (GncItemListClass* item_list_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (item_list_class);
|
||||
GObjectClass* object_class = G_OBJECT_CLASS (item_list_class);
|
||||
|
||||
gnc_item_list_parent_class = g_type_class_peek_parent (item_list_class);
|
||||
|
||||
@ -349,7 +354,7 @@ gnc_item_list_class_init (GncItemListClass *item_list_class)
|
||||
g_signal_new ("select_item",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GncItemListClass, select_item),
|
||||
G_STRUCT_OFFSET (GncItemListClass, select_item),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
@ -359,7 +364,7 @@ gnc_item_list_class_init (GncItemListClass *item_list_class)
|
||||
g_signal_new ("change_item",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GncItemListClass, change_item),
|
||||
G_STRUCT_OFFSET (GncItemListClass, change_item),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
@ -369,7 +374,7 @@ gnc_item_list_class_init (GncItemListClass *item_list_class)
|
||||
g_signal_new ("activate_item",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GncItemListClass, activate_item),
|
||||
G_STRUCT_OFFSET (GncItemListClass, activate_item),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
@ -390,13 +395,13 @@ gnc_item_list_get_type (void)
|
||||
{
|
||||
static const GTypeInfo gnc_item_list_info =
|
||||
{
|
||||
sizeof(GncItemListClass),
|
||||
sizeof (GncItemListClass),
|
||||
NULL,
|
||||
NULL,
|
||||
(GClassInitFunc) gnc_item_list_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof(GncItemList),
|
||||
sizeof (GncItemList),
|
||||
0,
|
||||
(GInstanceInitFunc) gnc_item_list_init
|
||||
};
|
||||
@ -411,40 +416,41 @@ gnc_item_list_get_type (void)
|
||||
|
||||
|
||||
static void
|
||||
tree_view_selection_changed (GtkTreeSelection *selection,
|
||||
tree_view_selection_changed (GtkTreeSelection* selection,
|
||||
gpointer data)
|
||||
{
|
||||
GncItemList *item_list = GNC_ITEM_LIST (data);
|
||||
GtkTreeModel *model;
|
||||
GncItemList* item_list = GNC_ITEM_LIST (data);
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter iter;
|
||||
char *string;
|
||||
char* string;
|
||||
|
||||
g_return_if_fail(data);
|
||||
g_return_if_fail(selection);
|
||||
g_return_if_fail (data);
|
||||
g_return_if_fail (selection);
|
||||
|
||||
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
|
||||
return;
|
||||
|
||||
gtk_tree_model_get (model, &iter, 0, &string, -1);
|
||||
|
||||
g_signal_emit (G_OBJECT (item_list), gnc_item_list_signals[CHANGE_ITEM], 0, string);
|
||||
g_signal_emit (G_OBJECT (item_list), gnc_item_list_signals[CHANGE_ITEM], 0,
|
||||
string);
|
||||
|
||||
g_free (string);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gnc_item_list_new(GtkListStore *list_store)
|
||||
GtkWidget*
|
||||
gnc_item_list_new (GtkListStore* list_store)
|
||||
{
|
||||
GtkWidget *tree_view;
|
||||
GtkWidget *scrollwin;
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkWidget* tree_view;
|
||||
GtkWidget* scrollwin;
|
||||
GtkCellRenderer* renderer;
|
||||
GtkTreeViewColumn* column;
|
||||
|
||||
GncItemList *item_list =
|
||||
GNC_ITEM_LIST(g_object_new (GNC_TYPE_ITEM_LIST,
|
||||
NULL));
|
||||
GncItemList* item_list =
|
||||
GNC_ITEM_LIST (g_object_new (GNC_TYPE_ITEM_LIST,
|
||||
NULL));
|
||||
|
||||
scrollwin = gnc_scrolled_window_new ();
|
||||
scrollwin = gnc_scrolled_window_new();
|
||||
gtk_container_add (GTK_CONTAINER (item_list), scrollwin);
|
||||
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
|
||||
@ -454,21 +460,22 @@ gnc_item_list_new(GtkListStore *list_store)
|
||||
if (NULL == list_store)
|
||||
list_store = gtk_list_store_new (1, G_TYPE_STRING);
|
||||
else
|
||||
g_object_ref(list_store);
|
||||
g_object_ref (list_store);
|
||||
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
|
||||
g_object_unref(list_store);
|
||||
g_object_unref (list_store);
|
||||
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (
|
||||
tree_view)),
|
||||
GTK_SELECTION_BROWSE);
|
||||
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list_store),
|
||||
0, GTK_SORT_ASCENDING);
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
|
||||
0, GTK_SORT_ASCENDING);
|
||||
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
column = gtk_tree_view_column_new_with_attributes (_("List"),
|
||||
renderer,
|
||||
"text", 0,
|
||||
NULL);
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
column = gtk_tree_view_column_new_with_attributes (_ ("List"),
|
||||
renderer,
|
||||
"text", 0,
|
||||
NULL);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (scrollwin), tree_view);
|
||||
@ -476,16 +483,17 @@ gnc_item_list_new(GtkListStore *list_store)
|
||||
item_list->tree_view = GTK_TREE_VIEW (tree_view);
|
||||
item_list->list_store = list_store;
|
||||
|
||||
g_signal_connect (G_OBJECT(tree_view), "button_press_event",
|
||||
g_signal_connect (G_OBJECT (tree_view), "button_press_event",
|
||||
G_CALLBACK (gnc_item_list_button_event), item_list);
|
||||
|
||||
g_signal_connect (G_OBJECT (tree_view), "key_press_event",
|
||||
G_CALLBACK (gnc_item_list_key_event), item_list);
|
||||
|
||||
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view))), "changed",
|
||||
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (
|
||||
tree_view))), "changed",
|
||||
G_CALLBACK (tree_view_selection_changed), item_list);
|
||||
|
||||
return GTK_WIDGET(item_list);
|
||||
return GTK_WIDGET (item_list);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user