From 93ac5d1008030ccd587dad72cc3d42fd9eaf2bdf Mon Sep 17 00:00:00 2001 From: pml68 Date: Sat, 26 Oct 2024 21:54:49 +0200 Subject: refactor: rename `ActionKind` to `Action` --- iced_builder/src/main.rs | 8 +++----- iced_builder/src/types/element_name.rs | 12 ++++++------ iced_builder/src/types/rendered_element.rs | 14 +++++++------- 3 files changed, 16 insertions(+), 18 deletions(-) (limited to 'iced_builder') diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index 8d8c382..195614e 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -11,9 +11,7 @@ use iced::{ Alignment, Element, Length, Settings, Task, Theme, }; use iced_builder::{ - types::{ - element_name::ElementName, project::Project, rendered_element::ActionKind, DesignerPage, - }, + types::{element_name::ElementName, project::Project, rendered_element::Action, DesignerPage}, views::{code_view, designer_view, element_list}, Message, }; @@ -131,7 +129,7 @@ impl App { Message::HandleNew(name, zones) => { let ids: Vec = zones.into_iter().map(|z| z.0).collect(); if ids.len() > 0 { - let action = ActionKind::new(ids, &mut self.project.element_tree.clone(), None); + let action = Action::new(ids, &mut self.project.element_tree.clone(), None); let result = name.handle_action(self.project.element_tree.as_mut(), action); if let Ok(Some(ref element)) = result { self.project.element_tree = Some(element.clone()); @@ -153,7 +151,7 @@ impl App { Message::HandleMove(element, zones) => { let ids: Vec = zones.into_iter().map(|z| z.0).collect(); if ids.len() > 0 { - let action = ActionKind::new( + let action = Action::new( ids, &mut self.project.element_tree.clone(), Some(element.get_id()), diff --git a/iced_builder/src/types/element_name.rs b/iced_builder/src/types/element_name.rs index 8d00814..93e12a1 100644 --- a/iced_builder/src/types/element_name.rs +++ b/iced_builder/src/types/element_name.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::Error; use super::rendered_element::{ - button, column, container, image, row, svg, text, ActionKind, RenderedElement, + button, column, container, image, row, svg, text, Action, RenderedElement, }; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -31,7 +31,7 @@ impl ElementName { pub fn handle_action( &self, element_tree: Option<&mut RenderedElement>, - action: ActionKind, + action: Action, ) -> Result, Error> { let element = match self { Self::Text(_) => text(""), @@ -43,9 +43,9 @@ impl ElementName { Self::Column => column(None), }; match action { - ActionKind::Stop => Ok(None), - ActionKind::AddNew => Ok(Some(element)), - ActionKind::PushFront(id) => { + Action::Stop => Ok(None), + Action::AddNew => Ok(Some(element)), + Action::PushFront(id) => { element_tree .ok_or("The action was of kind `PushFront`, but no element tree was provided.")? .find_by_id(id) @@ -53,7 +53,7 @@ impl ElementName { .push_front(&element); Ok(None) } - ActionKind::InsertAfter(parent_id, child_id) => { + Action::InsertAfter(parent_id, child_id) => { element_tree .ok_or( "The action was of kind `InsertAfter`, but no element tree was provided.", diff --git a/iced_builder/src/types/rendered_element.rs b/iced_builder/src/types/rendered_element.rs index 50e591a..08d7ba3 100755 --- a/iced_builder/src/types/rendered_element.rs +++ b/iced_builder/src/types/rendered_element.rs @@ -120,16 +120,16 @@ impl RenderedElement { pub fn handle_action( &self, element_tree: Option<&mut RenderedElement>, - action: ActionKind, + action: Action, ) -> Result<(), Error> { let element_tree = element_tree.unwrap(); match action { - ActionKind::Stop => Ok(()), - ActionKind::AddNew => Err( + Action::Stop => Ok(()), + Action::AddNew => Err( "the action was of kind `AddNew`, but invoking it on an existing element tree is not possible".into(), ), - ActionKind::PushFront(id) => { + Action::PushFront(id) => { let old_parent = element_tree.find_parent(self).unwrap(); old_parent.remove(self); @@ -138,7 +138,7 @@ impl RenderedElement { Ok(()) } - ActionKind::InsertAfter(parent_id, target_id) => { + Action::InsertAfter(parent_id, target_id) => { let old_parent = element_tree.find_parent(self).unwrap(); old_parent.remove(self); @@ -300,14 +300,14 @@ impl std::fmt::Display for RenderedElement { } #[derive(Debug, Clone)] -pub enum ActionKind { +pub enum Action { AddNew, PushFront(Id), InsertAfter(Id, Id), Stop, } -impl ActionKind { +impl Action { pub fn new( ids: Vec, element_tree: &mut Option, -- cgit v1.2.3