If the report already has an id assigned (i.e. restored reports) then

add it to the table using that id.  Only generate ids for reports that
don't have them yet.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13810 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2006-04-20 00:05:00 +00:00
parent 1e53468d1e
commit 95995638b2
2 changed files with 39 additions and 6 deletions

View File

@ -1,5 +1,10 @@
2006-04-19 David Hampton <hampton@employees.org> 2006-04-19 David Hampton <hampton@employees.org>
* src/report/report-system/gnc-report.c: If the report already has
an id assigned (i.e. restored reports) then add it to the table
using that id. Only generate ids for reports that don't have them
yet.
* src/gnome-utils/gnc-main-window.c: Don't call shutdown directly * src/gnome-utils/gnc-main-window.c: Don't call shutdown directly
from the delete_event handler, but use a periodic idle function from the delete_event handler, but use a periodic idle function
that checks to insure that gnucash isn't saving the data file that checks to insure that gnucash isn't saving the data file

View File

@ -69,13 +69,41 @@ SCM gnc_report_find(gint id)
int gnc_report_add(SCM report) int gnc_report_add(SCM report)
{ {
gint *key; SCM get_id = scm_c_eval_string("gnc:report-id");
SCM value;
gint id, *key;
gnc_report_init_table(); gnc_report_init_table();
key = g_new(gint, 1);
*key = report_next_serial_id++; value = scm_call_1(get_id, report);
g_hash_table_insert(reports, key, (gpointer)report); if (SCM_NUMBERP(value)) {
scm_gc_protect_object(report); id = scm_num2int(value, SCM_ARG1, __FUNCTION__);
return *key; if (!g_hash_table_lookup(reports, &id)) {
key = g_new(gint, 1);
*key = id;
g_hash_table_insert(reports, key, (gpointer)report);
scm_gc_protect_object(report);
return id;
}
g_warning("Report specified id of %d is already is use. "
"Using generated id.", id);
}
id = report_next_serial_id++;
while (id < G_MAXINT) {
if (!g_hash_table_lookup(reports, &id)) {
key = g_new(gint, 1);
*key = id;
g_hash_table_insert(reports, key, (gpointer)report);
scm_gc_protect_object(report);
return id;
}
id = report_next_serial_id++;
}
g_warning("Unable to add report to table. %d reports in use.", G_MAXINT);
report_next_serial_id = G_MAXINT;
return G_MAXINT;
} }
static gboolean static gboolean