mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Kevin Finn's patch to add gui change-callbacks to guile options.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2677 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
048501b8ae
commit
83fcd68cdd
@ -445,6 +445,8 @@ gnc_option_toggled_cb(GtkToggleButton *button, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(button));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -457,6 +459,8 @@ gnc_option_changed_cb(GtkEditable *editable, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(editable));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -482,6 +486,8 @@ gnc_option_multichoice_cb(GtkWidget *w, gint index, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
omenu = gtk_object_get_data(GTK_OBJECT(w), "gnc_option_menu");
|
||||
pbox = gtk_widget_get_toplevel(omenu);
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
@ -545,6 +551,8 @@ gnc_option_account_cb(GNCAccountTree *tree, Account * account, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(tree));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -559,6 +567,8 @@ gnc_option_account_select_all_cb(GtkWidget *widget, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(widget));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -573,6 +583,8 @@ gnc_option_account_clear_all_cb(GtkWidget *widget, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(widget));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -655,6 +667,8 @@ gnc_option_list_select_cb(GtkCList *clist, gint row, gint column,
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
gtk_clist_set_row_data(clist, row, GINT_TO_POINTER(TRUE));
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(clist));
|
||||
@ -670,6 +684,8 @@ gnc_option_list_unselect_cb(GtkCList *clist, gint row, gint column,
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
gtk_clist_set_row_data(clist, row, GINT_TO_POINTER(FALSE));
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(clist));
|
||||
@ -686,6 +702,8 @@ gnc_option_list_select_all_cb(GtkWidget *widget, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(widget));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -700,6 +718,8 @@ gnc_option_list_clear_all_cb(GtkWidget *widget, gpointer data)
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(widget));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -800,6 +820,8 @@ gnc_option_color_changed_cb(GnomeColorPicker *picker, guint arg1, guint arg2,
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(picker));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -813,6 +835,8 @@ gnc_option_font_changed_cb(GnomeFontPicker *picker, gchar *font_name,
|
||||
|
||||
option->changed = TRUE;
|
||||
|
||||
gnc_option_call_option_widget_changed_proc(option);
|
||||
|
||||
pbox = gtk_widget_get_toplevel(GTK_WIDGET(picker));
|
||||
gnome_property_box_changed(GNOME_PROPERTY_BOX(pbox));
|
||||
}
|
||||
@ -1250,7 +1274,7 @@ gnc_build_options_dialog_contents(GnomePropertyBox *propertybox,
|
||||
gint default_page = -1;
|
||||
gint num_sections;
|
||||
gint page;
|
||||
gint i;
|
||||
gint i, j;
|
||||
|
||||
tooltips = gtk_tooltips_new();
|
||||
|
||||
@ -1274,6 +1298,21 @@ gnc_build_options_dialog_contents(GnomePropertyBox *propertybox,
|
||||
|
||||
if (default_section_name != NULL)
|
||||
free(default_section_name);
|
||||
|
||||
/* call each option widget changed callbacks once at this point,
|
||||
* now that all options widgets exist.
|
||||
*/
|
||||
for (i = 0; i < num_sections; i++)
|
||||
{
|
||||
section = gnc_option_db_get_section(odb, i);
|
||||
|
||||
for (j = 0; j < gnc_option_section_num_options(section); j++)
|
||||
{
|
||||
gnc_option_call_option_widget_changed_proc(
|
||||
gnc_get_option_section_option(section, j) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,16 +18,16 @@
|
||||
;; Boston, MA 02111-1307, USA gnu@gnu.org
|
||||
|
||||
(define (gnc:make-option
|
||||
;; The category of this option
|
||||
;; The category of this option
|
||||
section
|
||||
name
|
||||
;; The sort-tag determines the relative ordering of options in
|
||||
;; this category. It is used by the gui for display.
|
||||
;; The sort-tag determines the relative ordering of options in
|
||||
;; this category. It is used by the gui for display.
|
||||
sort-tag
|
||||
type
|
||||
documentation-string
|
||||
getter
|
||||
;; The setter is responsible for ensuring that the value is valid.
|
||||
;; The setter is responsible for ensuring that the value is valid.
|
||||
setter
|
||||
default-getter
|
||||
;; Restore form generator should generate an ascii representation
|
||||
@ -35,16 +35,23 @@
|
||||
;; option. The function should restore the option to the original
|
||||
;; value.
|
||||
generate-restore-form
|
||||
;; Validation func should accept a value and return (#t value)
|
||||
;; on success, and (#f "failure-message") on failure. If #t,
|
||||
;; the supplied value will be used by the gui to set the option.
|
||||
;; Validation func should accept a value and return (#t value)
|
||||
;; on success, and (#f "failure-message") on failure. If #t,
|
||||
;; the supplied value will be used by the gui to set the option.
|
||||
value-validator
|
||||
option-data
|
||||
option-data
|
||||
;; This function should return a list of all the strings in the
|
||||
;; option other than the section, name, and documentation-string
|
||||
;; that might be displayed to the user (and thus should be
|
||||
;; translated).
|
||||
strings-getter)
|
||||
strings-getter
|
||||
;; This function will be called when the GUI representation
|
||||
;; of the option is changed. This will normally occure before
|
||||
;; the setter is called, because setters are only called when
|
||||
;; the user selects "OK" or "Apply". Therefore, this callback
|
||||
;; shouldn't be used to make changes to the actual options
|
||||
;; database.
|
||||
option-widget-changed-proc)
|
||||
(let ((changed-callback #f))
|
||||
(vector section
|
||||
name
|
||||
@ -60,7 +67,8 @@
|
||||
value-validator
|
||||
option-data
|
||||
(lambda (callback) (set! changed-callback callback))
|
||||
strings-getter)))
|
||||
strings-getter
|
||||
option-widget-changed-proc)))
|
||||
|
||||
(define (gnc:option-section option)
|
||||
(vector-ref option 0))
|
||||
@ -89,6 +97,8 @@
|
||||
(cb-setter callback)))
|
||||
(define (gnc:option-strings-getter option)
|
||||
(vector-ref option 12))
|
||||
(define (gnc:option-widget-changed-proc option)
|
||||
(vector-ref option 13))
|
||||
|
||||
(define (gnc:option-value option)
|
||||
(let ((getter (gnc:option-getter option)))
|
||||
@ -127,7 +137,7 @@
|
||||
(lambda (x)
|
||||
(cond ((string? x)(list #t x))
|
||||
(else (list #f "string-option: not a string"))))
|
||||
#f #f )))
|
||||
#f #f #f)))
|
||||
|
||||
;; font options store fonts as strings a la the X Logical
|
||||
;; Font Description. You should always provide a default
|
||||
@ -151,7 +161,7 @@
|
||||
(lambda (x)
|
||||
(cond ((string? x)(list #t x))
|
||||
(else (list #f "font-option: not a string"))))
|
||||
#f #f )))
|
||||
#f #f #f)))
|
||||
|
||||
;; currency options use a specialized widget for entering currencies
|
||||
;; in the GUI implementation.
|
||||
@ -172,7 +182,7 @@
|
||||
(lambda (x)
|
||||
(cond ((string? x)(list #t x))
|
||||
(else (list #f "currency-option: not a currency code"))))
|
||||
#f #f )))
|
||||
#f #f #f)))
|
||||
|
||||
(define (gnc:make-simple-boolean-option
|
||||
section
|
||||
@ -192,19 +202,16 @@
|
||||
(if (boolean? x)
|
||||
(list #t x)
|
||||
(list #f "boolean-option: not a boolean")))
|
||||
#f #f )))
|
||||
#f #f #f)))
|
||||
|
||||
|
||||
;; Complex boolean options are the same as simple boolean options,
|
||||
;; with the addition of a function argument. The function should
|
||||
;; with the addition of two function arguments. Both functions should
|
||||
;; expect one boolean argument. When the option's value is changed,
|
||||
;; the function will be called with the new value of the option as
|
||||
;; the function's argument. For example:
|
||||
;;
|
||||
;; (gnc:make-complex-boolean-option
|
||||
;; "General" "complex boolean test"
|
||||
;; "a" "test the complex boolean option" #f
|
||||
;; (lambda (x) (gnc:warn "complex boolean option selected")))
|
||||
;; one function will be called with the new option value at the time
|
||||
;; that the GUI widget representing the option is changed, and the
|
||||
;; other function will be called when the option's setter is called
|
||||
;; (that is, when the user selects "OK" or "Apply").
|
||||
|
||||
(define (gnc:make-complex-boolean-option
|
||||
section
|
||||
@ -212,22 +219,22 @@
|
||||
sort-tag
|
||||
documentation-string
|
||||
default-value
|
||||
function)
|
||||
setter-function-called-cb
|
||||
option-widget-changed-cb)
|
||||
(let* ((value default-value)
|
||||
(value->string (lambda () (gnc:value->string value))))
|
||||
(gnc:make-option
|
||||
section name sort-tag 'boolean documentation-string
|
||||
(lambda () value)
|
||||
(lambda (x) (set! value x)
|
||||
(function x))
|
||||
(setter-function-called-cb x))
|
||||
(lambda () default-value)
|
||||
(gnc:restore-form-generator value->string)
|
||||
(lambda (x)
|
||||
(if (boolean? x)
|
||||
(list #t x)
|
||||
(list #f "boolean-option: not a boolean")))
|
||||
#f #f )))
|
||||
|
||||
#f #f (lambda (x) (option-widget-changed-cb x)))))
|
||||
|
||||
|
||||
;; date options use the option-data as a boolean value. If true,
|
||||
@ -259,7 +266,7 @@
|
||||
(if (date-legal date)
|
||||
(list #t date)
|
||||
(list #f "date-option: illegal date")))
|
||||
show-time #f)))
|
||||
show-time #f #f)))
|
||||
|
||||
;; account-list options use the option-data as a boolean value. If
|
||||
;; true, the gui should allow the user to select multiple accounts.
|
||||
@ -307,7 +314,7 @@
|
||||
(lambda () (map convert-to-account (default-getter)))
|
||||
#f
|
||||
validator
|
||||
multiple-selection #f)))
|
||||
multiple-selection #f #f)))
|
||||
|
||||
;; multichoice options use the option-data as a list of vectors.
|
||||
;; Each vector contains a permissible value (scheme symbol), a
|
||||
@ -349,7 +356,7 @@
|
||||
(list #t x)
|
||||
(list #f "multichoice-option: illegal choice")))
|
||||
ok-values
|
||||
(lambda () (multichoice-strings ok-values)))))
|
||||
(lambda () (multichoice-strings ok-values)) #f)))
|
||||
|
||||
;; list options use the option-data in the same way as multichoice
|
||||
;; options. List options allow the user to select more than one option.
|
||||
@ -397,7 +404,7 @@
|
||||
(list #t x)
|
||||
(list #f "list-option: illegal value")))
|
||||
ok-values
|
||||
(lambda () (list-strings ok-values)))))
|
||||
(lambda () (list-strings ok-values)) #f)))
|
||||
|
||||
;; number range options use the option-data as a list whose
|
||||
;; elements are: (lower-bound upper-bound num-decimals step-size)
|
||||
@ -426,7 +433,7 @@
|
||||
(list #t x))
|
||||
(else (list #f "number-range-option: out of range"))))
|
||||
(list lower-bound upper-bound num-decimals step-size)
|
||||
#f)))
|
||||
#f #f)))
|
||||
|
||||
(define (gnc:make-internal-option
|
||||
section
|
||||
@ -441,7 +448,7 @@
|
||||
(lambda () default-value)
|
||||
(gnc:restore-form-generator value->string)
|
||||
(lambda (x) (list #t x))
|
||||
#f #f)))
|
||||
#f #f #f)))
|
||||
|
||||
;; Color options store rgba values in a list.
|
||||
;; The option-data is a list, whose first element
|
||||
@ -487,7 +494,7 @@
|
||||
(gnc:restore-form-generator value->string)
|
||||
validate-color
|
||||
(list range use-alpha)
|
||||
#f)))
|
||||
#f #f)))
|
||||
|
||||
(define (gnc:color->html color range)
|
||||
|
||||
|
@ -422,6 +422,13 @@ the account instead of opening a register." #f))
|
||||
"General" "Automatic Decimal Point"
|
||||
"g" "Automatically insert a decimal point into values that are entered without one. Example: '2000' is changed to '20.00'." #f))
|
||||
|
||||
;(gnc:register-configuration-option
|
||||
; (gnc:make-complex-boolean-option
|
||||
; "General" "complex boolean test"
|
||||
; "h" "some random text" #f
|
||||
; (lambda (x) (gnc:warn "setter cb function"))
|
||||
; (lambda (x) (gnc:warn "widget cb function"))))
|
||||
|
||||
;(gnc:register-configuration-option
|
||||
; (gnc:make-number-range-option
|
||||
; "General" "Default precision"
|
||||
|
Loading…
Reference in New Issue
Block a user