[gimp/gimp-2-10] app: add gimp_tool_info_get_action_name()



commit 0bd3c2e18e7411d8e066e79b24b568af1877ed8e
Author: Ell <ell_se yahoo com>
Date:   Wed Jan 29 21:49:12 2020 +0200

    app: add gimp_tool_info_get_action_name()
    
    Move the logic for translating a tool identifier to a corresponding
    action name to GimpToolInfo.  It's currently only used in
    tools-actions.c, but the next commits will use it in tool buttons.

 app/actions/tools-actions.c |  9 ++-------
 app/core/gimptoolinfo.c     | 24 ++++++++++++++++++++++++
 app/core/gimptoolinfo.h     |  2 ++
 3 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/app/actions/tools-actions.c b/app/actions/tools-actions.c
index dab98a48eb..0d627a1243 100644
--- a/app/actions/tools-actions.c
+++ b/app/actions/tools-actions.c
@@ -768,19 +768,14 @@ tools_actions_setup (GimpActionGroup *group)
       if (tool_info->menu_label)
         {
           GimpStringActionEntry  entry;
+          gchar                 *name;
           const gchar           *icon_name;
           const gchar           *identifier;
-          gchar                 *tmp;
-          gchar                 *name;
 
+          name       = gimp_tool_info_get_action_name (tool_info);
           icon_name  = gimp_viewable_get_icon_name (GIMP_VIEWABLE (tool_info));
           identifier = gimp_object_get_name (tool_info);
 
-          tmp = g_strndup (identifier + strlen ("gimp-"),
-                           strlen (identifier) - strlen ("gimp--tool"));
-          name = g_strdup_printf ("tools-%s", tmp);
-          g_free (tmp);
-
           entry.name        = name;
           entry.icon_name   = icon_name;
           entry.label       = tool_info->menu_label;
diff --git a/app/core/gimptoolinfo.c b/app/core/gimptoolinfo.c
index b6531f70f5..34d93c3b8b 100644
--- a/app/core/gimptoolinfo.c
+++ b/app/core/gimptoolinfo.c
@@ -220,6 +220,30 @@ gimp_tool_info_get_standard (Gimp *gimp)
   return gimp->standard_tool_info;
 }
 
+gchar *
+gimp_tool_info_get_action_name (GimpToolInfo *tool_info)
+{
+  const gchar *identifier;
+  gchar       *tmp;
+  gchar       *name;
+
+  g_return_val_if_fail (GIMP_IS_TOOL_INFO (tool_info), NULL);
+
+  identifier = gimp_object_get_name (GIMP_OBJECT (tool_info));
+
+  g_return_val_if_fail (g_str_has_prefix (identifier, "gimp-"), NULL);
+  g_return_val_if_fail (g_str_has_suffix (identifier, "-tool"), NULL);
+
+  tmp = g_strndup (identifier + strlen ("gimp-"),
+                    strlen (identifier) - strlen ("gimp--tool"));
+
+  name = g_strdup_printf ("tools-%s", tmp);
+
+  g_free (tmp);
+
+  return name;
+}
+
 GFile *
 gimp_tool_info_get_options_file (GimpToolInfo *tool_info,
                                  const gchar  *suffix)
diff --git a/app/core/gimptoolinfo.h b/app/core/gimptoolinfo.h
index 2b3f73098e..0d54fc3486 100644
--- a/app/core/gimptoolinfo.h
+++ b/app/core/gimptoolinfo.h
@@ -85,6 +85,8 @@ void           gimp_tool_info_set_standard     (Gimp                *gimp,
                                                 GimpToolInfo        *tool_info);
 GimpToolInfo * gimp_tool_info_get_standard     (Gimp                *gimp);
 
+gchar        * gimp_tool_info_get_action_name (GimpToolInfo         *tool_info);
+
 GFile        * gimp_tool_info_get_options_file (GimpToolInfo        *tool_info,
                                                 const gchar         *suffix);
 


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