[gimp] app: don't completely clear a GimpOperationTool when it's halted



commit f6c2e807e0360cb9311f24750b7da4929d62acb9
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jul 5 12:28:40 2017 +0200

    app: don't completely clear a GimpOperationTool when it's halted
    
    Need to keep around the operation's name and its description, so
    everything can be re-created when an image is clicked.
    
    Instead, completely shut down GimpOperationTool when GimpGeglTool is
    halted, so the next click will bring up a dialog with only the
    operation selection combo.

 app/tools/gimpgegltool.c      |   44 ++++++++++++++++++++++++++++++++++++++++-
 app/tools/gimpoperationtool.c |   24 ++++++++--------------
 2 files changed, 52 insertions(+), 16 deletions(-)
---
diff --git a/app/tools/gimpgegltool.c b/app/tools/gimpgegltool.c
index c12e04f..3b496fc 100644
--- a/app/tools/gimpgegltool.c
+++ b/app/tools/gimpgegltool.c
@@ -49,10 +49,16 @@ enum
 
 /*  local function prototypes  */
 
+static void   gimp_gegl_tool_control           (GimpTool       *tool,
+                                                GimpToolAction  action,
+                                                GimpDisplay    *display);
+
 static void   gimp_gegl_tool_dialog            (GimpFilterTool *filter_tool);
 
+static void   gimp_gegl_tool_halt              (GimpGeglTool   *gegl_tool);
+
 static void   gimp_gegl_tool_operation_changed (GtkWidget      *widget,
-                                                GimpGeglTool   *tool);
+                                                GimpGeglTool   *gegl_tool);
 
 
 G_DEFINE_TYPE (GimpGeglTool, gimp_gegl_tool, GIMP_TYPE_OPERATION_TOOL)
@@ -80,8 +86,11 @@ gimp_gegl_tool_register (GimpToolRegisterCallback  callback,
 static void
 gimp_gegl_tool_class_init (GimpGeglToolClass *klass)
 {
+  GimpToolClass       *tool_class        = GIMP_TOOL_CLASS (klass);
   GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
 
+  tool_class->control       = gimp_gegl_tool_control;
+
   filter_tool_class->dialog = gimp_gegl_tool_dialog;
 }
 
@@ -90,6 +99,30 @@ gimp_gegl_tool_init (GimpGeglTool *tool)
 {
 }
 
+static void
+gimp_gegl_tool_control (GimpTool       *tool,
+                        GimpToolAction  action,
+                        GimpDisplay    *display)
+{
+  GimpGeglTool *gegl_tool = GIMP_GEGL_TOOL (tool);
+
+  switch (action)
+    {
+    case GIMP_TOOL_ACTION_PAUSE:
+    case GIMP_TOOL_ACTION_RESUME:
+      break;
+
+    case GIMP_TOOL_ACTION_HALT:
+      gimp_gegl_tool_halt (gegl_tool);
+      break;
+
+    case GIMP_TOOL_ACTION_COMMIT:
+      break;
+    }
+
+  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
+}
+
 static gboolean
 gimp_gegl_tool_operation_blacklisted (const gchar *name,
                                       const gchar *categories_str)
@@ -452,6 +485,15 @@ gimp_gegl_tool_dialog (GimpFilterTool *filter_tool)
 }
 
 static void
+gimp_gegl_tool_halt (GimpGeglTool *gegl_tool)
+{
+  GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (gegl_tool);
+
+  gimp_operation_tool_set_operation (op_tool, NULL,
+                                     NULL, NULL, NULL, NULL, NULL);
+}
+
+static void
 gimp_gegl_tool_operation_changed (GtkWidget    *widget,
                                   GimpGeglTool *tool)
 {
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index 22ca668..3995a95 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -425,20 +425,12 @@ gimp_operation_tool_color_picked (GimpFilterTool  *filter_tool,
 static void
 gimp_operation_tool_halt (GimpOperationTool *op_tool)
 {
-  if (op_tool->operation)
-    {
-      g_free (op_tool->operation);
-      op_tool->operation = NULL;
-    }
-
-  if (op_tool->description)
-    {
-      g_free (op_tool->description);
-      op_tool->description = NULL;
-    }
+  /*  don't reset op_tool->operation and op_tool->description so the
+   *  tool can be properly restarted by clicking on an image
+   */
 
   g_list_foreach (op_tool->aux_inputs,
-                  (GFunc) gimp_operation_tool_aux_input_free, NULL);
+                  (GFunc) gimp_operation_tool_aux_input_clear, NULL);
   op_tool->aux_inputs = NULL;
 }
 
@@ -654,7 +646,6 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
   gint            aux;
 
   g_return_if_fail (GIMP_IS_OPERATION_TOOL (tool));
-  g_return_if_fail (operation != NULL);
 
   filter_tool = GIMP_FILTER_TOOL (tool);
 
@@ -678,8 +669,6 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
 
   gimp_filter_tool_set_widget (filter_tool, NULL);
 
-  gimp_filter_tool_get_operation (filter_tool);
-
   if (tool->options_gui)
     {
       gtk_widget_destroy (tool->options_gui);
@@ -692,6 +681,11 @@ gimp_operation_tool_set_operation (GimpOperationTool *tool,
         }
     }
 
+  if (! operation)
+    return;
+
+  gimp_filter_tool_get_operation (filter_tool);
+
   for (aux = 1; ; aux++)
     {
       gchar pad[32];


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