From 3ca8bdf673a8a373194284e16e184dafb6f8755b Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 15 Sep 2023 19:59:09 +0500 Subject: [PATCH 01/11] library: Ported ViewSwitcher to rust --- src/Library/demos/View Switcher/code.rs | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Library/demos/View Switcher/code.rs diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs new file mode 100644 index 000000000..765966916 --- /dev/null +++ b/src/Library/demos/View Switcher/code.rs @@ -0,0 +1,47 @@ +use crate::workbench; +use adw::prelude::*; + +use crate::glib::clone; +use gtk::glib; +use std::cell::Cell; +use std::rc::Rc; + +pub fn main() { + let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap(); + let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap(); + + let notification_count = Rc::new(Cell::new(5)); + notifications_page.set_badge_number(notification_count.get()); + + for _ in 0..notification_count.get() { + let notification_row = adw::ActionRow::builder() + .title("Notification") + .selectable(false) + .build(); + + let button = gtk::Button::builder() + .halign(gtk::Align::Center) + .valign(gtk::Align::Center) + .margin_top(10) + .margin_bottom(10) + .icon_name("check-plain-symbolic") + .build(); + + button.connect_clicked(clone!( + @weak notification_count, @weak notifications_page, + @weak notification_list, @weak notification_row => move |_| { + notification_count.set(notification_count.get() - 1); + notifications_page.set_badge_number(notification_count.get()); + notification_list.remove(¬ification_row); + + if notifications_page.badge_number() == 0 { + notifications_page.set_needs_attention(false); + } + } + )); + + notification_row.add_suffix(&button); + + notification_list.append(¬ification_row); + } +} From 6b4b2a8d28206c568730fa47595af3aab72fcdcb Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 15 Sep 2023 20:00:02 +0500 Subject: [PATCH 02/11] library: Moved `title` --- src/Library/demos/View Switcher/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Library/demos/View Switcher/main.js b/src/Library/demos/View Switcher/main.js index b1981216c..d7f8d5ed3 100644 --- a/src/Library/demos/View Switcher/main.js +++ b/src/Library/demos/View Switcher/main.js @@ -9,11 +9,10 @@ notifications_page.badge_number = notification_count; for (let i = 0; i < notification_count; i++) { const notification_row = new Adw.ActionRow({ + title: "Notification", selectable: false, }); - notification_row.title = "Notification"; - const button = new Gtk.Button({ halign: "center", valign: "center", From cb771e6892b7ecf6a3f8ae003f77422d09b5b201 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 15 Sep 2023 20:41:25 +0500 Subject: [PATCH 03/11] Updated refrences to `strong` --- src/Library/demos/View Switcher/code.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs index 765966916..d88099f1b 100644 --- a/src/Library/demos/View Switcher/code.rs +++ b/src/Library/demos/View Switcher/code.rs @@ -2,7 +2,6 @@ use crate::workbench; use adw::prelude::*; use crate::glib::clone; -use gtk::glib; use std::cell::Cell; use std::rc::Rc; @@ -28,8 +27,8 @@ pub fn main() { .build(); button.connect_clicked(clone!( - @weak notification_count, @weak notifications_page, - @weak notification_list, @weak notification_row => move |_| { + @strong notification_count, @strong notifications_page, + @strong notification_list, @strong notification_row => move |_| { notification_count.set(notification_count.get() - 1); notifications_page.set_badge_number(notification_count.get()); notification_list.remove(¬ification_row); From e07a92ad9a49ef9d5291fd64c5e34de54aff6b66 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 15 Sep 2023 21:00:19 +0500 Subject: [PATCH 04/11] Updated `notification_count` to an integer value --- src/Library/demos/View Switcher/code.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs index d88099f1b..6dbb115b1 100644 --- a/src/Library/demos/View Switcher/code.rs +++ b/src/Library/demos/View Switcher/code.rs @@ -1,18 +1,17 @@ use crate::workbench; use adw::prelude::*; -use crate::glib::clone; -use std::cell::Cell; -use std::rc::Rc; +use glib::clone; +use gtk::glib; pub fn main() { let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap(); let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap(); - let notification_count = Rc::new(Cell::new(5)); - notifications_page.set_badge_number(notification_count.get()); + let notification_count = 5; + notifications_page.set_badge_number(notification_count); - for _ in 0..notification_count.get() { + for _ in 0..notification_count { let notification_row = adw::ActionRow::builder() .title("Notification") .selectable(false) @@ -29,8 +28,7 @@ pub fn main() { button.connect_clicked(clone!( @strong notification_count, @strong notifications_page, @strong notification_list, @strong notification_row => move |_| { - notification_count.set(notification_count.get() - 1); - notifications_page.set_badge_number(notification_count.get()); + notifications_page.set_badge_number(notifications_page.badge_number() - 1); notification_list.remove(¬ification_row); if notifications_page.badge_number() == 0 { From 2dcad419a332d5c29b16caba38fa3150a9f1604f Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 15 Sep 2023 21:07:36 +0500 Subject: [PATCH 05/11] Removed the unused reference --- src/Library/demos/View Switcher/code.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs index 6dbb115b1..966cd294b 100644 --- a/src/Library/demos/View Switcher/code.rs +++ b/src/Library/demos/View Switcher/code.rs @@ -26,8 +26,8 @@ pub fn main() { .build(); button.connect_clicked(clone!( - @strong notification_count, @strong notifications_page, - @strong notification_list, @strong notification_row => move |_| { + @strong notifications_page, @strong notification_list, + @strong notification_row => move |_| { notifications_page.set_badge_number(notifications_page.badge_number() - 1); notification_list.remove(¬ification_row); From 702577a9f78c5a0a03a9940c9d567ca8a0a24b43 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 15 Sep 2023 22:34:16 +0500 Subject: [PATCH 06/11] Works with weak refrences now as well --- src/Library/demos/View Switcher/code.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs index 966cd294b..7950b039c 100644 --- a/src/Library/demos/View Switcher/code.rs +++ b/src/Library/demos/View Switcher/code.rs @@ -26,8 +26,7 @@ pub fn main() { .build(); button.connect_clicked(clone!( - @strong notifications_page, @strong notification_list, - @strong notification_row => move |_| { + @weak notifications_page, @weak notification_list, @weak notification_row => move |_| { notifications_page.set_badge_number(notifications_page.badge_number() - 1); notification_list.remove(¬ification_row); From fbd7302f73d80bc70224ee0412d33bc98bf7b07d Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Sat, 16 Sep 2023 21:46:12 +0500 Subject: [PATCH 07/11] Sync JS --- src/Library/demos/View Switcher/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/View Switcher/main.js b/src/Library/demos/View Switcher/main.js index d7f8d5ed3..ba0a12e05 100644 --- a/src/Library/demos/View Switcher/main.js +++ b/src/Library/demos/View Switcher/main.js @@ -22,7 +22,7 @@ for (let i = 0; i < notification_count; i++) { }); button.connect("clicked", () => { - notifications_page.badge_number = --notification_count; + notifications_page.badge_number -= 1; notification_list.remove(notification_row); if (notifications_page.badge_number === 0) { From 56887ff99c6977edb4541d3840a6cb790801888d Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Sun, 17 Sep 2023 21:44:11 +0500 Subject: [PATCH 08/11] Changed indent to `2` to match other varients --- src/Library/demos/View Switcher/code.rs | 70 ++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs index 7950b039c..69ed8e4bf 100644 --- a/src/Library/demos/View Switcher/code.rs +++ b/src/Library/demos/View Switcher/code.rs @@ -5,39 +5,39 @@ use glib::clone; use gtk::glib; pub fn main() { - let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap(); - let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap(); - - let notification_count = 5; - notifications_page.set_badge_number(notification_count); - - for _ in 0..notification_count { - let notification_row = adw::ActionRow::builder() - .title("Notification") - .selectable(false) - .build(); - - let button = gtk::Button::builder() - .halign(gtk::Align::Center) - .valign(gtk::Align::Center) - .margin_top(10) - .margin_bottom(10) - .icon_name("check-plain-symbolic") - .build(); - - button.connect_clicked(clone!( - @weak notifications_page, @weak notification_list, @weak notification_row => move |_| { - notifications_page.set_badge_number(notifications_page.badge_number() - 1); - notification_list.remove(¬ification_row); - - if notifications_page.badge_number() == 0 { - notifications_page.set_needs_attention(false); - } - } - )); - - notification_row.add_suffix(&button); - - notification_list.append(¬ification_row); - } + let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap(); + let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap(); + + let notification_count = 5; + notifications_page.set_badge_number(notification_count); + + for _ in 0..notification_count { + let notification_row = adw::ActionRow::builder() + .title("Notification") + .selectable(false) + .build(); + + let button = gtk::Button::builder() + .halign(gtk::Align::Center) + .valign(gtk::Align::Center) + .margin_top(10) + .margin_bottom(10) + .icon_name("check-plain-symbolic") + .build(); + + button.connect_clicked(clone!( + @weak notifications_page, @weak notification_list, @weak notification_row => move |_| { + notifications_page.set_badge_number(notifications_page.badge_number() - 1); + notification_list.remove(¬ification_row); + + if notifications_page.badge_number() == 0 { + notifications_page.set_needs_attention(false); + } + } + )); + + notification_row.add_suffix(&button); + + notification_list.append(¬ification_row); + } } From 67d2ae62ee9c18e71495c142f83336daa83c3f80 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Sun, 17 Sep 2023 21:44:39 +0500 Subject: [PATCH 09/11] Sync vala --- src/Library/demos/View Switcher/main.vala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Library/demos/View Switcher/main.vala b/src/Library/demos/View Switcher/main.vala index 89e32b162..ddec60ecc 100644 --- a/src/Library/demos/View Switcher/main.vala +++ b/src/Library/demos/View Switcher/main.vala @@ -3,17 +3,16 @@ public void main() { var notifications_page = workbench.builder.get_object("page3") as Adw.ViewStackPage; var notification_list = workbench.builder.get_object("notification_list") as Gtk.ListBox; - + int notification_count = 5; - notifications_page.badge_number = notification_count; - + for (int i = 0; i < notification_count; i++){ var notification_row = new Adw.ActionRow(){ title = "Notification", selectable = false, }; - + var button = new Gtk.Button(){ halign = Gtk.Align.CENTER, valign = Gtk.Align.CENTER, @@ -21,15 +20,16 @@ public void main() { margin_bottom = 10, icon_name = "check-plain-symbolic" }; - + button.clicked.connect( () => { - notifications_page.badge_number = --notification_count; + notifications_page.badge_number -= 1; notification_list.remove(notification_row); - if (notifications_page.badge_number == 0) + if (notifications_page.badge_number == 0) { notifications_page.needs_attention = false; + } }); - + notification_row.add_suffix(button); notification_list.append(notification_row); From 8985bab8e76761e19fa4527c176bd020058f0ea9 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Sun, 17 Sep 2023 23:39:22 +0500 Subject: [PATCH 10/11] Test says so --- src/Library/demos/View Switcher/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/View Switcher/main.js b/src/Library/demos/View Switcher/main.js index ba0a12e05..43f1edf87 100644 --- a/src/Library/demos/View Switcher/main.js +++ b/src/Library/demos/View Switcher/main.js @@ -4,7 +4,7 @@ import Gtk from "gi://Gtk"; const notifications_page = workbench.builder.get_object("page3"); const notification_list = workbench.builder.get_object("notification_list"); -let notification_count = 5; +const notification_count = 5; notifications_page.badge_number = notification_count; for (let i = 0; i < notification_count; i++) { From 285acaf62589cd955aabd393d9893e9c99f8db3d Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Sun, 17 Sep 2023 23:56:52 +0500 Subject: [PATCH 11/11] Revert "Changed indent to `2` to match other varients" This reverts commit 56887ff99c6977edb4541d3840a6cb790801888d. --- src/Library/demos/View Switcher/code.rs | 70 ++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Library/demos/View Switcher/code.rs b/src/Library/demos/View Switcher/code.rs index 69ed8e4bf..7950b039c 100644 --- a/src/Library/demos/View Switcher/code.rs +++ b/src/Library/demos/View Switcher/code.rs @@ -5,39 +5,39 @@ use glib::clone; use gtk::glib; pub fn main() { - let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap(); - let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap(); - - let notification_count = 5; - notifications_page.set_badge_number(notification_count); - - for _ in 0..notification_count { - let notification_row = adw::ActionRow::builder() - .title("Notification") - .selectable(false) - .build(); - - let button = gtk::Button::builder() - .halign(gtk::Align::Center) - .valign(gtk::Align::Center) - .margin_top(10) - .margin_bottom(10) - .icon_name("check-plain-symbolic") - .build(); - - button.connect_clicked(clone!( - @weak notifications_page, @weak notification_list, @weak notification_row => move |_| { - notifications_page.set_badge_number(notifications_page.badge_number() - 1); - notification_list.remove(¬ification_row); - - if notifications_page.badge_number() == 0 { - notifications_page.set_needs_attention(false); - } - } - )); - - notification_row.add_suffix(&button); - - notification_list.append(¬ification_row); - } + let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap(); + let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap(); + + let notification_count = 5; + notifications_page.set_badge_number(notification_count); + + for _ in 0..notification_count { + let notification_row = adw::ActionRow::builder() + .title("Notification") + .selectable(false) + .build(); + + let button = gtk::Button::builder() + .halign(gtk::Align::Center) + .valign(gtk::Align::Center) + .margin_top(10) + .margin_bottom(10) + .icon_name("check-plain-symbolic") + .build(); + + button.connect_clicked(clone!( + @weak notifications_page, @weak notification_list, @weak notification_row => move |_| { + notifications_page.set_badge_number(notifications_page.badge_number() - 1); + notification_list.remove(¬ification_row); + + if notifications_page.badge_number() == 0 { + notifications_page.set_needs_attention(false); + } + } + )); + + notification_row.add_suffix(&button); + + notification_list.append(¬ification_row); + } }