[gnome-2048] Move Undo in the hamburger menu.



commit 49a54e8a02540c5b0dfdff0091430a29909acdb3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Jan 25 15:12:46 2019 +0100

    Move Undo in the hamburger menu.
    
    No need to force users who do not like
    this option to see all the time in the
    headerbar an insensitive button. Add a
    menu entry instead; ideally, in a menu
    dedicated to game actions, but for now
    in the hamburger menu. And only if the
    option is set to true, of course. That
    makes the window layout better anyway.

 data/mainwindow.ui   | 28 ----------------------------
 src/application.vala | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 28 deletions(-)
---
diff --git a/data/mainwindow.ui b/data/mainwindow.ui
index f9fadea..52bf376 100644
--- a/data/mainwindow.ui
+++ b/data/mainwindow.ui
@@ -31,31 +31,6 @@
         <!-- Translators: title of the window, displayed in the headerbar -->
         <property name="title" translatable="yes">GNOME 2048</property>
         <property name="show-close-button">True</property>
-        <child>
-          <object class="GtkButton">
-            <property name="visible">True</property>
-            <property name="can-focus">True</property>
-            <property name="receives-default">True</property>
-            <property name="action-name">app.undo</property>
-            <!-- Translators: tooltip text of the Undo button in the headerbar -->
-            <property name="tooltip-text" translatable="yes">Undo</property>
-            <property name="always-show-image">True</property>
-            <property name="focus-on-click">False</property>
-            <style>
-              <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="icon-name">edit-undo-symbolic</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkMenuButton" id="new-game-button">
             <!-- Translators: button in the headerbar -->
@@ -67,9 +42,6 @@
             <property name="focus-on-click">False</property>
             <property name="menu-model">new-game-menu</property>
           </object>
-          <packing>
-            <property name="position">2</property>
-          </packing>
         </child>
         <child>
           <object class="GtkMenuButton" id="hamburger-button">
diff --git a/src/application.vala b/src/application.vala
index ec7a38c..91dee25 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -227,6 +227,7 @@ public class Application : Gtk.Application
                 if (!_hamburger_button.active)
                     embed.grab_focus ();
             });
+        _settings.changed ["allow-undo"].connect (_update_hamburger_menu);
         _update_hamburger_menu ();
     }
 
@@ -246,6 +247,8 @@ public class Application : Gtk.Application
     {
         GLib.Menu menu = new GLib.Menu ();
 
+        if (_settings.get_boolean ("allow-undo"))
+            _append_undo_section (ref menu);
         _append_scores_section (ref menu);
         _append_app_actions_section (ref menu);
 
@@ -253,6 +256,17 @@ public class Application : Gtk.Application
         _hamburger_button.set_menu_model ((MenuModel) menu);
     }
 
+    private static inline void _append_undo_section (ref GLib.Menu menu)
+    {
+        GLib.Menu section = new GLib.Menu ();
+
+        /* Translators: entry in the hamburger menu, if the "Allow undo" option is set to true */
+        section.append (_("Undo"), "app.undo");
+
+        section.freeze ();
+        menu.append_section (null, section);
+    }
+
     private static inline void _append_scores_section (ref GLib.Menu menu)
     {
         GLib.Menu section = new GLib.Menu ();


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