From 244339156b3d75ab42ce87c1d0c82c929f5dcd48 Mon Sep 17 00:00:00 2001 From: dmn Date: Fri, 1 Apr 2016 11:06:56 +0300 Subject: [PATCH] gschem: add gschem-load-colors - loads a color map file at runtime. --- gschem/include/prototype.h | 1 + gschem/src/g_funcs.c | 32 ++++++++++++++++++++++++++++++++ gschem/src/g_register.c | 1 + 3 files changed, 34 insertions(+) diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h index 6e8e553..74e02ae 100644 --- a/gschem/include/prototype.h +++ b/gschem/include/prototype.h @@ -23,6 +23,7 @@ SCM g_funcs_msg(SCM msg); SCM g_funcs_confirm(SCM msg); SCM g_funcs_filesel(SCM msg, SCM templ, SCM flags); SCM g_funcs_use_rc_values(void); +SCM g_funcs_load_colors(SCM scm_filename); /* g_hook.c */ void g_init_hook (); void g_run_hook_object (GschemToplevel *w_current, const char *name, OBJECT *obj); diff --git a/gschem/src/g_funcs.c b/gschem/src/g_funcs.c index 4280a56..11a2b79 100644 --- a/gschem/src/g_funcs.c +++ b/gschem/src/g_funcs.c @@ -235,3 +235,35 @@ SCM g_funcs_use_rc_values(void) i_vars_set(g_current_window ()); return SCM_BOOL_T; } + + +/*! \brief Loads a color map file + * + * \param [in] scm_filename File name or full file path + * + * \return SCM_BOOL_T on success, SCM_BOOL_F otherwise + */ +SCM g_funcs_load_colors (SCM scm_filename) +{ + SCM_ASSERT (scm_is_string (scm_filename), scm_filename, + SCM_ARG1, "gschem-load-colors"); + + const char format[] = "(load-from-path \"%s\")"; + char* filename = scm_to_utf8_string (scm_filename); + + gchar* expr = g_strdup_printf (format, filename); + + x_color_free (); + SCM result = g_scm_c_eval_string_protected (expr); + x_color_allocate (); + + GschemToplevel* win = g_current_window (); + GschemPageView* view = gschem_toplevel_get_current_page_view (win); + if (view != NULL) { + gschem_page_view_invalidate_all (view); + } + + g_free (expr); + free (filename); + return result; +} diff --git a/gschem/src/g_register.c b/gschem/src/g_register.c index 44f2f85..c867f88 100644 --- a/gschem/src/g_register.c +++ b/gschem/src/g_register.c @@ -120,6 +120,7 @@ static struct gsubr_t gschem_funcs[] = { { "gschem-msg", 1, 0, 0, g_funcs_msg }, { "gschem-confirm", 1, 0, 0, g_funcs_confirm }, { "gschem-filesel", 2, 0, 1, g_funcs_filesel }, + { "gschem-load-colors", 1, 0, 0, g_funcs_load_colors }, /* keymapping callbacks */ { "file-new-window", 0, 0, 0, g_keys_file_new_window }, -- 2.7.4