Skip to content

Commit 77861f6

Browse files
committed
refactor: Training editor (Vala)
1 parent 735382a commit 77861f6

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

data/resources/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
blueprints = custom_target ('blueprints',
33
input: files (
44
'ui/shortcuts_dialog.blp',
5+
'ui/training_editor.blp',
56
'ui/training_list_row.blp',
67
'ui/window.blp',
78
),

data/resources/resources.gresource.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<gresources>
33
<gresource prefix="/xyz/safeworlds/hiit/">
44
<file compressed="true" preprocess="xml-stripblanks">ui/shortcuts_dialog.ui</file>
5+
<file compressed="true" preprocess="xml-stripblanks">ui/training_editor.ui</file>
56
<file compressed="true" preprocess="xml-stripblanks">ui/training_list_row.ui</file>
67
<file compressed="true" preprocess="xml-stripblanks">ui/window.ui</file>
78
<file compressed="true">audio/ping.wav</file>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
template $ExerciseTimerTrainingEditor : Adw.Dialog {
5+
Adw.ToolbarView {
6+
[top]
7+
Adw.HeaderBar {
8+
title-widget: Adw.WindowTitle {
9+
// Translators: The editor window's title when modifying a training
10+
title: _("Edit Training");
11+
};
12+
}
13+
14+
Adw.Clamp {
15+
margin-top: 12;
16+
margin-start: 12;
17+
margin-bottom: 12;
18+
margin-end: 12;
19+
20+
Gtk.Box {
21+
orientation: vertical;
22+
23+
Adw.PreferencesGroup {
24+
margin-bottom: 12;
25+
26+
Adw.EntryRow name_row {
27+
// Translators: The title of the field for the name of the training in the editor window
28+
title: _("Name");
29+
}
30+
}
31+
32+
Adw.PreferencesGroup {
33+
margin-bottom: 12;
34+
35+
Adw.SpinRow {
36+
// Translators: The title of the field for the number of sets in the training in the editor window
37+
title: _("Number of Sets");
38+
adjustment: Gtk.Adjustment sets_adjustment {
39+
lower: 1;
40+
upper: 1000000;
41+
step-increment: 1;
42+
};
43+
}
44+
Adw.SpinRow {
45+
// Translators: The title of the field for the rest duration in the training in the editor window
46+
title: _("Rest Time");
47+
// Translators: The subtitle of the field for the duration which refers to the unit. Singular form in some localizations.
48+
subtitle: _("Seconds");
49+
adjustment: Gtk.Adjustment rest_adjustment {
50+
lower: 0;
51+
upper: 1000000;
52+
step-increment: 1;
53+
};
54+
}
55+
Adw.SpinRow {
56+
// Translators: The title of the field for the exercise duration in the training in the editor window
57+
title: _("Exercise Time");
58+
// Translators: The subtitle of the field for the duration which refers to the unit. Singular form in some localizations.
59+
subtitle: _("Seconds");
60+
adjustment: Gtk.Adjustment exercise_adjustment {
61+
lower: 1;
62+
upper: 1000000;
63+
step-increment: 1;
64+
};
65+
}
66+
Adw.SpinRow {
67+
// Translators: The title of the field for the preparation duration in the training in the editor window
68+
title: _("Preparation Time");
69+
// Translators: The subtitle of the field for the duration which refers to the unit. Singular form in some localizations.
70+
subtitle: _("Seconds");
71+
adjustment: Gtk.Adjustment preparation_adjustment {
72+
lower: 0;
73+
upper: 1000000;
74+
step-increment: 1;
75+
};
76+
}
77+
}
78+
79+
Gtk.Button {
80+
label: "Apply";
81+
css-classes: ["suggested-action"];
82+
clicked => $on_apply_clicked();
83+
}
84+
}
85+
}
86+
}
87+
}

data/resources/ui/training_list_row.blp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ template $ExerciseTimerTrainingListRow : Gtk.ListBoxRow {
4242
margin-end: 10;
4343
// Translators: tooltip text for exercise card button to open the training editor
4444
tooltip-text: _("Edit Training");
45+
clicked => $on_edit_clicked();
4546
}
4647
Gtk.Button {
4748
icon-name: "user-trash-symbolic";

src/TrainingEditor.vala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace ExerciseTimer {
2+
[GtkTemplate(ui = "/xyz/safeworlds/hiit/ui/training_editor.ui")]
3+
public class TrainingEditor : Adw.Dialog {
4+
public signal void Applied(TrainingSetup setup);
5+
6+
public TrainingEditor(TrainingSetup _setup) {
7+
setup = new TrainingSetup(){
8+
Title = _setup.Title,
9+
Sets = _setup.Sets,
10+
ExerciseSec = _setup.ExerciseSec,
11+
RestSec = _setup.RestSec,
12+
WarmupSec = _setup.WarmupSec,
13+
};
14+
setup.bind_property("Title", name_row, "text", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE, null, null);
15+
setup.bind_property("Sets", sets_adjustment, "value", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE, null, null);
16+
setup.bind_property("ExerciseSec", exercise_adjustment, "value", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE, null, null);
17+
setup.bind_property("RestSec", rest_adjustment, "value", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE, null, null);
18+
setup.bind_property("WarmupSec", preparation_adjustment, "value", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE, null, null);
19+
}
20+
21+
[GtkCallback]
22+
private void on_apply_clicked() {
23+
Applied(setup);
24+
this.close();
25+
}
26+
27+
private TrainingSetup setup;
28+
[GtkChild]
29+
private unowned Adw.EntryRow name_row;
30+
[GtkChild]
31+
private unowned Gtk.Adjustment sets_adjustment;
32+
[GtkChild]
33+
private unowned Gtk.Adjustment exercise_adjustment;
34+
[GtkChild]
35+
private unowned Gtk.Adjustment rest_adjustment;
36+
[GtkChild]
37+
private unowned Gtk.Adjustment preparation_adjustment;
38+
}
39+
}

src/TrainingListRow.vala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ namespace ExerciseTimer {
55

66
public signal void Deleted(Gtk.Widget sender);
77

8+
[GtkCallback]
9+
private void on_edit_clicked() {
10+
var dialog = new TrainingEditor(Setup);
11+
dialog.Applied.connect((setup) => { Setup = setup; });
12+
dialog.present(this);
13+
}
14+
815
[GtkCallback]
916
private void on_delete_clicked() {
1017
Deleted(this);

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config_source = configure_file(
2626

2727
sources = [
2828
'Application.vala',
29+
'TrainingEditor.vala',
2930
'TrainingListRow.vala',
3031
'TrainingSetup.vala',
3132
'Window.vala',

0 commit comments

Comments
 (0)