node: ViewPort for editor, cleanup PTYListEditor

- move split/join functions into ListEditor
- separate PTYListStyle and PTYListController
This commit is contained in:
Michael Sippel 2023-03-25 08:56:38 +01:00
parent 1575fa756e
commit b6bd888d3d
Signed by: senvas
GPG key ID: 060F22F65102F95C
7 changed files with 282 additions and 290 deletions

View file

@ -12,7 +12,7 @@ use {
}, },
crate::{ crate::{
type_system::{Context, TypeTerm, ReprTree}, type_system::{Context, TypeTerm, ReprTree},
editors::list::{PTYListEditor}, editors::list::{ListEditor, PTYListController, PTYListStyle},
terminal::{ terminal::{
TerminalAtom, TerminalEvent, TerminalStyle, make_label TerminalAtom, TerminalEvent, TerminalStyle, make_label
}, },
@ -114,7 +114,7 @@ impl DigitEditor {
pub fn get_type(&self) -> TypeTerm { pub fn get_type(&self) -> TypeTerm {
TypeTerm::Type { TypeTerm::Type {
id: self.ctx.read().unwrap().get_typeid("Digit").unwrap(), id: self.ctx.read().unwrap().get_fun_typeid("Digit").unwrap(),
args: vec![ args: vec![
TypeTerm::Num(self.radix as i64).into() TypeTerm::Num(self.radix as i64).into()
] ]
@ -140,38 +140,31 @@ pub struct PosIntEditor {
impl PosIntEditor { impl PosIntEditor {
pub fn new(ctx: Arc<RwLock<Context>>, radix: u32) -> Self { pub fn new(ctx: Arc<RwLock<Context>>, radix: u32) -> Self {
let editor = PTYListEditor::new( let mut node = Context::make_node(&ctx, (&ctx, format!("( List ( Digit {} ) )", radix).as_str()).into(), 0).unwrap();
ctx.clone(),
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("Digit").unwrap(),
args: vec![
TypeTerm::Num(radix as i64).into()
]
},
None,
0
);
let view = editor.pty_view(( PTYListController::for_node( &mut node, Some(' '), None );
PTYListStyle::for_node( &mut node,
(
match radix { match radix {
2 => "0d".into(), 2 => "0d".into(),
16 => "0x".into(), 16 => "0x".into(),
_ => "".into() _ => "".into()
}, },
"".into(), "".into(),
"".into())); "".into()
let mut node = editor.into_node().set_view(view); )
);
// Set Type // Set Type
let data = node.data.clone().unwrap(); let data = node.data.clone().unwrap();
node = node.set_data(ReprTree::ascend( node = node.set_data(ReprTree::ascend(
&data, &data,
TypeTerm::Type { TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("PosInt").unwrap(), id: ctx.read().unwrap().get_fun_typeid("PosInt").unwrap(),
args: vec![ args: vec![
TypeTerm::Num(radix as i64).into(), TypeTerm::Num(radix as i64).into(),
TypeTerm::Type { TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("BigEndian").unwrap(), id: ctx.read().unwrap().get_fun_typeid("BigEndian").unwrap(),
args: vec![] args: vec![]
}.into() }.into()
] ]

View file

@ -7,3 +7,4 @@ pub use {
editor::{DigitEditor, PosIntEditor}, editor::{DigitEditor, PosIntEditor},
radix::RadixProjection, radix::RadixProjection,
}; };

View file

@ -1,12 +1,13 @@
use { use {
r3vi::{ r3vi::{
view::{OuterViewPort, singleton::*, sequence::*}, view::{port::UpdateTask, OuterViewPort, singleton::*, sequence::*},
buffer::{singleton::*, vec::*} buffer::{singleton::*, vec::*}
}, },
crate::{ crate::{
type_system::{Context, TypeTerm, ReprTree}, type_system::{Context, TypeTerm, ReprTree},
editors::list::{ListCursor, ListCursorMode}, editors::list::{ListCursor, ListCursorMode},
tree::{NestedNode, TreeNav} tree::{NestedNode, TreeNav, TreeCursor},
diagnostics::Diagnostics
}, },
std::sync::{Arc, RwLock} std::sync::{Arc, RwLock}
}; };
@ -27,6 +28,31 @@ pub struct ListEditor {
} }
impl ListEditor { impl ListEditor {
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
let mut ctx = ctx.write().unwrap();
ctx.add_list_typename("List".into());
ctx.add_node_ctor(
"List", Arc::new(
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
match ty {
TypeTerm::Type {
id: _, args
} => {
if args.len() > 0 {
let typ = (args[0].clone().0)[0].clone();
Some(ListEditor::new(ctx, typ).into_node(depth))
} else {
None
}
}
_ => None
}
}
)
);
}
pub fn new( pub fn new(
ctx: Arc<RwLock<Context>>, ctx: Arc<RwLock<Context>>,
typ: TypeTerm, typ: TypeTerm,
@ -92,30 +118,33 @@ impl ListEditor {
let ctx = self.ctx.clone(); let ctx = self.ctx.clone();
let editor = Arc::new(RwLock::new(self)); let editor = Arc::new(RwLock::new(self));
let e = editor.read().unwrap();
NestedNode::new(depth) NestedNode::new(depth)
.set_ctx(ctx) .set_ctx(ctx)
.set_data(data) .set_data(data)
.set_editor(editor.clone()) .set_editor(editor.clone())
.set_nav(editor.clone()) .set_nav(editor.clone())
// .set_cmd(editor.clone()) //.set_cmd(editor.clone())
} .set_diag(e
.get_data_port()
pub fn new_node( .enumerate()
node: NestedNode, .map(
item_type: TypeTerm |(idx, item_editor)| {
) -> NestedNode { let idx = *idx;
let ctx = node.ctx.clone().unwrap(); item_editor
.get_msg_port()
let editor = ListEditor::new( .map(
ctx.clone(), move |msg| {
item_type, let mut msg = msg.clone();
); msg.addr.insert(0, idx);
let data = editor.get_data(); msg
let editor = Arc::new(RwLock::new(editor)); }
)
node.set_data(data) }
.set_editor(editor.clone()) )
.set_nav(editor.clone()) .flatten()
)
} }
pub fn get_item_type(&self) -> TypeTerm { pub fn get_item_type(&self) -> TypeTerm {
@ -124,7 +153,7 @@ impl ListEditor {
pub fn get_seq_type(&self) -> TypeTerm { pub fn get_seq_type(&self) -> TypeTerm {
TypeTerm::Type { TypeTerm::Type {
id: self.ctx.read().unwrap().get_typeid("List").unwrap(), id: self.ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![ self.get_item_type().into() ] args: vec![ self.get_item_type().into() ]
} }
} }
@ -255,8 +284,10 @@ impl ListEditor {
let prev_node = self.data.get(prev_idx); let prev_node = self.data.get(prev_idx);
if let Some(prev_editor) = prev_node.editor.clone() { if let Some(prev_editor) = prev_node.editor.clone() {
let prev_editor = prev_editor.downcast::<RwLock<ListEditor>>().unwrap(); prev_editor.0.update();
let prev_editor = prev_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let prev_editor = prev_editor.write().unwrap(); let prev_editor = prev_editor.write().unwrap();
prev_editor.get_data_port().0.update();
if prev_editor.get_data_port().get_view().unwrap().iter() if prev_editor.get_data_port().get_view().unwrap().iter()
.filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0 .filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0
@ -305,6 +336,110 @@ impl ListEditor {
self.data.push(other.data.get(i)); self.data.push(other.data.get(i));
} }
} }
pub fn listlist_split(&mut self) {
let cur = self.get_cursor();
if let Some(item) = self.get_item_mut() {
let depth = item.depth;
if let Some(head_editor) = item.editor.clone() {
head_editor.0.update();
let head = head_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap();
if head.data.len() > 0 {
if cur.tree_addr.len() > 2 {
head.listlist_split();
}
let mut tail = head.split();
head.goto(TreeCursor::none());
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
}
);
let item_type =
if let Some(data) = item.data.clone() {
let data = data.read().unwrap();
Some(data.get_type().clone())
} else {
None
};
let mut tail_node = tail.into_node(depth);
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
// if let Some(item_type) = item_type {
tail_node = tail_node.morph(self.typ.clone());
//}
self.insert(
tail_node
);
}
}
}
}
pub fn listlist_join_pxev(&mut self, idx: isize, item: &NestedNode) {
{
let prev_editor = self.data.get_mut(idx as usize-1);
let prev_editor = prev_editor.editor.clone();
if let Some(prev_editor) = prev_editor {
prev_editor.0.update();
if let Ok(prev_editor) = prev_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>() {
let mut prev_editor = prev_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
cur_editor.0.update();
let cur_editor = cur_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let cur_editor = cur_editor.write().unwrap();
prev_editor.join(&cur_editor);
self.cursor.set(
ListCursor {
idx: Some(idx - 1), mode: ListCursorMode::Select
}
);
}
}
}
self.data.remove(idx as usize);
}
pub fn listlist_join_nexd(&mut self, next_idx: usize, item: &NestedNode) {
{
let next_editor = self.data.get_mut(next_idx).editor.clone();
if let Some(next_editor) = next_editor {
next_editor.0.update();
if let Ok(next_editor) = next_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>() {
let mut next_editor = next_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
cur_editor.0.update();
let cur_editor = cur_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let mut cur_editor = cur_editor.write().unwrap();
cur_editor.join(&next_editor);
}
}
}
self.data.remove(next_idx);
}
} }
/* /*
use crate::{ use crate::{

View file

@ -10,6 +10,6 @@ pub use {
cursor::{ListCursor, ListCursorMode}, cursor::{ListCursor, ListCursorMode},
editor::ListEditor, editor::ListEditor,
segment::{ListSegment, ListSegmentSequence}, segment::{ListSegment, ListSegmentSequence},
pty_editor::{PTYListEditor} pty_editor::{PTYListStyle, PTYListController}
}; };

View file

@ -18,56 +18,30 @@ use {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub struct PTYListEditor { pub struct PTYListStyle {
pub editor: Arc<RwLock<ListEditor>>, style: (String, String, String),
split_char: Option<char>,
depth: usize depth: usize
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> impl PTYListStyle {
pub fn new(style: (&str, &str, &str), depth: usize) -> PTYListStyle {
impl PTYListEditor { PTYListStyle {
pub fn new( style: (style.0.into(), style.1.into(), style.2.into()),
ctx: Arc<RwLock<Context>>,
typ: TypeTerm,
split_char: Option<char>,
depth: usize
) -> Self {
Self::from_editor(
Arc::new(RwLock::new(ListEditor::new(ctx, typ))),
split_char,
depth depth
) }
} }
pub fn from_editor( pub fn get_seg_seq_view(&self, editor: &ListEditor) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
editor: Arc<RwLock<ListEditor>>,
split_char: Option<char>,
depth: usize
) -> Self {
PTYListEditor {
split_char,
depth,
editor,
}
}
pub fn get_seg_seq_view(&self) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
let seg_seq = ListSegmentSequence::new( let seg_seq = ListSegmentSequence::new(
self.editor.read().unwrap().get_cursor_port(), editor.get_cursor_port(),
self.editor.read().unwrap().get_data_port(), editor.get_data_port(),
self.depth self.depth
); );
let se = seg_seq.read().unwrap(); let se = seg_seq.read().unwrap();
se.get_view().map(move |segment| segment.pty_view()) se.get_view().map(move |segment| segment.pty_view())
} }
pub fn pty_view( pub fn pty_view(&self, editor: &ListEditor) -> OuterViewPort<dyn TerminalView> {
&self,
display_style: (&str, &str, &str),
) -> OuterViewPort<dyn TerminalView> {
let editor = self.editor.read().unwrap();
let seg_seq = ListSegmentSequence::new( let seg_seq = ListSegmentSequence::new(
editor.get_cursor_port(), editor.get_cursor_port(),
editor.get_data_port(), editor.get_data_port(),
@ -78,44 +52,59 @@ impl PTYListEditor {
seg_seq seg_seq
.get_view() .get_view()
.map(move |segment| segment.pty_view()) .map(move |segment| segment.pty_view())
.separate(make_label(display_style.1)) .separate(make_label(&self.style.1))
.wrap(make_label(display_style.0), make_label(display_style.2)) .wrap(make_label(&self.style.0), make_label(&self.style.2))
.to_grid_horizontal() .to_grid_horizontal()
.flatten() .flatten()
} }
pub fn into_node(self) -> NestedNode {
let depth = self.depth;
let editor = Arc::new(RwLock::new(self));
let ed = editor.read().unwrap(); pub fn for_node(node: &mut NestedNode, style: (&str, &str, &str)) {
let edd = ed.editor.read().unwrap(); node.view = Some(
Self::new(style, node.depth)
NestedNode::new(depth) .pty_view(
.set_data(edd.get_data()) &node.get_edit::<ListEditor>().unwrap().read().unwrap()
.set_cmd(editor.clone()) )
.set_editor(ed.editor.clone()) );
.set_nav(ed.editor.clone()) }
.set_ctx(edd.ctx.clone()) }
.set_diag(
edd.get_data_port() //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
.enumerate()
.map( pub struct PTYListController {
|(idx, item_editor)| { pub editor: Arc<RwLock<ListEditor>>,
let idx = *idx;
item_editor split_char: Option<char>,
.get_msg_port() close_char: Option<char>,
.map(
move |msg| { depth: usize
let mut msg = msg.clone(); }
msg.addr.insert(0, idx);
msg //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
}
) impl PTYListController {
} pub fn from_editor(
) editor: Arc<RwLock<ListEditor>>,
.flatten() split_char: Option<char>,
) close_char: Option<char>,
depth: usize
) -> Self {
PTYListController {
editor,
split_char,
close_char,
depth
}
}
pub fn for_node(
node: &mut NestedNode,
split_char: Option<char>,
close_char: Option<char>
) {
let editor = node.get_edit::<ListEditor>().unwrap();
let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.depth )));
node.cmd = Some(controller.clone());
} }
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> { pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> {
@ -133,113 +122,16 @@ impl PTYListEditor {
pub fn set_depth(&mut self, depth: usize) { pub fn set_depth(&mut self, depth: usize) {
self.depth = depth; self.depth = depth;
} }
pub fn split(e: &mut ListEditor) {
let cur = e.get_cursor();
if let Some(item) = e.get_item_mut() {
let depth = item.depth;
if let Some(head_editor) = item.editor.clone() {
let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap();
if head.data.len() > 0 {
if cur.tree_addr.len() > 2 {
PTYListEditor::split(&mut head);
}
let mut tail = head.split();
head.goto(TreeCursor::none());
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
}
);
let item_type =
if let Some(data) = item.data.clone() {
let data = data.read().unwrap();
Some(data.get_type().clone())
} else {
None
};
let mut tail_node = tail.into_node(depth);
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
if let Some(item_type) = item_type {
tail_node = tail_node.morph(item_type);
}
e.insert(
tail_node
);
}
}
}
}
fn join_pxev(e: &mut ListEditor, idx: isize, item: &NestedNode) {
{
let prev_editor = e.data.get_mut(idx as usize-1);
let prev_editor = prev_editor.editor.clone();
if let Some(prev_editor) = prev_editor {
if let Ok(prev_editor) = prev_editor.downcast::<RwLock<ListEditor>>() {
let mut prev_editor = prev_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
let cur_editor = cur_editor.downcast::<RwLock<ListEditor>>().unwrap();
let cur_editor = cur_editor.write().unwrap();
prev_editor.join(&cur_editor);
e.cursor.set(
ListCursor {
idx: Some(idx - 1), mode: ListCursorMode::Select
}
);
}
}
}
e.data.remove(idx as usize);
}
fn join_nexd(e: &mut ListEditor, next_idx: usize, item: &NestedNode) {
{
let next_editor = e.data.get_mut(next_idx).editor.clone();
if let Some(next_editor) = next_editor {
if let Ok(next_editor) = next_editor.downcast::<RwLock<ListEditor>>() {
let mut next_editor = next_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
let cur_editor = cur_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut cur_editor = cur_editor.write().unwrap();
cur_editor.join(&next_editor);
}
}
}
e.data.remove(next_idx);
}
} }
use r3vi::view::singleton::SingletonView; use r3vi::view::singleton::SingletonView;
use crate::commander::ObjCommander; use crate::commander::ObjCommander;
impl ObjCommander for PTYListEditor { impl ObjCommander for PTYListController {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult { fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
let mut e = self.editor.write().unwrap(); let mut e = self.editor.write().unwrap();
let cur = e.cursor.get(); let cur = e.cursor.get();
let cur_depth = e.get_cursor().tree_addr.len();
let ctx = e.ctx.clone(); let ctx = e.ctx.clone();
let ctx = ctx.read().unwrap(); let ctx = ctx.read().unwrap();
@ -247,8 +139,24 @@ impl ObjCommander for PTYListEditor {
let co = cmd_obj.read().unwrap(); let co = cmd_obj.read().unwrap();
let cmd_type = co.get_type().clone(); let cmd_type = co.get_type().clone();
let term_event_type = ctx.type_term_from_str("( TerminalEvent )").unwrap(); let term_event_type = ctx.type_term_from_str("( TerminalEvent )").unwrap();
let nested_node_type = ctx.type_term_from_str("( NestedNode )").unwrap();
let char_type = ctx.type_term_from_str("( Char )").unwrap(); let char_type = ctx.type_term_from_str("( Char )").unwrap();
if cmd_type == nested_node_type {
if let Some(node_view) = co.get_view::<dyn SingletonView<Item = NestedNode>>() {
if let Some(idx) = cur.idx {
match cur.mode {
ListCursorMode::Select => {
*e.data.get_mut(idx as usize) = node_view.get();
}
ListCursorMode::Insert => {
e.data.insert(idx as usize, node_view.get());
}
}
}
}
}
if cmd_type == term_event_type { if cmd_type == term_event_type {
if let Some(te_view) = co.get_view::<dyn SingletonView<Item = TerminalEvent>>() { if let Some(te_view) = co.get_view::<dyn SingletonView<Item = TerminalEvent>>() {
drop(co); drop(co);
@ -309,7 +217,7 @@ impl ObjCommander for PTYListEditor {
|is_zero, x| is_zero && (*x == 0) |is_zero, x| is_zero && (*x == 0)
) )
{ {
PTYListEditor::join_pxev(&mut e, idx, &item); e.listlist_join_pxev(idx, &item);
/* Optional: recursive joining /* Optional: recursive joining
@ -333,7 +241,7 @@ impl ObjCommander for PTYListEditor {
|is_end, x| is_end && (*x == -1) |is_end, x| is_end && (*x == -1)
) )
{ {
PTYListEditor::join_nexd(&mut e, next_idx, &item); e.listlist_join_nexd(next_idx, &item);
/* Optional: recursive joining /* Optional: recursive joining
@ -351,7 +259,7 @@ impl ObjCommander for PTYListEditor {
TerminalEvent::Input(Event::Key(Key::Char(c))) => { TerminalEvent::Input(Event::Key(Key::Char(c))) => {
if Some(c) == self.split_char { if Some(c) == self.split_char {
PTYListEditor::split(&mut e); e.listlist_split();
TreeNavResult::Continue TreeNavResult::Continue
} else { } else {
item.send_cmd_obj(cmd_obj) item.send_cmd_obj(cmd_obj)
@ -382,14 +290,18 @@ impl ObjCommander for PTYListEditor {
drop(co); drop(co);
let c = cmd_view.get(); let c = cmd_view.get();
if Some(c) == self.split_char { if Some(c) == self.split_char && cur_depth == 2 {
PTYListEditor::split(&mut e); e.listlist_split();
TreeNavResult::Continue TreeNavResult::Continue
} else { } else {
if let Some(mut item) = e.get_item_mut() { if let Some(mut item) = e.get_item_mut() {
match item.send_cmd_obj(cmd_obj) { match item.send_cmd_obj(cmd_obj) {
TreeNavResult::Continue => TreeNavResult::Continue, TreeNavResult::Continue => TreeNavResult::Continue,
TreeNavResult::Exit => { TreeNavResult::Exit => {
if Some(c) == self.split_char {
e.listlist_split();
}
item.goto(TreeCursor::none()); item.goto(TreeCursor::none());
e.cursor.set(ListCursor { e.cursor.set(ListCursor {
mode: ListCursorMode::Insert, mode: ListCursorMode::Insert,

View file

@ -24,7 +24,7 @@ pub struct NestedNode {
pub ctx: Option<Arc<RwLock<Context>>>, pub ctx: Option<Arc<RwLock<Context>>>,
/// abstract editor /// abstract editor
pub editor: Option<Arc<dyn Any + Send + Sync>>, pub editor: Option<OuterViewPort<dyn SingletonView<Item = Option<Arc<dyn Any + Send + Sync>>>>>,
/// abstract data view /// abstract data view
pub data: Option<Arc<RwLock<ReprTree>>>, pub data: Option<Arc<RwLock<ReprTree>>>,
@ -195,7 +195,7 @@ impl NestedNode {
} }
pub fn set_editor(mut self, editor: Arc<dyn Any + Send + Sync>) -> Self { pub fn set_editor(mut self, editor: Arc<dyn Any + Send + Sync>) -> Self {
self.editor = Some(editor); self.editor = Some(SingletonBuffer::new(Some(editor)).get_port());
self self
} }
@ -267,7 +267,7 @@ impl NestedNode {
*/ */
pub fn get_edit<T: Send + Sync + 'static>(&self) -> Option<Arc<RwLock<T>>> { pub fn get_edit<T: Send + Sync + 'static>(&self) -> Option<Arc<RwLock<T>>> {
if let Some(edit) = self.editor.clone() { if let Some(edit) = self.editor.clone() {
if let Ok(edit) = edit.downcast::<RwLock<T>>() { if let Ok(edit) = edit.get_view().unwrap().get().unwrap().downcast::<RwLock<T>>() {
Some(edit) Some(edit)
} else { } else {
None None

View file

@ -61,38 +61,13 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
} }
) )
); );
ctx.write().unwrap().add_list_typename("Seq".into()); ctx.write().unwrap().add_list_typename("Seq".into());
ctx.write().unwrap().add_list_typename("Sequence".into()); ctx.write().unwrap().add_list_typename("Sequence".into());
ctx.write().unwrap().add_list_typename("SepSeq".into());
ctx.write().unwrap().add_typename("NestedNode".into());
ctx.write().unwrap().add_list_typename("List".into()); ListEditor::init_ctx( &ctx );
ctx.write().unwrap().add_node_ctor(
"List", Arc::new(
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
match ty {
TypeTerm::Type {
id: _, args
} => {
if args.len() > 0 {
let editor = PTYListEditor::new(
ctx,
(args[0].clone().0)[0].clone(),
Some(','),
depth + 1
);
let view = editor.pty_view(("{",", ", "}"));
Some(editor
.into_node()
.set_view(view))
} else {
None
}
}
_ => None
}
}
)
);
ctx.write().unwrap().add_list_typename("Symbol".into()); ctx.write().unwrap().add_list_typename("Symbol".into());
let pattern = MorphismTypePattern { let pattern = MorphismTypePattern {
@ -102,17 +77,9 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
ctx.write().unwrap().add_morphism(pattern, ctx.write().unwrap().add_morphism(pattern,
Arc::new( Arc::new(
|mut node, _dst_type:_| { |mut node, _dst_type:_| {
let depth = node.depth; PTYListController::for_node( &mut node, None, None );
let editor = node.editor.clone().unwrap().downcast::<RwLock<ListEditor>>().unwrap(); PTYListStyle::for_node( &mut node, ("","","") );
let pty_editor = PTYListEditor::from_editor( Some(node)
editor,
None,
depth
);
node.view = Some(pty_editor.pty_view(("", "", "")));
node.cmd = Some(Arc::new(RwLock::new(pty_editor)));
Some(node)
} }
) )
); );
@ -123,7 +90,7 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
let mut node = Context::make_node( let mut node = Context::make_node(
&ctx, &ctx,
TypeTerm::Type { TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("List").unwrap(), id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![ args: vec![
TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into() TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into()
] ]
@ -146,20 +113,8 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
ctx.write().unwrap().add_morphism(pattern, ctx.write().unwrap().add_morphism(pattern,
Arc::new( Arc::new(
|mut node, _dst_type:_| { |mut node, _dst_type:_| {
let depth = node.depth; PTYListController::for_node( &mut node, None, Some('\"') );
let editor = node.editor.clone().unwrap().downcast::<RwLock<ListEditor>>().unwrap(); PTYListStyle::for_node( &mut node, ("\"","","\"") );
let pty_editor = PTYListEditor::from_editor(
editor,
None,
depth
);
node.view = Some(pty_editor.pty_view((
"\"".into(),
"".into(),
"\"".into()
)));
node.cmd = Some(Arc::new(RwLock::new(pty_editor)));
Some(node) Some(node)
} }
) )
@ -171,7 +126,7 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
let mut node = Context::make_node( let mut node = Context::make_node(
&ctx, &ctx,
TypeTerm::Type { TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("List").unwrap(), id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![ args: vec![
TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into() TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into()
] ]
@ -243,7 +198,7 @@ pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
Arc::new( Arc::new(
|mut node, dst_type| { |mut node, dst_type| {
let depth = node.depth; let depth = node.depth;
let editor = node.editor.clone().unwrap().downcast::<RwLock<ListEditor>>().unwrap(); let editor = node.editor.clone().unwrap().get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
// todo: check src_type parameter to be ( Digit radix ) // todo: check src_type parameter to be ( Digit radix )
@ -254,21 +209,17 @@ pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
if args.len() > 0 { if args.len() > 0 {
match (args[0].0)[0] { match (args[0].0)[0] {
TypeTerm::Num(_radix) => { TypeTerm::Num(_radix) => {
let pty_editor = PTYListEditor::from_editor( PTYListController::for_node(
editor, &mut node,
Some(','), Some(','),
depth None,
);
PTYListStyle::for_node(
&mut node,
("0d", "", "")
); );
// todo: set data view
node.view = Some(pty_editor.pty_view(
(
"{".into(),
", ".into(),
"}".into()
)
));
node.cmd = Some(Arc::new(RwLock::new(pty_editor)));
Some(node) Some(node)
}, },
_ => None _ => None
@ -297,7 +248,7 @@ pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
let mut node = Context::make_node( let mut node = Context::make_node(
&ctx, &ctx,
TypeTerm::Type { TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("List").unwrap(), id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![ args: vec![
TypeTerm::new(ctx.read().unwrap().get_typeid("Digit").unwrap()) TypeTerm::new(ctx.read().unwrap().get_typeid("Digit").unwrap())
.num_arg(radix) .num_arg(radix)