[gnome-clocks/bilelmoussaoui/redesign-timer] Timer: allow deleting timers
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/bilelmoussaoui/redesign-timer] Timer: allow deleting timers
- Date: Tue, 28 Jan 2020 05:21:19 +0000 (UTC)
commit 0ddcacdff170aecaee9a56378d4b5934a51bdabf
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Tue Jan 28 06:20:57 2020 +0100
Timer: allow deleting timers
src/timer.vala | 12 ++++++++++++
src/widgets.vala | 12 ++++++++++++
2 files changed, 24 insertions(+)
---
diff --git a/src/timer.vala b/src/timer.vala
index 96e0e1c..c3667b7 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -228,6 +228,7 @@ public class Setup : Gtk.Box {
[GtkTemplate (ui = "/org/gnome/clocks/ui/timer_row.ui")]
public class Row : Gtk.Box {
+ public signal void deleted (Item item);
public enum State {
STOPPED,
RUNNING,
@@ -269,6 +270,9 @@ public class Row : Gtk.Box {
timeout_id = 0;
}
});
+ delete_button.clicked.connect(() => {
+ this.deleted (this.item);
+ });
reset ();
}
@@ -435,6 +439,9 @@ public class Face : Gtk.Stack, Clocks.Clock {
timers_list.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) Hdy.list_box_separator_header);
timers_list.bind_model (timers, (timer) => {
var timer_row = new Row ((Item)timer);
+ timer_row.deleted.connect((item) => {
+ this.remove_timer(item);
+ });
return timer_row;
});
@@ -464,6 +471,11 @@ public class Face : Gtk.Stack, Clocks.Clock {
load ();
}
+ private void remove_timer (Item item) {
+ timers.remove (item);
+ save ();
+ }
+
public void activate_new () {
var dialog = new NewTimerDialog ((Gtk.Window) get_toplevel ());
diff --git a/src/widgets.vala b/src/widgets.vala
index 206e348..f7f8312 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -72,6 +72,18 @@ public class ContentStore : GLib.Object, GLib.ListModel {
item.notify["selected"].connect (on_item_selection_toggle);
}
+ public void remove (ContentItem item) {
+
+ var n = store.get_n_items ();
+ for (int i = 0; i < n; i++) {
+ var compared_item = (ContentItem) store.get_object (i);
+ if (compared_item == item) {
+ store.remove (i);
+ break;
+ }
+ }
+ }
+
public delegate void ForeachFunc (ContentItem item);
public void foreach (ForeachFunc func) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]