From eec6a8a90918f5aca0630013f034f50a2b1eb9b8 Mon Sep 17 00:00:00 2001 From: Deren Vural <35734401+derenv@users.noreply.github.com> Date: Mon, 20 May 2024 20:35:43 +0100 Subject: [PATCH] Updated src/modificationwindow/imp.rs: - Updated reuse copyright year - Added clearer import headers - Refactored to now import std::cell::OnceCell as it has been [merged into std](https://github.com/rust-lang/rust/pull/105587) - Refactored to now import std::sync::OncelLock as it has been [merged into std](https://github.com/rust-lang/rust/pull/105587) - Added glib::BorrowedObject import - Refactored to import Value from glib::value as it now has its own module in glib - Refactored to import Variant and FromVariant from glib::variant as it now has its own module in glib - Refactored "properties()"function to reflect OnceLock changes - Removed now unused "_obj" parameter to "property()" and "set_property()" functions - Refactored to use glib::signal::Propagation instead of glib::signal::Inhibit - Refactored "constructed()" function to get "obj" reference via "self" instead of as a parameter - Updated "parent_constructed()" call in "constructed()" function - Removed deprecated "window" parameter from "close_request()" function - Updated "close_request()" function to return a Propagation type Updated src/modificationwindow/mod.rs: - Updated reuse copyright year - Added clearer import headers - Removed GString import - Updated "new()" function to use "Object::builder::().build()" instead of untyped "Obect::new()"" - Commented out "settings()" function - Refactored "setup_widgets()" function to use self.imp().get_setting::>() instead of getting GString directly Signed-off-by: Deren Vural <35734401+derenv@users.noreply.github.com> --- src/modificationwindow/imp.rs | 72 ++++++++++++++++++++++++----------- src/modificationwindow/mod.rs | 44 +++++++++++++-------- 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/src/modificationwindow/imp.rs b/src/modificationwindow/imp.rs index 72b6551..da65883 100644 --- a/src/modificationwindow/imp.rs +++ b/src/modificationwindow/imp.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 Deren Vural +// SPDX-FileCopyrightText: 2024 Deren Vural // SPDX-License-Identifier: GPL-3.0-or-later /** @@ -18,17 +18,29 @@ * */ // Imports -use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ActionRow}; -use gio::Settings; -use glib::{ - once_cell::sync::Lazy, once_cell::sync::OnceCell, signal::Inhibit, - subclass::InitializingObject, FromVariant, ParamSpec, Value, +// std +use std::sync::OnceLock; +use std::cell::{ + Cell, OnceCell, RefCell }; +use std::rc::Rc; +// gtk-rs use gtk::{ - subclass::prelude::*, Button, CompositeTemplate, DropDown, Entry, ListBox, SpinButton, - StringList, TemplateChild, + subclass::prelude::*, + Button, CompositeTemplate, DropDown, Entry, ListBox, SpinButton, StringList, TemplateChild +}; +use adwaita::{ + gio, glib, + prelude::*, subclass::prelude::*, + ActionRow +}; +use gio::Settings; +use glib::{ + signal::Propagation, + subclass::InitializingObject, ParamSpec, + variant::FromVariant, variant::Variant, + value::Value }; -use std::{cell::Cell, cell::RefCell, rc::Rc}; // Modules use crate::gpu_page::GpuPage; @@ -825,7 +837,10 @@ impl ModificationWindow { * Notes: * */ - pub fn get_setting(&self, name: &str) -> T { + pub fn get_setting( + &self, + name: &str + ) -> T { // Return the value of the property match self.settings.get() { Some(settings) => settings.get::(name), @@ -849,7 +864,11 @@ impl ModificationWindow { * Notes: * */ - pub fn update_setting(&self, name: &str, value: T) { + pub fn update_setting + Clone>( + &self, + name: &str, + value: T + ) { // Fetch settings match self.settings.get() { Some(settings) => match settings.set(name, &value) { @@ -1082,11 +1101,12 @@ impl ObjectImpl for ModificationWindow { * Notes: * */ - fn constructed(&self, obj: &Self::Type) { + fn constructed(&self) { // Call "constructed" on parent - self.parent_constructed(obj); + self.parent_constructed(); // Setup + let _obj: glib::BorrowedObject = self.obj(); // obj.setup_settings(); // obj.setup_widgets(); // obj.restore_data(); @@ -1119,20 +1139,19 @@ impl ObjectImpl for ModificationWindow { * glib::ParamSpecObject::builder("formatter").build(), */ fn properties() -> &'static [ParamSpec] { - static PROPERTIES: Lazy> = Lazy::new(|| { + static PROPERTIES: OnceLock> = OnceLock::new(); + PROPERTIES.get_or_init(|| { vec![ glib::ParamSpecInt::builder("old-view-id").build(), glib::ParamSpecInt::builder("new-view-id").build(), glib::ParamSpecString::builder("old-view-title").build(), glib::ParamSpecString::builder("new-view-title").build(), - glib::ParamSpecString::builder("uuid").build(), + glib::ParamSpecString::builder("uuid").build() ] - }); + }) //println!("PROPERTIES: {:?}", PROPERTIES);//TEST //println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST - - PROPERTIES.as_ref() } /** @@ -1151,7 +1170,12 @@ impl ObjectImpl for ModificationWindow { * Notes: * */ - fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) { + fn set_property( + &self, + _id: usize, + value: &Value, + pspec: &ParamSpec + ) { //println!("setting: {:?}", pspec.name());//TEST match pspec.name() { @@ -1204,7 +1228,11 @@ impl ObjectImpl for ModificationWindow { * Notes: * */ - fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value { + fn property( + &self, + _id: usize, + pspec: &ParamSpec + ) -> Value { //println!("getting: {:?}", pspec.name());//TEST match pspec.name() { @@ -1284,12 +1312,12 @@ impl WindowImpl for ModificationWindow { * Notes: * */ - fn close_request(&self, window: &Self::Type) -> Inhibit { + fn close_request(&self) -> Propagation { // Store state in settings self.update_setting("modification-open", false); // Pass close request on to the parent - self.parent_close_request(window) + self.parent_close_request() } } diff --git a/src/modificationwindow/mod.rs b/src/modificationwindow/mod.rs index cf242b7..995e8df 100644 --- a/src/modificationwindow/mod.rs +++ b/src/modificationwindow/mod.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 Deren Vural +// SPDX-FileCopyrightText: 2024 Deren Vural // SPDX-License-Identifier: GPL-3.0-or-later /** @@ -21,11 +21,21 @@ mod imp; // Imports -use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ActionRow}; -use gio::Settings; -use glib::{clone, GString, Object}; -use gtk::{Adjustment, DropDown, StringList}; +// std use std::cell::RefMut; +// gtk-rs +use adwaita::{ + gio, glib, + prelude::*, subclass::prelude::*, + ActionRow +}; +use gio::Settings; +use glib::{ + clone, Object +}; +use gtk::{ + Adjustment, DropDown, StringList +}; // Modules use crate::{ @@ -81,8 +91,9 @@ impl ModificationWindow { parent_window: &GpuPage, ) -> Self { // Create new window - let obj: ModificationWindow = Object::new(&[("application", app)]) - .expect("`ModificationWindow` should be instantiable."); + let obj: ModificationWindow = Object::builder::() + .property("application", app) + .build(); // Set custom properties obj.set_property("old-view-id", view_id); @@ -144,12 +155,12 @@ impl ModificationWindow { * Notes: * */ - fn settings(&self) -> &Settings { - self.imp() - .settings - .get() - .expect("`settings` should be set in `setup_settings`.") - } + // fn settings(&self) -> &Settings { + // self.imp() + // .settings + // .get() + // .expect("`settings` should be set in `setup_settings`.") + // } /** * Name: @@ -169,7 +180,9 @@ impl ModificationWindow { */ fn setup_widgets(&self) { // Retrieve names of stored views - let view_title_list: Vec = self.settings().strv("viewconfigs"); + let view_title_list: Vec = self.imp().get_setting::>("viewconfigs"); + // let view_title_list: Vec = self.imp().get_setting::>("viewconfigs"); + // let view_title_list: Vec = self.settings().strv("viewconfigs"); let view_id: String = self.property::("old-view-id").to_string(); // Create empty string for the title @@ -209,7 +222,8 @@ impl ModificationWindow { self.set_property("new-view-title", view_title); // Retrieve list of in-use properties - let view_components_list = self.settings().strv("viewcomponentconfigs"); + let view_components_list: Vec = self.imp().get_setting::>("viewcomponentconfigs"); + // let view_components_list = self.settings().strv("viewcomponentconfigs"); // println!("Possible Components: {:?}", view_components_list); //TEST // Create list of components in current view