feat: add propety-update argument to widget control command

This commit is contained in:
Byson94
2025-11-25 20:49:26 +05:30
parent 357dcaacbc
commit b50f41b1e0
3 changed files with 56 additions and 2 deletions

View File

@@ -801,6 +801,25 @@ impl<B: DisplayBackend> App<B> {
}
}
}
crate::opts::WidgetControlAction::PropertyUpdate {
property_and_value,
widget_name,
} => {
if let Ok(mut maybe_registry) = self.widget_reg_store.lock() {
if let Some(widget_registry) = maybe_registry.as_mut() {
for (key, value) in &property_and_value {
widget_registry.update_property_by_name(
&widget_name,
(key.clone(), value.clone()),
);
}
} else {
log::error!("Widget registry is empty");
}
} else {
log::error!("Failed to acquire lock on widget registry");
}
}
}
Ok(())

View File

@@ -252,13 +252,26 @@ pub enum WidgetControlAction {
/// Create widgets
Create {
/// Rhai code to create widgets from.
/// Rhai code to create widgets from
rhai_codes: Vec<String>,
/// Name of the widget to add these widgets as a child to.
/// Name of the widget to add these widgets as a child to
#[arg(long = "parent", short = 'p')]
parent_name: String,
},
/// Update properties of a widget by name
PropertyUpdate {
/// Properties and its value
///
/// Format: value="val1" widget_name="val2"
#[arg(value_parser = parse_inject_var_map)]
property_and_value: HashMap<String, String>,
/// Name of the widget to update the property of
#[arg(long = "widget", short = 'w')]
widget_name: String,
}
}
impl Opt {

View File

@@ -235,6 +235,28 @@ impl WidgetRegistry {
.find(|(_, entry)| entry.widget.widget_name().as_str() == name)
.map(|(&id, _)| id)
}
pub fn update_property_by_name(
&mut self,
widget_name: &str,
property_and_value: (String, String),
) -> bool {
if let Some((&id, _)) = self
.widgets
.iter()
.find(|(_, entry)| entry.widget.widget_name().as_str() == widget_name)
{
if let Some(entry) = self.widgets.get(&id) {
set_property_from_string_anywhere(
&entry.widget,
&property_and_value.0,
&property_and_value.1,
);
}
}
false
}
}
pub(super) fn build_gtk_box(