Skip to content

Commit 8b56449

Browse files
committed
Moved button for deleting subject to edit dialog
1 parent c6c58d4 commit 8b56449

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

src/application.vala

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MyApp : Adw.Application {
2323
{ "preferences", this.on_preferences_action },
2424
{ "help", this.on_help_action },
2525
{ "about", this.on_about_action },
26-
{ "newsubject", this.on_newsubject_action}
26+
{ "newsubject", this.on_newsubject_action},
2727
};
2828
this.add_action_entries (action_entries, this);
2929
}
@@ -252,11 +252,27 @@ public class MyApp : Adw.Application {
252252

253253

254254
public void edit_subject_dialog (int index) {
255-
var dialog = new EditSubjectDialog (main_window, subjects[index]);
255+
var dialog = new EditSubjectDialog (main_window, subjects[index], this);
256256

257257
dialog.response.connect ((response_id) => {
258258
if (response_id == Gtk.ResponseType.ACCEPT) {
259-
subjects[index] = dialog.subject;
259+
if(dialog.subject != null) {
260+
subjects[index] = dialog.subject;
261+
} else {
262+
subjects[index] = null;
263+
264+
for (int i = index; i < subjects.length - 1; i++) {
265+
subjects[i] = subjects[i + 1];
266+
}
267+
268+
subjects[subjects.length - 1] = null;
269+
270+
if (subjects[index] != null) {
271+
window_stack_ui (index);
272+
} else {
273+
window_stack_ui (index - 1);
274+
}
275+
}
260276
}
261277
dialog.destroy ();
262278
});
@@ -351,10 +367,6 @@ public class MyApp : Adw.Application {
351367
var edit_subject_button = new EditSubjectButton (i) {margin_end = 20};
352368
bottom_end_box.append (edit_subject_button);
353369

354-
var delete_subject_button = new DeleteSubjectButton (i);
355-
delete_subject_button.add_css_class ("destructive-action");
356-
bottom_end_box.append (delete_subject_button);
357-
358370

359371
//CALL LISTBOX WITH GRADES
360372
window_grade_rows_ui (i);
@@ -369,10 +381,6 @@ public class MyApp : Adw.Application {
369381
new_grade_dialog (new_grade_button.index);
370382
});
371383

372-
delete_subject_button.clicked.connect (() => {
373-
delete_subject (delete_subject_button.index);
374-
});
375-
376384
edit_subject_button.clicked.connect (() => {
377385
edit_subject_dialog (edit_subject_button.index);
378386
});
@@ -504,27 +512,6 @@ public class MyApp : Adw.Application {
504512
}
505513

506514

507-
508-
509-
public void delete_subject (int index) {
510-
subjects[index] = null;
511-
512-
for (int i = index; i < subjects.length - 1; i++) {
513-
subjects[i] = subjects[i + 1];
514-
}
515-
516-
subjects[subjects.length - 1] = null;
517-
518-
if (subjects[index] != null) {
519-
window_stack_ui (index);
520-
} else {
521-
window_stack_ui (index - 1);
522-
}
523-
}
524-
525-
526-
527-
528515
protected override void activate () {
529516
main_window = new Adw.ApplicationWindow (this) {
530517
default_height = 600,

src/edit-subject-button.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ public class EditSubjectButton : Gtk.Button {
66
index = i;
77
halign = END;
88
}
9-
}
9+
}

src/edit-subject-dialog.vala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ public class EditSubjectDialog : Gtk.Dialog {
22
public Subject subject;
33
public Gtk.ScrolledWindow scroll_container;
44

5-
public EditSubjectDialog (Adw.ApplicationWindow parent, Subject s) {
5+
public EditSubjectDialog (Adw.ApplicationWindow parent, Subject s, Adw.Application app) {
66
Object (
77
modal: true,
88
title: "Edit Subject",
@@ -48,6 +48,24 @@ public class EditSubjectDialog : Gtk.Dialog {
4848
};
4949
bottom_box.append (new_cat_button);
5050

51+
var bottom_delete_box = new Gtk.Box (HORIZONTAL, 0) {
52+
margin_start = 20,
53+
margin_end = 20,
54+
margin_bottom = 20,
55+
homogeneous = true
56+
};
57+
main_box.append(bottom_delete_box);
58+
59+
var subject_delete_button = new Gtk.Button.with_label("Delete subject") {
60+
halign = END
61+
};
62+
subject_delete_button.add_css_class("destructive-action");
63+
bottom_delete_box.append(subject_delete_button);
64+
65+
subject_delete_button.clicked.connect (() => {
66+
subject = null;
67+
});
68+
5169
new_cat_button.clicked.connect (() => {
5270
var dialog = new AddCategoryDialog (this);
5371

0 commit comments

Comments
 (0)