rename NestedNode to EditTree

This commit is contained in:
Michael Sippel 2024-01-07 20:04:23 +01:00
parent 47a35f22b7
commit 668b0b8b96
Signed by: senvas
GPG key ID: F96CF119C34B64A6
14 changed files with 84 additions and 84 deletions

View file

@ -9,7 +9,7 @@ use {
nested::{
editors::ObjCommander,
repr_tree::{Context, ReprTree},
edit_tree::{NestedNode}
edit_tree::{EditTree}
},
nested_tty::{
DisplaySegment, TTYApplication,
@ -48,8 +48,8 @@ async fn main() {
let rt_digit = ReprTree::new_arc( Context::parse(&ctx, "<Digit 10>") );
let port_char = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = char>>::new();
let port_u32 = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = u32>>::new();
let port_edit = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = NestedNode>>::new();
let port_char_edit = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = NestedNode>>::new();
let port_edit = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = EditTree>>::new();
let port_char_edit = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = EditTree>>::new();
rt_digit.write().unwrap()
.insert_leaf(
@ -85,15 +85,14 @@ async fn main() {
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
);
node_edit_char = nested_tty::editors::edittree_make_char_view( edittree_char );
let mut edit_char = node_edit_char.get_edit::< nested::editors::char::CharEditor >().unwrap();
edittree_char = nested_tty::editors::edittree_make_char_view( edittree_char );
let mut edit_char = edittree_char.get_edit::< nested::editors::char::CharEditor >().unwrap();
port_char.attach_to( edit_char.read().unwrap().get_port() );
let buf_edit_char = r3vi::buffer::singleton::SingletonBuffer::new( node_edit_char.clone() );
let buf_edit_char = r3vi::buffer::singleton::SingletonBuffer::new( edittree_char.clone() );
port_char_edit.attach_to( buf_edit_char.get_port() );
// created by <Digit 10> ==> <Digit 10>~EditTree
let mut node_edit_digit =
nested::editors::integer::DigitEditor::new(

View file

@ -10,6 +10,6 @@ pub use {
cursor::TreeCursor,
nav::{TreeNav, TreeNavResult, TreeHeightOp},
treetype::{TreeType},
node::NestedNode
node::EditTree
};

View file

@ -14,7 +14,7 @@ use {
};
#[derive(Clone)]
pub struct NestedNodeDisplay {
pub struct EdittreeDisplay {
/// display view
pub view: Arc<RwLock<ReprTree>>,
@ -26,13 +26,13 @@ pub struct NestedNodeDisplay {
}
#[derive(Clone)]
pub struct NestedNodeEdit {
pub struct EdittreeControl {
/// abstract editor
pub editor: SingletonBuffer<
Option< Arc<dyn Any + Send + Sync> >
>,
pub spillbuf: Arc<RwLock< Vec< Arc<RwLock< NestedNode >> > >>,
pub spillbuf: Arc<RwLock< Vec< Arc<RwLock< EditTree >> > >>,
/// commander & navigation
pub cmd: SingletonBuffer<
@ -51,26 +51,26 @@ pub struct NestedNodeEdit {
* TODO: rename to EditNode
*/
#[derive(Clone)]
pub struct NestedNode {
pub struct EditTree {
/// context
pub ctx: Arc<RwLock<Context>>,
/// viewports for terminal display
pub disp: NestedNodeDisplay,
pub disp: EdittreeDisplay,
/// editor & commander objects
pub edit: NestedNodeEdit
pub ctrl: EdittreeControl
}
impl NestedNode {
impl EditTree {
pub fn new(ctx: Arc<RwLock<Context>>, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> Self {
NestedNode {
disp: NestedNodeDisplay {
EditTree {
disp: EdittreeDisplay {
view: ReprTree::new_arc(Context::parse(&ctx, "Display")),
diag: None,
depth,
},
edit: NestedNodeEdit {
ctrl: EdittreeControl {
editor: SingletonBuffer::new(None),
spillbuf: Arc::new(RwLock::new(Vec::new())),
cmd: SingletonBuffer::new(None),
@ -82,17 +82,17 @@ impl NestedNode {
}
pub fn set_editor(mut self, editor: Arc<dyn Any + Send + Sync>) -> Self {
self.edit.editor.set(Some(editor));
self.ctrl.editor.set(Some(editor));
self
}
pub fn set_cmd(mut self, cmd: Arc<RwLock<dyn ObjCommander + Send + Sync>>) -> Self {
self.edit.cmd.set(Some(cmd));
self.ctrl.cmd.set(Some(cmd));
self
}
pub fn set_nav(mut self, nav: Arc<RwLock<dyn TreeNav + Send + Sync>>) -> Self {
self.edit.tree_nav.set(Some(nav));
self.ctrl.tree_nav.set(Some(nav));
self
}
@ -108,7 +108,7 @@ impl NestedNode {
}
pub fn get_edit<T: Send + Sync + 'static>(&self) -> Option<Arc<RwLock<T>>> {
if let Some(edit) = self.edit.editor.get() {
if let Some(edit) = self.ctrl.editor.get() {
if let Ok(edit) = edit.downcast::<RwLock<T>>() {
Some(edit)
} else {
@ -132,9 +132,9 @@ impl TreeType for NestedNode {
}
*/
impl TreeNav for NestedNode {
impl TreeNav for EditTree {
fn get_cursor(&self) -> TreeCursor {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.read().unwrap().get_cursor()
} else {
TreeCursor::default()
@ -142,7 +142,7 @@ impl TreeNav for NestedNode {
}
fn get_addr_view(&self) -> OuterViewPort<dyn SequenceView<Item = isize>> {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.read().unwrap().get_addr_view()
} else {
OuterViewPort::default()
@ -150,7 +150,7 @@ impl TreeNav for NestedNode {
}
fn get_mode_view(&self) -> OuterViewPort<dyn SingletonView<Item = ListCursorMode>> {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.read().unwrap().get_mode_view()
} else {
OuterViewPort::default()
@ -158,7 +158,7 @@ impl TreeNav for NestedNode {
}
fn get_cursor_warp(&self) -> TreeCursor {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.read().unwrap().get_cursor_warp()
} else {
TreeCursor::default()
@ -166,7 +166,7 @@ impl TreeNav for NestedNode {
}
fn get_height(&self, op: &TreeHeightOp) -> usize {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.read().unwrap().get_height( op )
} else {
0
@ -174,7 +174,7 @@ impl TreeNav for NestedNode {
}
fn goby(&mut self, direction: Vector2<isize>) -> TreeNavResult {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.write().unwrap().goby(direction)
} else {
TreeNavResult::Exit
@ -182,7 +182,7 @@ impl TreeNav for NestedNode {
}
fn goto(&mut self, new_cursor: TreeCursor) -> TreeNavResult {
if let Some(tn) = self.edit.tree_nav.get() {
if let Some(tn) = self.ctrl.tree_nav.get() {
tn.write().unwrap().goto(new_cursor)
} else {
TreeNavResult::Exit
@ -192,7 +192,7 @@ impl TreeNav for NestedNode {
use crate::edit_tree::nav::TreeNavCmd;
impl ObjCommander for NestedNode {
impl ObjCommander for EditTree {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
if cmd_obj.read().unwrap().get_type() == &Context::parse(&self.ctx, "TreeNavCmd") {
@ -211,7 +211,7 @@ impl ObjCommander for NestedNode {
} else {
TreeNavResult::Exit
}
} else if let Some(cmd) = self.edit.cmd.get() {
} else if let Some(cmd) = self.ctrl.cmd.get() {
// todo: filter out tree-nav cmds and send them to tree_nav
cmd.write().unwrap().send_cmd_obj(cmd_obj)
} else {
@ -221,7 +221,7 @@ impl ObjCommander for NestedNode {
}
impl Diagnostics for NestedNode {
impl Diagnostics for EditTree {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> {
self.get_diag()
}

View file

@ -9,7 +9,7 @@ use {
laddertypes::{TypeTerm},
crate::{
repr_tree::{Context, ReprTree},
edit_tree::{NestedNode, TreeNavResult},
edit_tree::{EditTree, TreeNavResult},
editors::ObjCommander,
},
std::sync::Arc,
@ -74,12 +74,12 @@ impl CharEditor {
pub fn new_edit_tree(
ctx0: Arc<RwLock<Context>>,
depth: OuterViewPort<dyn SingletonView<Item = usize>>
) -> NestedNode {
) -> EditTree {
let data = SingletonBuffer::new('\0');
let ctx = ctx0.clone();
let editor = Arc::new(RwLock::new(CharEditor{ ctx, data: data.clone() }));
NestedNode::new(
EditTree::new(
ctx0.clone(),
depth
)

View file

@ -14,7 +14,7 @@ use {
crate::{
editors::{list::{ListCmd}, ObjCommander},
repr_tree::{Context, ReprTree},
edit_tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor, diagnostics::{Message}},
edit_tree::{EditTree, TreeNav, TreeNavResult, TreeCursor, diagnostics::{Message}},
},
std::sync::Arc,
std::sync::RwLock,
@ -81,13 +81,13 @@ impl DigitEditor {
}
}
pub fn into_node(self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> NestedNode {
pub fn into_node(self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> EditTree {
let data = self.get_data();
let editor = Arc::new(RwLock::new(self));
let ed = editor.write().unwrap();
let r = ed.radix;
NestedNode::new(ed.ctx.clone(), depth)
EditTree::new(ed.ctx.clone(), depth)
.set_editor(editor.clone())
.set_cmd(editor.clone())
.set_diag(
@ -133,7 +133,7 @@ impl DigitEditor {
pub struct PosIntEditor {
radix: u32,
digits: NestedNode,
digits: EditTree,
// todo: endianness
}
@ -175,7 +175,7 @@ impl PosIntEditor {
*/
PosIntEditor {
radix,
digits: NestedNode::new(
digits: EditTree::new(
ctx,
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
)
@ -203,7 +203,7 @@ impl PosIntEditor {
self.digits.goto(TreeCursor::none());
}
pub fn into_node(self) -> NestedNode {
pub fn into_node(self) -> EditTree {
self.digits
}

View file

@ -5,7 +5,7 @@ use {
crate::{
editors::{list::{ListEditor, ListCursor, ListCursorMode}, ObjCommander},
repr_tree::{Context, ReprTree},
edit_tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
edit_tree::{EditTree, TreeNav, TreeNavResult, TreeCursor},
},
std::sync::{Arc, RwLock}
};
@ -35,7 +35,7 @@ impl ObjCommander for ListEditor {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
let cmd_repr = cmd_obj.read().unwrap();
if let Some(view) = cmd_repr.get_view::<dyn SingletonView<Item = NestedNode>>() {
if let Some(view) = cmd_repr.get_view::<dyn SingletonView<Item = EditTree>>() {
let node = view.get();
let cur = self.cursor.get();

View file

@ -6,7 +6,7 @@ use {
laddertypes::{TypeTerm},
crate::{
repr_tree::{Context, ReprTree},
edit_tree::{NestedNode, TreeNav, TreeCursor, diagnostics::Diagnostics},
edit_tree::{EditTree, TreeNav, TreeCursor, diagnostics::Diagnostics},
editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander},
},
std::sync::{Arc, RwLock}
@ -18,9 +18,9 @@ pub struct ListEditor {
pub cursor: SingletonBuffer<ListCursor>,
// todo: (?) remove RwLock<..> around NestedNode ??
pub data: VecBuffer< Arc<RwLock<NestedNode>> >,
pub data: VecBuffer< Arc<RwLock<EditTree>> >,
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<EditTree>>>>>,
pub(super) addr_port: OuterViewPort<dyn SequenceView<Item = isize>>,
pub(super) mode_port: OuterViewPort<dyn SingletonView<Item = ListCursorMode>>,
@ -39,7 +39,7 @@ impl ListEditor {
typ: TypeTerm,
) -> Self {
let cursor = SingletonBuffer::new(ListCursor::default());
let data : VecBuffer<Arc<RwLock<NestedNode>>> = VecBuffer::new();
let data : VecBuffer<Arc<RwLock<EditTree>>> = VecBuffer::new();
ListEditor {
mode_port: cursor
@ -100,7 +100,7 @@ impl ListEditor {
}
}
pub fn into_node(mut self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> NestedNode {
pub fn into_node(mut self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> EditTree {
let data = self.get_data();
let ctx = self.ctx.clone();
@ -109,7 +109,7 @@ impl ListEditor {
let e = editor.read().unwrap();
let mut node = NestedNode::new(ctx, depth)
let mut node = EditTree::new(ctx, depth)
.set_editor(editor.clone())
.set_nav(editor.clone())
.set_cmd(editor.clone())
@ -131,7 +131,7 @@ impl ListEditor {
.flatten()
);
node.edit.spillbuf = e.spillbuf.clone();
node.ctrl.spillbuf = e.spillbuf.clone();
node
}
@ -150,7 +150,7 @@ impl ListEditor {
self.cursor.get_port()
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> {
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
self.data.get_port().to_sequence().map(
|x| x.read().unwrap().clone()
)
@ -164,7 +164,7 @@ impl ListEditor {
)
}
pub fn get_item(&self) -> Option<NestedNode> {
pub fn get_item(&self) -> Option<EditTree> {
if let Some(idx) = self.cursor.get().idx {
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
if idx < self.data.len() {
@ -177,7 +177,7 @@ impl ListEditor {
}
}
pub fn get_item_mut(&mut self) -> Option<MutableVecAccess<Arc<RwLock<NestedNode>>>> {
pub fn get_item_mut(&mut self) -> Option<MutableVecAccess<Arc<RwLock<EditTree>>>> {
if let Some(idx) = self.cursor.get().idx {
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
if idx < self.data.len() {
@ -228,7 +228,7 @@ impl ListEditor {
}
/// insert a new element
pub fn insert(&mut self, item: Arc<RwLock<NestedNode>>) {
pub fn insert(&mut self, item: Arc<RwLock<EditTree>>) {
item.read().unwrap().disp.depth.0.set_view(
self.depth.map(|d| d+1).get_view()
);
@ -306,7 +306,7 @@ impl ListEditor {
self.set_leaf_mode(ListCursorMode::Insert);
self.nexd();
let mut b = item.edit.spillbuf.write().unwrap();
let mut b = item.ctrl.spillbuf.write().unwrap();
/* TODO
let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), self.depth.map(|d| d+1)).unwrap();
tail_node.goto(TreeCursor::home());
@ -366,12 +366,12 @@ impl ListEditor {
let old_cur = pxv_editor.get_cursor();
let data = cur_editor.edit.spillbuf.read().unwrap();
let data = cur_editor.ctrl.spillbuf.read().unwrap();
for x in data.iter() {
pxv_editor.send_cmd_obj(
ReprTree::new_leaf(
Context::parse(&self.ctx, "NestedNode"),
SingletonBuffer::<NestedNode>::new(
SingletonBuffer::<EditTree>::new(
x.read().unwrap().clone()
).get_port().into()
)
@ -424,13 +424,13 @@ impl ListEditor {
leaf_mode: ListCursorMode::Insert
});
let data = nxd_editor.edit.spillbuf.read().unwrap();
let data = nxd_editor.ctrl.spillbuf.read().unwrap();
for x in data.iter() {
cur_editor.send_cmd_obj(
ReprTree::new_leaf(
Context::parse(&self.ctx, "NestedNode"),
SingletonBuffer::<NestedNode>::new(
SingletonBuffer::<EditTree>::new(
x.read().unwrap().clone()
).get_port().into()
)

View file

@ -9,7 +9,7 @@ use {
},
crate::{
editors::list::{ListCursor, ListCursorMode},
edit_tree::{NestedNode}
edit_tree::{EditTree}
},
std::sync::Arc,
std::sync::RwLock,
@ -18,13 +18,13 @@ use {
pub enum ListSegment {
InsertCursor,
Item {
editor: NestedNode,
editor: EditTree,
cur_dist: isize,
}
}
pub struct ListSegmentSequence {
data: Arc<dyn SequenceView<Item = NestedNode>>,
data: Arc<dyn SequenceView<Item = EditTree>>,
cursor: Arc<dyn SingletonView<Item = ListCursor>>,
cur_cursor: ListCursor,
@ -88,7 +88,7 @@ impl SequenceView for ListSegmentSequence {
impl ListSegmentSequence {
pub fn new(
cursor_port: OuterViewPort<dyn SingletonView<Item = ListCursor>>,
data_port: OuterViewPort<dyn SequenceView<Item = NestedNode>>,
data_port: OuterViewPort<dyn SequenceView<Item = EditTree>>,
) -> Arc<RwLock<Self>> {
let out_port = ViewPort::new();
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());

View file

@ -3,7 +3,7 @@ use {
laddertypes::{TypeDict, TypeTerm, TypeID},
crate::{
repr_tree::{ReprTree, MorphismType, GenericReprTreeMorphism, MorphismBase},
edit_tree::NestedNode
edit_tree::EditTree
},
std::{
collections::HashMap,

View file

@ -99,11 +99,12 @@ impl TerminalEvent {
}
}
_ => {
ReprTree::new_leaf(
Context::parse(&ctx, "TerminalEvent"),
SingletonBuffer::new(self.clone()).get_port().into()
)
ReprTree::new_leaf(
Context::parse(&ctx, "TerminalEvent"),
SingletonBuffer::new(self.clone()).get_port().into()
)
}
}
}
}

View file

@ -6,7 +6,7 @@ use {
nested::{
repr_tree::{Context, ReprTree},
editors::list::*,
edit_tree::{TreeCursor, TreeNav, TreeNavResult, NestedNode},
edit_tree::{TreeCursor, TreeNav, TreeNavResult, EditTree},
},
crate::{
DisplaySegment,
@ -91,7 +91,7 @@ impl PTYListStyle {
.flatten()
}
pub fn for_node(node: &mut NestedNode, style: (&str, &str, &str)) {
pub fn for_node(node: &mut EditTree, style: (&str, &str, &str)) {
node.disp.view
.write().unwrap()
.insert_branch(ReprTree::new_leaf(
@ -135,7 +135,7 @@ impl PTYListController {
}
pub fn for_node(
node: &mut NestedNode,
node: &mut EditTree,
split_char: Option<char>,
close_char: Option<char>
) {
@ -154,11 +154,11 @@ impl PTYListController {
let editor = node.get_edit::<ListEditor>().unwrap();
let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.disp.depth.clone() )));
node.edit.cmd.set(Some(controller.clone()));
node.edit.close_char.set(close_char);
node.ctrl.cmd.set(Some(controller.clone()));
node.ctrl.close_char.set(close_char);
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> {
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
self.editor.read().unwrap().get_data_port()
}
@ -166,7 +166,7 @@ impl PTYListController {
self.editor.write().unwrap().clear();
}
pub fn get_item(&self) -> Option<NestedNode> {
pub fn get_item(&self) -> Option<EditTree> {
self.editor.read().unwrap().get_item()
}
@ -238,7 +238,7 @@ impl PTYListController {
ListCursorMode::Select => {
if let Some(item) = e.get_item_mut() {
let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone());
let child_close_char = item.read().unwrap().edit.close_char.get();
let child_close_char = item.read().unwrap().ctrl.close_char.get();
match res {
TreeNavResult::Continue => TreeNavResult::Continue,

View file

@ -3,7 +3,7 @@ pub mod list;
use {
nested::{
edit_tree::{NestedNode},
edit_tree::{EditTree},
repr_tree::{ReprTree, Context}
},
r3vi::{
@ -18,8 +18,8 @@ use {
};
pub fn edittree_make_char_view(
node: NestedNode
) -> NestedNode {
node: EditTree
) -> EditTree {
node.disp.view
.write().unwrap()
.insert_branch(ReprTree::new_leaf(
@ -38,8 +38,8 @@ pub fn edittree_make_char_view(
}
pub fn edittree_make_digit_view(
node: NestedNode
) -> NestedNode {
node: EditTree
) -> EditTree {
node.disp.view
.write().unwrap()
.insert_branch(ReprTree::new_leaf(

View file

@ -42,7 +42,7 @@ pub trait DisplaySegment {
use nested::repr_tree::Context;
use std::sync::{Arc, RwLock};
impl DisplaySegment for nested::edit_tree::NestedNode {
impl DisplaySegment for nested::edit_tree::EditTree {
fn display_view(&self) -> OuterViewPort<dyn TerminalView> {
if let Some( tv_repr ) = self.disp.view
.read().unwrap()

View file

@ -1,7 +1,7 @@
use {
cgmath::Vector2,
nested::{
edit_tree::NestedNode,
edit_tree::EditTree,
repr_tree::{Context, ReprTree},
},
crate::{