From 2e0d2f02605b2ff55070489e0b552092336000cf Mon Sep 17 00:00:00 2001 From: Leonhard Date: Tue, 28 Nov 2023 22:08:00 +0100 Subject: [PATCH] Formatting lol --- src/add-category-dialog.vala | 4 +-- src/application.vala | 66 ++++++++++++++++++------------------ src/edit-subject-dialog.vala | 24 ++++++------- src/grade.vala | 2 +- src/new-subject-dialog.vala | 12 +++---- src/newgradebutton.vala | 2 +- src/subject-parser.vala | 20 +++++------ 7 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/add-category-dialog.vala b/src/add-category-dialog.vala index 2121f6f..57110b2 100644 --- a/src/add-category-dialog.vala +++ b/src/add-category-dialog.vala @@ -16,8 +16,8 @@ public class AddCategoryDialog : Adw.MessageDialog { this.set_response_enabled ("add", false); this.set_close_response ("cancel"); - var lb = new Gtk.ListBox() { css_classes = { "boxed-list" } }; - name_entry = new Adw.EntryRow() { + var lb = new Gtk.ListBox () { css_classes = { "boxed-list" } }; + name_entry = new Adw.EntryRow () { input_hints = Gtk.InputHints.SPELLCHECK, title = _("Category Name") }; diff --git a/src/application.vala b/src/application.vala index a1e5be1..e4cf978 100644 --- a/src/application.vala +++ b/src/application.vala @@ -14,7 +14,7 @@ public class MyApp : Adw.Application { - public MyApp() { + public MyApp () { Object ( application_id: "io.github.leolost2605.gradebook", flags: ApplicationFlags.FLAGS_NONE @@ -42,7 +42,7 @@ public class MyApp : Adw.Application { public void on_help_action () { - Gtk.show_uri(main_window, "https://github.com/leolost2605/Gradebook/wiki", 0); + Gtk.show_uri (main_window, "https://github.com/leolost2605/Gradebook/wiki", 0); } @@ -51,10 +51,10 @@ public class MyApp : Adw.Application { public void on_newsubject_action () { var dialog = new NewSubjectDialog (main_window); dialog.close_request.connect (() => { - if(dialog.accept) { + if (dialog.accept) { new_subject (dialog.name_entry_box.get_text (), dialog.categories); } - dialog.destroy(); + dialog.destroy (); return true; }); dialog.present (); @@ -146,14 +146,14 @@ public class MyApp : Adw.Application { } - public void read_data() { + public void read_data () { 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)); + var parser = new SubjectParser (); + Subject sub = parser.to_object (read_from_file (file)); subjects[i] = sub; } @@ -161,19 +161,19 @@ public class MyApp : Adw.Application { public void write_data () { int z = 0; - File dir = File.new_for_path(Environment.get_user_data_dir () + "/gradebook/savedata/"); - if(!dir.query_exists ()) { + File dir = File.new_for_path (Environment.get_user_data_dir () + "/gradebook/savedata/"); + if (!dir.query_exists ()) { try { - dir.make_directory_with_parents(); + dir.make_directory_with_parents (); } catch (Error e) { - print(e.message); + print (e.message); } } for (int i = 0; i < subjects.length && subjects[i] != null; i++) { var parser = new SubjectParser (); File file = File.new_for_path (Environment.get_user_data_dir () + @"/gradebook/savedata/subjectsave$i"); - write_to_file (file, parser.to_string(subjects[i])); + write_to_file (file, parser.to_string (subjects[i])); z = i + 1; } for (int i = z; i < subjects.length && FileUtils.test (Environment.get_user_data_dir () + @"/gradebook/savedata/subjectsave$i", FileTest.EXISTS); i++) { @@ -182,10 +182,10 @@ public class MyApp : Adw.Application { try { file.delete (); } catch (Error e) { - print(e.message); + print (e.message); } } - main_window.destroy(); + main_window.destroy (); } @@ -236,7 +236,7 @@ public class MyApp : Adw.Application { public void new_grade_dialog (int index) { - if(subjects[index].categories[0] != null){ + if (subjects[index].categories[0] != null){ var dialog = new NewGradeDialog (main_window, subjects, index); dialog.response.connect ((response_id) => { @@ -248,10 +248,10 @@ public class MyApp : Adw.Application { }); 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(); + 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 (); } } @@ -262,7 +262,7 @@ public class MyApp : Adw.Application { dialog.close_request.connect ((response_id) => { if (dialog.accept) { - if(dialog.subject != null) { + if (dialog.subject != null) { subjects[index] = dialog.subject; } else { subjects[index] = null; @@ -304,7 +304,7 @@ public class MyApp : Adw.Application { var menu_button = new Gtk.MenuButton () { icon_name = "open-menu-symbolic" }; - header_bar.pack_end(menu_button); + header_bar.pack_end (menu_button); var menu = new Menu (); var menu_section1 = new Menu (); @@ -342,7 +342,7 @@ public class MyApp : Adw.Application { stack_box.add_top_bar (header_bar); - var placeholderlabel = new Adw.StatusPage() { + var placeholderlabel = new Adw.StatusPage () { vexpand = true, hexpand = true, title = _("No Subjects"), @@ -353,7 +353,7 @@ public class MyApp : Adw.Application { } else { //Create StackPages for every subject - for(int i = 0; subjects[i] != null; i++) + for( int i = 0; subjects[i] != null; i++) { subject_boxes[i] = new Adw.ToolbarView (); @@ -363,7 +363,7 @@ public class MyApp : Adw.Application { var menu_button = new Gtk.MenuButton () { icon_name = "open-menu-symbolic" }; - header_bar.pack_end(menu_button); + header_bar.pack_end (menu_button); var menu = new Menu (); var menu_section1 = new Menu (); @@ -424,7 +424,7 @@ public class MyApp : Adw.Application { }; gtk_sw.set_child (adw_c); adw_c.set_child (nyttbox); - + //TOP BOX var top_box = new Gtk.Box (HORIZONTAL, 0) { height_request = 40, @@ -524,7 +524,7 @@ public class MyApp : Adw.Application { main_box.set_content (stack); } - + @@ -553,13 +553,13 @@ public class MyApp : Adw.Application { } else { var list_box = new Gtk.ListBox () {vexpand = false, margin_top = 20}; - list_box.add_css_class("boxed-list"); + list_box.add_css_class ("boxed-list"); //list_box.set_sort_func (sort_list); //list_box.set_filter_func (filter_list); nyttbox.append (list_box); - for(int j = 0; subjects[i].grades[j] != null; j++) { - average[subjects[i].grades[j].cat] += int.parse(subjects[i].grades[j].grade); + for (int j = 0; subjects[i].grades[j] != null; j++) { + average[subjects[i].grades[j].cat] += int.parse (subjects[i].grades[j].grade); number_of_grades[subjects[i].grades[j].cat]++; @@ -607,13 +607,13 @@ public class MyApp : Adw.Application { double percentage_divider = 0; for (int j = 0; j < subjects[i].categories.length && subjects[i].categories[j] != null; j++) { - if(number_of_grades[j] != 0) { + if (number_of_grades[j] != 0) { avg_calculated[j] = average[j] / number_of_grades[j]; final_avg += avg_calculated[j] * subjects[i].categories[j].percentage; percentage_divider += subjects[i].categories[j].percentage; } } - if(percentage_divider != 0) { + if (percentage_divider != 0) { string average_string = "%.2f".printf (final_avg / percentage_divider); avg[i].set_label (average_string); } @@ -665,14 +665,14 @@ public class MyApp : Adw.Application { main_window.add_breakpoint (bpoint); window_stack_ui (0); - + //PRESENT WINDOW main_window.present (); main_window.close_request.connect (() => { main_window.set_visible (false); - write_data(); + write_data (); return true; }); } diff --git a/src/edit-subject-dialog.vala b/src/edit-subject-dialog.vala index b61778b..4f4447d 100644 --- a/src/edit-subject-dialog.vala +++ b/src/edit-subject-dialog.vala @@ -31,13 +31,13 @@ public Subject subject; }; var cb = new Gtk.Button.with_label (_("Cancel")); - cb.clicked.connect(() => { + cb.clicked.connect (() => { accept = false; this.close (); }); var ab = new Gtk.Button.with_label (_("Save")) { css_classes = { "suggested-action" } }; - ab.clicked.connect(() => { + ab.clicked.connect (() => { accept = true; this.close (); }); @@ -67,19 +67,19 @@ public Subject subject; load_list (); - 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); + 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); 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)); + 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.add_response ("0", _("Cancel")); message_dialog.add_response ("1", _("Delete")); message_dialog.set_response_appearance ("1", DESTRUCTIVE); - message_dialog.present(); + message_dialog.present (); message_dialog.response.connect ((id) => { switch (id) { case "0": @@ -118,7 +118,7 @@ public Subject subject; public void add_cat (string n, double p) { for (int i = 0; i < categories.length; i++) { - if(categories[i] == null) { + if (categories[i] == null) { categories[i] = new Category (n, p); i = categories.length; load_list (); @@ -149,7 +149,7 @@ public Subject subject; dialog.response.connect ((response_id) => { if (response_id == "add") { - add_cat(dialog.name_entry.get_text(), dialog.percentage.get_value()); + add_cat (dialog.name_entry.get_text (), dialog.percentage.get_value ()); } dialog.destroy (); }); @@ -159,8 +159,8 @@ public Subject subject; cat_list_box.set_header_suffix (new_cat_button); - main_box.append(cat_list_box); - main_box.append(subject_delete_button); + main_box.append (cat_list_box); + 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 () { diff --git a/src/grade.vala b/src/grade.vala index cfc30aa..e3ff103 100644 --- a/src/grade.vala +++ b/src/grade.vala @@ -2,7 +2,7 @@ public class Grade : Object{ public string grade { get; set; } public string note { get; set; } public int cat { get; set; } - + public Grade (string g, string n, int c) { this.grade = g; this.note = n; diff --git a/src/new-subject-dialog.vala b/src/new-subject-dialog.vala index d8fc5e9..f21ce68 100644 --- a/src/new-subject-dialog.vala +++ b/src/new-subject-dialog.vala @@ -27,13 +27,13 @@ public class NewSubjectDialog : Adw.Window { }; var cb = new Gtk.Button.with_label (_("Cancel")); - cb.clicked.connect(() => { + cb.clicked.connect (() => { accept = false; this.close (); }); var ab = new Gtk.Button.with_label (_("Save")) { css_classes = { "suggested-action" }, sensitive = false }; - ab.clicked.connect(() => { + ab.clicked.connect (() => { accept = true; this.close (); }); @@ -102,7 +102,7 @@ public class NewSubjectDialog : Adw.Window { public void add_cat (string n, double p) { for (int i = 0; i < categories.length; i++) { - if(categories[i] == null) { + if (categories[i] == null) { categories[i] = new Category (n, p); i = categories.length; categories_list_ui (); @@ -135,7 +135,7 @@ public class NewSubjectDialog : Adw.Window { dialog.response.connect ((response_id) => { if (response_id == "add") { - add_cat(dialog.name_entry.get_text(), dialog.percentage.get_value()); + add_cat (dialog.name_entry.get_text (), dialog.percentage.get_value ()); } dialog.destroy (); }); @@ -144,7 +144,7 @@ public class NewSubjectDialog : Adw.Window { }); cat_list_box.set_header_suffix (new_cat_button); - main_box.insert_child_after(cat_list_box, main_box.get_first_child ()); + main_box.insert_child_after (cat_list_box, main_box.get_first_child ()); for (int i = 0; i < categories.length && categories[i] != null; i++) { @@ -152,7 +152,7 @@ public class NewSubjectDialog : Adw.Window { title = categories[i].name, subtitle = categories[i].percentage.to_string () + "%" }; - cat_list_box.add(cat_row); + cat_list_box.add (cat_row); } } } diff --git a/src/newgradebutton.vala b/src/newgradebutton.vala index 074ebef..f0f177c 100644 --- a/src/newgradebutton.vala +++ b/src/newgradebutton.vala @@ -1,6 +1,6 @@ public class NewGradeButton : Gtk.Button{ public int index; - + public NewGradeButton (int i) { index = i; } diff --git a/src/subject-parser.vala b/src/subject-parser.vala index 0e10650..76ef2b9 100644 --- a/src/subject-parser.vala +++ b/src/subject-parser.vala @@ -12,7 +12,7 @@ public class SubjectParser : Object { regex_for_main = new Regex ("%"); regex_for_sub = new Regex ("#"); } catch (Error e) { - print(e.message); + print (e.message); return null; } @@ -20,11 +20,11 @@ public class SubjectParser : Object { var cat_string_arr = new string[10]; var grade_string_arr = new string[10]; - subject_string_arr = regex_for_main.split(str); - cat_string_arr = regex_for_sub.split(subject_string_arr[1]); - grade_string_arr = regex_for_sub.split(subject_string_arr[2]); + subject_string_arr = regex_for_main.split (str); + cat_string_arr = regex_for_sub.split (subject_string_arr[1]); + grade_string_arr = regex_for_sub.split (subject_string_arr[2]); - var result_subject = new Subject(subject_string_arr[0]); + var result_subject = new Subject (subject_string_arr[0]); var cats = new Category[cat_arr_size]; @@ -33,7 +33,7 @@ public class SubjectParser : Object { cats[i] = new Category ("", 0); cats[i].name = cat_string_arr[j1]; j1++; - cats[i].percentage = int.parse(cat_string_arr[j1]); + cats[i].percentage = int.parse (cat_string_arr[j1]); j1++; } @@ -46,7 +46,7 @@ public class SubjectParser : Object { j2++; grades[i].note = grade_string_arr[j2]; j2++; - grades[i].cat = int.parse(grade_string_arr[j2]); + grades[i].cat = int.parse (grade_string_arr[j2]); j2++; } @@ -64,7 +64,7 @@ public class SubjectParser : Object { for (int i = 0; i < sub.categories.length && sub.categories[i] != null; i++) { result = result + sub.categories[i].name + "#"; result = result + sub.categories[i].percentage.to_string (); - if(sub.categories[i + 1] != null) { + if (sub.categories[i + 1] != null) { result = result + "#"; } } @@ -73,8 +73,8 @@ public class SubjectParser : Object { for (int i = 0; i < sub.grades.length && sub.grades[i] != null; i++) { result = result + sub.grades[i].grade + "#"; result = result + sub.grades[i].note + "#"; - result = result + sub.grades[i].cat.to_string() + "#"; - if(sub.grades[i + 1] != null) { + result = result + sub.grades[i].cat.to_string () + "#"; + if (sub.grades[i + 1] != null) { result = result + "#"; } }