[gtk+] inspector: Add a button for rtl flipping



commit be532bc1962ca12d6f5be0e26a669fc78e3b361a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 10 10:40:55 2014 -0400

    inspector: Add a button for rtl flipping
    
    Nice to have a quick way of testing this everywhere.
    
    The implementation is not quite perfect: due to the way text
    direction works in GTK+, widgets that appear in the inspector
    window while we are flipped will inherit the flipped direction
    instead of the fixed direction of the inspector window.

 modules/inspector/window.c  |   37 +++++++++++++++++++++++++++++++++++++
 modules/inspector/window.ui |   17 +++++++++++++++--
 2 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/modules/inspector/window.c b/modules/inspector/window.c
index 479c4e5..37363ef 100644
--- a/modules/inspector/window.c
+++ b/modules/inspector/window.c
@@ -50,6 +50,40 @@ on_graphic_updates_toggled (GtkToggleButton    *button,
   gdk_window_set_debug_updates (gtk_toggle_button_get_active (button));
 }
 
+static void
+fix_direction_recurse (GtkWidget *widget, gpointer data)
+{
+  GtkTextDirection dir = GPOINTER_TO_INT (data);
+
+  g_object_ref (widget);
+
+  gtk_widget_set_direction (widget, dir);
+  if (GTK_IS_CONTAINER (widget))
+    gtk_container_forall (GTK_CONTAINER (widget), fix_direction_recurse, data);
+
+  g_object_unref (widget);
+}
+
+static GtkTextDirection initial_direction;
+
+static void
+fix_direction (GtkInspectorWindow *iw)
+{
+  fix_direction_recurse (GTK_WIDGET (iw), GINT_TO_POINTER (initial_direction));
+}
+
+static void
+on_flip (GtkButton          *button,
+         GtkInspectorWindow *iw)
+{
+  fix_direction (iw);
+
+  if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR)
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+  else
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
+}
+
 static gboolean
 on_widget_tree_button_press (GtkInspectorWidgetTree *wt,
                              GdkEventButton         *event,
@@ -126,6 +160,8 @@ gtk_inspector_window_init (GtkInspectorWindow *iw)
       g_signal_connect (G_OBJECT (iw->widget_tree), "button-press-event",
                         G_CALLBACK (on_widget_tree_button_press), iw);
     }
+
+  initial_direction = gtk_widget_get_default_direction ();
 }
 
 static void
@@ -182,6 +218,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
 
   gtk_widget_class_bind_template_callback (widget_class, on_inspect);
   gtk_widget_class_bind_template_callback (widget_class, on_graphic_updates_toggled);
+  gtk_widget_class_bind_template_callback (widget_class, on_flip);
   gtk_widget_class_bind_template_callback (widget_class, on_widget_tree_selection_changed);
   gtk_widget_class_bind_template_callback (widget_class, on_send_widget_to_shell_activate);
 }
diff --git a/modules/inspector/window.ui b/modules/inspector/window.ui
index e6f643b..66d7515 100644
--- a/modules/inspector/window.ui
+++ b/modules/inspector/window.ui
@@ -1,13 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
+  <object class="GtkImage" id="inspect_image">
+    <property name="visible">True</property>
+    <property name="icon-name">edit-find</property>
+    <property name="icon-size">4</property>
+  </object>
   <object class="GtkImage" id="update_image">
     <property name="visible">True</property>
     <property name="icon-name">view-refresh</property>
     <property name="icon-size">4</property>
   </object>
-  <object class="GtkImage" id="inspect_image">
+  <object class="GtkImage" id="flip_image">
     <property name="visible">True</property>
-    <property name="icon-name">edit-find</property>
+    <property name="icon-name">object-flip-horizontal</property>
     <property name="icon-size">4</property>
   </object>
   <object class="GtkMenu" id="widget_popup">
@@ -49,6 +54,14 @@
                 <signal name="toggled" handler="on_graphic_updates_toggled"/>
               </object>
             </child>
+            <child>
+              <object class="GtkButton">
+                <property name="visible">True</property>
+                <property name="image">flip_image</property>
+                <property name="tooltip-text" translatable="yes">Change Text Direction</property>
+                <signal name="clicked" handler="on_flip"/>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="pack-type">start</property>


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