sum editor: forward diagnostics

This commit is contained in:
Michael Sippel 2022-11-18 00:13:02 +01:00
parent 0a8c77772c
commit 2db92ef6aa
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -28,7 +28,7 @@ pub struct SumEditor {
editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >, editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >,
port: ViewPort< dyn TerminalView >, port: ViewPort< dyn TerminalView >,
diag_port: OuterViewPort< dyn SequenceView<Item = Message> > diag_port: ViewPort< dyn SequenceView<Item = Message> >
} }
impl SumEditor { impl SumEditor {
@ -36,23 +36,30 @@ impl SumEditor {
editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> > editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >
) -> Self { ) -> Self {
let port = ViewPort::new(); let port = ViewPort::new();
let mut diag_buf = VecBuffer::new(); //let mut diag_buf = VecBuffer::new();
SumEditor { SumEditor {
cur: 0, cur: 0,
editors, editors,
port, port,
diag_port: diag_buf.get_port().to_sequence() diag_port: ViewPort::new()//diag_buf.get_port().to_sequence()
} }
} }
pub fn select(&mut self, idx: usize) { pub fn select(&mut self, idx: usize) {
self.cur = idx; self.cur = idx;
let tv = self.editors[ self.cur ].read().unwrap().get_term_view(); let tv = self.editors[ self.cur ].read().unwrap().get_term_view();
tv.add_observer( self.port.get_cast() ); tv.add_observer( self.port.get_cast() );
self.port.update_hooks.write().unwrap().clear(); self.port.update_hooks.write().unwrap().clear();
self.port.add_update_hook( Arc::new(tv.0.clone()) ); self.port.add_update_hook( Arc::new(tv.0.clone()) );
self.port.set_view( Some(tv.get_view_arc()) ); self.port.set_view( Some(tv.get_view_arc()) );
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()) );
} }
} }
@ -82,12 +89,18 @@ impl TerminalEditor for SumEditor {
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult { fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
match event { match event {
TerminalEvent::Input( termion::event::Event::Key(Key::Ctrl('x')) ) => { TerminalEvent::Input( termion::event::Event::Key(Key::Ctrl('x')) ) => {
let res = self.editors[ self.cur ].write().unwrap().handle_terminal_event( event );
match res {
TerminalEditorResult::Exit => {
self.select( (self.cur + 1) % self.editors.len() ); self.select( (self.cur + 1) % self.editors.len() );
if self.editors[ self.cur ].read().unwrap().get_cursor().tree_addr.len() == 0 { if self.editors[ self.cur ].read().unwrap().get_cursor().tree_addr.len() == 0 {
self.dn(); self.dn();
} }
TerminalEditorResult::Continue TerminalEditorResult::Continue
}, },
_ => TerminalEditorResult::Continue
}
},
event => { event => {
self.editors[ self.cur ].write().unwrap().handle_terminal_event( event ) self.editors[ self.cur ].write().unwrap().handle_terminal_event( event )
} }
@ -97,7 +110,7 @@ impl TerminalEditor for SumEditor {
impl Diagnostics for SumEditor { impl Diagnostics for SumEditor {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> { fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> {
self.diag_port.clone() self.diag_port.outer()
} }
} }