[gimp] app: Add and use return_if_no_shell()



commit 4a4d6abe56e77b211fcbc3684fbd43a88995de51
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Feb 28 09:39:37 2010 +0100

    app: Add and use return_if_no_shell()

 app/actions/actions.c       |   14 +++++
 app/actions/actions.h       |   74 +++++++++++++++-------------
 app/actions/view-commands.c |  113 +++++++++----------------------------------
 3 files changed, 77 insertions(+), 124 deletions(-)
---
diff --git a/app/actions/actions.c b/app/actions/actions.c
index d2ee381..6dcf74c 100644
--- a/app/actions/actions.c
+++ b/app/actions/actions.c
@@ -408,6 +408,20 @@ action_data_get_display (gpointer data)
   return NULL;
 }
 
+GimpDisplayShell *
+action_data_get_shell (gpointer data)
+{
+  GimpDisplay      *display = NULL;
+  GimpDisplayShell *shell   = NULL;
+
+  display = action_data_get_display (data);
+
+  if (display)
+    shell = gimp_display_get_shell (display);
+
+  return shell;
+}
+
 GtkWidget *
 action_data_get_widget (gpointer data)
 {
diff --git a/app/actions/actions.h b/app/actions/actions.h
index c068a3a..6db2db3 100644
--- a/app/actions/actions.h
+++ b/app/actions/actions.h
@@ -22,40 +22,41 @@
 extern GimpActionFactory *global_action_factory;
 
 
-void          actions_init            (Gimp                 *gimp);
-void          actions_exit            (Gimp                 *gimp);
-
-Gimp        * action_data_get_gimp    (gpointer              data);
-GimpContext * action_data_get_context (gpointer              data);
-GimpImage   * action_data_get_image   (gpointer              data);
-GimpDisplay * action_data_get_display (gpointer              data);
-GtkWidget   * action_data_get_widget  (gpointer              data);
-
-gdouble       action_select_value     (GimpActionSelectType  select_type,
-                                       gdouble               value,
-                                       gdouble               min,
-                                       gdouble               max,
-                                       gdouble               def,
-                                       gdouble               small_inc,
-                                       gdouble               inc,
-                                       gdouble               skip_inc,
-                                       gdouble               delta_factor,
-                                       gboolean              wrap);
-void          action_select_property  (GimpActionSelectType  select_type,
-                                       GimpDisplay          *display,
-                                       GObject              *object,
-                                       const gchar          *property_name,
-                                       gdouble               small_inc,
-                                       gdouble               inc,
-                                       gdouble               skip_inc,
-                                       gboolean              wrap);
-GimpObject  * action_select_object    (GimpActionSelectType  select_type,
-                                       GimpContainer        *container,
-                                       GimpObject           *current);
-void          action_message          (GimpDisplay          *display,
-                                       GObject              *object,
-                                       const gchar          *format,
-                                       ...) G_GNUC_PRINTF(3,4);
+void               actions_init            (Gimp                 *gimp);
+void               actions_exit            (Gimp                 *gimp);
+
+Gimp             * action_data_get_gimp    (gpointer              data);
+GimpContext      * action_data_get_context (gpointer              data);
+GimpImage        * action_data_get_image   (gpointer              data);
+GimpDisplay      * action_data_get_display (gpointer              data);
+GimpDisplayShell * action_data_get_shell   (gpointer              data);
+GtkWidget        * action_data_get_widget  (gpointer              data);
+
+gdouble            action_select_value     (GimpActionSelectType  select_type,
+                                            gdouble               value,
+                                            gdouble               min,
+                                            gdouble               max,
+                                            gdouble               def,
+                                            gdouble               small_inc,
+                                            gdouble               inc,
+                                            gdouble               skip_inc,
+                                            gdouble               delta_factor,
+                                            gboolean              wrap);
+void               action_select_property  (GimpActionSelectType  select_type,
+                                            GimpDisplay          *display,
+                                            GObject              *object,
+                                            const gchar          *property_name,
+                                            gdouble               small_inc,
+                                            gdouble               inc,
+                                            gdouble               skip_inc,
+                                            gboolean              wrap);
+GimpObject       * action_select_object    (GimpActionSelectType  select_type,
+                                            GimpContainer        *container,
+                                            GimpObject           *current);
+void               action_message          (GimpDisplay          *display,
+                                            GObject              *object,
+                                            const gchar          *format,
+                                            ...) G_GNUC_PRINTF(3,4);
 
 
 #define return_if_no_gimp(gimp,data) \
@@ -78,6 +79,11 @@ void          action_message          (GimpDisplay          *display,
   if (! display) \
     return
 
+#define return_if_no_shell(shell,data) \
+  shell = action_data_get_shell (data); \
+  if (! shell) \
+    return
+
 #define return_if_no_widget(widget,data) \
   widget = action_data_get_widget (data); \
   if (! widget) \
diff --git a/app/actions/view-commands.c b/app/actions/view-commands.c
index 0514321..d5022b0 100644
--- a/app/actions/view-commands.c
+++ b/app/actions/view-commands.c
@@ -128,11 +128,8 @@ view_zoom_cmd_callback (GtkAction *action,
                         gint       value,
                         gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   switch ((GimpActionSelectType) value)
     {
@@ -206,12 +203,9 @@ view_zoom_explicit_cmd_callback (GtkAction *action,
                                  GtkAction *current,
                                  gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gint              value;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
 
@@ -229,11 +223,8 @@ void
 view_zoom_other_cmd_callback (GtkAction *action,
                               gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   /* check if we are activated by the user or from
    * view_actions_set_zoom()
@@ -279,12 +270,9 @@ view_scroll_horizontal_cmd_callback (GtkAction *action,
                                      gint       value,
                                      gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gdouble           offset;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   offset = action_select_value ((GimpActionSelectType) value,
                                 gtk_adjustment_get_value (shell->hsbdata),
@@ -306,12 +294,9 @@ view_scroll_vertical_cmd_callback (GtkAction *action,
                                    gint       value,
                                    gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gdouble           offset;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   offset = action_select_value ((GimpActionSelectType) value,
                                 gtk_adjustment_get_value (shell->vsbdata),
@@ -332,11 +317,8 @@ void
 view_navigation_window_cmd_callback (GtkAction *action,
                                      gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   gimp_dialog_factory_dialog_raise (global_dialog_factory,
                                     gtk_widget_get_screen (GTK_WIDGET (shell)),
@@ -347,11 +329,8 @@ void
 view_display_filters_cmd_callback (GtkAction *action,
                                    gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   if (! shell->filters_dialog)
     {
@@ -369,12 +348,9 @@ void
 view_toggle_selection_cmd_callback (GtkAction *action,
                                     gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -385,12 +361,9 @@ void
 view_toggle_layer_boundary_cmd_callback (GtkAction *action,
                                          gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -401,12 +374,9 @@ void
 view_toggle_menubar_cmd_callback (GtkAction *action,
                                   gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -417,12 +387,9 @@ void
 view_toggle_rulers_cmd_callback (GtkAction *action,
                                  gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -433,12 +400,9 @@ void
 view_toggle_scrollbars_cmd_callback (GtkAction *action,
                                      gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -449,12 +413,9 @@ void
 view_toggle_statusbar_cmd_callback (GtkAction *action,
                                     gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -465,12 +426,9 @@ void
 view_toggle_guides_cmd_callback (GtkAction *action,
                                  gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -481,12 +439,9 @@ void
 view_toggle_grid_cmd_callback (GtkAction *action,
                                gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -497,12 +452,9 @@ void
 view_toggle_sample_points_cmd_callback (GtkAction *action,
                                         gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -513,12 +465,9 @@ void
 view_snap_to_guides_cmd_callback (GtkAction *action,
                                   gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -529,12 +478,9 @@ void
 view_snap_to_grid_cmd_callback (GtkAction *action,
                                 gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -545,12 +491,9 @@ void
 view_snap_to_canvas_cmd_callback (GtkAction *action,
                                   gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -561,12 +504,9 @@ void
 view_snap_to_vectors_cmd_callback (GtkAction *action,
                                    gpointer   data)
 {
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   gboolean          active;
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
@@ -672,14 +612,10 @@ void
 view_shrink_wrap_cmd_callback (GtkAction *action,
                                gpointer   data)
 {
-  GimpDisplay *display;
   GimpDisplayShell *shell;
-  return_if_no_display (display, data);
+  return_if_no_shell (shell, data);
 
-  shell = gimp_display_get_shell (display);
-
-  gimp_display_shell_scale_shrink_wrap (shell,
-                                        FALSE);
+  gimp_display_shell_scale_shrink_wrap (shell, FALSE);
 }
 
 void
@@ -709,15 +645,12 @@ view_use_gegl_cmd_callback (GtkAction *action,
                             gpointer   data)
 {
   GimpImage        *image;
-  GimpDisplay      *display;
   GimpDisplayShell *shell;
   GList            *layers;
   GList            *list;
   gboolean          active;
   return_if_no_image (image, data);
-  return_if_no_display (display, data);
-
-  shell = gimp_display_get_shell (display);
+  return_if_no_shell (shell, data);
 
   active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 



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