Skip to content

Commit 76cb4ee

Browse files
committed
refactor: Create training with dialog
1 parent 7efdfa7 commit 76cb4ee

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

data/resources/ui/training_editor.blp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ template $ExerciseTimerTrainingEditor : Adw.Dialog {
99
// Translators: The editor window's title when modifying a training
1010
title: _("Edit Training");
1111
};
12+
show-end-title-buttons: false;
13+
14+
[start]
15+
Gtk.Button {
16+
// Translators: Button to close the training editor window without modifications
17+
label: _("Cancel");
18+
clicked => $on_cancel_clicked();
19+
}
20+
21+
[end]
22+
Gtk.Button {
23+
// Translators: Button to close the training editor window with saving modifications
24+
label: _("Apply");
25+
css-classes: ["suggested-action"];
26+
clicked => $on_apply_clicked();
27+
}
1228
}
1329

1430
Adw.Clamp {
@@ -21,16 +37,14 @@ template $ExerciseTimerTrainingEditor : Adw.Dialog {
2137
orientation: vertical;
2238

2339
Adw.PreferencesGroup {
24-
margin-bottom: 12;
25-
2640
Adw.EntryRow name_row {
2741
// Translators: The title of the field for the name of the training in the editor window
2842
title: _("Name");
2943
}
3044
}
3145

3246
Adw.PreferencesGroup {
33-
margin-bottom: 12;
47+
margin-top: 12;
3448

3549
Adw.SpinRow {
3650
// Translators: The title of the field for the number of sets in the training in the editor window
@@ -75,12 +89,6 @@ template $ExerciseTimerTrainingEditor : Adw.Dialog {
7589
};
7690
}
7791
}
78-
79-
Gtk.Button {
80-
label: "Apply";
81-
css-classes: ["suggested-action"];
82-
clicked => $on_apply_clicked();
83-
}
8492
}
8593
}
8694
}

src/TrainingEditor.vala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ namespace ExerciseTimer {
2424
this.close();
2525
}
2626

27+
[GtkCallback]
28+
private void on_cancel_clicked() {
29+
this.close();
30+
}
31+
2732
private TrainingSetup setup;
2833
[GtkChild]
2934
private unowned Adw.EntryRow name_row;

src/Window.vala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ namespace ExerciseTimer {
1515

1616
[GtkCallback]
1717
private void on_add_training() {
18-
training_list_stack.set_visible_child(training_list_scrolled);
19-
var row = new TrainingListRow(){
20-
Setup = new TrainingSetup(){ Title = "Sample Exercise %d".printf(i++), WarmupSec = 5, ExerciseSec = 30, RestSec = 10, Sets = 4 }
21-
};
22-
row.Deleted.connect(on_training_deleted);
23-
training_listbox.append(row);
18+
var editor_dialog = new TrainingEditor(default_setup);
19+
editor_dialog.Applied.connect((new_setup) => {
20+
training_list_stack.set_visible_child(training_list_scrolled);
21+
var row = new TrainingListRow(){
22+
Setup = new_setup
23+
};
24+
row.Deleted.connect(on_training_deleted);
25+
training_listbox.append(row);
26+
});
27+
editor_dialog.present(this);
2428
}
2529

2630
private void on_training_deleted(Gtk.Widget row) {
@@ -39,6 +43,6 @@ namespace ExerciseTimer {
3943
[GtkChild]
4044
private unowned Gtk.ListBox training_listbox;
4145

42-
private int i = 0;
46+
private static TrainingSetup default_setup = new TrainingSetup(){ Title = "Exercise", WarmupSec = 5, ExerciseSec = 30, RestSec = 10, Sets = 4 };
4347
}
4448
}

0 commit comments

Comments
 (0)