-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
// Copyright 2025 Shota FUJI
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// SPDX-License-Identifier: MPL-2.0
using GLib;
namespace TimeTracker.Widget {
private class ActiveTimersView : Gtk.Box {
public Model.Model model { get; construct; }
private NewTimerForm form = new NewTimerForm();
private Adw.StatusPage empty = new Adw.StatusPage() {
title = "No active timers",
description = "Type timer name in to bottom input and press start",
hexpand = true,
hexpand_set = true,
vexpand = true,
// This widget steals focus.
sensitive = false,
};
private Gtk.ScrolledWindow body = new Gtk.ScrolledWindow() {
vexpand = true,
};
public ActiveTimersView(Model.Model model) {
Object(model: model, orientation: Gtk.Orientation.VERTICAL, spacing: 4);
}
construct {
this.append(body);
this.append(empty);
var list = new TimerList(model.active_timers);
list.stop.connect((timer) => {
model.update(new Event.TimerStopped(timer.id));
});
body.child = list;
form.create.connect((title) => {
model.update(new Event.TimerStarted(title));
});
this.append(form);
model.active_timers.notify["n-items"].connect(() => {
on_item_count_changed();
});
on_item_count_changed();
}
private void on_item_count_changed() {
var has_items = model.active_timers.get_n_items() > 0;
form.primary = !has_items;
body.visible = has_items;
empty.visible = !has_items;
}
}
}