feat: add add/remove-class subcommand to wc command
This commit is contained in:
@@ -820,6 +820,36 @@ impl<B: DisplayBackend> App<B> {
|
|||||||
log::error!("Failed to acquire lock on widget registry");
|
log::error!("Failed to acquire lock on widget registry");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
crate::opts::WidgetControlAction::AddClass { class, widget_name } => {
|
||||||
|
if let Ok(mut maybe_registry) = self.widget_reg_store.lock() {
|
||||||
|
if let Some(widget_registry) = maybe_registry.as_mut() {
|
||||||
|
widget_registry.update_class_of_widget_by_name(
|
||||||
|
&widget_name,
|
||||||
|
&class,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log::error!("Widget registry is empty");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to acquire lock on widget registry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crate::opts::WidgetControlAction::RemoveClass { class, widget_name } => {
|
||||||
|
if let Ok(mut maybe_registry) = self.widget_reg_store.lock() {
|
||||||
|
if let Some(widget_registry) = maybe_registry.as_mut() {
|
||||||
|
widget_registry.update_class_of_widget_by_name(
|
||||||
|
&widget_name,
|
||||||
|
&class,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log::error!("Widget registry is empty");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to acquire lock on widget registry");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -272,6 +272,26 @@ pub enum WidgetControlAction {
|
|||||||
#[arg(long = "widget", short = 'w')]
|
#[arg(long = "widget", short = 'w')]
|
||||||
widget_name: String,
|
widget_name: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Add a class to a widget with given name
|
||||||
|
AddClass {
|
||||||
|
/// The class to add to the widget
|
||||||
|
class: String,
|
||||||
|
|
||||||
|
/// Name of the widget to add class to
|
||||||
|
#[arg(long = "widget", short = 'w')]
|
||||||
|
widget_name: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Remove a class to a widget with given name
|
||||||
|
RemoveClass {
|
||||||
|
/// The class to remove from the widget
|
||||||
|
class: String,
|
||||||
|
|
||||||
|
/// Name of the widget to remove class from
|
||||||
|
#[arg(long = "widget", short = 'w')]
|
||||||
|
widget_name: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Opt {
|
impl Opt {
|
||||||
|
|||||||
@@ -257,6 +257,29 @@ impl WidgetRegistry {
|
|||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_class_of_widget_by_name(
|
||||||
|
&mut self,
|
||||||
|
widget_name: &str,
|
||||||
|
class: &str,
|
||||||
|
remove: bool,
|
||||||
|
) -> 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) {
|
||||||
|
if !remove {
|
||||||
|
entry.widget.style_context().add_class(class);
|
||||||
|
} else {
|
||||||
|
entry.widget.style_context().remove_class(class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn build_gtk_box(
|
pub(super) fn build_gtk_box(
|
||||||
|
|||||||
Reference in New Issue
Block a user