* kvp-option-registry.scm: create a registry of kvp-options

generators for various objects.  This simplifies the distributed
	  generation of kvp-option dialogs.
	* app-utils.scm: export kvp-option-registry functions
	* option-util: add option_db_changed() function
	* business-gnome.scm: add "File -> File Preferences" menu item
	  which is the kvp-option dialog for the Book.
	* business-prefs.scm: register a kvp-option generator for gnc:id-book
	* gnc-book: add gnc_book_kvp_changed() function
	* gw-engine-spec.scm: wrap gnc_book_kvp_changed
	* dialog-options.c: only call the SCM apply_cb if the optiondb
	  actually changed.
	* gnome-utils.scm: create gnc:kvp-option-dialog procedure to create
	  an kvp-option dialog for the speficied type.  Export this procedure.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7097 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-07-08 14:52:55 +00:00
parent 5904e6d487
commit c6ca88665b
14 changed files with 213 additions and 67 deletions

View File

@ -1,3 +1,20 @@
2002-07-08 Derek Atkins <derek@ihtfp.com>
* kvp-option-registry.scm: create a registry of kvp-options
generators for various objects. This simplifies the distributed
generation of kvp-option dialogs.
* app-utils.scm: export kvp-option-registry functions
* option-util: add option_db_changed() function
* business-gnome.scm: add "File -> File Preferences" menu item
which is the kvp-option dialog for the Book.
* business-prefs.scm: register a kvp-option generator for gnc:id-book
* gnc-book: add gnc_book_kvp_changed() function
* gw-engine-spec.scm: wrap gnc_book_kvp_changed
* dialog-options.c: only call the SCM apply_cb if the optiondb
actually changed.
* gnome-utils.scm: create gnc:kvp-option-dialog procedure to create
an kvp-option dialog for the speficied type. Export this procedure.
2002-07-07 Derek Atkins <derek@ihtfp.com>
* options.scm: change gnc:make-option; add two new args, scm->kvp

View File

@ -62,6 +62,7 @@ gncscm_DATA = \
config-var.scm \
date-utilities.scm \
hooks.scm \
kvp-option-registry.scm \
options.scm \
prefs.scm \
simple-obj.scm

View File

@ -248,9 +248,15 @@
(export simple-obj-from-list)
(export make-simple-obj)
;; kvp-option-registry
(export gnc:register-kvp-option-generator)
(export gnc:unregister-kvp-option-generator)
(export gnc:make-kvp-options)
(load-from-path "c-interface.scm")
(load-from-path "config-var.scm")
(load-from-path "options.scm")
(load-from-path "kvp-option-registry.scm")
(load-from-path "hooks.scm")
(load-from-path "prefs.scm")
(load-from-path "date-utilities.scm")

View File

@ -0,0 +1,58 @@
;; Code for the kvp/option registry
;;
;; Copyright (C) 2002, Derek Atkins <derek@ihtfp.com>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 59 Temple Place - Suite 330 Fax: +1-617-542-2652
;; Boston, MA 02111-1307, USA gnu@gnu.org
(require 'hash)
(define gnc:*kvp-option-registry* (make-hash-table 23))
(define (get-ref id-type)
(let ((gen-list (hash-ref gnc:*kvp-option-registry* id-type)))
(if gen-list gen-list '())))
;;
;; the generator should be a procedure that takes one argument,
;; an options object. The procedure should fill in the options with
;; its defined kvp options.
;;
(define (gnc:register-kvp-option-generator id-type generator)
(let ((gen-list (get-ref id-type)))
(hash-set! gnc:*kvp-option-registry*
id-type (append gen-list (list generator)))))
(define (gnc:unregister-kvp-option-generator id-type generator)
(let ((gen-list (get-ref id-type)))
(hash-set! gnc:*kvp-option-registry*
id-type (delq! generator gen-list))))
;;
;; create a new options object for the requested type
;;
(define (gnc:make-kvp-options id-type)
(let ((gen-list (get-ref id-type))
(options (gnc:new-options)))
(map
(lambda (generator)
(generator options))
gen-list)
options))

View File

@ -1671,6 +1671,42 @@ gnc_commit_option(GNCOption *option)
}
/********************************************************************\
* gnc_option_db_get_changed *
* returns a boolean value, TRUE if any option has changed, *
* FALSE is none of the options have changed *
* *
* Args: odb - option database to check *
* Return: boolean *
\********************************************************************/
gboolean
gnc_option_db_get_changed(GNCOptionDB *odb)
{
GSList *section_node;
GSList *option_node;
GNCOptionSection *section;
GNCOption *option;
g_return_val_if_fail (odb, FALSE);
for (section_node = odb->option_sections; section_node;
section_node = section_node->next) {
section = section_node->data;
for (option_node = section->options; option_node;
option_node = option_node->next) {
option = option_node->data;
if (option->changed)
return TRUE;
}
}
return FALSE;
}
/********************************************************************\
* gnc_option_db_commit *
* commits the options which have changed, and which are valid *

View File

@ -136,6 +136,7 @@ GNCOption * gnc_option_db_get_option_by_SCM(GNCOptionDB *odb,
gboolean gnc_option_db_dirty(GNCOptionDB *odb);
void gnc_option_db_clean(GNCOptionDB *odb);
gboolean gnc_option_db_get_changed(GNCOptionDB *odb);
void gnc_option_db_commit(GNCOptionDB *odb);
char * gnc_option_db_get_default_section(GNCOptionDB *odb);

View File

@ -196,6 +196,21 @@
(gnc:tax-table-new (gnc:get-current-book)))))
(add-vendor-items)
(add-customer-items)
(gnc:add-extension
(gnc:make-menu-item (N_ "File Properties")
(N_ "View and edit the properties of this file.")
(list "File" "Save As...")
(lambda ()
(let* ((book (gnc:get-current-book))
(slots (gnc:book-get-slots book)))
(define (changed_cb)
(gnc:book-kvp-changed book))
(gnc:kvp-option-dialog gnc:id-book
slots "Book Options"
changed_cb)))))
)
@ -353,54 +368,6 @@
))))
(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)

View File

@ -44,3 +44,18 @@
"This setting is inherited by new customers and vendors"))
#f))
(define (book-options-generator 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") "")))
(gnc:register-kvp-option-generator gnc:id-book book-options-generator)

View File

@ -44,6 +44,7 @@ struct gnc_book_struct
/* The kvp_frame provides a place for top-level data associated
* with this book. */
kvp_frame *kvp_data;
gboolean dirty;
/* The entity table associates the GUIDs of all the objects
* belonging to this book, with their pointers to the respective

View File

@ -326,21 +326,6 @@ book_sxns_mark_saved(GNCBook *book)
return;
}
void
gnc_book_mark_saved(GNCBook *book)
{
if (!book) return;
xaccGroupMarkSaved(gnc_book_get_group(book));
gnc_pricedb_mark_clean(gnc_book_get_pricedb(book));
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
/* Mark everything as clean */
gncObjectMarkClean (book);
}
static gboolean
book_sxlist_notsaved(GNCBook *book)
{
@ -362,12 +347,31 @@ book_sxlist_notsaved(GNCBook *book)
return FALSE;
}
void
gnc_book_mark_saved(GNCBook *book)
{
if (!book) return;
book->dirty = FALSE;
xaccGroupMarkSaved(gnc_book_get_group(book));
gnc_pricedb_mark_clean(gnc_book_get_pricedb(book));
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
/* Mark everything as clean */
gncObjectMarkClean (book);
}
gboolean
gnc_book_not_saved(GNCBook *book)
{
if (!book) return FALSE;
return(xaccGroupNotSaved(book->topgroup)
return(book->dirty
||
xaccGroupNotSaved(book->topgroup)
||
gnc_pricedb_dirty(book->pricedb)
||
@ -376,6 +380,12 @@ gnc_book_not_saved(GNCBook *book)
gncObjectIsDirty (book));
}
void gnc_book_kvp_changed (GNCBook *book)
{
if (!book) return;
book->dirty = TRUE;
}
/* ====================================================================== */
gboolean

View File

@ -84,6 +84,11 @@ gpointer gnc_book_get_data (GNCBook *book, const char *key);
*/
gboolean gnc_book_not_saved (GNCBook *book);
/* Call this function when you change the book kvp, to make sure the book
* is marked 'dirty'.
*/
void gnc_book_kvp_changed (GNCBook *book);
/* The gnc_book_equal() method returns TRUE if the engine data
* in the two given books is equal. */
gboolean gnc_book_equal (GNCBook *book_1, GNCBook *book_2);

View File

@ -1406,6 +1406,14 @@ when no longer needed.")
'((<gnc:Book*> book))
"Get the book's pricedb.")
(gw:wrap-function
ws
'gnc:book-kvp-changed
'<gw:void>
"gnc_book_kvp_changed"
'((<gnc:Book*> book))
"Set the flag that the Book's kvp changed.")
(gw:wrap-function
ws
'gnc:session-get-error

View File

@ -2746,9 +2746,11 @@ 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);
if (gnc_option_db_get_changed (win->option_db)) {
gnc_option_db_commit (win->option_db);
if (cbdata->apply_cb != SCM_BOOL_F) {
gh_call0 (cbdata->apply_cb);
}
}
}

View File

@ -18,4 +18,23 @@
(export gnc:new-menu-namer)
(export gnc:*add-extension-hook*)
(export gnc:kvp-option-dialog)
(load-from-path "gnc-menu-extensions.scm")
(define (gnc:kvp-option-dialog id-type slots title changed_cb)
(let* ((options (gnc:make-kvp-options id-type))
(optiondb (gnc:option-db-new options))
(optionwin (gnc:option-dialog-new #t title)))
(define (apply-cb)
(gnc:options-scm->kvp options slots '("options") #t)
(if changed_cb (changed_cb)))
(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)))