Skip to content

Commit eec6a8a

Browse files
committed
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](rust-lang/rust#105587) - Refactored to now import std::sync::OncelLock as it has been [merged into std](rust-lang/rust#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::<ModificationWindow>().build()" instead of untyped "Obect::new()"" - Commented out "settings()" function - Refactored "setup_widgets()" function to use self.imp().get_setting::<Vec<String>>() instead of getting GString directly Signed-off-by: Deren Vural <[email protected]>
1 parent e578080 commit eec6a8a

File tree

2 files changed

+79
-37
lines changed

2 files changed

+79
-37
lines changed

src/modificationwindow/imp.rs

+50-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
/**
@@ -18,17 +18,29 @@
1818
*
1919
*/
2020
// Imports
21-
use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ActionRow};
22-
use gio::Settings;
23-
use glib::{
24-
once_cell::sync::Lazy, once_cell::sync::OnceCell, signal::Inhibit,
25-
subclass::InitializingObject, FromVariant, ParamSpec, Value,
21+
// std
22+
use std::sync::OnceLock;
23+
use std::cell::{
24+
Cell, OnceCell, RefCell
2625
};
26+
use std::rc::Rc;
27+
// gtk-rs
2728
use gtk::{
28-
subclass::prelude::*, Button, CompositeTemplate, DropDown, Entry, ListBox, SpinButton,
29-
StringList, TemplateChild,
29+
subclass::prelude::*,
30+
Button, CompositeTemplate, DropDown, Entry, ListBox, SpinButton, StringList, TemplateChild
31+
};
32+
use adwaita::{
33+
gio, glib,
34+
prelude::*, subclass::prelude::*,
35+
ActionRow
36+
};
37+
use gio::Settings;
38+
use glib::{
39+
signal::Propagation,
40+
subclass::InitializingObject, ParamSpec,
41+
variant::FromVariant, variant::Variant,
42+
value::Value
3043
};
31-
use std::{cell::Cell, cell::RefCell, rc::Rc};
3244

3345
// Modules
3446
use crate::gpu_page::GpuPage;
@@ -825,7 +837,10 @@ impl ModificationWindow {
825837
* Notes:
826838
*
827839
*/
828-
pub fn get_setting<T: FromVariant>(&self, name: &str) -> T {
840+
pub fn get_setting<T: FromVariant>(
841+
&self,
842+
name: &str
843+
) -> T {
829844
// Return the value of the property
830845
match self.settings.get() {
831846
Some(settings) => settings.get::<T>(name),
@@ -849,7 +864,11 @@ impl ModificationWindow {
849864
* Notes:
850865
*
851866
*/
852-
pub fn update_setting<T: ToVariant>(&self, name: &str, value: T) {
867+
pub fn update_setting<T: Into<Variant> + Clone>(
868+
&self,
869+
name: &str,
870+
value: T
871+
) {
853872
// Fetch settings
854873
match self.settings.get() {
855874
Some(settings) => match settings.set(name, &value) {
@@ -1082,11 +1101,12 @@ impl ObjectImpl for ModificationWindow {
10821101
* Notes:
10831102
*
10841103
*/
1085-
fn constructed(&self, obj: &Self::Type) {
1104+
fn constructed(&self) {
10861105
// Call "constructed" on parent
1087-
self.parent_constructed(obj);
1106+
self.parent_constructed();
10881107

10891108
// Setup
1109+
let _obj: glib::BorrowedObject<super::ModificationWindow> = self.obj();
10901110
// obj.setup_settings();
10911111
// obj.setup_widgets();
10921112
// obj.restore_data();
@@ -1119,20 +1139,19 @@ impl ObjectImpl for ModificationWindow {
11191139
* glib::ParamSpecObject::builder("formatter").build(),
11201140
*/
11211141
fn properties() -> &'static [ParamSpec] {
1122-
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
1142+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
1143+
PROPERTIES.get_or_init(|| {
11231144
vec![
11241145
glib::ParamSpecInt::builder("old-view-id").build(),
11251146
glib::ParamSpecInt::builder("new-view-id").build(),
11261147
glib::ParamSpecString::builder("old-view-title").build(),
11271148
glib::ParamSpecString::builder("new-view-title").build(),
1128-
glib::ParamSpecString::builder("uuid").build(),
1149+
glib::ParamSpecString::builder("uuid").build()
11291150
]
1130-
});
1151+
})
11311152

11321153
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
11331154
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
1134-
1135-
PROPERTIES.as_ref()
11361155
}
11371156

11381157
/**
@@ -1151,7 +1170,12 @@ impl ObjectImpl for ModificationWindow {
11511170
* Notes:
11521171
*
11531172
*/
1154-
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
1173+
fn set_property(
1174+
&self,
1175+
_id: usize,
1176+
value: &Value,
1177+
pspec: &ParamSpec
1178+
) {
11551179
//println!("setting: {:?}", pspec.name());//TEST
11561180

11571181
match pspec.name() {
@@ -1204,7 +1228,11 @@ impl ObjectImpl for ModificationWindow {
12041228
* Notes:
12051229
*
12061230
*/
1207-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
1231+
fn property(
1232+
&self,
1233+
_id: usize,
1234+
pspec: &ParamSpec
1235+
) -> Value {
12081236
//println!("getting: {:?}", pspec.name());//TEST
12091237

12101238
match pspec.name() {
@@ -1284,12 +1312,12 @@ impl WindowImpl for ModificationWindow {
12841312
* Notes:
12851313
*
12861314
*/
1287-
fn close_request(&self, window: &Self::Type) -> Inhibit {
1315+
fn close_request(&self) -> Propagation {
12881316
// Store state in settings
12891317
self.update_setting("modification-open", false);
12901318

12911319
// Pass close request on to the parent
1292-
self.parent_close_request(window)
1320+
self.parent_close_request()
12931321
}
12941322
}
12951323

src/modificationwindow/mod.rs

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 Deren Vural
1+
// SPDX-FileCopyrightText: 2024 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
/**
@@ -21,11 +21,21 @@
2121
mod imp;
2222

2323
// Imports
24-
use adwaita::{gio, glib, prelude::*, subclass::prelude::*, ActionRow};
25-
use gio::Settings;
26-
use glib::{clone, GString, Object};
27-
use gtk::{Adjustment, DropDown, StringList};
24+
// std
2825
use std::cell::RefMut;
26+
// gtk-rs
27+
use adwaita::{
28+
gio, glib,
29+
prelude::*, subclass::prelude::*,
30+
ActionRow
31+
};
32+
use gio::Settings;
33+
use glib::{
34+
clone, Object
35+
};
36+
use gtk::{
37+
Adjustment, DropDown, StringList
38+
};
2939

3040
// Modules
3141
use crate::{
@@ -81,8 +91,9 @@ impl ModificationWindow {
8191
parent_window: &GpuPage,
8292
) -> Self {
8393
// Create new window
84-
let obj: ModificationWindow = Object::new(&[("application", app)])
85-
.expect("`ModificationWindow` should be instantiable.");
94+
let obj: ModificationWindow = Object::builder::<ModificationWindow>()
95+
.property("application", app)
96+
.build();
8697

8798
// Set custom properties
8899
obj.set_property("old-view-id", view_id);
@@ -144,12 +155,12 @@ impl ModificationWindow {
144155
* Notes:
145156
*
146157
*/
147-
fn settings(&self) -> &Settings {
148-
self.imp()
149-
.settings
150-
.get()
151-
.expect("`settings` should be set in `setup_settings`.")
152-
}
158+
// fn settings(&self) -> &Settings {
159+
// self.imp()
160+
// .settings
161+
// .get()
162+
// .expect("`settings` should be set in `setup_settings`.")
163+
// }
153164

154165
/**
155166
* Name:
@@ -169,7 +180,9 @@ impl ModificationWindow {
169180
*/
170181
fn setup_widgets(&self) {
171182
// Retrieve names of stored views
172-
let view_title_list: Vec<GString> = self.settings().strv("viewconfigs");
183+
let view_title_list: Vec<String> = self.imp().get_setting::<Vec<String>>("viewconfigs");
184+
// let view_title_list: Vec<GString> = self.imp().get_setting::<Vec<GString>>("viewconfigs");
185+
// let view_title_list: Vec<GString> = self.settings().strv("viewconfigs");
173186
let view_id: String = self.property::<i32>("old-view-id").to_string();
174187

175188
// Create empty string for the title
@@ -209,7 +222,8 @@ impl ModificationWindow {
209222
self.set_property("new-view-title", view_title);
210223

211224
// Retrieve list of in-use properties
212-
let view_components_list = self.settings().strv("viewcomponentconfigs");
225+
let view_components_list: Vec<String> = self.imp().get_setting::<Vec<String>>("viewcomponentconfigs");
226+
// let view_components_list = self.settings().strv("viewcomponentconfigs");
213227
// println!("Possible Components: {:?}", view_components_list); //TEST
214228

215229
// Create list of components in current view

0 commit comments

Comments
 (0)