Skip to content

Commit 6a9ec5e

Browse files
committed
Updated src/formatter/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) - Refactored to import Value from glib::value as it now has its own module in glib - Refactored to import FromVariant from glib::variant as it now has its own module in glib - Refactored "constructed()" function to get "obj" reference via "self" instead of as a parameter - Updated "parent_constructed()" call in "constructed()" function - Refactored "properties()"function to reflect OnceLock changes - Removed now unused "_obj" parameter to "property()" and "set_property()" functions Updated src/formatter/mod.rs: - Updated reuse copyright year - Added clearer import headers - Updated "new()" function to use "Object::builder::<Formatter>().build()" instead of untyped "Obect::new()"" Signed-off-by: Deren Vural <[email protected]>
1 parent c939ac0 commit 6a9ec5e

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

src/formatter/imp.rs

+34-13
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,11 +18,23 @@
1818
* Most of this left blank, may add fields later
1919
*/
2020
// Imports
21-
use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
22-
use gio::Settings;
23-
use glib::{once_cell::sync::Lazy, once_cell::sync::OnceCell, FromVariant, ParamSpec, Value};
21+
// std
22+
use std::sync::OnceLock;
23+
use std::cell::{
24+
Cell, OnceCell
25+
};
26+
// gtk-rs
2427
use gtk::subclass::prelude::*;
25-
use std::cell::Cell;
28+
use adwaita::{
29+
gio, glib,
30+
prelude::*,// subclass::prelude::*
31+
};
32+
use gio::Settings;
33+
use glib::{
34+
ParamSpec,
35+
variant::FromVariant,
36+
value::Value
37+
};
2638

2739
// Modules
2840
//
@@ -104,11 +116,12 @@ impl ObjectImpl for Formatter {
104116
* Notes:
105117
*
106118
*/
107-
fn constructed(&self, obj: &Self::Type) {
119+
fn constructed(&self) {
108120
// Call "constructed" on parent
109-
self.parent_constructed(obj);
121+
self.parent_constructed();
110122

111123
// Setup
124+
let obj: glib::BorrowedObject<super::Formatter> = self.obj();
112125
obj.setup_settings();
113126
}
114127

@@ -137,16 +150,15 @@ impl ObjectImpl for Formatter {
137150
* glib::ParamSpecObject::builder("formatter").build(),
138151
*/
139152
fn properties() -> &'static [ParamSpec] {
140-
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
153+
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
154+
PROPERTIES.get_or_init(|| {
141155
vec![
142156
//
143157
]
144-
});
158+
})
145159

146160
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
147161
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
148-
149-
PROPERTIES.as_ref()
150162
}
151163

152164
/**
@@ -165,7 +177,12 @@ impl ObjectImpl for Formatter {
165177
* Notes:
166178
*
167179
*/
168-
fn set_property(&self, _obj: &Self::Type, _id: usize, _value: &Value, pspec: &ParamSpec) {
180+
fn set_property(
181+
&self,
182+
_id: usize,
183+
_value: &Value,
184+
pspec: &ParamSpec
185+
) {
169186
//println!("setting: {:?}", pspec.name());//TEST
170187

171188
match pspec.name() {
@@ -190,7 +207,11 @@ impl ObjectImpl for Formatter {
190207
* Notes:
191208
*
192209
*/
193-
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
210+
fn property(
211+
&self,
212+
_id: usize,
213+
pspec: &ParamSpec
214+
) -> Value {
194215
//println!("getting: {:?}", pspec.name());//TEST
195216

196217
match pspec.name() {

src/formatter/mod.rs

+13-4
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,10 +21,16 @@
2121
mod imp;
2222

2323
// Imports
24-
use adwaita::{gio, glib};
24+
// std
25+
//
26+
// gtk-rs
27+
use adwaita::{
28+
gio, glib
29+
};
2530
use gio::Settings;
2631
use glib::Object;
2732
use gtk::subclass::prelude::*;
33+
2834
// Modules
2935
use crate::APP_ID;
3036

@@ -68,8 +74,11 @@ impl Formatter {
6874
* Notes:
6975
*
7076
*/
71-
pub fn new(func: fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String>) -> Self {
72-
let obj: Formatter = Object::new(&[]).expect("Failed to create `Formatter`.");
77+
pub fn new(
78+
func: fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String>
79+
) -> Self {
80+
// Create Object
81+
let obj: Formatter = Object::builder::<Formatter>().build();
7382

7483
// Set properties
7584
obj.imp().func.set(Some(func));

0 commit comments

Comments
 (0)