Bill Gribble's patch.

* src/gnome/dialog-column-view.c: maintain the report window
	edited list when closing dialog.  raise an existing edit dialog.

	* src/gnome/gnc-html.c: make sure we know about options editors
	launched from gnc-options: urls

	* src/gnome/window-report.c: numerous changes to improve handling
	of options dialogs.

	* src/scm/report.scm: new function, gnc:report-edit-options.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3999 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-04-21 00:39:54 +00:00
parent 20a1efa349
commit 1cd084961c
7 changed files with 199 additions and 145 deletions

View File

@ -1,3 +1,16 @@
2001-04-20 Bill Gribble <grib@billgribble.com>
* src/gnome/dialog-column-view.c: maintain the report window
edited list when closing dialog. raise an existing edit dialog.
* src/gnome/gnc-html.c: make sure we know about options editors
launched from gnc-options: urls
* src/gnome/window-report.c: numerous changes to improve handling
of options dialogs.
* src/scm/report.scm: new function, gnc:report-edit-options.
2001-04-20 Dave Peticolas <dave@krondo.com> 2001-04-20 Dave Peticolas <dave@krondo.com>
* src/guile/gnc-helpers.c: remove cruft. work on converting * src/guile/gnc-helpers.c: remove cruft. work on converting

View File

@ -24,6 +24,7 @@
#include <gnome.h> #include <gnome.h>
#include <guile/gh.h> #include <guile/gh.h>
#include <g-wrap-runtime-guile.h>
#include "dialog-column-view.h" #include "dialog-column-view.h"
#include "dialog-options.h" #include "dialog-options.h"
@ -31,7 +32,7 @@
#include "glade-gnc-dialogs.h" #include "glade-gnc-dialogs.h"
#include "messages.h" #include "messages.h"
#include "option-util.h" #include "option-util.h"
#include "window-report.h"
struct gncp_column_view_edit { struct gncp_column_view_edit {
GNCOptionWin * optwin; GNCOptionWin * optwin;
@ -138,6 +139,17 @@ gnc_column_view_edit_apply_cb(GNCOptionWin * w, gpointer user_data) {
static void static void
gnc_column_view_edit_close_cb(GNCOptionWin * win, gpointer user_data) { gnc_column_view_edit_close_cb(GNCOptionWin * win, gpointer user_data) {
gnc_column_view_edit * r = user_data; gnc_column_view_edit * r = user_data;
SCM set_editor = gh_eval_str("gnc:report-set-editor-widget!");
SCM get_windows = gh_eval_str("gnc:report-display-list");
SCM windows;
for(windows = gh_call1(get_windows, r->view);
!gh_null_p(windows); windows = gh_cdr(windows)) {
gnc_report_window_remove_edited_report(gw_wcp_get_ptr(gh_car(windows)),
r->view);
}
gh_call2(set_editor, r->view, SCM_BOOL_F);
gnc_column_view_edit_destroy(r); gnc_column_view_edit_destroy(r);
} }
@ -147,12 +159,22 @@ gnc_column_view_edit_close_cb(GNCOptionWin * win, gpointer user_data) {
* create the editor. * create the editor.
********************************************************************/ ********************************************************************/
void GtkWidget *
gnc_column_view_edit_options(SCM options, SCM view) { gnc_column_view_edit_options(SCM options, SCM view) {
gnc_column_view_edit * r = g_new0(gnc_column_view_edit, 1); SCM get_editor = gh_eval_str("gnc:report-editor-widget");
SCM ptr;
GtkObject * tlo; GtkObject * tlo;
GtkWidget * editor; GtkWidget * editor;
ptr = gh_call1(get_editor, view);
if(ptr != SCM_BOOL_F) {
GtkWidget * w = gw_wcp_get_ptr(ptr);
gdk_window_raise(GTK_WIDGET(w)->window);
return NULL;
}
else {
gnc_column_view_edit * r = g_new0(gnc_column_view_edit, 1);
r->optwin = gnc_options_dialog_new(TRUE); r->optwin = gnc_options_dialog_new(TRUE);
tlo = GTK_OBJECT(create_Edit_Column_View_Page()); tlo = GTK_OBJECT(create_Edit_Column_View_Page());
@ -197,6 +219,8 @@ gnc_column_view_edit_options(SCM options, SCM view) {
gnc_column_view_edit_close_cb, r); gnc_column_view_edit_close_cb, r);
gtk_widget_show_all(gnc_options_dialog_widget(r->optwin)); gtk_widget_show_all(gnc_options_dialog_widget(r->optwin));
return gnc_options_dialog_widget(r->optwin);
}
} }

View File

@ -24,4 +24,4 @@
typedef struct gncp_column_view_edit gnc_column_view_edit; typedef struct gncp_column_view_edit gnc_column_view_edit;
void gnc_column_view_edit_options(SCM options, SCM view); GtkWidget * gnc_column_view_edit_options(SCM options, SCM view);

View File

@ -1071,20 +1071,14 @@ static void
gnc_html_open_options(gnc_html * html, const gchar * location) { gnc_html_open_options(gnc_html * html, const gchar * location) {
int report_id; int report_id;
SCM find_report = gh_eval_str("gnc:find-report"); SCM find_report = gh_eval_str("gnc:find-report");
SCM get_options = gh_eval_str("gnc:report-options"); SCM start_editor = gh_eval_str("gnc:report-edit-options");
SCM get_editor = gh_eval_str("gnc:report-options-editor");
SCM report; SCM report;
SCM options;
SCM editor;
/* href="gnc-options:report-id=2676" */ /* href="gnc-options:report-id=2676" */
if(!strncmp("report-id=", location, 10)) { if(!strncmp("report-id=", location, 10)) {
sscanf(location+10, "%d", &report_id); sscanf(location+10, "%d", &report_id);
report = gh_call1(find_report, gh_int2scm(report_id)); report = gh_call1(find_report, gh_int2scm(report_id));
options = gh_call1(get_options, report); gh_call1(start_editor, report);
editor = gh_call1(get_editor, report);
gh_call2(editor, options, report);
} }
else { else {
gnc_warning_dialog(_("Badly formed gnc-options: URL.")); gnc_warning_dialog(_("Badly formed gnc-options: URL."));

View File

@ -53,11 +53,10 @@ struct _gnc_report_window {
GtkWidget * container; GtkWidget * container;
SCM scm_report; SCM scm_report;
SCM scm_options;
SCM scm_options_edit;
SCM name_change_callback_id; SCM name_change_callback_id;
GNCOptionDB * odb; /* used to get callbacks from parameter edit */ GNCOptionDB * odb; /* used to get callbacks from parameter edit */
SCM edited_reports;
gnc_html * html; gnc_html * html;
}; };
@ -331,23 +330,13 @@ gnc_report_window_export_button_cb(GtkWidget * w, gpointer data) {
static int static int
gnc_report_window_params_cb(GtkWidget * w, gpointer data) { gnc_report_window_params_cb(GtkWidget * w, gpointer data) {
gnc_report_window * report = data; gnc_report_window * report = data;
SCM start_editor = gh_eval_str("gnc:report-edit-options");
if((report->scm_report != SCM_BOOL_F) && if(report->scm_report != SCM_BOOL_F) {
(report->scm_options != SCM_BOOL_F)) { if(gh_call1(start_editor, report->scm_report) == SCM_BOOL_F) {
if(gh_procedure_p(report->scm_options_edit)) {
gh_call2(report->scm_options_edit,
report->scm_options,
report->scm_report);
}
else {
gnc_report_window_default_params_editor(report->scm_options,
report->scm_report);
}
}
else {
gnc_warning_dialog("There are no options for this report."); gnc_warning_dialog("There are no options for this report.");
} }
}
return TRUE; return TRUE;
} }
@ -433,19 +422,12 @@ gnc_report_window_load_cb(gnc_html * html, URLType type,
gw_wcp_assimilate_ptr(win, scm_wintype)); gw_wcp_assimilate_ptr(win, scm_wintype));
} }
inst_options = gh_call1(get_options, inst_report);
inst_options_ed = gh_call1(get_editor, inst_report);
scm_unprotect_object(win->scm_options);
win->scm_options = inst_options;
scm_protect_object(win->scm_options);
if(win->odb) { if(win->odb) {
gnc_option_db_unregister_change_callback_id(win->odb, gnc_option_db_unregister_change_callback_id(win->odb,
win->name_change_callback_id); win->name_change_callback_id);
gnc_option_db_destroy(win->odb); gnc_option_db_destroy(win->odb);
} }
win->odb = gnc_option_db_new(win->scm_options); win->odb = gnc_option_db_new(gh_call1(get_options, inst_report));
win->name_change_callback_id = win->name_change_callback_id =
gnc_option_db_register_change_callback(win->odb, gnc_option_db_register_change_callback(win->odb,
@ -453,10 +435,6 @@ gnc_report_window_load_cb(gnc_html * html, URLType type,
win->mc, win->mc,
"General", "Report name"); "General", "Report name");
scm_unprotect_object(win->scm_options_edit);
win->scm_options_edit = inst_options_ed;
scm_protect_object(win->scm_options_edit);
scm_unprotect_object(win->scm_report); scm_unprotect_object(win->scm_report);
win->scm_report = inst_report; win->scm_report = inst_report;
scm_protect_object(win->scm_report); scm_protect_object(win->scm_report);
@ -551,14 +529,12 @@ gnc_report_window_new(GNCMainChildInfo * mc) {
report->mc = mc; report->mc = mc;
report->html = gnc_html_new(); report->html = gnc_html_new();
report->scm_options = SCM_BOOL_F;
report->scm_options_edit = SCM_BOOL_F;
report->scm_report = SCM_BOOL_F; report->scm_report = SCM_BOOL_F;
report->edited_reports = SCM_EOL;
report->name_change_callback_id = SCM_BOOL_F; report->name_change_callback_id = SCM_BOOL_F;
scm_protect_object(report->scm_options);
scm_protect_object(report->scm_options_edit);
scm_protect_object(report->scm_report); scm_protect_object(report->scm_report);
scm_protect_object(report->edited_reports);
gnc_html_history_set_node_destroy_cb(gnc_html_get_history(report->html), gnc_html_history_set_node_destroy_cb(gnc_html_get_history(report->html),
gnc_report_window_history_destroy_cb, gnc_report_window_history_destroy_cb,
@ -692,8 +668,25 @@ gnc_report_window_destroy(gnc_report_window * win) {
SCM scm_wintype = gh_eval_str("<gnc:report-window*>"); SCM scm_wintype = gh_eval_str("<gnc:report-window*>");
SCM unshow_report = gh_eval_str("gnc:report-unregister-display"); SCM unshow_report = gh_eval_str("gnc:report-unregister-display");
SCM get_editor = gh_eval_str("gnc:report-editor-widget");
SCM set_editor = gh_eval_str("gnc:report-set-editor-widget!");
SCM disp_list; SCM disp_list;
SCM editor; SCM edited, editor;
if(win->scm_report != SCM_BOOL_F) {
gh_call2(unshow_report, win->scm_report,
gw_wcp_assimilate_ptr(win, scm_wintype));
}
/* close any open editors */
for(edited = scm_list_copy(win->edited_reports); !gh_null_p(edited);
edited = gh_cdr(edited)) {
editor = gh_call1(get_editor, gh_car(edited));
gh_call2(set_editor, gh_car(edited), SCM_BOOL_F);
if(editor != SCM_BOOL_F) {
gtk_widget_destroy(GTK_WIDGET(gw_wcp_get_ptr(editor)));
}
}
if(win->odb) { if(win->odb) {
gnc_option_db_unregister_change_callback_id(win->odb, gnc_option_db_unregister_change_callback_id(win->odb,
@ -703,19 +696,13 @@ gnc_report_window_destroy(gnc_report_window * win) {
win->odb = NULL; win->odb = NULL;
} }
if(win->scm_report != SCM_BOOL_F) {
gh_call2(unshow_report, win->scm_report,
gw_wcp_assimilate_ptr(win, scm_wintype));
}
gnc_html_destroy(win->html); gnc_html_destroy(win->html);
win->container = NULL; win->container = NULL;
win->html = NULL; win->html = NULL;
scm_unprotect_object(win->scm_options);
scm_unprotect_object(win->scm_options_edit);
scm_unprotect_object(win->scm_report); scm_unprotect_object(win->scm_report);
scm_unprotect_object(win->edited_reports);
g_free(win); g_free(win);
} }
@ -803,6 +790,14 @@ gnc_options_dialog_close_cb(GNCOptionWin * propertybox,
gpointer user_data) { gpointer user_data) {
struct report_default_params_data * win = user_data; struct report_default_params_data * win = user_data;
SCM set_editor = gh_eval_str("gnc:report-set-editor-widget!"); SCM set_editor = gh_eval_str("gnc:report-set-editor-widget!");
SCM get_windows = gh_eval_str("gnc:report-display-list");
SCM windows;
for(windows = gh_call1(get_windows, win->scm_report);
!gh_null_p(windows); windows = gh_cdr(windows)) {
gnc_report_window_remove_edited_report(gw_wcp_get_ptr(gh_car(windows)),
win->scm_report);
}
gh_call2(set_editor, win->scm_report, SCM_BOOL_F); gh_call2(set_editor, win->scm_report, SCM_BOOL_F);
gnc_option_db_destroy(win->db); gnc_option_db_destroy(win->db);
@ -812,17 +807,19 @@ gnc_options_dialog_close_cb(GNCOptionWin * propertybox,
} }
void GtkWidget *
gnc_report_window_default_params_editor(SCM options, SCM report) { gnc_report_window_default_params_editor(SCM options, SCM report) {
SCM get_editor = gh_eval_str("gnc:report-editor-widget"); SCM get_editor = gh_eval_str("gnc:report-editor-widget");
SCM set_editor = gh_eval_str("gnc:report-set-editor-widget!"); SCM set_editor = gh_eval_str("gnc:report-set-editor-widget!");
SCM ptr_type = gh_eval_str("<gnc:UIWidget>"); SCM ptr_type = gh_eval_str("<gnc:UIWidget>");
SCM ptr; SCM ptr;
SCM new_edited;
ptr = gh_call1(get_editor, report); ptr = gh_call1(get_editor, report);
if(ptr != SCM_BOOL_F) { if(ptr != SCM_BOOL_F) {
GtkWidget * w = gw_wcp_get_ptr(ptr); GtkWidget * w = gw_wcp_get_ptr(ptr);
gdk_window_raise(GTK_WIDGET(w)->window); gdk_window_raise(GTK_WIDGET(w)->window);
return NULL;
} }
else { else {
struct report_default_params_data * prm = struct report_default_params_data * prm =
@ -846,8 +843,30 @@ gnc_report_window_default_params_editor(SCM options, SCM report) {
gnc_options_dialog_set_close_cb(prm->win, gnc_options_dialog_set_close_cb(prm->win,
gnc_options_dialog_close_cb, gnc_options_dialog_close_cb,
(gpointer)prm); (gpointer)prm);
gh_call2(set_editor, report, return gnc_options_dialog_widget(prm->win);
gw_wcp_assimilate_ptr(gnc_options_dialog_widget(prm->win),
ptr_type));
} }
} }
void
gnc_report_window_remove_edited_report(gnc_report_window * win, SCM report) {
SCM new_edited = scm_delete(win->edited_reports, report);
scm_unprotect_object(win->edited_reports);
win->edited_reports = new_edited;
scm_protect_object(win->edited_reports);
}
void
gnc_report_window_add_edited_report(gnc_report_window * win, SCM report) {
SCM new_edited = gh_cons(report, win->edited_reports);
scm_unprotect_object(win->edited_reports);
win->edited_reports = new_edited;
scm_protect_object(win->edited_reports);
}
void
gnc_report_raise_editor(SCM report) {
SCM get_editor = gh_eval_str("gnc:report-editor-widget");
SCM editor = gh_call1(get_editor, report);
gdk_window_raise(GTK_WIDGET(gw_wcp_get_ptr(editor))->window);
}

View File

@ -47,7 +47,7 @@ void gnc_report_window_create_menu(gnc_report_window * report,
void gnc_report_window_create_toolbar(gnc_report_window * report, void gnc_report_window_create_toolbar(gnc_report_window * report,
GNCMainChildInfo * child); GNCMainChildInfo * child);
void gnc_report_window_default_params_editor(SCM options, SCM report); GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report);
void gnc_main_window_open_report (int report_id, gint toplevel); void gnc_main_window_open_report (int report_id, gint toplevel);
void gnc_main_window_open_report_url (const char * url, gint toplevel); void gnc_main_window_open_report_url (const char * url, gint toplevel);
@ -56,4 +56,9 @@ GnomeMDIChild * gnc_report_window_create_child(const gchar * url);
void reportWindow(int id); void reportWindow(int id);
void gnc_print_report (int report_id); void gnc_print_report (int report_id);
void gnc_report_window_add_edited_report(gnc_report_window * win,
SCM report);
void gnc_report_window_remove_edited_report(gnc_report_window * win,
SCM report);
void gnc_report_raise_editor(SCM report);
#endif #endif

View File

@ -153,16 +153,16 @@
(define (blank-report) (define (blank-report)
((record-constructor <report-template>) ((record-constructor <report-template>)
#f ;version #f ;; version
#f ;name #f ;; name
#f ;options-generator #f ;; options-generator
gnc:default-options-editor ;options-editor gnc:default-options-editor ;; options-editor
#f ;renderer #f ;; renderer
#t ;in-menu? #t ;; in-menu?
#f ;menu-path #f ;; menu-path
#f ;menu-name #f ;; menu-name
#f ;menu-tip #f ;; menu-tip
#f ;export-thunk #f ;; export-thunk
)) ))
(define (args-to-defn in-report-rec args) (define (args-to-defn in-report-rec args)
@ -361,17 +361,38 @@
(gnc:report-unregister-display (gnc:find-report rep) window)) (gnc:report-unregister-display (gnc:find-report rep) window))
(gnc:report-parents report))))) (gnc:report-parents report)))))
(define (gnc:report-edit-options report)
(let* ((editor-widg (gnc:report-editor-widget report))
(displist (gnc:report-display-list report)))
(if editor-widg
(gnc:report-raise-editor report)
(begin
(if (gnc:report-options report)
(begin
(set! editor-widg
((gnc:report-options-editor report)
(gnc:report-options report)
report))
(gnc:report-set-editor-widget! report editor-widg)
(if (and editor-widg (not (null? displist)))
(for-each
(lambda (repwin)
(gnc:report-window-add-edited-report repwin report))
displist)))
(gnc:warning-dialog "This report has no options."))))))
(define (gnc:make-report template-name . rest) (define (gnc:make-report template-name . rest)
(let ((r ((record-constructor <report>) (let ((r ((record-constructor <report>)
template-name ;type template-name ;; type
#f ;id #f ;; id
#f ;options #f ;; options
'() ;parents '() ;; parents
'() ;children '() ;; children
#t ;dirty #t ;; dirty
'() ;display-list '() ;; display-list
#f ;editor-widget #f ;; editor-widget
#f ;ctext #f ;; ctext
)) ))
(template (hash-ref *gnc:_report-templates_* template-name)) (template (hash-ref *gnc:_report-templates_* template-name))
(id *gnc:_report-next-serial_*)) (id *gnc:_report-next-serial_*))
@ -438,28 +459,6 @@
(string->symbol (string->symbol
(gnc:html-style-sheet-name stylesheet)))) (gnc:html-style-sheet-name stylesheet))))
;;; (define (gnc:report-default-options-editor)
;;; (let* ((option-db #f)
;;; (option-dlg #f))
;;; (define (editor options action report-win)
;;; (if (string? action)
;;; (cond
;;; ;; open: start the options editor.
;;; ((string=? action "open")
;;; (set! option-db
;;; (gnc:option-db-new options))
;;; (set! option-dlg
;;; (gnc:options-dialog-new #t))
;;; (gnc:build-options-dialog-contents
;;; option-dlg option-db)
;;; ;; set up the default callbacks
;;; (gnc:report-default-options-setup option-dlg report-win))
;;; ;; close: shut it down, probably because the report window
;;; ;; is getting closed.
;;; ((string=? action "close")
;;; (gnc:options-dialog-destroy option-dlg)))
(define (gnc:all-report-template-names) (define (gnc:all-report-template-names)
(sort (sort
(hash-fold (hash-fold