diff --git a/lib-nested-core/src/editors/char/mod.rs b/lib-nested-core/src/editors/char/mod.rs index 8b587ad..079fa85 100644 --- a/lib-nested-core/src/editors/char/mod.rs +++ b/lib-nested-core/src/editors/char/mod.rs @@ -9,7 +9,7 @@ use { }, laddertypes::{TypeTerm}, crate::{ - repr_tree::{Context, ReprTree, ReprTreeExt}, + repr_tree::{Context, ReprTree, ReprLeaf, ReprTreeExt}, edit_tree::{EditTree, TreeNavResult}, editors::ObjCommander, }, @@ -31,24 +31,27 @@ pub fn init_ctx( ctx: Arc> ) { { let ctx = ctx.clone(); move |rt, σ| { - if let Some(v) = rt.read().unwrap().get_view::>() { - eprintln!("prev value: {}", v.get()); + { + let mut rt = rt.write().unwrap(); + if let Some(buf) = rt.singleton_buffer::() { + // buffer already exists + } else { + rt.insert_leaf( + vec![].into_iter(), + ReprLeaf::from_singleton_buffer( + SingletonBuffer::new('\0') + )); + } } - /* Create EditTree object - */ - rt.view_char().0.update(); + let char_buf = rt.singleton_buffer::(); - let char_buf = rt.write().unwrap().singleton_buffer::().unwrap(); - - eprintln!("make edittree: char val = {}", char_buf.get()); let mut edittree = CharEditor::new_edit_tree( ctx.clone(), char_buf, - r3vi::buffer::singleton::SingletonBuffer::::new(0).get_port() + SingletonBuffer::::new(0).get_port() ); - eprintln!("insert Char~EditTree"); rt.write().unwrap() .insert_branch( ReprTree::from_singleton_buffer( diff --git a/lib-nested-core/src/editors/list/ctx.rs b/lib-nested-core/src/editors/list/ctx.rs index 3c3ae8f..0f97c3c 100644 --- a/lib-nested-core/src/editors/list/ctx.rs +++ b/lib-nested-core/src/editors/list/ctx.rs @@ -1,9 +1,19 @@ use { - r3vi::{view::{OuterViewPort, singleton::*}, buffer::singleton::*}, + r3vi::{ + view::{ + ViewPort, + OuterViewPort, Observer, singleton::* + }, + buffer::{singleton::*, vec::*} + }, laddertypes::{TypeTerm}, crate::{ - repr_tree::{Context, ReprTree}, - editors::list::{ListEditor}//, PTYListController, PTYListStyle} + repr_tree::{Context, ReprTree, ReprLeaf, ReprTreeExt}, + edit_tree::{EditTree}, + editors::{ + char::{CharEditor}, + list::{ListEditor}//, PTYListController, PTYListStyle} + } }, std::sync::{Arc, RwLock} }; @@ -30,7 +40,7 @@ pub fn init_ctx(ctx: Arc>) { ctx.clone(), item_type.clone() ).into_node( - r3vi::buffer::singleton::SingletonBuffer::::new(0).get_port() + SingletonBuffer::::new(0).get_port() ); src_rt.write().unwrap().insert_branch( @@ -45,5 +55,39 @@ pub fn init_ctx(ctx: Arc>) { } } ); + + let mt = crate::repr_tree::MorphismType { + src_type: Context::parse(&ctx, "~EditTree"), + dst_type: Context::parse(&ctx, "") + }; + ctx.write().unwrap().morphisms.add_morphism( + mt, + { + let ctx = ctx.clone(); + move |src_rt, σ| { + let edittree = + src_rt + .descend(Context::parse(&ctx, "EditTree")).unwrap() + .singleton_buffer::(); + + let list_edit = edittree.get().get_edit::< ListEditor >().unwrap(); + let edittree_items = list_edit.read().unwrap().data.get_port().to_list(); + src_rt.write().unwrap().insert_leaf( + vec![].into_iter(), + ReprLeaf::from_view( + edittree_items + .map( + |edittree_char| + edittree_char + .read().unwrap() + .get_edit::().unwrap() + .read().unwrap() + .get() + ) + ) + ); + } + } + ); } diff --git a/lib-nested-core/src/repr_tree/context.rs b/lib-nested-core/src/repr_tree/context.rs index abd23ff..3d0bfce 100644 --- a/lib-nested-core/src/repr_tree/context.rs +++ b/lib-nested-core/src/repr_tree/context.rs @@ -153,12 +153,12 @@ impl Context { pub fn type_term_to_str(&self, t: &TypeTerm) -> String { self.type_dict.read().unwrap().unparse(&t) } + /// adds an object without any representations pub fn add_obj(ctx: Arc>, name: String, typename: &str) { let type_tag = ctx.read().unwrap() .type_dict.write().unwrap() .parse(typename).unwrap(); - /* if let Some(node) = Context::make_node(&ctx, type_tag, SingletonBuffer::new(0).get_port()) { ctx.write().unwrap().nodes.insert(name, node); @@ -186,14 +186,12 @@ impl Context { self.type_term_from_str("EditTree").expect("") ]); - eprintln!("setp_edittree: apply morphism T -> T~EditTree"); self.morphisms.apply_morphism( rt.clone(), &rt.get_type(), &ladder ); - eprintln!("get repr-node of editTree"); if let Some(new_edittree) = rt.descend(self.type_term_from_str("EditTree").unwrap()) { diff --git a/lib-nested-tty/src/editors/list.rs b/lib-nested-tty/src/editors/list.rs index b3ce8a9..4af92fc 100644 --- a/lib-nested-tty/src/editors/list.rs +++ b/lib-nested-tty/src/editors/list.rs @@ -225,21 +225,18 @@ impl PTYListController { rt, self.depth.map(|d| d+1) ); - /* - let mut ne = new_edittree.write().unwrap(); + + let mut ne = new_edittree.get(); match ne.send_cmd_obj(cmd_obj.clone()) { TreeNavResult::Continue => { drop(ne); - e.insert(new_edittree.clone()); + e.insert(new_edittree.value.clone()); TreeNavResult::Continue } TreeNavResult::Exit => { - */ TreeNavResult::Exit - /* } } - */ }, ListCursorMode::Select => { if let Some(item) = e.get_item_mut() {