[gnome-clocks/bilelmoussaoui/timer-fixes: 1/2] Timer: re-add needs-attention



commit 3270d75c87d7fd7eb3aa67f9f339c1c43b0de7ac
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Mon Feb 3 02:11:00 2020 +0100

    Timer: re-add needs-attention
    
    set the stack child's needs-attention prop to true
    if there are any timers running

 src/timer.vala  | 21 +++++++++++++++------
 src/window.vala |  5 +++++
 2 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/src/timer.vala b/src/timer.vala
index f2055f2..8ab1acb 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -312,11 +312,7 @@ public class Row : Gtk.ListBoxRow {
 
     [GtkCallback]
     private void on_pause_button_clicked () {
-        if (item.state == Item.State.RUNNING) {
-            item.pause ();
-        } else {
-            item.start ();
-        }
+        item.pause ();
     }
 
     [GtkCallback]
@@ -410,6 +406,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
     public PanelId panel_id { get; construct set; }
     public ButtonMode button_mode { get; set; default = NONE; }
     public ViewMode view_mode { get; set; default = NORMAL; }
+    public bool is_running { get; set; default = false; }
     public bool can_select { get; set; default = false; }
     public bool n_selected { get; set; }
     public string title { get; set; default = _("Clocks"); }
@@ -436,7 +433,9 @@ public class Face : Gtk.Stack, Clocks.Clock {
             row.deleted.connect (() => remove_timer ((Item) timer));
             row.edited.connect (() => save ());
             ((Item)timer).ring.connect (() => ring ());
-
+            ((Item)timer).notify["state"].connect (() => {
+                this.is_running = this.get_total_active_timers () != 0;
+            });
             return row;
         });
 
@@ -472,6 +471,16 @@ public class Face : Gtk.Stack, Clocks.Clock {
         load ();
     }
 
+    private int get_total_active_timers () {
+        var total_items = 0;
+        this.timers.foreach ((timer) => {
+            if (((Item)timer).state == Item.State.RUNNING) {
+                total_items += 1;
+            }
+        });
+        return total_items;
+    }
+
     private void remove_timer (Item item) {
         timers.remove (item);
     }
diff --git a/src/window.vala b/src/window.vala
index e85b681..4a528e4 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -106,6 +106,11 @@ public class Window : Gtk.ApplicationWindow {
             stack.visible_child = w;
         });
 
+
+        timer.notify["is-running"].connect ((w) => {
+            stack.child_set_property (timer, "needs-attention", timer.is_running);
+        });
+
         unowned Gtk.BindingSet binding_set = Gtk.BindingSet.by_class (get_class ());
 
         // plain ctrl+page_up/down is easten by the scrolled window...


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