[gimp/goat-invasion: 321/418] app: turn gimp_image_map_tool_add_settings_gui() into a virtual function



commit 324c3570744b10d18073d19451bf33bdec84c74a
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 30 00:12:48 2012 +0200

    app: turn gimp_image_map_tool_add_settings_gui() into a virtual function
    
    and change it to return the settings ui, not add it.

 app/tools/gimpimagemaptool-settings.c |   46 ++++++++++++++++----------------
 app/tools/gimpimagemaptool-settings.h |   16 +++++-----
 app/tools/gimpimagemaptool.c          |   23 ++++++++++++++--
 app/tools/gimpimagemaptool.h          |   27 ++++++++++--------
 4 files changed, 66 insertions(+), 46 deletions(-)
---
diff --git a/app/tools/gimpimagemaptool-settings.c b/app/tools/gimpimagemaptool-settings.c
index 9e175e9..1b59c62 100644
--- a/app/tools/gimpimagemaptool-settings.c
+++ b/app/tools/gimpimagemaptool-settings.c
@@ -58,11 +58,13 @@ static gboolean gimp_image_map_tool_settings_export (GimpSettingsBox  *box,
 
 /*  public functions  */
 
-gboolean
-gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool)
+GtkWidget *
+gimp_image_map_tool_real_get_settings_ui (GimpImageMapTool  *image_map_tool,
+                                          GtkWidget        **settings_box)
 {
   GimpImageMapToolClass *klass;
   GimpToolInfo          *tool_info;
+  GtkSizeGroup          *label_group;
   GtkWidget             *hbox;
   GtkWidget             *label;
   GtkWidget             *settings_combo;
@@ -71,41 +73,39 @@ gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool)
 
   klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
 
+  if (! klass->settings_name)
+    return NULL;
+
   tool_info = GIMP_TOOL (image_map_tool)->tool_info;
 
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-  gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), hbox,
-                      FALSE, FALSE, 0);
-  gtk_widget_show (hbox);
+
+  label_group = gimp_image_map_tool_dialog_get_label_group (image_map_tool);
 
   label = gtk_label_new_with_mnemonic (_("Pre_sets:"));
   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+  gtk_size_group_add_widget (label_group, label);
   gtk_widget_show (label);
 
-  image_map_tool->label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-  gtk_size_group_add_widget (image_map_tool->label_group, label);
-  g_object_unref (image_map_tool->label_group);
-
   filename = gimp_tool_info_build_options_filename (tool_info, ".settings");
   folder   = g_build_filename (gimp_directory (), klass->settings_name, NULL);
 
-  image_map_tool->settings_box = gimp_settings_box_new (tool_info->gimp,
-                                                        image_map_tool->config,
-                                                        klass->recent_settings,
-                                                        filename,
-                                                        klass->import_dialog_title,
-                                                        klass->export_dialog_title,
-                                                        tool_info->help_id,
-                                                        folder,
-                                                        NULL);
-  gtk_box_pack_start (GTK_BOX (hbox), image_map_tool->settings_box,
-                      TRUE, TRUE, 0);
-  gtk_widget_show (image_map_tool->settings_box);
+  *settings_box = gimp_settings_box_new (tool_info->gimp,
+                                         image_map_tool->config,
+                                         klass->recent_settings,
+                                         filename,
+                                         klass->import_dialog_title,
+                                         klass->export_dialog_title,
+                                         tool_info->help_id,
+                                         folder,
+                                         NULL);
+  gtk_box_pack_start (GTK_BOX (hbox), *settings_box, TRUE, TRUE, 0);
+  gtk_widget_show (*settings_box);
 
   g_free (filename);
   g_free (folder);
 
-  settings_combo = gimp_settings_box_get_combo (GIMP_SETTINGS_BOX (image_map_tool->settings_box));
+  settings_combo = gimp_settings_box_get_combo (GIMP_SETTINGS_BOX (*settings_box));
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), settings_combo);
 
   g_signal_connect (image_map_tool->settings_box, "import",
@@ -116,7 +116,7 @@ gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool)
                     G_CALLBACK (gimp_image_map_tool_settings_export),
                     image_map_tool);
 
-  return TRUE;
+  return hbox;
 }
 
 gboolean
diff --git a/app/tools/gimpimagemaptool-settings.h b/app/tools/gimpimagemaptool-settings.h
index b2874e5..94cdccc 100644
--- a/app/tools/gimpimagemaptool-settings.h
+++ b/app/tools/gimpimagemaptool-settings.h
@@ -21,14 +21,14 @@
 #define __GIMP_IMAGE_MAP_TOOL_SETTINGS_H__
 
 
-gboolean gimp_image_map_tool_add_settings_gui     (GimpImageMapTool *image_map_tool);
-
-gboolean gimp_image_map_tool_real_settings_import (GimpImageMapTool *tool,
-                                                   const gchar      *filename,
-                                                   GError          **error);
-gboolean gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
-                                                   const gchar      *filename,
-                                                   GError          **error);
+GtkWidget * gimp_image_map_tool_real_get_settings_ui (GimpImageMapTool *tool,
+                                                      GtkWidget       **settings_box);
+gboolean    gimp_image_map_tool_real_settings_import (GimpImageMapTool *tool,
+                                                      const gchar      *filename,
+                                                      GError          **error);
+gboolean    gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
+                                                      const gchar      *filename,
+                                                      GError          **error);
 
 
 #endif /* __GIMP_IMAGE_MAP_TOOL_SETTINGS_H__ */
diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c
index e01ad18..8ecce5d 100644
--- a/app/tools/gimpimagemaptool.c
+++ b/app/tools/gimpimagemaptool.c
@@ -178,6 +178,7 @@ gimp_image_map_tool_class_init (GimpImageMapToolClass *klass)
   klass->map                 = NULL;
   klass->dialog              = NULL;
   klass->reset               = NULL;
+  klass->get_settings_ui     = gimp_image_map_tool_real_get_settings_ui;
   klass->settings_import     = gimp_image_map_tool_real_settings_import;
   klass->settings_export     = gimp_image_map_tool_real_settings_export;
 }
@@ -296,6 +297,7 @@ gimp_image_map_tool_initialize (GimpTool     *tool,
       GtkWidget             *dialog;
       GtkWidget             *vbox;
       GtkWidget             *toggle;
+      GtkWidget             *settings_ui;
 
       klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
 
@@ -353,8 +355,15 @@ gimp_image_map_tool_initialize (GimpTool     *tool,
                                G_CALLBACK (gimp_image_map_tool_response),
                                G_OBJECT (image_map_tool), 0);
 
-      if (klass->settings_name)
-        gimp_image_map_tool_add_settings_gui (image_map_tool);
+      settings_ui = klass->get_settings_ui (image_map_tool,
+                                            &image_map_tool->settings_box);
+
+      if (settings_ui)
+        {
+          gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), settings_ui,
+                              FALSE, FALSE, 0);
+          gtk_widget_show (settings_ui);
+        }
 
       /*  The preview toggle  */
       toggle = gimp_prop_check_button_new (G_OBJECT (tool_info->tool_options),
@@ -693,6 +702,12 @@ gimp_image_map_tool_dialog_hide (GimpImageMapTool *image_map_tool)
 static void
 gimp_image_map_tool_dialog_destroy (GimpImageMapTool *image_map_tool)
 {
+  if (image_map_tool->label_group)
+    {
+      g_object_unref (image_map_tool->label_group);
+      image_map_tool->label_group = NULL;
+    }
+
   if (GTK_IS_DIALOG (image_map_tool->dialog) ||
       gtk_widget_get_parent (image_map_tool->dialog))
     gtk_widget_destroy (image_map_tool->dialog);
@@ -702,7 +717,6 @@ gimp_image_map_tool_dialog_destroy (GimpImageMapTool *image_map_tool)
   image_map_tool->dialog       = NULL;
   image_map_tool->main_vbox    = NULL;
   image_map_tool->settings_box = NULL;
-  image_map_tool->label_group  = NULL;
 }
 
 void
@@ -789,5 +803,8 @@ gimp_image_map_tool_dialog_get_label_group (GimpImageMapTool *tool)
 {
   g_return_val_if_fail (GIMP_IS_IMAGE_MAP_TOOL (tool), NULL);
 
+  if (! tool->label_group)
+    tool->label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
   return tool->label_group;
 }
diff --git a/app/tools/gimpimagemaptool.h b/app/tools/gimpimagemaptool.h
index 0ace946..62d8752 100644
--- a/app/tools/gimpimagemaptool.h
+++ b/app/tools/gimpimagemaptool.h
@@ -66,18 +66,21 @@ struct _GimpImageMapToolClass
   GimpContainer      *recent_settings;
 
   /* virtual functions */
-  GeglNode * (* get_operation)   (GimpImageMapTool  *image_map_tool,
-                                  GObject          **config);
-  void       (* map)             (GimpImageMapTool  *image_map_tool);
-  void       (* dialog)          (GimpImageMapTool  *image_map_tool);
-  void       (* reset)           (GimpImageMapTool  *image_map_tool);
-
-  gboolean   (* settings_import) (GimpImageMapTool  *image_map_tool,
-                                  const gchar       *filename,
-                                  GError           **error);
-  gboolean   (* settings_export) (GimpImageMapTool  *image_map_tool,
-                                  const gchar       *filename,
-                                  GError           **error);
+  GeglNode  * (* get_operation)   (GimpImageMapTool  *image_map_tool,
+                                   GObject          **config);
+  void        (* map)             (GimpImageMapTool  *image_map_tool);
+  void        (* dialog)          (GimpImageMapTool  *image_map_tool);
+  void        (* reset)           (GimpImageMapTool  *image_map_tool);
+
+  GtkWidget * (* get_settings_ui) (GimpImageMapTool  *image_map_tool,
+                                   GtkWidget        **settings_box);
+
+  gboolean    (* settings_import) (GimpImageMapTool  *image_map_tool,
+                                   const gchar       *filename,
+                                   GError           **error);
+  gboolean    (* settings_export) (GimpImageMapTool  *image_map_tool,
+                                   const gchar       *filename,
+                                   GError           **error);
 };
 
 



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