a toolbox can now be stopped and started (blocking)

This commit is contained in:
2022-05-01 19:59:14 +02:00
parent f111fea698
commit 4366ec578d

View File

@@ -21,6 +21,7 @@ use super::messages::AppMsg;
#[derive(Debug)] #[derive(Debug)]
pub struct FactoryWidgets { pub struct FactoryWidgets {
pub action_row: adw::ActionRow, pub action_row: adw::ActionRow,
status_button: gtk::Button,
} }
impl FactoryPrototype for ToolbxContainer { impl FactoryPrototype for ToolbxContainer {
@@ -109,6 +110,20 @@ impl FactoryPrototype for ToolbxContainer {
let index = key.clone(); let index = key.clone();
view! {
status_button = &gtk::Button::from_icon_name(status_button_icon) {
set_margin_top: 10,
set_margin_bottom: 10,
set_tooltip_text: Some(status_button_tooltip),
set_css_classes: &["circular"],
connect_clicked(sender) => move |btn| {
// Disable button
btn.set_sensitive(false);
send!(sender, AppMsg::ToolbxContainerToggleStartStop(index.clone()));
},
}
};
view! { view! {
action_row = &adw::ActionRow { action_row = &adw::ActionRow {
set_title: &self.name, set_title: &self.name,
@@ -116,24 +131,14 @@ impl FactoryPrototype for ToolbxContainer {
add_prefix = &gtk::Box { add_prefix = &gtk::Box {
append = &gtk::AspectFrame{ append = &gtk::AspectFrame{
set_ratio: 1.0, set_ratio: 1.0,
set_child = Some(&gtk::Button::from_icon_name(status_button_icon)) { set_child: Some(&status_button),
set_margin_top: 10, }
set_margin_bottom: 10,
set_tooltip_text: Some(status_button_tooltip),
set_css_classes: &["circular"],
connect_clicked(sender) => move |btn| {
// Disable button
btn.set_sensitive(false);
send!(sender, AppMsg::ToolbxContainerToggleStartStop(index.clone()));
},
},
},
}, },
add_suffix: &suffix_box, add_suffix: &suffix_box,
} }
}; };
FactoryWidgets { action_row } FactoryWidgets { action_row, status_button }
} }
fn view( fn view(
@@ -141,8 +146,23 @@ impl FactoryPrototype for ToolbxContainer {
key: &<Self::Factory as relm4::factory::Factory<Self, Self::View>>::Key, key: &<Self::Factory as relm4::factory::Factory<Self, Self::View>>::Key,
widgets: &Self::Widgets, widgets: &Self::Widgets,
) { ) {
//widgets.action_row.set_label(&self.name.to_string());
println!("updated {}", key.current_index()); println!("updated {}", key.current_index());
// fixme: IDEALY this is would be done with message handling and only if the request actually is done
match self.status {
ToolbxStatus::Running => {
widgets.status_button.set_icon_name(SHUTDOWN_ICON);
widgets.status_button.set_tooltip_text(Some(SHUTDOWN_TOOLTIP));
}
_ => {
widgets.status_button.set_icon_name(START_ICON);
widgets.status_button.set_tooltip_text(Some(START_TOOLTIP));
}
}
widgets.status_button.set_sensitive(true);
} }
fn root_widget(widgets: &Self::Widgets) -> &Self::Root { fn root_widget(widgets: &Self::Widgets) -> &Self::Root {