[fractal/fractal-next] Use Default for every subclass



commit 0deb8457b098fd6f6b7cbf50a5afa2a233e95887
Author: Julian Hofer <julianhofer gnome org>
Date:   Tue Aug 17 09:45:07 2021 +0200

    Use Default for every subclass
    
    That makes it also easier to see if the derive(Default) macro
    is enough at some point.

 src/application.rs                   | 16 +++++++++-------
 src/components/context_menu_bin.rs   | 20 +++++++++++---------
 src/components/label_with_widgets.rs | 18 ++++++++++--------
 src/window.rs                        | 10 +---------
 4 files changed, 31 insertions(+), 33 deletions(-)
---
diff --git a/src/application.rs b/src/application.rs
index 0137f76d..82ec6f89 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -20,18 +20,20 @@ mod imp {
         pub settings: Settings,
     }
 
+    impl Default for Application {
+        fn default() -> Self {
+            Self {
+                window: Default::default(),
+                settings: Settings::new(config::APP_ID),
+            }
+        }
+    }
+
     #[glib::object_subclass]
     impl ObjectSubclass for Application {
         const NAME: &'static str = "Application";
         type Type = super::Application;
         type ParentType = gtk::Application;
-
-        fn new() -> Self {
-            Self {
-                window: OnceCell::new(),
-                settings: Settings::new(config::APP_ID),
-            }
-        }
     }
 
     impl ObjectImpl for Application {}
diff --git a/src/components/context_menu_bin.rs b/src/components/context_menu_bin.rs
index 10864e9a..fa34bc5f 100644
--- a/src/components/context_menu_bin.rs
+++ b/src/components/context_menu_bin.rs
@@ -18,16 +18,11 @@ mod imp {
         pub popover: gtk::PopoverMenu,
     }
 
-    #[glib::object_subclass]
-    impl ObjectSubclass for ContextMenuBin {
-        const NAME: &'static str = "ContextMenuBin";
-        type Type = super::ContextMenuBin;
-        type ParentType = adw::Bin;
-
-        fn new() -> Self {
+    impl Default for ContextMenuBin {
+        fn default() -> Self {
             Self {
-                click_gesture: TemplateChild::default(),
-                long_press_gesture: TemplateChild::default(),
+                click_gesture: Default::default(),
+                long_press_gesture: Default::default(),
                 // WORKAROUND: there is some issue with creating the popover from the template
                 popover: gtk::PopoverMenuBuilder::new()
                     .position(gtk::PositionType::Bottom)
@@ -36,6 +31,13 @@ mod imp {
                     .build(),
             }
         }
+    }
+
+    #[glib::object_subclass]
+    impl ObjectSubclass for ContextMenuBin {
+        const NAME: &'static str = "ContextMenuBin";
+        type Type = super::ContextMenuBin;
+        type ParentType = adw::Bin;
 
         fn class_init(klass: &mut Self::Class) {
             Self::bind_template(klass);
diff --git a/src/components/label_with_widgets.rs b/src/components/label_with_widgets.rs
index e1ab5037..07f6ce78 100644
--- a/src/components/label_with_widgets.rs
+++ b/src/components/label_with_widgets.rs
@@ -24,14 +24,8 @@ mod imp {
         pub text: RefCell<Option<String>>,
     }
 
-    #[glib::object_subclass]
-    impl ObjectSubclass for LabelWithWidgets {
-        const NAME: &'static str = "LabelWithWidgets";
-        type Type = super::LabelWithWidgets;
-        type ParentType = gtk::Widget;
-        type Interfaces = (gtk::Buildable,);
-
-        fn new() -> Self {
+    impl Default for LabelWithWidgets {
+        fn default() -> Self {
             Self {
                 label: gtk::LabelBuilder::new().wrap(true).build(),
                 widgets: Default::default(),
@@ -42,6 +36,14 @@ mod imp {
         }
     }
 
+    #[glib::object_subclass]
+    impl ObjectSubclass for LabelWithWidgets {
+        const NAME: &'static str = "LabelWithWidgets";
+        type Type = super::LabelWithWidgets;
+        type ParentType = gtk::Widget;
+        type Interfaces = (gtk::Buildable,);
+    }
+
     impl ObjectImpl for LabelWithWidgets {
         fn properties() -> &'static [glib::ParamSpec] {
             use once_cell::sync::Lazy;
diff --git a/src/window.rs b/src/window.rs
index 7485a1d9..b15df917 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -16,7 +16,7 @@ mod imp {
     use super::*;
     use glib::subclass::InitializingObject;
 
-    #[derive(Debug, CompositeTemplate)]
+    #[derive(Debug, CompositeTemplate, Default)]
     #[template(resource = "/org/gnome/FractalNext/window.ui")]
     pub struct Window {
         #[template_child]
@@ -33,14 +33,6 @@ mod imp {
         type Type = super::Window;
         type ParentType = adw::ApplicationWindow;
 
-        fn new() -> Self {
-            Self {
-                main_stack: TemplateChild::default(),
-                login: TemplateChild::default(),
-                sessions: TemplateChild::default(),
-            }
-        }
-
         fn class_init(klass: &mut Self::Class) {
             Self::bind_template(klass);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]