2022-11-05 22:33:46 +01:00
|
|
|
use {
|
|
|
|
crate::{
|
|
|
|
core::{ViewPort, OuterViewPort, TypeLadder, Context},
|
|
|
|
terminal::{
|
|
|
|
TerminalEditor, TerminalEditorResult,
|
|
|
|
TerminalEvent, TerminalView
|
|
|
|
},
|
|
|
|
vec::{VecBuffer, MutableVecAccess},
|
|
|
|
index::{buffer::{IndexBuffer, MutableIndexAccess}, IndexView},
|
|
|
|
list::ListCursorMode,
|
|
|
|
product::{segment::ProductEditorSegment},
|
|
|
|
sequence::{SequenceView},
|
2022-11-13 15:26:25 +01:00
|
|
|
tree::{TreeNav, TreeCursor, TreeNavResult},
|
2022-11-05 22:33:46 +01:00
|
|
|
diagnostics::{Diagnostics, Message},
|
2022-11-13 15:26:25 +01:00
|
|
|
terminal::{TerminalStyle},
|
|
|
|
Nested
|
2022-11-05 22:33:46 +01:00
|
|
|
},
|
|
|
|
cgmath::{Vector2, Point2},
|
|
|
|
std::sync::{Arc, RwLock},
|
|
|
|
termion::event::{Event, Key},
|
|
|
|
std::ops::{Deref, DerefMut}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct SumEditor {
|
|
|
|
cur: usize,
|
2022-11-13 15:26:25 +01:00
|
|
|
editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >,
|
2022-11-05 22:33:46 +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-11-13 15:26:25 +01:00
|
|
|
editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >
|
2022-11-05 22:33:46 +01:00
|
|
|
) -> Self {
|
|
|
|
let port = ViewPort::new();
|
2022-11-18 00:13:02 +01:00
|
|
|
//let mut diag_buf = VecBuffer::new();
|
2022-11-05 22:33:46 +01:00
|
|
|
|
|
|
|
SumEditor {
|
|
|
|
cur: 0,
|
|
|
|
editors,
|
|
|
|
port,
|
2022-11-18 00:13:02 +01:00
|
|
|
diag_port: ViewPort::new()//diag_buf.get_port().to_sequence()
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-13 15:26:25 +01:00
|
|
|
|
2022-11-05 22:33:46 +01:00
|
|
|
pub fn select(&mut self, idx: usize) {
|
|
|
|
self.cur = idx;
|
2022-11-18 00:13:02 +01:00
|
|
|
|
2022-11-05 22:33:46 +01:00
|
|
|
let tv = self.editors[ self.cur ].read().unwrap().get_term_view();
|
|
|
|
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
|
|
|
|
|
|
|
let dv = self.editors[ self.cur ].read().unwrap().get_msg_port();
|
|
|
|
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()) );
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TreeNav for SumEditor {
|
|
|
|
fn get_cursor(&self) -> TreeCursor {
|
|
|
|
self.editors[ self.cur ].write().unwrap().get_cursor()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_cursor_warp(&self) -> TreeCursor {
|
|
|
|
self.editors[ self.cur ].write().unwrap().get_cursor_warp()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn goby(&mut self, direction: Vector2<isize>) -> TreeNavResult {
|
|
|
|
self.editors[ self.cur ].write().unwrap().goby( direction )
|
|
|
|
}
|
|
|
|
|
|
|
|
fn goto(&mut self, new_cursor: TreeCursor) -> TreeNavResult {
|
|
|
|
self.editors[ self.cur ].write().unwrap().goto( new_cursor )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TerminalEditor for SumEditor {
|
|
|
|
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
|
|
|
|
self.port.outer()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
|
|
|
|
match event {
|
|
|
|
TerminalEvent::Input( termion::event::Event::Key(Key::Ctrl('x')) ) => {
|
2022-11-18 00:13:02 +01:00
|
|
|
let res = self.editors[ self.cur ].write().unwrap().handle_terminal_event( event );
|
|
|
|
match res {
|
|
|
|
TerminalEditorResult::Exit => {
|
|
|
|
self.select( (self.cur + 1) % self.editors.len() );
|
|
|
|
if self.editors[ self.cur ].read().unwrap().get_cursor().tree_addr.len() == 0 {
|
|
|
|
self.dn();
|
|
|
|
}
|
|
|
|
TerminalEditorResult::Continue
|
|
|
|
},
|
|
|
|
_ => TerminalEditorResult::Continue
|
2022-11-13 15:26:25 +01:00
|
|
|
}
|
2022-11-05 22:33:46 +01:00
|
|
|
},
|
|
|
|
event => {
|
|
|
|
self.editors[ self.cur ].write().unwrap().handle_terminal_event( event )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Diagnostics for SumEditor {
|
|
|
|
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> {
|
2022-11-18 00:13:02 +01:00
|
|
|
self.diag_port.outer()
|
2022-11-05 22:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 15:26:25 +01:00
|
|
|
impl Nested for SumEditor {}
|
2022-11-05 22:33:46 +01:00
|
|
|
|
|
|
|
|