char editor: add editor field in node

hack type term editor to support splits
This commit is contained in:
Michael Sippel 2023-08-08 17:37:27 +02:00
parent 0062e5ca07
commit 8e03a1711d
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 31 additions and 20 deletions

View file

@ -69,6 +69,8 @@ impl CharEditor {
let ctx = ctx0.clone(); let ctx = ctx0.clone();
let editor = Arc::new(RwLock::new(CharEditor{ ctx, data: data.clone() }));
NestedNode::new(0) NestedNode::new(0)
.set_ctx(ctx0.clone()) .set_ctx(ctx0.clone())
.set_data( .set_data(
@ -87,9 +89,8 @@ impl CharEditor {
}) })
.to_grid() .to_grid()
) )
.set_cmd( .set_cmd( editor.clone() )
Arc::new(RwLock::new(CharEditor{ ctx, data })) .set_editor( editor.clone() )
)
} }
} }
/* /*

View file

@ -14,7 +14,7 @@ use {
PtySegment PtySegment
}, },
termion::event::{Key}, termion::event::{Key},
std::{sync::{Arc, RwLock}}, std::{sync::{Arc, RwLock}, any::Any},
cgmath::{Vector2, Point2} cgmath::{Vector2, Point2}
}; };
@ -32,6 +32,10 @@ enum State {
pub struct TypeTermEditor { pub struct TypeTermEditor {
ctx: Arc<RwLock<Context>>, ctx: Arc<RwLock<Context>>,
editor: SingletonBuffer<
Option< Arc<dyn Any + Send + Sync> >
>,
state: State, state: State,
cur_node: SingletonBuffer< NestedNode > cur_node: SingletonBuffer< NestedNode >
} }
@ -68,21 +72,23 @@ impl TypeTermEditor {
PTYListStyle::for_node( &mut node, ("","","") ); PTYListStyle::for_node( &mut node, ("","","") );
let mut new_node = TypeTermEditor::with_node( node.ctx.clone().unwrap(), node.depth.get(), node.clone(), State::Any ); let mut new_node = TypeTermEditor::with_node( node.ctx.clone().unwrap(), node.depth.get(), node.clone(), State::Any );
let item_nodes = node.get_edit::<ListEditor>().clone().unwrap(); let item_editor1 = node.get_edit::<ListEditor>().clone().unwrap();
let item_nodes = item_nodes.read().unwrap(); let item_editor = item_editor1.read().unwrap();
for i in 0..item_editor.data.len() {
let item_node = item_editor.data.get(i);
let item_node = item_node.read().unwrap();
let item_val_editor = item_node.get_edit::<crate::editors::char::CharEditor>().clone().unwrap();
let item_val_editor = item_val_editor.read().unwrap();
let c = item_val_editor.get();
for i in 0..item_nodes.data.len() {
if let Some(x) = &item_nodes.data.get(i).read().unwrap().data {
//eprintln!("item with {:?}", x);
//let c = x.read().unwrap().get_view::<dyn SingletonView<Item = NestedNode>>().unwrap().get();
new_node.send_cmd_obj( new_node.send_cmd_obj(
ReprTree::from_char(&new_node.ctx.as_ref().unwrap(), 'x') ReprTree::from_char(new_node.ctx.as_ref().unwrap(), c)
); );
//new_node.send_cmd_obj(c);
}
} }
if item_nodes.data.len() > 0 { if item_editor.data.len() > 0 {
new_node.goto(TreeCursor::home()); new_node.goto(TreeCursor::home());
} }
@ -135,6 +141,7 @@ impl TypeTermEditor {
node.goto(TreeCursor::home()); node.goto(TreeCursor::home());
self.editor.set(node.editor.get());
self.cur_node.set(node); self.cur_node.set(node);
self.state = new_state; self.state = new_state;
} }
@ -147,7 +154,8 @@ impl TypeTermEditor {
let mut editor = TypeTermEditor { let mut editor = TypeTermEditor {
ctx: ctx.clone(), ctx: ctx.clone(),
state, state,
cur_node: SingletonBuffer::new(node) cur_node: SingletonBuffer::new(node),
editor: SingletonBuffer::new(None)
}; };
let view = editor.cur_node let view = editor.cur_node
@ -177,6 +185,8 @@ impl TypeTermEditor {
.set_cmd(editor.clone()) .set_cmd(editor.clone())
.set_editor(editor.clone()); .set_editor(editor.clone());
editor.write().unwrap().editor = node.editor.clone();
node node
} }
} }