[goffice] Show in-use custom formats in teh custom format selector. [#658472]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Show in-use custom formats in teh custom format selector. [#658472]
- Date: Wed, 7 Sep 2011 17:30:21 +0000 (UTC)
commit defc28726bf8524b1a3fe7a3071dd8237b9c840e
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Wed Sep 7 11:29:20 2011 -0600
Show in-use custom formats in teh custom format selector. [#658472]
2011-09-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* goffice/utils/go-format.h (go_format_set_build_in): new
(go_format_is_build_in): new
(go_format_foreach): new
* goffice/utils/go-format.c (go_format_set_build_in): new
(go_format_is_build_in): new
(go_format_foreach): new
(go_format_refcount_cb): new
* goffice/gtk/go-format-sel.c (fmt_dialog_load_true_custom_cb): new
(fmt_dialog_enable_widgets): call fmt_dialog_load_true_custom_cb
ChangeLog | 12 ++++++++++
NEWS | 1 +
goffice/gtk/go-format-sel.c | 39 +++++++++++++++++++++++++++++++---
goffice/utils/go-format.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
goffice/utils/go-format.h | 6 ++++-
5 files changed, 100 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bb720e9..e6b1e9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2011-09-07 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * goffice/utils/go-format.h (go_format_set_build_in): new
+ (go_format_is_build_in): new
+ (go_format_foreach): new
+ * goffice/utils/go-format.c (go_format_set_build_in): new
+ (go_format_is_build_in): new
+ (go_format_foreach): new
+ (go_format_refcount_cb): new
+ * goffice/gtk/go-format-sel.c (fmt_dialog_load_true_custom_cb): new
+ (fmt_dialog_enable_widgets): call fmt_dialog_load_true_custom_cb
+
+2011-09-07 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* goffice/utils/go-format.c (handle_common_token): try harder to find the
locale, Ubuntu, for example, does not understand fi_FI but fi_FI.utf-8.
diff --git a/NEWS b/NEWS
index 960fabb..504f95f 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Andreas:
* Improve the scientific number formats selector. [#657187][#623847]
* Improve fraction format selector. [#117215]
* Support SI prefixes and units in scientific format selector. [#588516]
+ * Show in-use custom formats in teh custom format selector. [#658472]
Jean:
* Port to gtk+-3.0.
diff --git a/goffice/gtk/go-format-sel.c b/goffice/gtk/go-format-sel.c
index 28eaee7..bf39192 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -565,6 +565,8 @@ fmt_dialog_init_fmt_list (GOFormatSel *gfs, char const *const *formats,
GOFormatMagic magic = go_format_get_magic (f);
gboolean found;
+ go_format_set_build_in (f, TRUE);
+
gtk_list_store_append (gfs->format.formats.model, &iter);
gtk_list_store_set (gfs->format.formats.model, &iter,
0, fmt, -1);
@@ -612,6 +614,33 @@ find_builtin (const char *fmtstr, int page, gboolean def)
return candidates[list_elem];
}
+typedef struct {
+ GOFormatSel *gfs;
+ GtkTreeIter *select;
+} fmt_dialog_closure_t;
+
+static void
+fmt_dialog_load_true_custom_cb (char const *key, GOFormat const *fmt,
+ fmt_dialog_closure_t *cl)
+{
+ GtkTreeIter iter;
+ char *fmt_string;
+ if (go_format_is_build_in (fmt))
+ return;
+ fmt_string = go_format_str_localize (key);
+ gtk_list_store_insert_with_values (cl->gfs->format.formats.model, &iter,
+ 0, 0, fmt_string, -1);
+ g_free (fmt_string);
+ if (cl->select->stamp == 0) {
+ GOFormatMagic cur_magic = go_format_get_magic (cl->gfs->format.spec);
+ GOFormatMagic magic = go_format_get_magic (fmt);
+ gboolean found = cur_magic
+ ? (cur_magic == magic)
+ : go_format_eq (fmt, cl->gfs->format.spec);
+ if (found)
+ *(cl->select) = iter;
+ }
+}
static void
fmt_dialog_enable_widgets (GOFormatSel *gfs, int page)
@@ -808,12 +837,14 @@ stays:
fmt_dialog_init_fmt_list (gfs,
_go_format_builtins[start], &select);
+ if (page == FMT_CUSTOM) {
+ fmt_dialog_closure_t cl = {gfs, &select};
+
+ go_format_foreach ((GHFunc)fmt_dialog_load_true_custom_cb, &cl);
+ }
+
/* If this is the custom page and the format has
* not been found append it */
- /* TODO We should add the list of other custom formats created.
- * It should be easy. All that is needed is a way to differentiate
- * the std formats and the custom formats in the GOFormat hash.
- */
if (page == FMT_CUSTOM && select.stamp == 0) {
const char *fmtstr = go_format_as_XL (gfs->format.spec);
char *tmp = go_format_str_localize (fmtstr);
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 009b48e..c4bf4d7 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -316,7 +316,9 @@ struct _GOFormat {
unsigned int typ : 8;
unsigned int ref_count : 24;
GOColor color;
- unsigned char has_fill;
+ unsigned int has_fill : 7;
+ /* Note: is_build_in is only set by the format selector! */
+ unsigned int is_build_in : 1;
GOFormatMagic magic;
char *format;
union {
@@ -578,6 +580,29 @@ static long double beyond_precisionl;
/* WARNING : Global */
static GHashTable *style_format_hash = NULL;
+typedef struct {
+ GHFunc func;
+ gpointer user_data;
+} _go_format_foreach_t;
+
+static void
+go_format_refcount_cb (char *key, GOFormat *fmt,
+ _go_format_foreach_t *cl)
+{
+ if (fmt->ref_count > 1)
+ cl->func (key, fmt, cl->user_data);
+}
+
+void
+go_format_foreach (GHFunc func, gpointer user_data)
+{
+ if (style_format_hash != NULL) {
+ _go_format_foreach_t cl = {func, user_data};
+ g_hash_table_foreach (style_format_hash,
+ (GHFunc) go_format_refcount_cb, &cl);
+ }
+}
+
/* used to generate formats when delocalizing so keep the leadings caps */
static struct {
char const *name;
@@ -1181,6 +1206,8 @@ go_format_create (GOFormatClass cl, const char *format)
fmt->typ = cl;
fmt->ref_count = 1;
fmt->format = g_strdup (format);
+ /* Note: is_build_in is only set to TRUE by the format selector! */
+ fmt->is_build_in = FALSE;
return fmt;
}
@@ -5238,6 +5265,25 @@ go_format_is_var_width (GOFormat const *fmt)
#endif
#ifdef DEFINE_COMMON
+void
+go_format_set_build_in (GOFormat *fmt, gboolean build_in)
+{
+ g_return_if_fail (fmt != NULL);
+ fmt->is_build_in = build_in;
+}
+#endif
+
+#ifdef DEFINE_COMMON
+gboolean
+go_format_is_build_in (GOFormat const *fmt)
+{
+ g_return_val_if_fail (fmt != NULL, TRUE);
+ /* Note: is_build_in is only set by the format selector! */
+ return fmt->is_build_in;
+}
+#endif
+
+#ifdef DEFINE_COMMON
/**
* go_format_is_date:
* @fmt: Format to query
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index da7a918..4312e24 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -143,6 +143,7 @@ void go_render_generall (PangoLayout *layout, GString *str,
/*************************************************************************/
GOFormat *go_format_new_from_XL (char const *str);
+void go_format_set_build_in (GOFormat *fmt, gboolean build_in);
GOFormat *go_format_new_markup (PangoAttrList *markup, gboolean add_ref);
/* these do not add a reference to the result */
@@ -185,6 +186,7 @@ gboolean go_format_is_text (GOFormat const *fmt);
gboolean go_format_is_var_width (GOFormat const *fmt);
int go_format_is_date (GOFormat const *fmt);
int go_format_is_time (GOFormat const *fmt);
+gboolean go_format_is_build_in (GOFormat const *fmt);
int go_format_month_before_day (GOFormat const *fmt);
gboolean go_format_has_hour (GOFormat const *fmt);
@@ -242,13 +244,15 @@ GOFormat *go_format_inc_precision (GOFormat const *fmt);
GOFormat *go_format_dec_precision (GOFormat const *fmt);
GOFormat *go_format_toggle_1000sep (GOFormat const *fmt);
+
+
/******************* GOFormat ODF Support ********************************/
char *go_format_odf_style_map (GOFormat const *fmt, int cond_part);
gboolean go_format_output_to_odf (GsfXMLOut *xout, GOFormat const *fmt,
int cond_part, char const *name,
gboolean with_extension);
-
+void go_format_foreach (GHFunc func, gpointer user_data);
/*************************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]