Changes
4 changed files (+148/-27)
-
-
@@ -20,6 +20,11 @@ namespace TimeTracker.Widget {*/ public signal void remove(Model.Timer timer); /** * User requested to edit this entry. */ public signal void edit(Model.Timer timer); public Model.Timer? timer { get; set; } private Gtk.Label title = new Gtk.Label("") {
-
@@ -45,6 +50,15 @@ namespace TimeTracker.Widget {construct { var action_group = new SimpleActionGroup(); var edit_action = new SimpleAction("Edit", null); edit_action.activate.connect(() => { if (timer != null) { edit(timer); } }); action_group.add_action(edit_action); var delete_action = new SimpleAction("Delete", null); delete_action.activate.connect(() => { if (timer != null) {
-
@@ -52,32 +66,8 @@ namespace TimeTracker.Widget {} }); action_group.add_action(delete_action); this.insert_action_group("HistoryRow", action_group); this.notify["timer"].connect(() => { if (timer == null) { return; } if (timer.title.length > 0) { title.label = timer.title; title.tooltip_text = timer.title; title.remove_css_class("dimmed"); } else { title.label = "(No title)"; title.add_css_class("dimmed"); } var start = new DateTime.from_unix_local(timer.started_at); var end = new DateTime.from_unix_local(timer.stopped_at); duration.span = end.difference(start); var is_span_days = start.get_year() != end.get_year() || start.get_day_of_year() != end.get_day_of_year(); span.label = "%s - %s".printf( start.format("%Y-%m-%d %H:%M"), is_span_days ? end.format("%Y-%m-%d %H:%M") : end.format("%H:%M") ); }); this.insert_action_group("HistoryRow", action_group); this.orientation = HORIZONTAL; this.spacing = 16;
-
@@ -98,6 +88,7 @@ namespace TimeTracker.Widget {this.append(info); var menu = new Menu(); menu.append("Edit", "HistoryRow.Edit"); menu.append("Delete", "HistoryRow.Delete"); actions.menu_model = menu; this.append(actions);
-
@@ -108,5 +99,44 @@ namespace TimeTracker.Widget {} }); } public void bind(Model.Timer timer) { this.timer = timer; render(timer); timer.notify.connect(on_timer_update); } public void unbind(Model.Timer timer) { this.timer = null; timer.notify.disconnect(on_timer_update); } private void on_timer_update(Object object, ParamSpec _params) { render((Model.Timer) object); } private void render(Model.Timer timer) { if (timer.title.length > 0) { title.label = timer.title; title.tooltip_text = timer.title; title.remove_css_class("dimmed"); } else { title.label = "(No title)"; title.add_css_class("dimmed"); } var start = new DateTime.from_unix_local(timer.started_at); var end = new DateTime.from_unix_local(timer.stopped_at); duration.span = end.difference(start); var is_span_days = start.get_year() != end.get_year() || start.get_day_of_year() != end.get_day_of_year(); span.label = "%s - %s".printf( start.format("%Y-%m-%d %H:%M"), is_span_days ? end.format("%Y-%m-%d %H:%M") : end.format("%H:%M") ); } } }
-
-
-
@@ -10,6 +10,8 @@ using GLib;namespace TimeTracker.Widget { private class HistoryView : Gtk.Box { public signal void edit_entry(Model.Timer timer); public Model.Model model { get; construct; } private Gtk.ListView list = new Gtk.ListView(null, null) {
-
@@ -53,6 +55,9 @@ namespace TimeTracker.Widget {row.remove.connect((timer) => { model.update(new Event.TimerDeleted(timer.id)); }); row.edit.connect((timer) => { edit_entry(timer); }); list_item.child = row; }
-
@@ -61,7 +66,15 @@ namespace TimeTracker.Widget {var timer = (Model.Timer) list_item.item; var row = (HistoryRow) list_item.child; row.timer = timer; row.bind(timer); } private void unbind(Gtk.ListItemFactory _factory, Object object) { var list_item = (Gtk.ListItem) object; var timer = (Model.Timer) list_item.item; var row = (HistoryRow) list_item.child; row.unbind(timer); } } }
-
-
-
@@ -31,8 +31,15 @@ namespace TimeTracker.Widget {"appointment-new-symbolic" ); var history = new HistoryView(model); history.edit_entry.connect((timer) => { var dialog = new TimerEditDialog(model, timer); dialog.present(this); }); stack.add_titled_with_icon( new HistoryView(model), history, "history", "History", "view-list-bullet-symbolic"
-
-
-
@@ -0,0 +1,71 @@// 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 TimerEditDialog : Adw.Dialog { public Model.Model model { get; construct; } public Model.Timer timer { get; construct; } private Adw.EntryRow title_row = new Adw.EntryRow() { title = "Title", }; public TimerEditDialog(Model.Model model, Model.Timer timer) { Object(model: model, timer: timer, title: timer.title); } construct { var box = new Gtk.Box(VERTICAL, 12) { margin_top = 12, margin_bottom = 12, margin_start = 12, margin_end = 12, }; var entries = new Gtk.ListBox() { css_classes = { "boxed-list" }, }; title_row.text = timer.title; entries.append(title_row); box.append(entries); var actions = new Gtk.Box(HORIZONTAL, 8) { halign = END, }; box.append(actions); var cancel = new Gtk.Button() { label = "Cancel", }; cancel.clicked.connect(() => { this.close(); }); var submit = new Gtk.Button() { label = "Update", css_classes = { "suggested-action" }, }; submit.clicked.connect(() => { var new_title = title_row.text; if (timer.title != new_title) { model.update(new Event.TimerTitleChanged(timer.id, new_title)); } this.close(); }); actions.append(cancel); actions.append(submit); this.set_child(box); } } }
-