[gimp] app: allow to set the text layer back to dynamic resizing



commit 8574f4c4e83e576d0221b64f638d3001ed5b968f
Author: Michael Natterer <mitch gimp org>
Date:   Wed Feb 17 15:50:03 2010 +0100

    app: allow to set the text layer back to dynamic resizing
    
    Add a "Dynamic Text Box" button to the tool options which sets the
    text box' mode back to dynamically resizing with the text.  This badly
    needs UI review but is at least possible now.

 app/tools/gimptextoptions.c |    5 ++++
 app/tools/gimptextoptions.h |    1 +
 app/tools/gimptexttool.c    |   50 +++++++++++++++++++++++++++++++++++++------
 3 files changed, 49 insertions(+), 7 deletions(-)
---
diff --git a/app/tools/gimptextoptions.c b/app/tools/gimptextoptions.c
index 84efd06..1904b09 100644
--- a/app/tools/gimptextoptions.c
+++ b/app/tools/gimptextoptions.c
@@ -517,6 +517,11 @@ gimp_text_options_gui (GimpToolOptions *tool_options)
   gimp_table_attach_stock (GTK_TABLE (table), row++,
                            GIMP_STOCK_LETTER_SPACING, spinbutton, 1, TRUE);
 
+  options->dynamic_box_button = button =
+    gtk_button_new_with_label (_("Dynamic Text Box"));
+  gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
+  gtk_widget_show (button);
+
   /*  Only add the language entry if the iso-codes package is available.  */
 
 #ifdef HAVE_ISO_CODES
diff --git a/app/tools/gimptextoptions.h b/app/tools/gimptextoptions.h
index 25b9633..e656015 100644
--- a/app/tools/gimptextoptions.h
+++ b/app/tools/gimptextoptions.h
@@ -55,6 +55,7 @@ struct _GimpTextOptions
 
   /*  options gui  */
   GtkWidget             *size_entry;
+  GtkWidget             *dynamic_box_button;
 };
 
 
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index 1d70a57..dd20f7e 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -149,6 +149,7 @@ static void      gimp_text_tool_select_all      (GimpTextTool      *text_tool,
 static void      gimp_text_tool_connect         (GimpTextTool      *text_tool,
                                                  GimpTextLayer     *layer,
                                                  GimpText          *text);
+static void      gimp_text_tool_set_dynamic_box (GimpTextTool      *text_tool);
 static void      gimp_text_tool_layer_notify    (GimpTextLayer     *layer,
                                                  GParamSpec        *pspec,
                                                  GimpTextTool      *text_tool);
@@ -1815,7 +1816,8 @@ gimp_text_tool_connect (GimpTextTool  *text_tool,
                         GimpTextLayer *layer,
                         GimpText      *text)
 {
-  GimpTool *tool = GIMP_TOOL (text_tool);
+  GimpTool        *tool    = GIMP_TOOL (text_tool);
+  GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
 
   g_return_if_fail (text == NULL || (layer != NULL && layer->text == text));
 
@@ -1857,16 +1859,30 @@ gimp_text_tool_connect (GimpTextTool  *text_tool,
   if (text_tool->layer != layer)
     {
       if (text_tool->layer)
-        g_signal_handlers_disconnect_by_func (text_tool->layer,
-                                              gimp_text_tool_layer_notify,
-                                              text_tool);
+        {
+          g_signal_handlers_disconnect_by_func (text_tool->layer,
+                                                gimp_text_tool_layer_notify,
+                                                text_tool);
+
+          gtk_widget_set_sensitive (options->dynamic_box_button, FALSE);
+          g_signal_handlers_disconnect_by_func (options->dynamic_box_button,
+                                                gimp_text_tool_set_dynamic_box,
+                                                text_tool);
+        }
 
       text_tool->layer = layer;
 
       if (layer)
-        g_signal_connect_object (text_tool->layer, "notify::modified",
-                                 G_CALLBACK (gimp_text_tool_layer_notify),
-                                 text_tool, 0);
+        {
+          gtk_widget_set_sensitive (options->dynamic_box_button, TRUE);
+          g_signal_connect_swapped (options->dynamic_box_button, "clicked",
+                                    G_CALLBACK (gimp_text_tool_set_dynamic_box),
+                                    text_tool);
+
+          g_signal_connect_object (text_tool->layer, "notify::modified",
+                                   G_CALLBACK (gimp_text_tool_layer_notify),
+                                   text_tool, 0);
+        }
     }
 }
 
@@ -1888,6 +1904,26 @@ gimp_text_tool_use_editor_notify (GimpTextOptions *options,
 }
 
 static void
+gimp_text_tool_set_dynamic_box (GimpTextTool *text_tool)
+{
+  if (text_tool->layer &&
+      text_tool->text  &&
+      text_tool->text->box_mode == GIMP_TEXT_BOX_FIXED)
+    {
+      g_object_set (text_tool->proxy,
+                    "box-mode", GIMP_TEXT_BOX_DYNAMIC,
+                    NULL);
+
+      gimp_image_undo_group_start (text_tool->image, GIMP_UNDO_GROUP_TEXT,
+                                   _("Reshape Text Layer"));
+
+      gimp_text_tool_apply (text_tool);
+
+      gimp_image_undo_group_end (text_tool->image);
+    }
+}
+
+static void
 gimp_text_tool_layer_notify (GimpTextLayer *layer,
                              GParamSpec    *pspec,
                              GimpTextTool  *text_tool)



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