From da92f6cc04de7424ebe5ccd622885145fc6dc5db Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 30 Apr 2017 08:40:23 -0400 Subject: [PATCH] Rename data to parent_id --- Cargo.toml | 2 +- examples/multi-container-attribute.rs | 6 +++--- examples/multi-container.rs | 16 ++++++++-------- relm-gen-widget/Cargo.toml | 2 +- relm-gen-widget/src/gen.rs | 8 ++++---- relm-gen-widget/src/lib.rs | 14 +++++++------- relm-gen-widget/src/parser.rs | 14 +++++++------- src/widget.rs | 16 ++++++++-------- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c6a4739..f2f37a35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ documentation = "https://docs.rs/relm/" license = "MIT" name = "relm" repository = "https://github.com/antoyo/relm" -version = "0.9.2" +version = "0.9.3" [badges] travis-ci = { repository = "antoyo/relm" } diff --git a/examples/multi-container-attribute.rs b/examples/multi-container-attribute.rs index 0f76944b..4171aa8b 100644 --- a/examples/multi-container-attribute.rs +++ b/examples/multi-container-attribute.rs @@ -65,7 +65,7 @@ impl Widget for CenterButton { } view! { - #[data="center"] + #[parent="center"] gtk::Button { label: "-", }, @@ -81,7 +81,7 @@ impl Widget for Button { } view! { - #[data="right"] + #[parent="right"] gtk::Button { label: "+", }, @@ -105,7 +105,7 @@ impl Widget for SplitBox { gtk::Box { orientation: Vertical, }, - // Specify where the widgets will be added in this container when the child's data is + // Specify where the widgets will be added in this container when the child's parent id is // "center". #[container="center"] gtk::Frame { diff --git a/examples/multi-container.rs b/examples/multi-container.rs index 91cac001..8f40eab4 100644 --- a/examples/multi-container.rs +++ b/examples/multi-container.rs @@ -53,11 +53,11 @@ impl Widget for CenterButton { type Msg = (); type Root = gtk::Button; - fn data() -> Option<&'static str> { - Some("center") + fn model(_: ()) -> () { } - fn model(_: ()) -> () { + fn parent_id() -> Option<&'static str> { + Some("center") } fn root(&self) -> &Self::Root { @@ -86,11 +86,11 @@ impl Widget for Button { type Msg = (); type Root = gtk::Button; - fn data() -> Option<&'static str> { - Some("right") + fn model(_: ()) -> () { } - fn model(_: ()) -> () { + fn parent_id() -> Option<&'static str> { + Some("right") } fn root(&self) -> &Self::Root { @@ -161,11 +161,11 @@ impl Container for SplitBox { } fn add_widget(&self, widget: &WIDGET) -> gtk::Container { - if WIDGET::data() == Some("right") { + if WIDGET::parent_id() == Some("right") { self.hbox3.add(widget.root()); self.hbox3.widget().root().clone().upcast() } - else if WIDGET::data() == Some("center") { + else if WIDGET::parent_id() == Some("center") { self.hbox2.add(widget.root()); self.hbox2.clone().upcast() } diff --git a/relm-gen-widget/Cargo.toml b/relm-gen-widget/Cargo.toml index 14c50404..49094893 100644 --- a/relm-gen-widget/Cargo.toml +++ b/relm-gen-widget/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://docs.rs/relm-gen-widget/" license = "MIT" name = "relm-gen-widget" repository = "https://github.com/antoyo/relm" -version = "0.9.8" +version = "0.9.9" [dependencies] lazy_static = "^0.2.4" diff --git a/relm-gen-widget/src/gen.rs b/relm-gen-widget/src/gen.rs index 48f21578..a22cb347 100644 --- a/relm-gen-widget/src/gen.rs +++ b/relm-gen-widget/src/gen.rs @@ -384,7 +384,7 @@ fn gen_add_widget_method(container_names: &HashMap, (Ident, Path) if container_names.len() > 1 { let mut default_container = Tokens::new(); let mut other_containers = Tokens::new(); - for (data, &(ref name, ref typ)) in container_names { + for (parent_id, &(ref name, ref typ)) in container_names { let first_type_part = &typ.segments.first().expect("first segment").ident; let (container_trait, upcast_container) = if first_type_part == "gtk" { @@ -401,7 +401,7 @@ fn gen_add_widget_method(container_names: &HashMap, (Ident, Path) ::relm::Cast::upcast(self.#name.widget().root().clone()) }) }; - if data.is_none() { + if parent_id.is_none() { default_container = quote! { #container_trait::add(&self.#name, widget.root()); #upcast_container @@ -410,7 +410,7 @@ fn gen_add_widget_method(container_names: &HashMap, (Ident, Path) else { if other_containers.as_str().is_empty() { other_containers = quote! { - if WIDGET::data() == Some(#data) { + if WIDGET::parent_id() == Some(#parent_id) { #container_trait::add(&self.#name, widget.root()); #upcast_container } @@ -419,7 +419,7 @@ fn gen_add_widget_method(container_names: &HashMap, (Ident, Path) else { other_containers = quote! { #other_containers - else if WIDGET::data() == Some(#data) { + else if WIDGET::parent_id() == Some(#parent_id) { #container_trait::add(&self.#name, widget.root()); #upcast_container } diff --git a/relm-gen-widget/src/lib.rs b/relm-gen-widget/src/lib.rs index fde65aa4..fce8d619 100644 --- a/relm-gen-widget/src/lib.rs +++ b/relm-gen-widget/src/lib.rs @@ -85,9 +85,9 @@ pub struct Driver { root_widget_type: Option, update_method: Option, view_macro: Option, - widget_data: Option, widget_model_type: Option, widget_msg_type: Option, + widget_parent_id: Option, widgets: HashMap, // Map widget ident to widget type. } @@ -115,9 +115,9 @@ impl Driver { root_widget_type: None, update_method: None, view_macro: None, - widget_data: None, widget_model_type: None, widget_msg_type: None, + widget_parent_id: None, widgets: HashMap::new(), } } @@ -175,7 +175,7 @@ impl Driver { Macro(mac) => self.view_macro = Some(mac), Method(sig, _) => { match item.ident.to_string().as_ref() { - "data" => self.data_method = Some(i), + "parent_id" => self.data_method = Some(i), "root" => self.root_method = Some(i), "model" => { self.widget_model_type = Some(get_return_type(sig)); @@ -235,10 +235,10 @@ impl Driver { fn get_data_method(&mut self) -> Option { self.data_method.take().or_else(|| { - if let Some(ref data) = self.widget_data { + if let Some(ref parent_id) = self.widget_parent_id { Some(block_to_impl_item(quote! { - fn data() -> Option<&'static str> { - Some(#data) + fn parent_id() -> Option<&'static str> { + Some(#parent_id) } })) } @@ -325,7 +325,7 @@ impl Driver { if let Gtk(ref mut widget) = widget.widget { widget.relm_name = Some(typ.clone()); } - self.widget_data = widget.data.clone(); + self.widget_parent_id = widget.parent_id.clone(); let mut properties_model_map = HashMap::new(); get_properties_model_map(&widget, &mut properties_model_map); self.add_widgets(&widget, &properties_model_map); diff --git a/relm-gen-widget/src/parser.rs b/relm-gen-widget/src/parser.rs index b9e71155..ac01af6d 100644 --- a/relm-gen-widget/src/parser.rs +++ b/relm-gen-widget/src/parser.rs @@ -83,9 +83,9 @@ pub struct Widget { pub child_properties: HashMap, pub children: Vec, pub container_type: Option>, - pub data: Option, pub init_parameters: Vec, pub name: syn::Ident, + pub parent_id: Option, pub properties: HashMap, pub typ: Path, pub widget: EitherWidget, @@ -100,9 +100,9 @@ impl Widget { child_properties, children, container_type: None, - data: None, init_parameters, name: syn::Ident::new(name), + parent_id: None, properties, typ, widget: Gtk(widget), @@ -121,9 +121,9 @@ impl Widget { child_properties, children, container_type: None, - data: None, init_parameters, name: syn::Ident::new(name), + parent_id: None, properties, typ, widget: Relm(widget), @@ -202,8 +202,8 @@ pub fn parse(tokens: &[TokenTree]) -> Widget { else { tokens.to_vec() }; - let (mut widget, _, data) = parse_child(&tokens); - widget.data = data; + let (mut widget, _, parent_id) = parse_child(&tokens); + widget.parent_id = parent_id; widget } @@ -274,8 +274,8 @@ fn parse_child(mut tokens: &[TokenTree]) -> (Widget, &[TokenTree], Option (String, &[TokenTree]) { diff --git a/src/widget.rs b/src/widget.rs index 761fe8b5..514306df 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -38,14 +38,6 @@ pub trait Widget /// The type of the root widget. type Root; - /// Get some string data. - /// This is useful for custom Container implementation: when you implement the - /// [`Container::add_widget()`](trait.Container.html#tymethod.add_widget), you might want to - /// insert widgets elsewhere depending of this data. - fn data() -> Option<&'static str> { - None - } - /// Update the view after it is initially created. /// This method is only useful when using the `#[widget]` attribute, because when not using it, /// you can use the [`view()`](trait.Widget.html#tymethod.view) method instead. @@ -59,6 +51,14 @@ pub trait Widget fn on_add + IsA>(&self, _parent: W) { } + /// Get the parent ID. + /// This is useful for custom Container implementation: when you implement the + /// [`Container::add_widget()`](trait.Container.html#tymethod.add_widget), you might want to + /// insert widgets elsewhere depending of this id. + fn parent_id() -> Option<&'static str> { + None + } + // TODO: ajouter une méthode param() pour déterminer des paramètres qui seront pris en compte à // l’ajout du widget.