[gnome-builder/wip/gtk4-port] libide/foundry: add toggles for rtl/ltr



commit cb5da2df543e051247eac5e2075162122f8500d1
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 27 13:21:31 2022 -0700

    libide/foundry: add toggles for rtl/ltr
    
    This is dependent on GNOME/gtk!4768 or something like it in the near
    future. However, for testing purposes we can have this in tree since
    the other option is the menu item continuing to do nothing.
    
    Related #935

 src/libide/foundry/ide-run-manager.c | 51 ++++++++++++++++++++++++++++++++++++
 src/plugins/buildui/gtk/menus.ui     | 21 ++++++++++-----
 2 files changed, 66 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/foundry/ide-run-manager.c b/src/libide/foundry/ide-run-manager.c
index a52c6e210..218e188a8 100644
--- a/src/libide/foundry/ide-run-manager.c
+++ b/src/libide/foundry/ide-run-manager.c
@@ -103,6 +103,8 @@ static void ide_run_manager_actions_color_scheme        (IdeRunManager  *self,
                                                          GVariant       *param);
 static void ide_run_manager_actions_high_contrast       (IdeRunManager  *self,
                                                          GVariant       *param);
+static void ide_run_manager_actions_text_direction      (IdeRunManager  *self,
+                                                         GVariant       *param);
 
 IDE_DEFINE_ACTION_GROUP (IdeRunManager, ide_run_manager, {
   { "run", ide_run_manager_actions_run },
@@ -112,6 +114,7 @@ IDE_DEFINE_ACTION_GROUP (IdeRunManager, ide_run_manager, {
   { "default-run-command", ide_run_manager_actions_default_run_command, "s", "''" },
   { "color-scheme", ide_run_manager_actions_color_scheme, "s", "'follow'" },
   { "high-contrast", ide_run_manager_actions_high_contrast, NULL, "false" },
+  { "text-direction", ide_run_manager_actions_text_direction, "s", "''" },
 })
 
 G_DEFINE_TYPE_EXTENDED (IdeRunManager, ide_run_manager, IDE_TYPE_OBJECT, G_TYPE_FLAG_FINAL,
@@ -161,6 +164,23 @@ ide_run_manager_actions_high_contrast (IdeRunManager *self,
                                     g_variant_new_boolean (!g_variant_get_boolean (state)));
 }
 
+static void
+ide_run_manager_actions_text_direction (IdeRunManager *self,
+                                        GVariant      *param)
+{
+  const char *str;
+
+  g_assert (IDE_IS_RUN_MANAGER (self));
+  g_assert (param != NULL);
+  g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_STRING));
+
+  str = g_variant_get_string (param, NULL);
+  if (g_strv_contains (IDE_STRV_INIT ("ltr", "rtl"), str))
+    ide_run_manager_set_action_state (self,
+                                      "text-direction",
+                                      g_variant_new_string (str));
+}
+
 static void
 ide_run_manager_actions_color_scheme (IdeRunManager *self,
                                       GVariant      *param)
@@ -623,6 +643,25 @@ apply_high_contrast (IdeEnvironment *env,
   IDE_EXIT;
 }
 
+static void
+apply_text_direction (IdeEnvironment *env,
+                      const char     *text_dir_str)
+{
+  GtkTextDirection dir;
+
+  if (ide_str_equal0 (text_dir_str, "rtl"))
+    dir = GTK_TEXT_DIR_RTL;
+  else if (ide_str_equal0 (text_dir_str, "ltr"))
+    dir = GTK_TEXT_DIR_LTR;
+  else
+    g_return_if_reached ();
+
+  if (dir == gtk_widget_get_default_direction ())
+    text_dir_str = NULL;
+
+  ide_environment_setenv (env, "GTK_DEBUG_TEXT_DIR", text_dir_str);
+}
+
 static inline const char *
 get_action_state_string (IdeRunManager *self,
                          const char    *action_name)
@@ -731,6 +770,7 @@ create_runner_cb (GObject      *object,
   color_scheme = get_action_state_string (self, "color-scheme");
   apply_color_scheme (environment, color_scheme);
   apply_high_contrast (environment, get_action_state_bool (self, "high-contrast"));
+  apply_text_direction (environment, get_action_state_string (self, "text-direction"));
 
   g_signal_emit (self, signals [RUN], 0, runner);
 
@@ -1528,8 +1568,19 @@ ide_run_manager_actions_stop (IdeRunManager *self,
 static void
 ide_run_manager_init (IdeRunManager *self)
 {
+  GtkTextDirection text_dir;
+
   self->cancellable = g_cancellable_new ();
 
+  /* Setup initial text direction state */
+  text_dir = gtk_widget_get_default_direction ();
+  if (text_dir == GTK_TEXT_DIR_LTR)
+    ide_run_manager_set_action_state (self,
+                                      "text-direction",
+                                      text_dir == GTK_TEXT_DIR_LTR ?
+                                        g_variant_new_string ("ltr") :
+                                        g_variant_new_string ("rtl"));
+
   ide_run_manager_add_handler (self,
                                "run",
                                _("Run"),
diff --git a/src/plugins/buildui/gtk/menus.ui b/src/plugins/buildui/gtk/menus.ui
index ad877a46f..a94566e55 100644
--- a/src/plugins/buildui/gtk/menus.ui
+++ b/src/plugins/buildui/gtk/menus.ui
@@ -156,12 +156,21 @@
           <attribute name="role">check</attribute>
           <attribute name="action">run-manager.high-contrast</attribute>
         </item>
-        <item>
-          <attribute name="label" translatable="yes">Right-to-Left</attribute>
-          <attribute name="role">check</attribute>
-          <attribute name="action">runui.textdir</attribute>
-          <attribute name="target" type="s">'rtl'</attribute>
-        </item>
+        <section id="run-menu-a11y-text-direction">
+          <attribute name="label" translatable="yes">Text Direction</attribute>
+          <item>
+            <attribute name="label" translatable="yes">Left-to-Right</attribute>
+            <attribute name="role">check</attribute>
+            <attribute name="action">run-manager.text-direction</attribute>
+            <attribute name="target" type="s">'ltr'</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">Right-to-Left</attribute>
+            <attribute name="role">check</attribute>
+            <attribute name="action">run-manager.text-direction</attribute>
+            <attribute name="target" type="s">'rtl'</attribute>
+          </item>
+        </section>
       </submenu>
       <item>
         <attribute name="id">run-menu-verbose-logging</attribute>


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