auto-complete typed user input.
[GUI]


Detailed Description

QuickFill is meant to be used by the GUI to auto-complete (e.g. tab-complete) typed user input. Quickfill is implemented as a heirarchical tree of partial matching strings. The root of the tree contains all of the strings that user input should be matched to. Then, given a short string segment, quickfill will return a subtree containing only those strings that start with desired substring. As additional letters are added to the substring, Quickfill will thus narrow down to the unique matching string (or to nothing if no match).

QuickFill works with national-language i18n'ed/l10n'ed multi-byte and wide-char strings, as well as plain-old C-locale strings.


Files

file  QuickFill.h
 Quickfill is used to auto-complete typed user entries.

Modules

 Account Names

Typedefs

typedef _QuickFill QuickFill

Enumerations

enum  QuickFillSort { QUICKFILL_LIFO, QUICKFILL_ALPHA }

Functions

QuickFillgnc_quickfill_new (void)
void gnc_quickfill_destroy (QuickFill *qf)
void gnc_quickfill_purge (QuickFill *qf)
const char * gnc_quickfill_string (QuickFill *qf)
QuickFillgnc_quickfill_get_char_match (QuickFill *qf, gunichar c)
QuickFillgnc_quickfill_get_string_match (QuickFill *qf, const char *str)
QuickFillgnc_quickfill_get_string_len_match (QuickFill *qf, const char *str, int len)
QuickFillgnc_quickfill_get_unique_len_match (QuickFill *qf, int *len)
void gnc_quickfill_insert (QuickFill *root, const char *text, QuickFillSort sort_code)
void gnc_quickfill_remove (QuickFill *root, const gchar *text, QuickFillSort sort_code)


Enumeration Type Documentation

enum QuickFillSort

Enumerator:
QUICKFILL_LIFO 
QUICKFILL_ALPHA 

Definition at line 56 of file QuickFill.h.

00057 {
00058   QUICKFILL_LIFO,
00059   QUICKFILL_ALPHA
00060 } QuickFillSort;


Function Documentation

QuickFill* gnc_quickfill_get_char_match ( QuickFill qf,
gunichar  c 
)

Return the subnode of the tree whose strings all hold 'wc' as the next letter. That is, if 'qf' holds all strings starting with the letter 'a', and we ask for the letter 'b', then this routine will return the node holding all strings that start with "ab".

The best-guess matching string can be retreived with gnc_quickfill_string().

Definition at line 136 of file QuickFill.c.

00137 {
00138   guint key = g_unichar_toupper (uc);
00139 
00140   if (NULL == qf) return NULL;
00141 
00142   DEBUG ("xaccGetQuickFill(): index = %u\n", key);
00143 
00144   return g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
00145 }

QuickFill* gnc_quickfill_get_string_len_match ( QuickFill qf,
const char *  str,
int  len 
)

Same as gnc_quickfill_get_string_match(), except that the string length is explicilty specified.

Definition at line 151 of file QuickFill.c.

00153 {
00154   const char *c;
00155   gunichar uc;
00156 
00157   if (NULL == qf) return NULL;
00158   if (NULL == str) return NULL;
00159 
00160   c = str;
00161   while (*c && (len > 0))
00162   {
00163     if (qf == NULL)
00164       return NULL;
00165 
00166     uc = g_utf8_get_char (c);
00167     qf = gnc_quickfill_get_char_match (qf, uc);
00168 
00169     c = g_utf8_next_char (c);
00170     len--;
00171   }
00172 
00173   return qf;
00174 }

QuickFill* gnc_quickfill_get_string_match ( QuickFill qf,
const char *  str 
)

Return a subnode in the tree whose strings all match the string 'str' as the next substring. Thus, for example, if the argument 'qf' holds strings that start with "abc", and this routine is called with "def", then the returned node will hold strings that start with "abcdef".

The best-guess matching string can be retreived with gnc_quickfill_string().

To convert a plain C-locale char * string to GdkWChar *, use the gnc_mbstowcs() routine.

Definition at line 180 of file QuickFill.c.

00181 {
00182   if (NULL == qf) return NULL;
00183   if (NULL == str) return NULL;
00184 
00185   return gnc_quickfill_get_string_len_match (qf, str, g_utf8_strlen (str, -1));
00186 }

QuickFill* gnc_quickfill_get_unique_len_match ( QuickFill qf,
int *  len 
)

Walk a 'unique' part of the quickfill tree. This routine is typically used to assist in the tab-completion of strings. If the inital portion of the string is unique, but some later portion is not, this routine will advance to the first non-unique part of the string. If len is non-NULL, then *len will be set to the length of the unique portion of the string.

Thus, for example, if the root node contains the strings "The Book" and "The Movie", then the returned len will be 4, and the returned node will distinguish "Book" and "Movie". Thus, for example, gnc_quickfill_get_char_match(.., 'B') on the result will identify "The Book".

Definition at line 200 of file QuickFill.c.

00201 {
00202   if (length != NULL)
00203     *length = 0;
00204 
00205   if (qf == NULL)
00206     return NULL;
00207 
00208   while (1)
00209   {
00210     guint count;
00211 
00212     count = g_hash_table_size (qf->matches);
00213 
00214     if (count != 1)
00215     {
00216       return qf;
00217     }
00218 
00219     g_hash_table_foreach (qf->matches, unique_len_helper, &qf);
00220 
00221     if (length != NULL)
00222       (*length)++;
00223   }
00224 }

void gnc_quickfill_insert ( QuickFill root,
const char *  text,
QuickFillSort  sort_code 
)

Add the string "text" to the collection of searchable strings.

Definition at line 230 of file QuickFill.c.

00231 {
00232   gchar *normalized_str;
00233 
00234   if (NULL == qf) return;
00235   if (NULL == text) return;
00236 
00237 
00238   normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
00239   quickfill_insert_recursive (qf, normalized_str, 0, sort);
00240   g_free (normalized_str);
00241 }

const char* gnc_quickfill_string ( QuickFill qf  ) 

For the given node 'qf', return the best-guess matching string.

Definition at line 124 of file QuickFill.c.

00125 {
00126   if (qf == NULL)
00127     return NULL;
00128 
00129   return qf->text;
00130 }


Generated on Fri Jul 25 05:06:04 2008 for GnuCash by  doxygen 1.5.2