Skip to content

Commit

Permalink
Updated src/formatter/imp.rs:
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
derenv committed May 20, 2024
1 parent c939ac0 commit 6a9ec5e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
47 changes: 34 additions & 13 deletions src/formatter/imp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

/**
Expand All @@ -18,11 +18,23 @@
* Most of this left blank, may add fields later
*/
// Imports
use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
use gio::Settings;
use glib::{once_cell::sync::Lazy, once_cell::sync::OnceCell, FromVariant, ParamSpec, Value};
// std
use std::sync::OnceLock;
use std::cell::{
Cell, OnceCell
};
// gtk-rs
use gtk::subclass::prelude::*;
use std::cell::Cell;
use adwaita::{
gio, glib,
prelude::*,// subclass::prelude::*
};
use gio::Settings;
use glib::{
ParamSpec,
variant::FromVariant,
value::Value
};

// Modules
//
Expand Down Expand Up @@ -104,11 +116,12 @@ impl ObjectImpl for Formatter {
* 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<super::Formatter> = self.obj();
obj.setup_settings();
}

Expand Down Expand Up @@ -137,16 +150,15 @@ impl ObjectImpl for Formatter {
* glib::ParamSpecObject::builder("formatter").build(),
*/
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
static PROPERTIES: OnceLock<Vec<ParamSpec>> = OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![
//
]
});
})

//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST

PROPERTIES.as_ref()
}

/**
Expand All @@ -165,7 +177,12 @@ impl ObjectImpl for Formatter {
* 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() {
Expand All @@ -190,7 +207,11 @@ impl ObjectImpl for Formatter {
* 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() {
Expand Down
17 changes: 13 additions & 4 deletions src/formatter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 Deren Vural
// SPDX-FileCopyrightText: 2024 Deren Vural
// SPDX-License-Identifier: GPL-3.0-or-later

/**
Expand All @@ -21,10 +21,16 @@
mod imp;

// Imports
use adwaita::{gio, glib};
// std
//
// gtk-rs
use adwaita::{
gio, glib
};
use gio::Settings;
use glib::Object;
use gtk::subclass::prelude::*;

// Modules
use crate::APP_ID;

Expand Down Expand Up @@ -68,8 +74,11 @@ impl Formatter {
* Notes:
*
*/
pub fn new(func: fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String>) -> Self {
let obj: Formatter = Object::new(&[]).expect("Failed to create `Formatter`.");
pub fn new(
func: fn(Vec<String>, Option<Vec<(String, String)>>) -> Option<String>
) -> Self {
// Create Object
let obj: Formatter = Object::builder::<Formatter>().build();

// Set properties
obj.imp().func.set(Some(func));
Expand Down

0 comments on commit 6a9ec5e

Please sign in to comment.