[gnome-clocks/wip/flowbox] Simplify the update header bar logic



commit d4ef8df84ac4ac5bad7c8eded29b77f7479aae0d
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Apr 30 12:04:00 2017 +0200

    Simplify the update header bar logic
    
    Bubble up an update request to the toplevel and then update the
    bar from top to bottom. This does not require to play tricks with
    whether the widget is mapped or not.

 src/alarm.vala   |    1 +
 src/clock.vala   |    2 ++
 src/widgets.vala |   31 +++++--------------------------
 src/window.vala  |    3 +++
 src/world.vala   |    1 +
 5 files changed, 12 insertions(+), 26 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 82444f3..001ebc0 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -720,6 +720,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
 
     private void reset_view () {
         visible_child = alarms.get_n_items () == 0 ? empty_view : content_view;
+        request_header_bar_update ();
     }
 
     public void activate_new () {
diff --git a/src/clock.vala b/src/clock.vala
index bcede58..2fb963f 100644
--- a/src/clock.vala
+++ b/src/clock.vala
@@ -48,6 +48,8 @@ public interface Clock : GLib.Object {
     public virtual void back () {
     }
 
+    public signal void request_header_bar_update ();
+
     public virtual void update_header_bar () {
     }
 }
diff --git a/src/widgets.vala b/src/widgets.vala
index a28fc89..f3a114a 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -292,25 +292,7 @@ public class ContentView : Gtk.Bin {
         }
     }
 
-    private bool can_select {
-        get {
-            return _can_select;
-        }
-
-        private set {
-            if (_can_select != value) {
-                _can_select = value;
-
-                // show the select button only if we are mapped,
-                // since we do not want to show it when the geolocation
-                // query ends, but we are on another page
-                select_button.visible = _can_select && get_mapped ();
-            }
-        }
-    }
-
     private Mode _mode;
-    private bool _can_select;
     private ContentStore model;
     private Gtk.FlowBox flow_box;
     private Gtk.Button select_button;
@@ -372,13 +354,6 @@ public class ContentView : Gtk.Bin {
 
     public void bind_model (ContentStore store, owned ContentViewCreateWidgetFunc create_func) {
         model = store;
-        model.items_changed.connect ((position, removed, added) => {
-            var first_selectable = model.find ((i) => {
-                return i.selectable;
-            });
-
-            can_select = first_selectable != null;
-        });
 
         model.selection_changed.connect (() => {
             var n_items = model.get_n_selected ();
@@ -519,7 +494,11 @@ public class ContentView : Gtk.Bin {
             cancel_button.show ();
             break;
         case HeaderBar.Mode.NORMAL:
-            select_button.visible = can_select;
+            var first_selectable = model.find ((i) => {
+                return i.selectable;
+            });
+
+            select_button.visible = first_selectable != null;
             break;
         }
     }
diff --git a/src/window.vala b/src/window.vala
index 2dabc9a..0cf2f7c 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -77,6 +77,9 @@ public class Window : Gtk.ApplicationWindow {
 
         foreach (var clock in panels) {
             stack.add_titled (clock, ((Clock)clock).label, ((Clock)clock).label);
+            ((Clock)clock).request_header_bar_update.connect (() => {
+                update_header_bar ();
+            });
         }
 
         stack_switcher.set_stack (stack);
diff --git a/src/world.vala b/src/world.vala
index bccc9fa..6c98312 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -486,6 +486,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
     public void reset_view () {
         standalone_location = null;
         visible_child = locations.get_n_items () == 0 ? empty_view : content_view;
+        request_header_bar_update ();
     }
 
     public void update_header_bar () {


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