Add address auto-completion of r20272 also for address line 4.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20279 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-02-12 15:18:46 +00:00
parent 4978611f28
commit 4741dc2b42
4 changed files with 148 additions and 4 deletions

View File

@ -34,6 +34,7 @@ typedef struct
{ {
QuickFill *qf_addr2; QuickFill *qf_addr2;
QuickFill *qf_addr3; QuickFill *qf_addr3;
QuickFill *qf_addr4;
QuickFillSort qf_sort; QuickFillSort qf_sort;
QofBook *book; QofBook *book;
gint listener; gint listener;
@ -44,7 +45,7 @@ listen_for_gncaddress_events(QofInstance *entity, QofEventId event_type,
gpointer user_data, gpointer event_data) gpointer user_data, gpointer event_data)
{ {
AddressQF *qfb = user_data; AddressQF *qfb = user_data;
const char *addr2, *addr3; const char *addr2, *addr3, *addr4;
/* We only listen for GncAddress events */ /* We only listen for GncAddress events */
if (!GNC_IS_ADDRESS (entity)) if (!GNC_IS_ADDRESS (entity))
@ -61,6 +62,7 @@ listen_for_gncaddress_events(QofInstance *entity, QofEventId event_type,
addr2 = gncAddressGetAddr2(GNC_ADDRESS(entity)); addr2 = gncAddressGetAddr2(GNC_ADDRESS(entity));
addr3 = gncAddressGetAddr3(GNC_ADDRESS(entity)); addr3 = gncAddressGetAddr3(GNC_ADDRESS(entity));
addr4 = gncAddressGetAddr4(GNC_ADDRESS(entity));
if (event_type & QOF_EVENT_MODIFY) if (event_type & QOF_EVENT_MODIFY)
{ {
/* If the description was changed into something non-empty, so /* If the description was changed into something non-empty, so
@ -75,6 +77,11 @@ listen_for_gncaddress_events(QofInstance *entity, QofEventId event_type,
/* Add the new string to the quickfill */ /* Add the new string to the quickfill */
gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO); gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO);
} }
if (addr4 && strlen(addr4) > 0)
{
/* Add the new string to the quickfill */
gnc_quickfill_insert (qfb->qf_addr4, addr4, QUICKFILL_LIFO);
}
} }
else if (event_type & QOF_EVENT_DESTROY) else if (event_type & QOF_EVENT_DESTROY)
{ {
@ -88,6 +95,11 @@ listen_for_gncaddress_events(QofInstance *entity, QofEventId event_type,
/* Remove the description from the quickfill */ /* Remove the description from the quickfill */
gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO); gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO);
} }
if (addr4 && strlen(addr4) > 0)
{
/* Remove the description from the quickfill */
gnc_quickfill_insert (qfb->qf_addr4, addr4, QUICKFILL_LIFO);
}
} }
} }
@ -97,6 +109,7 @@ shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
AddressQF *qfb = user_data; AddressQF *qfb = user_data;
gnc_quickfill_destroy (qfb->qf_addr2); gnc_quickfill_destroy (qfb->qf_addr2);
gnc_quickfill_destroy (qfb->qf_addr3); gnc_quickfill_destroy (qfb->qf_addr3);
gnc_quickfill_destroy (qfb->qf_addr4);
qof_event_unregister_handler (qfb->listener); qof_event_unregister_handler (qfb->listener);
g_free (qfb); g_free (qfb);
} }
@ -113,6 +126,10 @@ static void address_cb(gpointer data, gpointer user_data)
gnc_quickfill_insert (s->qf_addr3, gnc_quickfill_insert (s->qf_addr3,
gncAddressGetAddr3(address), gncAddressGetAddr3(address),
s->qf_sort); s->qf_sort);
gnc_quickfill_insert (s->qf_addr4,
gncAddressGetAddr4(address),
s->qf_sort);
} }
/** Creates a new query that searches for all GncAddress items in the /** Creates a new query that searches for all GncAddress items in the
@ -141,7 +158,8 @@ static AddressQF* build_shared_quickfill (QofBook *book, const char * key)
result->qf_addr2 = gnc_quickfill_new(); result->qf_addr2 = gnc_quickfill_new();
result->qf_addr3 = gnc_quickfill_new(); result->qf_addr3 = gnc_quickfill_new();
result->qf_sort = QUICKFILL_LIFO; result->qf_addr4 = gnc_quickfill_new();
result->qf_sort = QUICKFILL_ALPHA;
result->book = book; result->book = book;
g_list_foreach (entries, address_cb, result); g_list_foreach (entries, address_cb, result);
@ -190,3 +208,20 @@ QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book, const char *
return qfb->qf_addr3; return qfb->qf_addr3;
} }
QuickFill * gnc_get_shared_address_addr4_quickfill (QofBook *book, const char * key)
{
AddressQF *qfb;
g_assert(book);
g_assert(key);
qfb = qof_book_get_data (book, key);
if (!qfb)
{
qfb = build_shared_quickfill(book, key);
}
return qfb->qf_addr4;
}

View File

@ -65,6 +65,16 @@ QuickFill * gnc_get_shared_address_addr2_quickfill (QofBook *book,
QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book, QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book,
const char * key); const char * key);
/** Create/fetch a quickfill GncAddress description strings on the
* Addr4 part.
*
* Identical to gnc_get_shared_address_addr2_quickfill(). You should
* also use the same key as for the other function because the
* internal quickfills are updated simultaneously.
*/
QuickFill * gnc_get_shared_address_addr4_quickfill (QofBook *book,
const char * key);
#endif #endif
/** @} */ /** @} */

View File

@ -71,12 +71,18 @@ void gnc_customer_addr2_insert_cb(GtkEditable *editable,
void gnc_customer_addr3_insert_cb(GtkEditable *editable, void gnc_customer_addr3_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length, gchar *new_text, gint new_text_length,
gint *position, gpointer user_data); gint *position, gpointer user_data);
void gnc_customer_addr4_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length,
gint *position, gpointer user_data);
void gnc_customer_shipaddr2_insert_cb(GtkEditable *editable, void gnc_customer_shipaddr2_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length, gchar *new_text, gint new_text_length,
gint *position, gpointer user_data); gint *position, gpointer user_data);
void gnc_customer_shipaddr3_insert_cb(GtkEditable *editable, void gnc_customer_shipaddr3_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length, gchar *new_text, gint new_text_length,
gint *position, gpointer user_data); gint *position, gpointer user_data);
void gnc_customer_shipaddr4_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length,
gint *position, gpointer user_data);
gboolean gboolean
gnc_customer_addr2_key_press_cb( GtkEntry *entry, GdkEventKey *event, gnc_customer_addr2_key_press_cb( GtkEntry *entry, GdkEventKey *event,
gpointer user_data ); gpointer user_data );
@ -84,11 +90,17 @@ gboolean
gnc_customer_addr3_key_press_cb( GtkEntry *entry, GdkEventKey *event, gnc_customer_addr3_key_press_cb( GtkEntry *entry, GdkEventKey *event,
gpointer user_data ); gpointer user_data );
gboolean gboolean
gnc_customer_addr4_key_press_cb( GtkEntry *entry, GdkEventKey *event,
gpointer user_data );
gboolean
gnc_customer_shipaddr2_key_press_cb( GtkEntry *entry, GdkEventKey *event, gnc_customer_shipaddr2_key_press_cb( GtkEntry *entry, GdkEventKey *event,
gpointer user_data ); gpointer user_data );
gboolean gboolean
gnc_customer_shipaddr3_key_press_cb( GtkEntry *entry, GdkEventKey *event, gnc_customer_shipaddr3_key_press_cb( GtkEntry *entry, GdkEventKey *event,
gpointer user_data ); gpointer user_data );
gboolean
gnc_customer_shipaddr4_key_press_cb( GtkEntry *entry, GdkEventKey *event,
gpointer user_data );
#define ADDR_QUICKFILL "GncAddress-Quickfill" #define ADDR_QUICKFILL "GncAddress-Quickfill"
@ -153,11 +165,11 @@ struct _customer_window
/* stored data for the description quickfill selection function */ /* stored data for the description quickfill selection function */
QuickFill *addr2_quickfill; QuickFill *addr2_quickfill;
QuickFill *addr3_quickfill;
QuickFill *addr4_quickfill;
gint addrX_start_selection; gint addrX_start_selection;
gint addrX_end_selection; gint addrX_end_selection;
guint addrX_selection_source_id; guint addrX_selection_source_id;
QuickFill *addr3_quickfill;
}; };
void void
@ -672,6 +684,7 @@ gnc_customer_new_window (QofBook *bookp, GncCustomer *cust)
/* Set up the addr line quickfill */ /* Set up the addr line quickfill */
cw->addr2_quickfill = gnc_get_shared_address_addr2_quickfill(cw->book, ADDR_QUICKFILL); cw->addr2_quickfill = gnc_get_shared_address_addr2_quickfill(cw->book, ADDR_QUICKFILL);
cw->addr3_quickfill = gnc_get_shared_address_addr3_quickfill(cw->book, ADDR_QUICKFILL); cw->addr3_quickfill = gnc_get_shared_address_addr3_quickfill(cw->book, ADDR_QUICKFILL);
cw->addr4_quickfill = gnc_get_shared_address_addr4_quickfill(cw->book, ADDR_QUICKFILL);
/* Set the Discount, and Credit amounts */ /* Set the Discount, and Credit amounts */
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount), gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount),
@ -946,6 +959,18 @@ idle_select_region_addr3(gpointer user_data)
wdata->addrX_selection_source_id = 0; wdata->addrX_selection_source_id = 0;
return FALSE; return FALSE;
} }
static gboolean
idle_select_region_addr4(gpointer user_data)
{
CustomerWindow *wdata = user_data;
g_return_val_if_fail(user_data, FALSE);
gtk_editable_select_region(GTK_EDITABLE(wdata->addr4_entry),
wdata->addrX_start_selection,
wdata->addrX_end_selection);
wdata->addrX_selection_source_id = 0;
return FALSE;
}
static gboolean static gboolean
idle_select_region_shipaddr2(gpointer user_data) idle_select_region_shipaddr2(gpointer user_data)
@ -974,6 +999,18 @@ idle_select_region_shipaddr3(gpointer user_data)
wdata->addrX_selection_source_id = 0; wdata->addrX_selection_source_id = 0;
return FALSE; return FALSE;
} }
static gboolean
idle_select_region_shipaddr4(gpointer user_data)
{
CustomerWindow *wdata = user_data;
g_return_val_if_fail(user_data, FALSE);
gtk_editable_select_region(GTK_EDITABLE(wdata->shipaddr4_entry),
wdata->addrX_start_selection,
wdata->addrX_end_selection);
wdata->addrX_selection_source_id = 0;
return FALSE;
}
/* Implementation of the steps common to all address lines. Returns /* Implementation of the steps common to all address lines. Returns
* TRUE if anything was inserted by quickfill, otherwise FALSE. */ * TRUE if anything was inserted by quickfill, otherwise FALSE. */
@ -1095,6 +1132,26 @@ void gnc_customer_addr3_insert_cb(GtkEditable *editable,
} }
} }
void gnc_customer_addr4_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length,
gint *position, gpointer user_data)
{
CustomerWindow *wdata = user_data;
gboolean r;
/* The handling common to all address lines is done in this other
* function. */
r = gnc_customer_addr_common_insert_cb(editable, new_text, new_text_length,
position, user_data, wdata->addr4_quickfill);
/* Did we insert something? Then set up the correct idle handler */
if (r)
{
wdata->addrX_selection_source_id = g_idle_add(idle_select_region_addr4,
user_data);
}
}
void gnc_customer_shipaddr2_insert_cb(GtkEditable *editable, void gnc_customer_shipaddr2_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length, gchar *new_text, gint new_text_length,
gint *position, gpointer user_data) gint *position, gpointer user_data)
@ -1135,6 +1192,26 @@ void gnc_customer_shipaddr3_insert_cb(GtkEditable *editable,
} }
} }
void gnc_customer_shipaddr4_insert_cb(GtkEditable *editable,
gchar *new_text, gint new_text_length,
gint *position, gpointer user_data)
{
CustomerWindow *wdata = user_data;
gboolean r;
/* The handling common to all address lines is done in this other
* function. */
r = gnc_customer_addr_common_insert_cb(editable, new_text, new_text_length,
position, user_data, wdata->addr4_quickfill);
/* Did we insert something? Then set up the correct idle handler */
if (r)
{
wdata->addrX_selection_source_id = g_idle_add(idle_select_region_shipaddr4,
user_data);
}
}
static gboolean static gboolean
gnc_customer_common_key_press_cb( GtkEntry *entry, gnc_customer_common_key_press_cb( GtkEntry *entry,
GdkEventKey *event, GdkEventKey *event,
@ -1183,6 +1260,15 @@ gnc_customer_addr3_key_press_cb( GtkEntry *entry,
wdata->addr3_entry); wdata->addr3_entry);
} }
gboolean gboolean
gnc_customer_addr4_key_press_cb( GtkEntry *entry,
GdkEventKey *event,
gpointer user_data )
{
CustomerWindow *wdata = user_data;
return gnc_customer_common_key_press_cb(entry, event, user_data,
wdata->addr4_entry);
}
gboolean
gnc_customer_shipaddr2_key_press_cb( GtkEntry *entry, gnc_customer_shipaddr2_key_press_cb( GtkEntry *entry,
GdkEventKey *event, GdkEventKey *event,
gpointer user_data ) gpointer user_data )
@ -1200,3 +1286,12 @@ gnc_customer_shipaddr3_key_press_cb( GtkEntry *entry,
return gnc_customer_common_key_press_cb(entry, event, user_data, return gnc_customer_common_key_press_cb(entry, event, user_data,
wdata->shipaddr3_entry); wdata->shipaddr3_entry);
} }
gboolean
gnc_customer_shipaddr4_key_press_cb( GtkEntry *entry,
GdkEventKey *event,
gpointer user_data )
{
CustomerWindow *wdata = user_data;
return gnc_customer_common_key_press_cb(entry, event, user_data,
wdata->shipaddr4_entry);
}

View File

@ -331,6 +331,8 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="activates_default">True</property> <property name="activates_default">True</property>
<signal name="insert_text" handler="gnc_customer_addr4_insert_cb"/>
<signal name="key_press_event" handler="gnc_customer_addr4_key_press_cb"/>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -911,6 +913,8 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="activates_default">True</property> <property name="activates_default">True</property>
<signal name="insert_text" handler="gnc_customer_shipaddr4_insert_cb"/>
<signal name="key_press_event" handler="gnc_customer_shipaddr4_key_press_cb"/>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>