From 0ef8a6ed133768eb8be83b40f7f698dc7de7e947 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 25 Apr 2020 09:56:34 +0300 Subject: [PATCH 1/2] basic_subclass: fix name of our GObject subclasss type Close #307 --- src/bin/basic_subclass.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/basic_subclass.rs b/src/bin/basic_subclass.rs index 51dda1e..10158b7 100644 --- a/src/bin/basic_subclass.rs +++ b/src/bin/basic_subclass.rs @@ -42,7 +42,7 @@ pub struct SimpleWindowPrivate { } impl ObjectSubclass for SimpleWindowPrivate { - const NAME: &'static str = "SimpleWindowPrivate"; + const NAME: &'static str = "SimpleWindow"; type ParentType = gtk::ApplicationWindow; type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; @@ -139,7 +139,7 @@ pub struct SimpleApplicationPrivate { } impl ObjectSubclass for SimpleApplicationPrivate { - const NAME: &'static str = "SimpleApplicationPrivate"; + const NAME: &'static str = "SimpleApplication"; type ParentType = gtk::Application; type Instance = subclass::simple::InstanceStruct; type Class = subclass::simple::ClassStruct; From 6dcd9c9303e6dd33cf6c0b9599f08792fe2f9d05 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sun, 26 Apr 2020 12:22:10 +0300 Subject: [PATCH 2/2] basic_subclass: remove useless code We already have access to the private part of the object. --- src/bin/basic_subclass.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/bin/basic_subclass.rs b/src/bin/basic_subclass.rs index 10158b7..27f31a5 100644 --- a/src/bin/basic_subclass.rs +++ b/src/bin/basic_subclass.rs @@ -165,10 +165,8 @@ impl ApplicationImpl for SimpleApplicationPrivate { // `gio::Application::activate` is what gets called when the // application is launched by the desktop environment and // aksed to present itself. - fn activate(&self, app: &gio::Application) { - let app = app.downcast_ref::().unwrap(); - let priv_ = SimpleApplicationPrivate::from_instance(app); - let window = priv_ + fn activate(&self, _app: &gio::Application) { + let window = self .window .get() .expect("Should always be initiliazed in gio_application_startup"); @@ -187,10 +185,8 @@ impl ApplicationImpl for SimpleApplicationPrivate { self.parent_startup(app); let app = app.downcast_ref::().unwrap(); - let priv_ = SimpleApplicationPrivate::from_instance(app); let window = SimpleWindow::new(&app); - priv_ - .window + self.window .set(window) .expect("Failed to initialize application window"); }