Skip to content

Commit

Permalink
Moved button for deleting subject to edit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Dec 14, 2022
1 parent c6c58d4 commit 8b56449
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
51 changes: 19 additions & 32 deletions src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MyApp : Adw.Application {
{ "preferences", this.on_preferences_action },
{ "help", this.on_help_action },
{ "about", this.on_about_action },
{ "newsubject", this.on_newsubject_action}
{ "newsubject", this.on_newsubject_action},
};
this.add_action_entries (action_entries, this);
}
Expand Down Expand Up @@ -252,11 +252,27 @@ public class MyApp : Adw.Application {


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

dialog.response.connect ((response_id) => {
if (response_id == Gtk.ResponseType.ACCEPT) {
subjects[index] = dialog.subject;
if(dialog.subject != null) {
subjects[index] = dialog.subject;
} else {
subjects[index] = null;

for (int i = index; i < subjects.length - 1; i++) {
subjects[i] = subjects[i + 1];
}

subjects[subjects.length - 1] = null;

if (subjects[index] != null) {
window_stack_ui (index);
} else {
window_stack_ui (index - 1);
}
}
}
dialog.destroy ();
});
Expand Down Expand Up @@ -351,10 +367,6 @@ public class MyApp : Adw.Application {
var edit_subject_button = new EditSubjectButton (i) {margin_end = 20};
bottom_end_box.append (edit_subject_button);

var delete_subject_button = new DeleteSubjectButton (i);
delete_subject_button.add_css_class ("destructive-action");
bottom_end_box.append (delete_subject_button);


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

delete_subject_button.clicked.connect (() => {
delete_subject (delete_subject_button.index);
});

edit_subject_button.clicked.connect (() => {
edit_subject_dialog (edit_subject_button.index);
});
Expand Down Expand Up @@ -504,27 +512,6 @@ public class MyApp : Adw.Application {
}




public void delete_subject (int index) {
subjects[index] = null;

for (int i = index; i < subjects.length - 1; i++) {
subjects[i] = subjects[i + 1];
}

subjects[subjects.length - 1] = null;

if (subjects[index] != null) {
window_stack_ui (index);
} else {
window_stack_ui (index - 1);
}
}




protected override void activate () {
main_window = new Adw.ApplicationWindow (this) {
default_height = 600,
Expand Down
2 changes: 1 addition & 1 deletion src/edit-subject-button.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class EditSubjectButton : Gtk.Button {
index = i;
halign = END;
}
}
}
20 changes: 19 additions & 1 deletion src/edit-subject-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public class EditSubjectDialog : Gtk.Dialog {
public Subject subject;
public Gtk.ScrolledWindow scroll_container;

public EditSubjectDialog (Adw.ApplicationWindow parent, Subject s) {
public EditSubjectDialog (Adw.ApplicationWindow parent, Subject s, Adw.Application app) {
Object (
modal: true,
title: "Edit Subject",
Expand Down Expand Up @@ -48,6 +48,24 @@ public class EditSubjectDialog : Gtk.Dialog {
};
bottom_box.append (new_cat_button);

var bottom_delete_box = new Gtk.Box (HORIZONTAL, 0) {
margin_start = 20,
margin_end = 20,
margin_bottom = 20,
homogeneous = true
};
main_box.append(bottom_delete_box);

var subject_delete_button = new Gtk.Button.with_label("Delete subject") {
halign = END
};
subject_delete_button.add_css_class("destructive-action");
bottom_delete_box.append(subject_delete_button);

subject_delete_button.clicked.connect (() => {
subject = null;
});

new_cat_button.clicked.connect (() => {
var dialog = new AddCategoryDialog (this);

Expand Down

0 comments on commit 8b56449

Please sign in to comment.