Make sure find dialog never uses a destroyed register.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3348 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-12-23 08:57:26 +00:00
parent 223fc82741
commit 1a2938ef96
4 changed files with 111 additions and 80 deletions

View File

@ -73,6 +73,18 @@ find_by_account (gpointer find_data, gpointer user_data)
return TRUE;
}
static gboolean
find_by_query (gpointer find_data, gpointer user_data)
{
Query *q = find_data;
xaccLedgerDisplay *ld = user_data;
if (!q || !ld)
return FALSE;
return ld->query == q;
}
static SplitRegisterStyle
gnc_get_default_register_style ()
{
@ -151,8 +163,8 @@ xaccLedgerDisplaySimple (Account *account)
return NULL;
}
return xaccLedgerDisplayGeneral (account, NULL, reg_type,
gnc_get_default_register_style ());
return xaccLedgerDisplayInternal (account, NULL, NULL, reg_type,
gnc_get_default_register_style ());
}
static GList *
@ -245,8 +257,8 @@ xaccLedgerDisplayAccGroup (Account *account)
return NULL;
}
ld = xaccLedgerDisplayGeneral (account, accounts, reg_type,
REG_STYLE_JOURNAL);
ld = xaccLedgerDisplayInternal (account, accounts, NULL,
reg_type, REG_STYLE_JOURNAL);
g_list_free (accounts);
@ -286,9 +298,9 @@ xaccGUIDMalloc (void)
{
GUID *guid;
guid = g_new(GUID, 1);
guid = g_new (GUID, 1);
*guid = *xaccGUIDNULL();
*guid = *xaccGUIDNULL ();
return guid;
}
@ -301,9 +313,9 @@ xaccGUIDFree (gpointer _guid)
if (guid == NULL)
return;
*guid = *xaccGUIDNULL();
*guid = *xaccGUIDNULL ();
g_free(guid);
g_free (guid);
}
static void
@ -312,10 +324,10 @@ xaccGUIDCopy (gpointer _to, gconstpointer _from)
GUID *to = _to;
const GUID *from = _from;
g_return_if_fail(to != NULL);
g_return_if_fail (to != NULL);
if (from == NULL)
*to = *xaccGUIDNULL();
*to = *xaccGUIDNULL ();
else
*to = *from;
}
@ -369,25 +381,6 @@ make_ledger_query (xaccLedgerDisplay *ld, gboolean show_all,
xaccQueryAddSingleAccountMatch (ld->query, ld->leader, QUERY_OR);
}
/********************************************************************\
* xaccLedgerDisplayGeneral *
* opens up a ledger window for a list of accounts *
* *
* Args: lead_account - the account associated with this register *
* (may be NULL) *
* accounts - the list of accounts to display *
* (may be NULL) *
* type - the type of split register to open *
* style - the style of register to use *
* Return: the register window instance *
\********************************************************************/
xaccLedgerDisplay *
xaccLedgerDisplayGeneral (Account *lead_account, GList *accounts,
SplitRegisterType type, SplitRegisterStyle style)
{
return xaccLedgerDisplayInternal (lead_account, accounts, NULL, type, style);
}
/********************************************************************\
* xaccLedgerDisplayQuery *
* opens up a ledger window for an arbitrary query *
@ -404,16 +397,6 @@ xaccLedgerDisplayQuery (Query *query, SplitRegisterType type,
return xaccLedgerDisplayInternal (NULL, NULL, query, type, style);
}
void
xaccLedgerDisplaySetQuery (xaccLedgerDisplay *ledger_display, Query *q)
{
if (!ledger_display || !q)
return;
xaccFreeQuery (ledger_display->query);
ledger_display->query = xaccQueryCopy (q);
}
static xaccLedgerDisplay *
xaccLedgerDisplayInternal (Account *lead_account, GList *accounts, Query *q,
SplitRegisterType type, SplitRegisterStyle style)
@ -430,6 +413,12 @@ xaccLedgerDisplayInternal (Account *lead_account, GList *accounts, Query *q,
return NULL;
}
if (q)
{
PWARN ("single-account register with external query");
q = NULL;
}
class = REGISTER_SINGLE_CM_CLASS;
ld = gnc_find_first_gui_component (class, find_by_account, lead_account);
@ -443,12 +432,25 @@ xaccLedgerDisplayInternal (Account *lead_account, GList *accounts, Query *q,
ld = gnc_find_first_gui_component (class, find_by_account, lead_account);
if (q)
{
PWARN ("account register with external query");
q = NULL;
}
if (ld)
return ld;
}
else
{
class = REGISTER_GL_CM_CLASS;
if (!q)
{
PWARN ("general ledger with no query");
}
}
ld = g_new (xaccLedgerDisplay, 1);
ld->type = type;
@ -502,6 +504,25 @@ xaccLedgerDisplayInternal (Account *lead_account, GList *accounts, Query *q,
return ld;
}
void
xaccLedgerDisplaySetQuery (xaccLedgerDisplay *ledger_display, Query *q)
{
if (!ledger_display || !q)
return;
xaccFreeQuery (ledger_display->query);
ledger_display->query = xaccQueryCopy (q);
}
xaccLedgerDisplay *
xaccFindGeneralLedgerByQuery (Query *q)
{
if (!q)
return NULL;
return gnc_find_first_gui_component (REGISTER_GL_CM_CLASS, find_by_query, q);
}
/********************************************************************\
* refresh only the indicated register window *
\********************************************************************/

View File

@ -73,13 +73,7 @@ xaccLedgerDisplay * xaccLedgerDisplaySimple (Account *account);
* its children. */
xaccLedgerDisplay * xaccLedgerDisplayAccGroup (Account *account);
/* display list of accounts in a general ledger. */
xaccLedgerDisplay * xaccLedgerDisplayGeneral (Account *lead_account,
GList *accounts,
SplitRegisterType type,
SplitRegisterStyle style);
/* display a register for an arbitrary query */
/* display a general ledger for an arbitrary query */
xaccLedgerDisplay * xaccLedgerDisplayQuery (Query *query,
SplitRegisterType type,
SplitRegisterStyle style);
@ -87,6 +81,10 @@ xaccLedgerDisplay * xaccLedgerDisplayQuery (Query *query,
/* Set the query used for a register. */
void xaccLedgerDisplaySetQuery (xaccLedgerDisplay *ledger_display, Query *q);
/* If the given ledger display still exists, return it. Otherwise,
* return NULL */
xaccLedgerDisplay * xaccFindGeneralLedgerByQuery (Query *q);
/* redisplay/redraw all windows that contain any transactions that are
* associated with the indicated account. */
void xaccAccountDisplayRefresh (Account *account);

View File

@ -49,10 +49,23 @@
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_GUI;
/********************************************************************\
* gnc_ui_find_transactions_dialog_create
* make a new print check dialog and wait for it.
\********************************************************************/
static int
gnc_find_dialog_close_cb(GnomeDialog *dialog, gpointer data) {
FindTransactionsDialog * ftd = data;
ftd->dialog = NULL;
xaccFreeQuery (ftd->q);
ftd->q = NULL;
g_free (ftd->ymd_format);
ftd->ymd_format = NULL;
g_free (ftd);
return FALSE;
}
FindTransactionsDialog *
gnc_ui_find_transactions_dialog_create(xaccLedgerDisplay * orig_ledg) {
@ -60,13 +73,14 @@ gnc_ui_find_transactions_dialog_create(xaccLedgerDisplay * orig_ledg) {
/* call the glade-defined creator */
ftd->dialog = create_Find_Transactions();
ftd->ledger = orig_ledg;
if(orig_ledg) {
ftd->q = xaccQueryCopy (orig_ledg->query);
ftd->ledger_q = orig_ledg->query;
}
else {
ftd->q = NULL;
ftd->ledger_q = NULL;
}
/* initialize the radiobutton state vars */
@ -216,8 +230,12 @@ gnc_ui_find_transactions_dialog_create(xaccLedgerDisplay * orig_ledg) {
(ftd->narrow_search_radiobutton),
1);
}
gtk_signal_connect(GTK_OBJECT(ftd->dialog), "close",
GTK_SIGNAL_FUNC(gnc_find_dialog_close_cb), ftd);
gtk_widget_show_all(ftd->dialog);
return ftd;
}
@ -228,19 +246,12 @@ gnc_ui_find_transactions_dialog_create(xaccLedgerDisplay * orig_ledg) {
void
gnc_ui_find_transactions_dialog_destroy(FindTransactionsDialog * ftd) {
if (!ftd)
return;
gnome_dialog_close(GNOME_DIALOG(ftd->dialog));
ftd->dialog = NULL;
xaccFreeQuery (ftd->q);
ftd->q = NULL;
g_free(ftd->ymd_format);
ftd->ymd_format = NULL;
g_free(ftd);
}
/********************************************************************\
* callbacks for radio button selections
@ -269,7 +280,7 @@ gnc_ui_find_transactions_dialog_search_type_cb(GtkToggleButton * tb,
void
gnc_ui_find_transactions_dialog_cancel_cb(GtkButton * button,
gpointer user_data) {
gpointer user_data) {
FindTransactionsDialog * ftd =
gtk_object_get_data(GTK_OBJECT(user_data), "find_transactions_structure");
@ -336,7 +347,9 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
GtkWidget * dialog = user_data;
FindTransactionsDialog * ftd =
gtk_object_get_data(GTK_OBJECT(dialog), "find_transactions_structure");
xaccLedgerDisplay *ledger;
GList * selected_accounts;
char * descript_match_text;
char * memo_match_text;
@ -399,7 +412,7 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
(ftd->match_accounts_picker),
QUERY_AND);
}
if(strlen(descript_match_text)) {
xaccQueryAddDescriptionMatch(q, descript_match_text,
gtk_toggle_button_get_active
@ -410,7 +423,6 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
(ftd->description_regexp_toggle)),
QUERY_AND);
}
if(strlen(number_match_text)) {
xaccQueryAddNumberMatch(q, number_match_text,
@ -422,7 +434,6 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
(ftd->number_regexp_toggle)),
QUERY_AND);
}
amt_temp =
(double)gtk_spin_button_get_value_as_float
@ -438,7 +449,7 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
(ftd->amount_comp_picker),
QUERY_AND);
}
use_start_date =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ftd->date_start_toggle));
use_end_date =
@ -453,7 +464,7 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
use_end_date, end_date,
QUERY_AND);
}
if(strlen(memo_match_text)) {
xaccQueryAddMemoMatch(q, memo_match_text,
gtk_toggle_button_get_active
@ -475,7 +486,7 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
amt_type,
QUERY_AND);
}
amt_temp =
(double)gtk_spin_button_get_value_as_float
(GTK_SPIN_BUTTON(ftd->shares_entry));
@ -551,21 +562,22 @@ gnc_ui_find_transactions_dialog_ok_cb(GtkButton * button,
break;
}
if(!ftd->ledger) {
ledger = xaccFindGeneralLedgerByQuery (ftd->ledger_q);
if(!ledger) {
new_ledger = TRUE;
ftd->ledger = xaccLedgerDisplayQuery (new_q, SEARCH_LEDGER,
REG_STYLE_JOURNAL);
ledger = xaccLedgerDisplayQuery (new_q, SEARCH_LEDGER,
REG_STYLE_JOURNAL);
}
else
xaccLedgerDisplaySetQuery (ftd->ledger, new_q);
xaccLedgerDisplaySetQuery (ledger, new_q);
xaccFreeQuery (new_q);
ftd->ledger->dirty = TRUE;
xaccLedgerDisplayRefresh(ftd->ledger);
ledger->dirty = TRUE;
xaccLedgerDisplayRefresh(ledger);
if (new_ledger)
regWindowLedger(ftd->ledger);
regWindowLedger(ledger);
gnc_ui_find_transactions_dialog_destroy(ftd);
}

View File

@ -47,8 +47,8 @@ typedef struct {
typedef struct {
GtkWidget * dialog;
Query * q;
xaccLedgerDisplay * ledger;
Query * ledger_q;
char * ymd_format;
int search_type;