mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Rewrite option dialog callback in C
This reduces the number of guile<->c roundtrips for the book options dialog and eliminates the guile dependency from one more file. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22650 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
45708e5620
commit
5b03182435
@ -305,6 +305,42 @@ gnc_option_db_load_from_kvp(GNCOptionDB* odb, kvp_frame *slots)
|
||||
|
||||
scm_call_3 (kvp_to_scm, odb->guile_options, scm_slots, kvp_option_path);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_option_db_save_to_kvp(GNCOptionDB* odb, kvp_frame *slots, gboolean clear_kvp)
|
||||
{
|
||||
static SCM scm_to_kvp = SCM_UNDEFINED;
|
||||
static SCM kvp_option_path = SCM_UNDEFINED;
|
||||
SCM scm_slots;
|
||||
SCM scm_clear_kvp;
|
||||
|
||||
if (!odb || !slots) return;
|
||||
|
||||
if (scm_to_kvp == SCM_UNDEFINED)
|
||||
{
|
||||
scm_to_kvp = scm_c_eval_string("gnc:options-scm->kvp");
|
||||
if (!scm_is_procedure (scm_to_kvp))
|
||||
{
|
||||
PERR ("not a procedure\n");
|
||||
scm_to_kvp = SCM_UNDEFINED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (kvp_option_path == SCM_UNDEFINED)
|
||||
{
|
||||
kvp_option_path = scm_c_eval_string("gnc:*kvp-option-path*");
|
||||
if (kvp_option_path == SCM_UNDEFINED)
|
||||
{
|
||||
PERR ("can't find the option path");
|
||||
return;
|
||||
}
|
||||
}
|
||||
scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery("_p_KvpFrame"), 0);
|
||||
scm_clear_kvp = scm_from_bool (clear_kvp);
|
||||
|
||||
scm_call_4 (scm_to_kvp, odb->guile_options, scm_slots, kvp_option_path, scm_clear_kvp);
|
||||
}
|
||||
/********************************************************************\
|
||||
* gnc_option_db_destroy *
|
||||
* unregister the scheme options and free all the memory *
|
||||
|
@ -72,6 +72,7 @@ void gnc_option_db_destroy(GNCOptionDB *odb);
|
||||
*/
|
||||
GNCOptionDB * gnc_option_db_new_for_type(QofIdType id_type);
|
||||
void gnc_option_db_load_from_kvp(GNCOptionDB* odb, kvp_frame *slots);
|
||||
void gnc_option_db_save_to_kvp(GNCOptionDB* odb, kvp_frame *slots, gboolean clear_kvp);
|
||||
|
||||
void gnc_register_kvp_option_generator(QofIdType id_type, SCM generator);
|
||||
SCM gnc_make_kvp_options(QofIdType id_type);
|
||||
|
@ -36,13 +36,12 @@
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <libguile.h>
|
||||
#include "guile-mappings.h"
|
||||
|
||||
#include "gnc-plugin.h"
|
||||
#include "gnc-plugin-manager.h"
|
||||
#include "gnc-main-window.h"
|
||||
|
||||
#include "dialog-options.h"
|
||||
#include "dialog-preferences.h"
|
||||
#include "dialog-reset-warnings.h"
|
||||
#include "dialog-transfer.h"
|
||||
@ -65,6 +64,7 @@
|
||||
#include "gnc-window.h"
|
||||
#include "gnc-main.h"
|
||||
#include "gnc-gconf-utils.h"
|
||||
#include "option-util.h"
|
||||
// +JSLED
|
||||
//#include "gnc-html.h"
|
||||
#include "gnc-autosave.h"
|
||||
@ -3753,16 +3753,50 @@ gnc_main_window_cmd_page_setup (GtkAction *action,
|
||||
gnc_ui_page_setup(gtk_window);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_options_dialog_apply_cb(GNCOptionWin * optionwin,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNCOptionDB * options = user_data;
|
||||
kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
|
||||
|
||||
if (!options) return;
|
||||
|
||||
gnc_option_db_commit (options);
|
||||
gnc_option_db_save_to_kvp (options, slots, TRUE);
|
||||
qof_book_kvp_changed (gnc_get_current_book());
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_options_dialog_close_cb(GNCOptionWin * optionwin,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNCOptionDB * options = user_data;
|
||||
|
||||
gnc_options_dialog_destroy(optionwin);
|
||||
gnc_option_db_destroy(options);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_main_window_cmd_file_properties (GtkAction *action, GncMainWindow *window)
|
||||
{
|
||||
SCM func = scm_c_eval_string("gnc:main-window-properties-cb");
|
||||
if (!scm_is_procedure (func))
|
||||
{
|
||||
PERR ("not a procedure\n");
|
||||
return;
|
||||
}
|
||||
scm_call_0(func);
|
||||
kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
|
||||
GNCOptionDB *options;
|
||||
GNCOptionWin *optionwin;
|
||||
|
||||
options = gnc_option_db_new_for_type (QOF_ID_BOOK);
|
||||
gnc_option_db_load_from_kvp (options, slots);
|
||||
gnc_option_db_clean (options);
|
||||
|
||||
optionwin = gnc_options_dialog_new (_( "Book Options"));
|
||||
gnc_options_dialog_build_contents (optionwin, options);
|
||||
|
||||
gnc_options_dialog_set_apply_cb (optionwin,
|
||||
gnc_options_dialog_apply_cb,
|
||||
(gpointer)options);
|
||||
gnc_options_dialog_set_close_cb (optionwin,
|
||||
gnc_options_dialog_close_cb,
|
||||
(gpointer)options);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -9,7 +9,6 @@ gncscmmod_DATA = main.scm price-quotes.scm printf.scm
|
||||
gnc_regular_scm_files = \
|
||||
string.scm \
|
||||
fin.scm \
|
||||
main-window.scm \
|
||||
substring-search.scm \
|
||||
xml-generator.scm
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; main-window.scm : utilities for dealing with main window
|
||||
;; Copyright 2001 Bill Gribble <grib@gnumatic.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
|
||||
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
;; Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; book open and close hooks for mdi
|
||||
;;
|
||||
;; we need to save all the active report and acct tree info during
|
||||
;; book close.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(define (gnc:main-window-properties-cb)
|
||||
(let* ((book (gnc-get-current-book))
|
||||
(slots (qof-book-get-slots book)))
|
||||
|
||||
(define (changed_cb)
|
||||
(qof-book-kvp-changed book))
|
||||
|
||||
(gnc:kvp-option-dialog QOF-ID-BOOK-SCM
|
||||
slots (_ "Book Options")
|
||||
changed_cb)))
|
||||
|
@ -35,7 +35,6 @@
|
||||
;; files we can load from the top-level because they're "well behaved"
|
||||
;; (these should probably be in modules eventually)
|
||||
(load-from-path "string.scm")
|
||||
(load-from-path "main-window.scm") ;; depends on app-utils (N_, etc.)...
|
||||
(load-from-path "fin.scm")
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@ -53,9 +52,6 @@
|
||||
|
||||
(re-export hash-fold)
|
||||
|
||||
;; from main-window.scm
|
||||
(export gnc:main-window-properties-cb)
|
||||
|
||||
;; Get the Makefile.am/configure.in generated variables.
|
||||
(load-from-path "build-config.scm")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user