[gnome-games/wip/exalm/gtk4: 199/238] shortcuts-window: Don't subclass GtkShortcutsWindow



commit 198cd0e379bc665ffb878f7c2b512e042ffab720
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Mon Aug 19 15:55:51 2019 +0500

    shortcuts-window: Don't subclass GtkShortcutsWindow
    
    Instead, use a standard help-overlay.ui and init the RTL logic in
    ApplicationWindow.

 data/{ui/shortcuts-window.ui => gtk/help-overlay.ui} |  7 +++----
 data/org.gnome.Games.gresource.xml                   |  2 +-
 src/main.vala                                        |  3 +++
 src/meson.build                                      |  1 -
 src/ui/application-window.vala                       | 19 ++++++++++++++++++-
 src/ui/shortcuts-window.vala                         | 16 ----------------
 6 files changed, 25 insertions(+), 23 deletions(-)
---
diff --git a/data/ui/shortcuts-window.ui b/data/gtk/help-overlay.ui
similarity index 98%
rename from data/ui/shortcuts-window.ui
rename to data/gtk/help-overlay.ui
index 76a42e38..a42310c3 100644
--- a/data/ui/shortcuts-window.ui
+++ b/data/gtk/help-overlay.ui
@@ -1,9 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.24"/>
-  <template class="GamesShortcutsWindow" parent="GtkShortcutsWindow">
-    <property name="modal">1</property>
-    <signal name="direction-changed" after="yes" handler="update_direction"/>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <property name="modal">True</property>
     <child>
       <object class="GtkShortcutsSection">
         <property name="max-height">12</property>
@@ -231,7 +230,7 @@
         </child>
       </object>
     </child>
-  </template>
+  </object>
   <object class="GThemedIcon" id="button_home_icon">
     <property name="name">button-home-symbolic</property>
   </object>
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index d157b0a0..b30c6da1 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -10,6 +10,7 @@
     <file preprocess="xml-stripblanks">gesture/dpad-symbolic.svg</file>
     <file preprocess="xml-stripblanks">gesture/shoulders-front-symbolic.svg</file>
     <file preprocess="xml-stripblanks">gesture/stick-symbolic.svg</file>
+    <file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
     <file preprocess="xml-stripblanks">ui/application-window.ui</file>
     <file preprocess="xml-stripblanks">ui/checkmark-item.ui</file>
     <file preprocess="xml-stripblanks">ui/collection-box.ui</file>
@@ -51,6 +52,5 @@
     <file preprocess="xml-stripblanks">ui/savestate-listbox-row.ui</file>
     <file preprocess="xml-stripblanks">ui/savestates-list.ui</file>
     <file preprocess="xml-stripblanks">ui/search-bar.ui</file>
-    <file preprocess="xml-stripblanks">ui/shortcuts-window.ui</file>
   </gresource>
 </gresources>
diff --git a/src/main.vala b/src/main.vala
index 493dad22..07bec5a3 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -8,6 +8,9 @@ int main (string[] args) {
        Grl.init (ref args);
        Hdy.init (ref args);
 
+       // Needed for shortcuts window
+       typeof (GLib.ThemedIcon).ensure ();
+
        var app = new Games.Application ();
        var result = app.run (args);
 
diff --git a/src/meson.build b/src/meson.build
index 86696c50..3bbe504f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -186,7 +186,6 @@ vala_sources = [
   'ui/savestates-list.vala',
   'ui/savestates-list-state.vala',
   'ui/search-bar.vala',
-  'ui/shortcuts-window.vala',
   'ui/ui-view.vala',
 
   'utils/composite-cover.vala',
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 4965b963..ce120003 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -110,7 +110,24 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                if (Config.PROFILE == "Devel")
                        get_style_context ().add_class ("devel");
 
-               set_help_overlay (new ShortcutsWindow ());
+               init_help_overlay ();
+       }
+
+       private void init_help_overlay () {
+               var builder = new Gtk.Builder.from_resource ("/org/gnome/Games/gtk/help-overlay.ui");
+               var shortcuts_window = builder.get_object ("help_overlay") as Gtk.ShortcutsWindow;
+               var shortcut = builder.get_object ("ingame_shortcut_alt_left") as Gtk.ShortcutsShortcut;
+
+               shortcuts_window.direction_changed.connect (() => {
+                       shortcut.accelerator = get_alt_left_right ();
+               });
+               shortcut.accelerator = get_alt_left_right ();
+
+               set_help_overlay (shortcuts_window);
+       }
+
+       private string get_alt_left_right () {
+               return get_direction () == Gtk.TextDirection.LTR ? "<alt>Left" : "<alt>Right";
        }
 
        public void show_error (string error_message) {


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