mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* gw-app-utils-spec.scm: wrap <gnc:OptionDB*>, option_db_new,
option_db_destroy() * options.scm: fix scm->kvp method; fix a typo; add clear-kvp? argument to gnc:options-scm->kvp for whether to clear out the kvp before saving it. * business-gnome.scm: add code to test the kvp option-dialog * kvp-scm.c: fix the delete_at_path() function to actually work right. * dialog-options: create a function (and support routines) to use SCM apply_cb and close_cb callback functions: options_dialog_set_callbacks() * gw-gnome-utils-spec.scm: wrap <gnc:OptionWin*>, options_dialog_new(), options_dialog_destroy(), options_dialog_build_contents(), and options_dialog_set_callbacks() git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7096 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
25e3a16191
commit
5904e6d487
14
ChangeLog
14
ChangeLog
@ -12,6 +12,20 @@
|
||||
* binary-import.scm: fix the book-opened-hook.
|
||||
* main-window.scm: fix the book-opened/closed-hook calls
|
||||
* main.scm: fix the book-opened/closed-hook calls
|
||||
|
||||
* gw-app-utils-spec.scm: wrap <gnc:OptionDB*>, option_db_new,
|
||||
option_db_destroy()
|
||||
* options.scm: fix scm->kvp method; fix a typo; add clear-kvp?
|
||||
argument to gnc:options-scm->kvp for whether to clear out the
|
||||
kvp before saving it.
|
||||
* business-gnome.scm: add code to test the kvp option-dialog
|
||||
* kvp-scm.c: fix the delete_at_path() function to actually work right.
|
||||
* dialog-options: create a function (and support routines) to
|
||||
use SCM apply_cb and close_cb callback functions:
|
||||
options_dialog_set_callbacks()
|
||||
* gw-gnome-utils-spec.scm: wrap <gnc:OptionWin*>, options_dialog_new(),
|
||||
options_dialog_destroy(), options_dialog_build_contents(), and
|
||||
options_dialog_set_callbacks()
|
||||
|
||||
2002-07-06 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
|
@ -44,6 +44,8 @@
|
||||
'<gnc:OptionChangeCallback>
|
||||
"GNCOptionChangeCallback" "const GNCOptionChangeCallback")
|
||||
|
||||
(gw:wrap-as-wct ws '<gnc:OptionDB*> "GNCOptionDB*" "const GNCOptionDB*")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:get-current-group
|
||||
@ -109,6 +111,22 @@
|
||||
'(((<gw:mchars> caller-owned const) str))
|
||||
"Returns the translated version of string")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:option-db-new
|
||||
'<gnc:OptionDB*>
|
||||
"gnc_option_db_new"
|
||||
'((<gw:scm> guile-options))
|
||||
"Create an option DB with the set of guile options")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:option-db-destroy
|
||||
'<gw:void>
|
||||
"gnc_option_db_destroy"
|
||||
'((<gnc:OptionDB*> option-db))
|
||||
"Destroy the OptionDB")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:c-options-init
|
||||
|
@ -1136,11 +1136,14 @@
|
||||
(options-for-each
|
||||
(lambda (option)
|
||||
(let ((value (gnc:option-value option))
|
||||
(default-value (gnc:option-default-value option)))
|
||||
(default-value (gnc:option-default-value option))
|
||||
(section (gnc:option-section option))
|
||||
(name (gnc:option-name option)))
|
||||
(gnc:debug "value: " value "; default: " default-value
|
||||
"; section: " section "; name: " name)
|
||||
(if (not (equal? value default-value))
|
||||
(let ((section (gnc:option-section option))
|
||||
(name (gnc:option-name option))
|
||||
(save-fcn (gnc:option-scm->kvp option)))
|
||||
(let ((save-fcn (gnc:option-scm->kvp option)))
|
||||
(gnc:debug "save-fcn: " save-fcn)
|
||||
(if save-fcn
|
||||
(save-fcn kvp-frame (append key-path
|
||||
(list section name))))))))))
|
||||
@ -1152,7 +1155,7 @@
|
||||
(name (gnc:option-name option))
|
||||
(load-fcn (gnc:option-kvp->scm option)))
|
||||
(if load-fcn
|
||||
(load-fcn kcp-frame (append key-path
|
||||
(load-fcn kvp-frame (append key-path
|
||||
(list section name))))))))
|
||||
|
||||
(define (register-callback section name callback)
|
||||
@ -1251,7 +1254,9 @@
|
||||
(define (gnc:generate-restore-forms options options-string)
|
||||
((options 'generate-restore-forms) options-string))
|
||||
|
||||
(define (gnc:options-scm->kvp options kvp-frame key-path)
|
||||
(define (gnc:options-scm->kvp options kvp-frame key-path clear-kvp?)
|
||||
(if clear-kvp?
|
||||
(gnc:kvp-frame-delete-at-path kvp-frame key-path))
|
||||
((options 'scm->kvp) kvp-frame key-path))
|
||||
|
||||
(define (gnc:options-kvp->scm options kvp-frame key-path)
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
(gnc:module-load "gnucash/report/report-gnome" 0)
|
||||
(use-modules (gnucash report business-reports))
|
||||
(use-modules (gnucash main)) ;for gnc:debug
|
||||
|
||||
(define top-level "_Business")
|
||||
(define new-label "New")
|
||||
@ -351,7 +352,55 @@
|
||||
(gnc:invoice-edit invoice)
|
||||
))))
|
||||
|
||||
|
||||
(define (test-book)
|
||||
(define (book-options)
|
||||
(let ((options (gnc:new-options)))
|
||||
(define (reg-option new-option)
|
||||
(gnc:register-option options new-option))
|
||||
|
||||
(reg-option
|
||||
(gnc:make-string-option
|
||||
(N_ "Business") (N_ "Company Name")
|
||||
"a" (N_ "The name of your business") ""))
|
||||
|
||||
(reg-option
|
||||
(gnc:make-text-option
|
||||
(N_ "Business") (N_ "Company Address")
|
||||
"b" (N_ "The address of your business") ""))
|
||||
|
||||
options))
|
||||
|
||||
(gnc:make-menu-item (N_ "Test Option Stuff")
|
||||
(N_ "Test Option Stuff")
|
||||
(list "Extensions" "")
|
||||
(lambda ()
|
||||
(let* ((book (gnc:get-current-book))
|
||||
(slots (gnc:book-get-slots book))
|
||||
(options (book-options))
|
||||
(optiondb (gnc:option-db-new options))
|
||||
(optionwin (gnc:option-dialog-new
|
||||
#t "Book Options")))
|
||||
|
||||
(define (apply-cb)
|
||||
(gnc:debug "options =" options)
|
||||
(gnc:debug "slots =" slots)
|
||||
(gnc:options-scm->kvp options slots
|
||||
'("options") #t))
|
||||
|
||||
(define (close-cb)
|
||||
(gnc:option-dialog-destroy optionwin)
|
||||
(gnc:option-db-destroy optiondb))
|
||||
|
||||
(gnc:options-kvp->scm options slots '("options"))
|
||||
(gnc:option-dialog-set-callbacks optionwin
|
||||
apply-cb
|
||||
close-cb)
|
||||
(gnc:option-dialog-build-contents
|
||||
optionwin optiondb)))))
|
||||
|
||||
|
||||
(gnc:add-extension (test-book))
|
||||
(gnc:add-extension init-data)
|
||||
(gnc:add-extension reload-receivable)
|
||||
(gnc:add-extension reload-invoice)
|
||||
|
@ -111,12 +111,5 @@ gnc_kvp_value_ptr_to_scm(kvp_value* val)
|
||||
void
|
||||
gnc_kvp_frame_delete_at_path (kvp_frame *frame, GSList *key_path)
|
||||
{
|
||||
kvp_value *val;
|
||||
|
||||
val = kvp_frame_get_slot_path_gslist (frame, key_path);
|
||||
if (!val) return;
|
||||
if (kvp_value_get_type (val) == KVP_TYPE_FRAME) {
|
||||
frame = kvp_value_get_frame (val);
|
||||
kvp_frame_delete (frame);
|
||||
}
|
||||
kvp_frame_set_slot_path_gslist (frame, NULL, key_path);
|
||||
}
|
||||
|
@ -2734,3 +2734,59 @@ void gnc_options_ui_initialize (void)
|
||||
/* add known types */
|
||||
gnc_options_initialize_options ();
|
||||
}
|
||||
|
||||
struct scm_cb
|
||||
{
|
||||
SCM apply_cb;
|
||||
SCM close_cb;
|
||||
};
|
||||
|
||||
static void
|
||||
scm_apply_cb (GNCOptionWin *win, gpointer data)
|
||||
{
|
||||
struct scm_cb *cbdata = data;
|
||||
|
||||
gnc_option_db_commit (win->option_db);
|
||||
if (cbdata->apply_cb != SCM_BOOL_F) {
|
||||
gh_call0 (cbdata->apply_cb);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
scm_close_cb (GNCOptionWin *win, gpointer data)
|
||||
{
|
||||
struct scm_cb *cbdata = data;
|
||||
|
||||
if (cbdata->close_cb != SCM_BOOL_F) {
|
||||
gh_call0 (cbdata->close_cb);
|
||||
scm_unprotect_object (cbdata->close_cb);
|
||||
}
|
||||
|
||||
if (cbdata->apply_cb != SCM_BOOL_F)
|
||||
scm_unprotect_object (cbdata->apply_cb);
|
||||
|
||||
g_free (cbdata);
|
||||
}
|
||||
|
||||
/* Both apply_cb and close_cb should be scheme functions with 0 arguments.
|
||||
* References to these functions will be held until the close_cb is called
|
||||
*/
|
||||
void
|
||||
gnc_options_dialog_set_scm_callbacks (GNCOptionWin *win, SCM apply_cb,
|
||||
SCM close_cb)
|
||||
{
|
||||
struct scm_cb *cbdata;
|
||||
|
||||
cbdata = g_new0 (struct scm_cb, 1);
|
||||
cbdata->apply_cb = apply_cb;
|
||||
cbdata->close_cb = close_cb;
|
||||
|
||||
if (apply_cb != SCM_BOOL_F)
|
||||
scm_protect_object (cbdata->apply_cb);
|
||||
|
||||
if (close_cb != SCM_BOOL_F)
|
||||
scm_protect_object (cbdata->close_cb);
|
||||
|
||||
gnc_options_dialog_set_apply_cb (win, scm_apply_cb, cbdata);
|
||||
gnc_options_dialog_set_close_cb (win, scm_close_cb, cbdata);
|
||||
}
|
||||
|
@ -57,6 +57,13 @@ void gnc_show_options_dialog(void);
|
||||
void gnc_build_options_dialog_contents(GNCOptionWin *win,
|
||||
GNCOptionDB *odb);
|
||||
|
||||
/* Both apply_cb and close_cb should be scheme functions with 0 arguments.
|
||||
* References to these functions will be held until the close_cb is called
|
||||
*/
|
||||
void gnc_options_dialog_set_scm_callbacks (GNCOptionWin *win,
|
||||
SCM apply_cb,
|
||||
SCM close_cb);
|
||||
|
||||
/*****************************************************************/
|
||||
/* Option Registration */
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
ws
|
||||
(lambda (wrapset client-wrapset)
|
||||
(list
|
||||
"#include <dialog-options.h>\n"
|
||||
"#include <dialog-utils.h>\n"
|
||||
"#include <druid-utils.h>\n"
|
||||
"#include <gnc-amount-edit.h>\n"
|
||||
@ -62,6 +63,7 @@
|
||||
|
||||
(gw:wrap-as-wct ws '<gnc:UIWidget> "gncUIWidget" "const gncUIWidget")
|
||||
(gw:wrap-as-wct ws '<gnc:mdi-info*> "GNCMDIInfo*" "const GNCMDIInfo*")
|
||||
(gw:wrap-as-wct ws '<gnc:OptionWin*> "GNCOptionWin*" "const GNCOptionWin*")
|
||||
(gw:wrap-as-wct ws '<gnc:url-type> "URLType" "const URLType")
|
||||
|
||||
;;
|
||||
@ -84,6 +86,38 @@
|
||||
(gw:wrap-value ws 'gnc:url-type-other '<gnc:url-type> "URL_TYPE_OTHER")
|
||||
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:option-dialog-new
|
||||
'<gnc:OptionWin*>
|
||||
"gnc_options_dialog_new"
|
||||
'((<gw:bool> make-toplevel) ((<gw:mchars> caller-owned) title))
|
||||
"Create a new option dialog")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:option-dialog-destroy
|
||||
'<gw:void>
|
||||
"gnc_options_dialog_destroy"
|
||||
'((<gnc:OptionWin*> option-window))
|
||||
"Destroy an option dialog")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:option-dialog-build-contents
|
||||
'<gw:void>
|
||||
"gnc_build_options_dialog_contents"
|
||||
'((<gnc:OptionWin*> option-window) (<gnc:OptionDB*> option-db))
|
||||
"Fill in the option window with the provided option db")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:option-dialog-set-callbacks
|
||||
'<gw:void>
|
||||
"gnc_options_dialog_set_scm_callbacks"
|
||||
'((<gnc:OptionWin*> option-window) (<gw:scm> apply-cb) (<gw:scm> close-cb))
|
||||
"Setup callbacks for the option window.")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:mdi-has-apps?
|
||||
|
Loading…
Reference in New Issue
Block a user