From d43d99c6d3266b539cd5898fdc77b70296a7b9f9 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sat, 11 Feb 2023 12:03:37 +0100 Subject: [PATCH] PTYListEditor: move style into node constructor --- nested/src/integer/editor.rs | 9 ++-- nested/src/list/pty_editor.rs | 60 ++++++++++----------------- nested/src/type_system/make_editor.rs | 3 +- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/nested/src/integer/editor.rs b/nested/src/integer/editor.rs index 62ed0e9..c500899 100644 --- a/nested/src/integer/editor.rs +++ b/nested/src/integer/editor.rs @@ -125,13 +125,14 @@ impl PosIntEditor { TypeTerm::Num(radix as i64) ] }, + None, + 0 + ).into_node( match radix { 16 => SeqDecorStyle::Hex, _ => SeqDecorStyle::Plain - }, - None, - 0 - ).into_node() + } + ) } } diff --git a/nested/src/list/pty_editor.rs b/nested/src/list/pty_editor.rs index d1d5286..560b4f2 100644 --- a/nested/src/list/pty_editor.rs +++ b/nested/src/list/pty_editor.rs @@ -26,12 +26,7 @@ use { pub struct PTYListEditor { pub editor: Arc>, split_char: Option, - - style: SeqDecorStyle, - depth: usize, - - pub diag: OuterViewPort>, - pub view: OuterViewPort + depth: usize } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> @@ -40,27 +35,38 @@ impl PTYListEditor { pub fn new( ctx: Arc>, typ: TypeTerm, - style: SeqDecorStyle, split_char: Option, depth: usize ) -> Self { Self::from_editor( - ListEditor::new(ctx, typ, depth), style, split_char, depth) + ListEditor::new(ctx, typ, depth), split_char, depth) } pub fn from_editor( editor: ListEditor, - style: SeqDecorStyle, split_char: Option, depth: usize ) -> Self { PTYListEditor { split_char, - style, depth, + editor: Arc::new(RwLock::new(editor)), + } + } - view: editor.get_seg_seq_view().pty_decorate(style, depth), - diag: editor.get_data_port() + pub fn into_node(self, style: SeqDecorStyle) -> NestedNode { + let editor = Arc::new(RwLock::new(self)); + + let ed = editor.read().unwrap(); + let edd = ed.editor.read().unwrap(); + + NestedNode::new() + .set_cmd(editor.clone()) + .set_nav(ed.editor.clone()) + .set_ctx(edd.ctx.clone()) + .set_view(edd.get_seg_seq_view().pty_decorate(style, ed.depth)) + .set_diag( + edd.get_data_port() .enumerate() .map( |(idx, item_editor)| { @@ -76,45 +82,25 @@ impl PTYListEditor { ) } ) - .flatten(), - - editor: Arc::new(RwLock::new(editor)), - } + .flatten() + ) } - pub fn into_node(self) -> NestedNode { - let editor = Arc::new(RwLock::new(self)); - - let ed = editor.read().unwrap(); - let edd = ed.editor.read().unwrap(); - - NestedNode::new() - .set_cmd(editor.clone()) - .set_nav(ed.editor.clone()) - .set_ctx(edd.ctx.clone()) - .set_diag(ed.diag.clone()) - .set_view(ed.view.clone()) - } - pub fn get_data_port(&self) -> OuterViewPort> { self.editor.read().unwrap().get_data_port() } - + pub fn clear(&mut self) { self.editor.write().unwrap().clear(); } - + pub fn get_item(&self) -> Option { self.editor.read().unwrap().get_item() } - + pub fn set_depth(&mut self, depth: usize) { self.depth = depth; } - - pub fn set_style(&mut self, style: SeqDecorStyle) { - self.style = style; - } } impl Commander for PTYListEditor { diff --git a/nested/src/type_system/make_editor.rs b/nested/src/type_system/make_editor.rs index 74b7aa7..1fd7f7c 100644 --- a/nested/src/type_system/make_editor.rs +++ b/nested/src/type_system/make_editor.rs @@ -74,10 +74,9 @@ pub fn init_editor_ctx(parent: Arc>) -> Arc> { PTYListEditor::new( ctx.clone(), args[0].clone(), - style, delim, depth - ).into_node() + ).into_node(style) ) } else { None