[gimp] app: streamline action_data_get_foo() functions



commit 914200f3adce71e513aae57008dc82de1ea6b205
Author: Ell <ell_se yahoo com>
Date:   Mon Feb 25 04:39:46 2019 -0500

    app: streamline action_data_get_foo() functions
    
    Streamline the various action_data_get_foo() functions, by having
    each function only match the action data directly against its
    specific type(s), and use the other functions to match the action
    data against their corresponding types, instead of having each
    function directly exhaust all possible matches.
    
    Other than reducing depulication, it fixes certain cases in which
    some action_data_get_foo() functions would fail to find a match,
    even though one exists, since they failed to exhaust all the
    options.

 app/actions/actions.c | 226 ++++++++++++++++++++++++++++----------------------
 1 file changed, 125 insertions(+), 101 deletions(-)
---
diff --git a/app/actions/actions.c b/app/actions/actions.c
index 157b21224d..cf8d6dca1c 100644
--- a/app/actions/actions.c
+++ b/app/actions/actions.c
@@ -280,172 +280,196 @@ actions_exit (Gimp *gimp)
 Gimp *
 action_data_get_gimp (gpointer data)
 {
-  GimpContext *context = NULL;
+  Gimp            *result    = NULL;
+  static gboolean  recursion = FALSE;
 
-  if (! data)
+  if (! data || recursion)
     return NULL;
 
-  if (GIMP_IS_DISPLAY (data))
-    return ((GimpDisplay *) data)->gimp;
-  else if (GIMP_IS_IMAGE_WINDOW (data))
+  recursion = TRUE;
+
+  if (GIMP_IS_GIMP (data))
+    result = data;
+
+  if (! result)
     {
-      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
-      return shell ? shell->display->gimp : NULL;
+      GimpDisplay *display = action_data_get_display (data);
+
+      if (display)
+        result = display->gimp;
+    }
+
+  if (! result)
+    {
+      GimpContext *context = action_data_get_context (data);
+
+      if (context)
+        result = context->gimp;
     }
-  else if (GIMP_IS_GIMP (data))
-    return data;
-  else if (GIMP_IS_DOCK (data))
-    context = gimp_dock_get_context (((GimpDock *) data));
-  else if (GIMP_IS_DOCK_WINDOW (data))
-    context = gimp_dock_window_get_context (((GimpDockWindow *) data));
-  else if (GIMP_IS_CONTAINER_VIEW (data))
-    context = gimp_container_view_get_context ((GimpContainerView *) data);
-  else if (GIMP_IS_CONTAINER_EDITOR (data))
-    context = gimp_container_view_get_context (((GimpContainerEditor *) data)->view);
-  else if (GIMP_IS_IMAGE_EDITOR (data))
-    context = ((GimpImageEditor *) data)->context;
-  else if (GIMP_IS_NAVIGATION_EDITOR (data))
-    context = ((GimpNavigationEditor *) data)->context;
 
-  if (context)
-    return context->gimp;
+  recursion = FALSE;
 
-  return NULL;
+  return result;
 }
 
 GimpContext *
 action_data_get_context (gpointer data)
 {
-  if (! data)
+  GimpContext     *result    = NULL;
+  static gboolean  recursion = FALSE;
+
+  if (! data || recursion)
     return NULL;
 
-  if (GIMP_IS_DISPLAY (data))
-    return gimp_get_user_context (((GimpDisplay *) data)->gimp);
-  else if (GIMP_IS_IMAGE_WINDOW (data))
-    {
-      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
-      return shell ? gimp_get_user_context (shell->display->gimp) : NULL;
-    }
-  else if (GIMP_IS_GIMP (data))
-    return gimp_get_user_context (data);
-  else if (GIMP_IS_DOCK (data))
-    return gimp_dock_get_context ((GimpDock *) data);
+  recursion = TRUE;
+
+  if (GIMP_IS_DOCK (data))
+    result = gimp_dock_get_context ((GimpDock *) data);
   else if (GIMP_IS_DOCK_WINDOW (data))
-    return gimp_dock_window_get_context (((GimpDockWindow *) data));
+    result = gimp_dock_window_get_context (((GimpDockWindow *) data));
   else if (GIMP_IS_CONTAINER_VIEW (data))
-    return gimp_container_view_get_context ((GimpContainerView *) data);
+    result = gimp_container_view_get_context ((GimpContainerView *) data);
   else if (GIMP_IS_CONTAINER_EDITOR (data))
-    return gimp_container_view_get_context (((GimpContainerEditor *) data)->view);
+    result = gimp_container_view_get_context (((GimpContainerEditor *) data)->view);
   else if (GIMP_IS_IMAGE_EDITOR (data))
-    return ((GimpImageEditor *) data)->context;
+    result = ((GimpImageEditor *) data)->context;
   else if (GIMP_IS_NAVIGATION_EDITOR (data))
-    return ((GimpNavigationEditor *) data)->context;
+    result = ((GimpNavigationEditor *) data)->context;
+
+  if (! result)
+    {
+      Gimp *gimp = action_data_get_gimp (data);
 
-  return NULL;
+      if (gimp)
+        result = gimp_get_user_context (gimp);
+    }
+
+  recursion = FALSE;
+
+  return result;
 }
 
 GimpImage *
 action_data_get_image (gpointer data)
 {
-  GimpContext *context = NULL;
-  GimpDisplay *display = NULL;
+  GimpImage       *result    = NULL;
+  static gboolean  recursion = FALSE;
 
-  if (! data)
+  if (! data || recursion)
     return NULL;
 
-  if (GIMP_IS_DISPLAY (data))
-    display = (GimpDisplay *) data;
-  else if (GIMP_IS_IMAGE_WINDOW (data))
+  recursion = TRUE;
+
+  if (GIMP_IS_ITEM_TREE_VIEW (data))
+    result = gimp_item_tree_view_get_image ((GimpItemTreeView *) data);
+  else if (GIMP_IS_IMAGE_EDITOR (data))
+    result = ((GimpImageEditor *) data)->image;
+
+  if (! result)
     {
-      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
-      display = shell ? shell->display : NULL;
+      GimpDisplay *display = action_data_get_display (data);
+
+      if (display)
+        result = gimp_display_get_image (display);
     }
-  else if (GIMP_IS_GIMP (data))
-    context = gimp_get_user_context (data);
-  else if (GIMP_IS_DOCK (data))
-    context = gimp_dock_get_context ((GimpDock *) data);
-  else if (GIMP_IS_DOCK_WINDOW (data))
-    context = gimp_dock_window_get_context (((GimpDockWindow *) data));
-  else if (GIMP_IS_ITEM_TREE_VIEW (data))
-    return gimp_item_tree_view_get_image ((GimpItemTreeView *) data);
-  else if (GIMP_IS_IMAGE_EDITOR (data))
-    return ((GimpImageEditor *) data)->image;
-  else if (GIMP_IS_NAVIGATION_EDITOR (data))
-    context = ((GimpNavigationEditor *) data)->context;
 
-  if (context)
-    return gimp_context_get_image (context);
-  else if (display)
-    return gimp_display_get_image (display);
+  if (! result)
+    {
+      GimpContext *context = action_data_get_context (data);
+
+      if (context)
+        result = gimp_context_get_image (context);
+    }
 
-  return NULL;
+  recursion = FALSE;
+
+  return result;
 }
 
 GimpDisplay *
 action_data_get_display (gpointer data)
 {
-  GimpContext *context = NULL;
+  GimpDisplay     *result    = NULL;
+  static gboolean  recursion = FALSE;
 
-  if (! data)
+  if (! data || recursion)
     return NULL;
 
+  recursion = TRUE;
+
   if (GIMP_IS_DISPLAY (data))
-    return data;
+    result = data;
   else if (GIMP_IS_IMAGE_WINDOW (data))
     {
       GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
-      return shell ? shell->display : NULL;
+      result = shell ? shell->display : NULL;
     }
-  else if (GIMP_IS_GIMP (data))
-    context = gimp_get_user_context (data);
-  else if (GIMP_IS_DOCK (data))
-    context = gimp_dock_get_context ((GimpDock *) data);
-  else if (GIMP_IS_DOCK_WINDOW (data))
-    context = gimp_dock_window_get_context (((GimpDockWindow *) data));
-  else if (GIMP_IS_IMAGE_EDITOR (data))
-    context = ((GimpImageEditor *) data)->context;
-  else if (GIMP_IS_NAVIGATION_EDITOR (data))
-    context = ((GimpNavigationEditor *) data)->context;
 
-  if (context)
-    return gimp_context_get_display (context);
+  if (! result)
+    {
+      GimpContext *context = action_data_get_context (data);
+
+      if (context)
+        result = gimp_context_get_display (context);
+    }
 
-  return NULL;
+  recursion = FALSE;
+
+  return result;
 }
 
 GimpDisplayShell *
 action_data_get_shell (gpointer data)
 {
-  GimpDisplay      *display = NULL;
-  GimpDisplayShell *shell   = NULL;
+  GimpDisplayShell *result    = NULL;
+  static gboolean   recursion = FALSE;
+
+  if (! data || recursion)
+    return NULL;
+
+  recursion = TRUE;
 
-  display = action_data_get_display (data);
+  if (! result)
+    {
+      GimpDisplay *display = action_data_get_display (data);
+
+      if (display)
+        result = gimp_display_get_shell (display);
+    }
 
-  if (display)
-    shell = gimp_display_get_shell (display);
+  recursion = FALSE;
 
-  return shell;
+  return result;
 }
 
 GtkWidget *
 action_data_get_widget (gpointer data)
 {
-  GimpDisplay *display = NULL;
+  GtkWidget       *result    = NULL;
+  static gboolean  recursion = FALSE;
 
-  if (! data)
+  if (! data || recursion)
     return NULL;
 
-  if (GIMP_IS_DISPLAY (data))
-    display = data;
-  else if (GIMP_IS_GIMP (data))
-    display = gimp_context_get_display (gimp_get_user_context (data));
-  else if (GTK_IS_WIDGET (data))
-    return data;
+  recursion = TRUE;
+
+  if (GTK_IS_WIDGET (data))
+    result = data;
+
+  if (! result)
+    {
+      GimpDisplay *display = action_data_get_display (data);
+
+      if (display)
+        result = GTK_WIDGET (gimp_display_get_shell (display));
+    }
+
+  if (! result)
+    result = dialogs_get_toolbox ();
 
-  if (display)
-    return GTK_WIDGET (gimp_display_get_shell (display));
+  recursion = FALSE;
 
-  return dialogs_get_toolbox ();
+  return result;
 }
 
 gint


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