feat: add propety-update argument to widget control command
This commit is contained in:
@@ -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(())
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user