Skip to content

Commit

Permalink
Works a bit better now
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Nov 28, 2023
1 parent 82c09a2 commit 50ca8f0
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 207 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ executable(
'src' / 'edit-subject-button.vala',
'src' / 'edit-subject-dialog.vala',
'src' / 'add-category-dialog.vala',
'src' / 'subject-manager.vala',
'src' / 'subject-page.vala',
'src' / 'subject-parser.vala',
'src' / 'window.vala',
Expand Down
116 changes: 41 additions & 75 deletions src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ public class MyApp : Adw.Application {


public void read_data () {
subjects = new Subject[number_of_subjects];
subjects = new Subject[number_of_subjects];

for (int i = 0; i < subjects.length && FileUtils.test (Environment.get_user_data_dir () + @"/gradebook/savedata/subjectsave$i", FileTest.EXISTS); i++) {
File file = File.new_for_path (Environment.get_user_data_dir () + @"/gradebook/savedata/subjectsave$i");

var parser = new SubjectParser ();
Subject sub = parser.to_object (read_from_file (file));
subjects[i] = sub;
}
for (int i = 0; i < subjects.length && FileUtils.test (Environment.get_user_data_dir () + @"/gradebook/savedata/subjectsave$i", FileTest.EXISTS); i++) {
File file = File.new_for_path (Environment.get_user_data_dir () + @"/gradebook/savedata/subjectsave$i");

var parser = new SubjectParser ();
Subject sub = parser.to_object (read_from_file (file));
subjects[i] = sub;
}

}

public void write_data () {
int z = 0;
File dir = File.new_for_path (Environment.get_user_data_dir () + "/gradebook/savedata/");
Expand Down Expand Up @@ -186,24 +186,24 @@ public class MyApp : Adw.Application {



public void new_grade (int index, string grade, string note, int c) {
bool worked = false;
// public void new_grade (int index, string grade, string note, int c) {
// bool worked = false;

for (int i = 0; i < subjects[index].grades.length; i++) {
if (subjects[index].grades[i] == null) {
subjects[index].grades[i] = new Grade (grade, note, c);
i = subjects[index].grades.length;
worked = true;
}
}
// for (int i = 0; i < subjects[index].grades.length; i++) {
// if (subjects[index].grades[i] == null) {
// subjects[index].grades[i] = new Grade (grade, note, c);
// i = subjects[index].grades.length;
// worked = true;
// }
// }


if (worked == false) {
print ("no more grades available");
} else {
window_grade_rows_ui (index);
}
}
// if (worked == false) {
// print ("no more grades available");
// } else {
// window_grade_rows_ui (index);
// }
// }



Expand All @@ -230,59 +230,25 @@ public class MyApp : Adw.Application {



public void new_grade_dialog (int index) {

if (subjects[index].categories[0] != null){
var dialog = new NewGradeDialog (main_window, subjects, index);

dialog.response.connect ((response_id) => {
if (response_id == "add") {
dialog.set_variables ();
new_grade (index, dialog.get_grade (), dialog.get_note (), (int) dialog.choose_cat_row.get_selected ());
}
dialog.destroy ();
});
dialog.present ();
} else {
var ErrorDialog = new Adw.MessageDialog (main_window, _("Error"), _("This subject has no categories. Add at least one category in order to add a grade."));
ErrorDialog.add_css_class ("error");
ErrorDialog.add_response ("ok", _("OK"));
ErrorDialog.present ();
}
}



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

dialog.close_request.connect ((response_id) => {
if (dialog.accept) {
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 ();
return true;
});
dialog.present ();
}

// public void new_grade_dialog (int index) {
// if (subjects[index].categories[0] != null){
// var dialog = new NewGradeDialog (main_window, subjects, index);

// dialog.response.connect ((response_id) => {
// if (response_id == "add") {
// dialog.set_variables ();
// new_grade (index, dialog.get_grade (), dialog.get_note (), (int) dialog.choose_cat_row.get_selected ());
// }
// dialog.destroy ();
// });
// dialog.present ();
// } else {
// var ErrorDialog = new Adw.MessageDialog (main_window, _("Error"), _("This subject has no categories. Add at least one category in order to add a grade."));
// ErrorDialog.add_css_class ("error");
// ErrorDialog.add_response ("ok", _("OK"));
// ErrorDialog.present ();
// }
// }


public void window_stack_ui (int index) {}
Expand Down
118 changes: 48 additions & 70 deletions src/edit-subject-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ public class EditSubjectDialog : Adw.Window {
public Gtk.Box main_box;
public Adw.EntryRow name_entry_box;
private Gtk.Button new_cat_button;
private Gtk.Button subject_delete_button;
private Gtk.Button subject_delete_button;
public bool accept = false;
public Subject subject;
public Subject subject;

public EditSubjectDialog (Adw.ApplicationWindow parent, Subject s, Adw.Application app) {
public EditSubjectDialog (Adw.ApplicationWindow parent, Subject s) {
Object (
modal: true,
title: _("Edit Subject"),
Expand All @@ -18,64 +18,64 @@ public Subject subject;
height_request: 360
);

subject = s;
subject = s;

categories = new Category[5];

var tbv = new Adw.ToolbarView ();
this.set_content (tbv);
var tbv = new Adw.ToolbarView ();
this.set_content (tbv);

var hb = new Adw.HeaderBar () {
show_end_title_buttons = false,
show_start_title_buttons = false,
};
var hb = new Adw.HeaderBar () {
show_end_title_buttons = false,
show_start_title_buttons = false,
};

var cb = new Gtk.Button.with_label (_("Cancel"));
cb.clicked.connect (() => {
accept = false;
this.close ();
});
var cb = new Gtk.Button.with_label (_("Cancel"));
cb.clicked.connect (() => {
accept = false;
this.close ();
});

var ab = new Gtk.Button.with_label (_("Save")) { css_classes = { "suggested-action" } };
ab.clicked.connect (() => {
accept = true;
this.close ();
});
var ab = new Gtk.Button.with_label (_("Save")) { css_classes = { "suggested-action" } };
ab.clicked.connect (() => {
accept = true;
this.close ();
});

hb.pack_start (cb);
hb.pack_end (ab);
hb.pack_start (cb);
hb.pack_end (ab);

tbv.add_top_bar (hb);
tbv.add_top_bar (hb);

Adw.Clamp ac = new Adw.Clamp () {
margin_start = 19,
margin_end = 19,
maximum_size = 500,
tightening_threshold = 400
};

var sw = new Gtk.ScrolledWindow ();
main_box = new Gtk.Box (VERTICAL, 0) {
margin_top = 20,
margin_bottom = 20
};
tbv.set_content (sw);

this.set_content (tbv);
sw.set_child (ac);
ac.set_child (main_box);
margin_start = 19,
margin_end = 19,
maximum_size = 500,
tightening_threshold = 400
};

var sw = new Gtk.ScrolledWindow ();
main_box = new Gtk.Box (VERTICAL, 0) {
margin_top = 20,
margin_bottom = 20
};
tbv.set_content (sw);

this.set_content (tbv);
sw.set_child (ac);
ac.set_child (main_box);

load_list ();

subject_delete_button = new Gtk.Button.with_label (_("Delete Subject…")) { hexpand = false, halign = Gtk.Align.START, margin_top = 20 };
subject_delete_button = new Gtk.Button.with_label (_("Delete Subject…")) { hexpand = false, halign = Gtk.Align.START, margin_top = 20 };
subject_delete_button.add_css_class ("destructive-action");
main_box.append (subject_delete_button);
main_box.append (subject_delete_button);

subject_delete_button.clicked.connect (() => {
string n = s.name;
///TRANSLATORS: %s is the name of a school subject
var message_dialog = new Adw.MessageDialog( this, _("Delete %s?").printf( n), null);
message_dialog.set_body (_("If you delete %s, its information will be deleted permanently.").printf( n));
message_dialog.set_body (_("If you delete %s, its information will be deleted permanently.").printf( n));
message_dialog.add_response ("0", _("Cancel"));
message_dialog.add_response ("1", _("Delete"));
message_dialog.set_response_appearance ("1", DESTRUCTIVE);
Expand All @@ -92,28 +92,6 @@ public Subject subject;
}
});
});
/*var cat_list_box = new Gtk.ListBox ();
cat_list_box.add_css_class("boxed-list");
var scroll_main_box = new Gtk.ScrolledWindow () {
margin_bottom = 20,
margin_top = 20,
margin_start = 20,
margin_end = 20,
hexpand = true,
vexpand = true
};
scroll_main_box.set_child(cat_list_box);
main_box.append(scroll_main_box);
for (int i = 0; i < subject.categories.length && subject.categories[i] != null; i++) {
var cat_row = new Adw.ActionRow () {
title = subject.categories[i].name,
subtitle = subject.categories[i].percentage.to_string () + "%"
};
cat_list_box.append(cat_row);
}*/
}

public void add_cat (string n, double p) {
Expand All @@ -127,8 +105,8 @@ public Subject subject;
}

public void load_list () {
main_box.remove (main_box.get_first_child ());
main_box.remove (main_box.get_first_child ());
main_box.remove (main_box.get_first_child ());
main_box.remove (main_box.get_first_child ());

var cat_list_box = new Adw.PreferencesGroup () {
margin_start = 1,
Expand All @@ -138,13 +116,13 @@ public Subject subject;
title = _("Subject Categories"),
};

new_cat_button = new Gtk.Button () {
new_cat_button = new Gtk.Button () {
icon_name = "list-add-symbolic",
tooltip_text = _("Add New Category"),
css_classes = { "flat" }
};

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

dialog.response.connect ((response_id) => {
Expand All @@ -157,10 +135,10 @@ public Subject subject;
dialog.present ();
});

cat_list_box.set_header_suffix (new_cat_button);
cat_list_box.set_header_suffix (new_cat_button);

main_box.append (cat_list_box);
main_box.append (subject_delete_button);
main_box.append (subject_delete_button);

for (int i = 0; i < subject.categories.length && subject.categories[i] != null; i++) {
var cat_row = new Adw.ActionRow () {
Expand Down
22 changes: 11 additions & 11 deletions src/new-grade-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class NewGradeDialog : Adw.MessageDialog {
//private Adw.EntryRow note_entry;
public Adw.ComboRow choose_cat_row;

public NewGradeDialog (Adw.ApplicationWindow parent, Subject[] subjects, int index) {
public NewGradeDialog (Adw.ApplicationWindow parent, Subject subject) {
Object (
heading: _("Add New Grade"),
transient_for: parent,
Expand All @@ -17,28 +17,28 @@ public class NewGradeDialog : Adw.MessageDialog {
this.add_response ("cancel", _("Cancel"));
this.add_response ("add", _("Add"));
this.set_close_response ("cancel");
this.set_response_appearance ("add", SUGGESTED);
this.set_response_enabled ("add", false);
this.set_response_appearance ("add", SUGGESTED);
this.set_response_enabled ("add", false);

var grade_adjustment = new Gtk.Adjustment (0, 0, 100, 1, 0, 0);

//CATEGORY
var cat_model = new Gtk.StringList (null);
for (int i = 0; subjects[index].categories[i] != null; i++) {
cat_model.append (subjects[index].categories[i].name);
for (int i = 0; subject.categories[i] != null; i++) {
cat_model.append (subject.categories[i].name);
}

grade_spinbutton = new Adw.SpinRow (grade_adjustment, 1, 2) {
title = _("Grade")
grade_spinbutton = new Adw.SpinRow (grade_adjustment, 1, 2) {
title = _("Grade")
};
choose_cat_row = new Adw.ComboRow () {
title = _("Category"),
model = cat_model
};
entry = new Adw.EntryRow () {
input_hints = SPELLCHECK,
title = _("Note")
};
entry = new Adw.EntryRow () {
input_hints = SPELLCHECK,
title = _("Note")
};
var preferences_group = new Adw.PreferencesGroup ();
preferences_group.add (grade_spinbutton);
preferences_group.add (choose_cat_row);
Expand Down
Loading

0 comments on commit 50ca8f0

Please sign in to comment.