[goffice] Format Selector: Eliminate empty Special category.



commit 9da4b233a5a467258c85c54bad33753dd293f99a
Author: Morten Welinder <terra gnome org>
Date:   Wed Mar 17 19:23:08 2021 -0400

    Format Selector: Eliminate empty Special category.

 ChangeLog                   |  3 +++
 NEWS                        |  1 +
 goffice/gtk/go-format-sel.c | 33 +++++++++++++--------------------
 3 files changed, 17 insertions(+), 20 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a0d1258fa..37e67306f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2021-03-17  Morten Welinder  <terra gnome org>
 
+       * goffice/gtk/go-format-sel.c: Get rid of empty categories.  (That
+       means "Special" which we never filled in.  See #29.)
+
        * goffice/graph/gog-label.c (gog_reg_eqn_get_str): Show only three
        decimals for R^2.
 
diff --git a/NEWS b/NEWS
index 78b8b42e8..639df41dc 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ goffice 0.10.50:
 Morten:
        * Simplify regression equation code.
        * Use only 3 decimals for R^2 for regression lines.
+       * Eliminate empty Special category from format selector.  [#29]
 
 --------------------------------------------------------------------------
 goffice 0.10.49:
diff --git a/goffice/gtk/go-format-sel.c b/goffice/gtk/go-format-sel.c
index 1c2062c8f..1dd2d9129 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -1162,23 +1162,14 @@ static void
 cb_format_class_changed (G_GNUC_UNUSED GtkTreeSelection *ignored,
                         GOFormatSel *gfs)
 {
-       int selected_item = 0;
-       GList *list;
        GtkTreeSelection *selection = gtk_tree_view_get_selection
                (GTK_TREE_VIEW(gfs->format.menu));
+       GtkTreeIter iter;
 
-       list = gtk_tree_selection_get_selected_rows
-               (selection, &gfs->format.menu_model);
-       if (list) {
-               GtkTreePath *path;
-               path = list->data;
-               selected_item = *(gtk_tree_path_get_indices (path));
-
-               if (selected_item >= 0) {
-                       fmt_dialog_enable_widgets (gfs, selected_item);
-               }
-               g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
-               g_list_free (list);
+       if (gtk_tree_selection_get_selected (selection, &gfs->format.menu_model, &iter)) {
+               int ifam;
+               gtk_tree_model_get (gfs->format.menu_model, &iter, 1, &ifam, -1);
+               fmt_dialog_enable_widgets (gfs, ifam);
        }
 }
 
@@ -1377,10 +1368,10 @@ populate_menu (GOFormatSel *gfs)
        GtkTreeSelection  *selection;
        GtkTreeIter iter;
        GtkCellRenderer *renderer;
-       char const * const *categories = format_category_names;
+       GOFormatFamily fam;
 
        gfs->format.menu_model = GTK_TREE_MODEL (gtk_list_store_new
-                                                (1, G_TYPE_STRING));
+                                                (2, G_TYPE_STRING, G_TYPE_INT));
        gtk_tree_view_set_model (GTK_TREE_VIEW (gfs->format.menu),
                                 gfs->format.menu_model);
        g_object_unref (gfs->format.menu_model);
@@ -1388,12 +1379,14 @@ populate_menu (GOFormatSel *gfs)
                (GTK_TREE_VIEW(gfs->format.menu));
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
 
-       while (*categories) {
+       for (fam = GO_FORMAT_GENERAL; fam <= FMT_CUSTOM; fam++) {
+               const char *name = format_category_names[fam];
+               if (fam != FMT_CUSTOM && _go_format_builtins (fam) == NULL)
+                       continue;
                gtk_list_store_append
                        (GTK_LIST_STORE (gfs->format.menu_model), &iter);
                gtk_list_store_set (GTK_LIST_STORE (gfs->format.menu_model),
-                                   &iter, 0, _(*categories), -1);
-               categories++;
+                                   &iter, 0, name, 1, (int)fam, -1);
        }
 
        renderer = gtk_cell_renderer_text_new ();
@@ -1941,7 +1934,7 @@ go_format_sel_format_classification (GOFormat const *style_format)
 
        page = study_format (style_format, &details);
 
-       if (page < 0 || page > FMT_CUSTOM)
+       if (page < 0 || page > FMT_CUSTOM || format_category_names[page] == NULL)
                page = FMT_CUSTOM; /* Default to custom */
 
        return _(format_category_names[page]);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]