2022-11-05 22:33:46 +01:00
|
|
|
use {
|
2023-02-13 18:39:45 +01:00
|
|
|
r3vi::{
|
|
|
|
view::{
|
|
|
|
ViewPort, OuterViewPort,
|
2023-02-20 03:40:37 +01:00
|
|
|
singleton::*,
|
2023-02-13 18:39:45 +01:00
|
|
|
sequence::*,
|
|
|
|
}
|
|
|
|
},
|
2023-11-12 18:07:20 +01:00
|
|
|
laddertypes::{TypeTerm},
|
2022-11-05 22:33:46 +01:00
|
|
|
crate::{
|
2023-11-24 21:26:17 +01:00
|
|
|
editors::{list::ListCursorMode, ObjCommander},
|
2023-11-28 20:52:25 +01:00
|
|
|
repr_tree::{Context, ReprTree},
|
|
|
|
edit_tree::{TreeNav, TreeCursor, TreeNavResult, diagnostics::{Diagnostics, Message}, NestedNode},
|
2022-11-05 22:33:46 +01:00
|
|
|
},
|
2022-12-18 01:39:01 +01:00
|
|
|
cgmath::{Vector2},
|
2023-02-24 19:26:46 +01:00
|
|
|
std::sync::{Arc, RwLock}
|
2022-11-05 22:33:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub struct SumEditor {
|
|
|
|
cur: usize,
|
2022-12-19 11:26:07 +01:00
|
|
|
pub editors: Vec< NestedNode >,
|
2022-11-05 22:33:46 +01:00
|
|
|
|
2023-02-20 03:40:37 +01:00
|
|
|
addr_port: ViewPort< dyn SequenceView<Item = isize> >,
|
|
|
|
mode_port: ViewPort< dyn SingletonView<Item = ListCursorMode> >,
|
|
|
|
|
2023-11-24 21:26:17 +01:00
|
|
|
// port: ViewPort< dyn TerminalView >,
|
2022-11-18 00:13:02 +01:00
|
|
|
diag_port: ViewPort< dyn SequenceView<Item = Message> >
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SumEditor {
|
|
|
|
pub fn new(
|
2022-12-19 11:26:07 +01:00
|
|
|
editors: Vec< NestedNode >
|
2022-11-05 22:33:46 +01:00
|
|
|
) -> Self {
|
2023-11-24 21:26:17 +01:00
|
|
|
// let port = ViewPort::new();
|
2022-11-05 22:33:46 +01:00
|
|
|
|
|
|
|
SumEditor {
|
|
|
|
cur: 0,
|
|
|
|
editors,
|
2023-11-24 21:26:17 +01:00
|
|
|
// port,
|
2023-02-20 03:40:37 +01:00
|
|
|
diag_port: ViewPort::new(),
|
|
|
|
|
|
|
|
|
|
|
|
addr_port: ViewPort::new(),
|
|
|
|
mode_port: ViewPort::new()
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-13 18:39:45 +01:00
|
|
|
|
2023-08-15 23:18:51 +02:00
|
|
|
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
|
|
|
|
ctx.write().unwrap().add_typename("Sum".into());
|
|
|
|
}
|
|
|
|
|
2023-02-13 18:39:45 +01:00
|
|
|
pub fn into_node(self, ctx: Arc<RwLock<Context>>) -> NestedNode {
|
2023-11-24 21:26:17 +01:00
|
|
|
// let view = self.pty_view();
|
2022-12-19 11:26:07 +01:00
|
|
|
let editor = Arc::new(RwLock::new(self));
|
2023-08-15 23:18:51 +02:00
|
|
|
|
|
|
|
NestedNode::new(
|
|
|
|
ctx.clone(),
|
2024-01-04 15:39:39 +01:00
|
|
|
// ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())),
|
2023-09-08 13:40:06 +02:00
|
|
|
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
|
2023-08-15 23:18:51 +02:00
|
|
|
)
|
2023-11-24 21:26:17 +01:00
|
|
|
// .set_view(view)
|
2023-02-20 03:40:37 +01:00
|
|
|
.set_editor(editor.clone())
|
2022-12-19 11:26:07 +01:00
|
|
|
.set_cmd(editor.clone())
|
|
|
|
.set_nav(editor.clone())
|
2023-02-13 18:39:45 +01:00
|
|
|
// .set_diag(editor.read().unwrap().diag.clone())
|
2022-12-19 11:26:07 +01:00
|
|
|
}
|
2023-02-13 18:39:45 +01:00
|
|
|
|
2022-12-19 11:26:07 +01:00
|
|
|
pub fn get(&self) -> NestedNode {
|
2022-12-18 01:20:17 +01:00
|
|
|
self.editors[ self.cur ].clone()
|
|
|
|
}
|
|
|
|
|
2022-11-05 22:33:46 +01:00
|
|
|
pub fn select(&mut self, idx: usize) {
|
|
|
|
self.cur = idx;
|
2023-11-24 21:26:17 +01:00
|
|
|
/* FIXME
|
2022-11-18 00:13:02 +01:00
|
|
|
|
2023-02-20 03:40:37 +01:00
|
|
|
let tv = self.editors[ self.cur ].get_view();
|
2022-11-05 22:33:46 +01:00
|
|
|
tv.add_observer( self.port.get_cast() );
|
2022-11-13 15:26:25 +01:00
|
|
|
self.port.update_hooks.write().unwrap().clear();
|
2022-11-05 22:33:46 +01:00
|
|
|
self.port.add_update_hook( Arc::new(tv.0.clone()) );
|
|
|
|
self.port.set_view( Some(tv.get_view_arc()) );
|
2022-11-18 00:13:02 +01:00
|
|
|
|
2022-12-19 11:26:07 +01:00
|
|
|
let dv = self.editors[ self.cur ].get_msg_port();
|
2022-11-18 00:13:02 +01:00
|
|
|
dv.add_observer( self.diag_port.get_cast() );
|
|
|
|
self.diag_port.update_hooks.write().unwrap().clear();
|
|
|
|
self.diag_port.add_update_hook( Arc::new(dv.0.clone()) );
|
|
|
|
self.diag_port.set_view( Some(dv.get_view_arc()) );
|
2023-02-20 03:40:37 +01:00
|
|
|
|
|
|
|
let dv = self.editors[ self.cur ].get_addr_view();
|
|
|
|
dv.add_observer( self.addr_port.get_cast() );
|
|
|
|
self.addr_port.update_hooks.write().unwrap().clear();
|
|
|
|
self.addr_port.add_update_hook( Arc::new(dv.0.clone()) );
|
|
|
|
self.addr_port.set_view( Some(dv.get_view_arc()) );
|
|
|
|
|
|
|
|
let dv = self.editors[ self.cur ].get_mode_view();
|
|
|
|
dv.add_observer( self.mode_port.get_cast() );
|
|
|
|
self.mode_port.update_hooks.write().unwrap().clear();
|
|
|
|
self.mode_port.add_update_hook( Arc::new(dv.0.clone()) );
|
|
|
|
self.mode_port.set_view( Some(dv.get_view_arc()) );
|
2023-11-24 21:26:17 +01:00
|
|
|
*/
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TreeNav for SumEditor {
|
|
|
|
fn get_cursor(&self) -> TreeCursor {
|
2022-12-19 11:26:07 +01:00
|
|
|
self.editors[ self.cur ].get_cursor()
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_cursor_warp(&self) -> TreeCursor {
|
2022-12-19 11:26:07 +01:00
|
|
|
self.editors[ self.cur ].get_cursor_warp()
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn goby(&mut self, direction: Vector2<isize>) -> TreeNavResult {
|
2022-12-19 11:26:07 +01:00
|
|
|
self.editors[ self.cur ].goby( direction )
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn goto(&mut self, new_cursor: TreeCursor) -> TreeNavResult {
|
2022-12-19 11:26:07 +01:00
|
|
|
self.editors[ self.cur ].goto( new_cursor )
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
2023-02-20 03:40:37 +01:00
|
|
|
|
|
|
|
fn get_addr_view(&self) -> OuterViewPort<dyn SequenceView<Item = isize>> {
|
|
|
|
self.addr_port.outer()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_mode_view(&self) -> OuterViewPort<dyn SingletonView<Item = ListCursorMode>> {
|
|
|
|
self.mode_port.outer()
|
|
|
|
}
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
|
2023-02-20 03:40:37 +01:00
|
|
|
impl ObjCommander for SumEditor {
|
2023-02-24 19:26:46 +01:00
|
|
|
fn send_cmd_obj(&mut self, obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
|
|
|
self.editors[ self.cur ].send_cmd_obj( obj )
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
}
|