diff --git a/gio/src/action_entry.rs b/gio/src/action_entry.rs index a0f27a02e08c..93ebc86df048 100644 --- a/gio/src/action_entry.rs +++ b/gio/src/action_entry.rs @@ -22,6 +22,16 @@ impl ActionEntry where O: IsA, { + pub fn new(name: &str) -> Self { + Self { + name: name.to_owned(), + parameter_type: Default::default(), + state: Default::default(), + activate: Default::default(), + change_state: Default::default(), + } + } + pub fn name(&self) -> &str { &self.name } @@ -34,8 +44,8 @@ where self.state.as_ref() } - pub fn builder(name: &str) -> ActionEntryBuilder { - ActionEntryBuilder::new(name) + pub fn builder() -> ActionEntryBuilder { + ActionEntryBuilder::new() } } @@ -61,9 +71,9 @@ impl ActionEntryBuilder where O: IsA, { - pub fn new(name: &str) -> Self { + pub fn new() -> Self { Self(ActionEntry { - name: name.to_owned(), + name: Default::default(), parameter_type: Default::default(), state: Default::default(), activate: Default::default(), @@ -71,6 +81,11 @@ where }) } + pub fn name(mut self, name: &str) -> Self { + name.clone_into(&mut self.0.name); + self + } + pub fn parameter_type(mut self, parameter_type: Option<&VariantTy>) -> Self { self.0.parameter_type = parameter_type.map(|vt| vt.to_owned()); self @@ -102,6 +117,15 @@ where } } +impl Default for ActionEntryBuilder +where + O: IsA, +{ + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use super::*; @@ -112,12 +136,14 @@ mod tests { let app = crate::Application::new(None, Default::default()); app.add_action_entries(vec![ - ActionEntry::builder("close") + ActionEntry::builder() + .name("close") .activate(move |_app, _, _| { //Do something }) .build(), - ActionEntry::builder("enable") + ActionEntry::builder() + .name("enable") .state(true.to_variant()) .change_state(move |_app, _, _| { //Do something