[gnumeric] gnm_action_group_add_actions: properly implement.



commit eb614f8fbd0213d67482263dca881d340bb38fb6
Author: Morten Welinder <terra gnome org>
Date:   Wed Dec 9 09:46:36 2015 -0500

    gnm_action_group_add_actions: properly implement.

 ChangeLog      |    5 +++++
 NEWS           |    1 +
 src/gui-util.c |   40 ++++++++++++++++++++++++++++++++--------
 src/gui-util.h |    3 +--
 4 files changed, 39 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4703de6..c644422 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-09  Morten Welinder  <terra gnome org>
+
+       * src/gui-util.c (gnm_action_group_add_actions): Handle
+       translation context.
+
 2015-12-08  Morten Welinder  <terra gnome org>
 
        * src/wbc-gtk-actions.c (actions): Use GnmActionEntry and C99
diff --git a/NEWS b/NEWS
index dc7326d..ace042b 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Morten:
        * Test also RANDWEIBULL and RANDLOGNORM.
        * Fix problem with R.QHYPER
        * Add R.DRAYLEIGH, R.PRAYLEIGH, R.QRAYLEIGH.
+       * Fix GUI translation problems.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.24
diff --git a/src/gui-util.c b/src/gui-util.c
index 861eddb..abb0c3c 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -1280,18 +1280,42 @@ gnm_widget_measure_string (GtkWidget *w, const char *s)
        return len;
 }
 
+static const char *
+gnm_ag_translate (const char *s, const char *ctxt)
+{
+       return ctxt
+               ? g_dpgettext2 (NULL, ctxt, s)
+               : _(s);
+}
+
 void
 gnm_action_group_add_actions (GtkActionGroup *group,
-                             GnmActionEntry *permanent_actions,
-                             size_t n,
+                             GnmActionEntry const *actions, size_t n,
                              gpointer user)
 {
-       /* Realy dumb implementation for now.  */
+       unsigned i;
+
+       for (i = 0; i < n; i++) {
+               GnmActionEntry const *entry = actions + i;
+               const char *label =
+                       gnm_ag_translate (entry->label, entry->label_context);
+               const char *tip =
+                       gnm_ag_translate (entry->tooltip, NULL);
+               GtkAction *a;
+
+               a = gtk_action_new (entry->name, label, tip, NULL);
+               g_object_set (a, "icon-name", entry->icon, NULL);
+
+               if (entry->callback) {
+                       GClosure *closure =
+                               g_cclosure_new (entry->callback, user, NULL);
+                       g_signal_connect_closure (a, "activate", closure,
+                                                 FALSE);
+               }
 
-       while (n > 0) {
-               GtkActionEntry *a = (GtkActionEntry *)permanent_actions;
-               gtk_action_group_add_actions (group, a, 1, user);
-               permanent_actions++;
-               n--;
+               gtk_action_group_add_action_with_accel (group,
+                                                       a,
+                                                       entry->accelerator);
+               g_object_unref (a);
        }
 }
diff --git a/src/gui-util.h b/src/gui-util.h
index ca74b7b..124a147 100644
--- a/src/gui-util.h
+++ b/src/gui-util.h
@@ -177,8 +177,7 @@ typedef struct
 } GnmActionEntry;
 
 void gnm_action_group_add_actions (GtkActionGroup *group,
-                                  GnmActionEntry *permanent_actions,
-                                  size_t n,
+                                  GnmActionEntry const *actions, size_t n,
                                   gpointer user);
 
 


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