add morphism to extract value-list from ListEditor
This commit is contained in:
parent
658f5c1000
commit
ecaa74ccfd
4 changed files with 66 additions and 24 deletions
|
@ -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<RwLock<Context>> ) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |rt, σ| {
|
||||
if let Some(v) = rt.read().unwrap().get_view::<dyn SingletonView<Item = char>>() {
|
||||
eprintln!("prev value: {}", v.get());
|
||||
{
|
||||
let mut rt = rt.write().unwrap();
|
||||
if let Some(buf) = rt.singleton_buffer::<char>() {
|
||||
// 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::<char>();
|
||||
|
||||
let char_buf = rt.write().unwrap().singleton_buffer::<char>().unwrap();
|
||||
|
||||
eprintln!("make edittree: char val = {}", char_buf.get());
|
||||
let mut edittree = CharEditor::new_edit_tree(
|
||||
ctx.clone(),
|
||||
char_buf,
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
eprintln!("insert Char~EditTree");
|
||||
rt.write().unwrap()
|
||||
.insert_branch(
|
||||
ReprTree::from_singleton_buffer(
|
||||
|
|
|
@ -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<RwLock<Context>>) {
|
|||
ctx.clone(),
|
||||
item_type.clone()
|
||||
).into_node(
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
src_rt.write().unwrap().insert_branch(
|
||||
|
@ -45,5 +55,39 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
let mt = crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<List Char>~EditTree"),
|
||||
dst_type: Context::parse(&ctx, "<List Char>")
|
||||
};
|
||||
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::<EditTree>();
|
||||
|
||||
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::<CharEditor>().unwrap()
|
||||
.read().unwrap()
|
||||
.get()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RwLock<Context>>, 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())
|
||||
{
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue