ObjCommander: return TreeNavResult
This commit is contained in:
parent
73499e0ab3
commit
4acce3921d
9 changed files with 91 additions and 75 deletions
|
@ -8,25 +8,20 @@ pub trait Commander {
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use crate::{
|
use crate::{
|
||||||
type_system::ReprTree,
|
type_system::ReprTree,
|
||||||
tree::{nav::TreeNavResult, NestedNode}
|
tree::{nav::TreeNavResult}
|
||||||
};
|
};
|
||||||
|
|
||||||
//use r3vi::view::singleton::*;
|
//use r3vi::view::singleton::*;
|
||||||
|
|
||||||
pub trait ObjCommander {
|
pub trait ObjCommander {
|
||||||
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult;
|
||||||
fn send_cmd_node(&mut self, node: NestedNode) -> TreeNavResult {
|
|
||||||
TreeNavResult::Continue
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>);
|
|
||||||
}
|
|
||||||
|
|
||||||
//impl<Cmd: 'static, T: Commander<Cmd>> ObjCommander for T {
|
//impl<Cmd: 'static, T: Commander<Cmd>> ObjCommander for T {
|
||||||
impl<C: Commander> ObjCommander for C
|
impl<C: Commander> ObjCommander for C
|
||||||
where C::Cmd: 'static
|
where C::Cmd: 'static
|
||||||
{
|
{
|
||||||
fn send_cmd_obj(&mut self, _cmd_obj: Arc<RwLock<ReprTree>>) {
|
fn send_cmd_obj(&mut self, _cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult{
|
||||||
/*
|
/*
|
||||||
self.send_cmd(
|
self.send_cmd(
|
||||||
&cmd_obj.read().unwrap()
|
&cmd_obj.read().unwrap()
|
||||||
|
@ -41,8 +36,9 @@ where C::Cmd: 'static
|
||||||
impl<T: Clone + Send + Sync> Commander for r3vi::buffer::vec::VecBuffer<T> {
|
impl<T: Clone + Send + Sync> Commander for r3vi::buffer::vec::VecBuffer<T> {
|
||||||
type Cmd = r3vi::buffer::vec::VecDiff<T>;
|
type Cmd = r3vi::buffer::vec::VecDiff<T>;
|
||||||
|
|
||||||
fn send_cmd(&mut self, cmd: &Self::Cmd) {
|
fn send_cmd(&mut self, cmd: &Self::Cmd) -> TreeNavResult {
|
||||||
self.apply_diff(cmd.clone());
|
self.apply_diff(cmd.clone());
|
||||||
|
TreeNavResult::
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -9,7 +9,7 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
terminal::{TerminalAtom, TerminalStyle},
|
terminal::{TerminalAtom, TerminalStyle},
|
||||||
tree::NestedNode,
|
tree::{NestedNode, TreeNavResult},
|
||||||
commander::{ObjCommander}
|
commander::{ObjCommander}
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
|
@ -22,7 +22,7 @@ pub struct CharEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjCommander for CharEditor {
|
impl ObjCommander for CharEditor {
|
||||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) {
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
let cmd_obj = cmd_obj.read().unwrap();
|
let cmd_obj = cmd_obj.read().unwrap();
|
||||||
let cmd_type = cmd_obj.get_type().clone();
|
let cmd_type = cmd_obj.get_type().clone();
|
||||||
|
|
||||||
|
@ -35,25 +35,8 @@ impl ObjCommander for CharEditor {
|
||||||
self.data.set(Some(value));
|
self.data.set(Some(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if cmd_type == term_event_type {
|
|
||||||
if let Some(te_view) = cmd_obj.get_view::<dyn SingletonView<Item = TerminalEvent>>() {
|
|
||||||
let event = te_view.get();
|
|
||||||
match event {
|
|
||||||
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
|
||||||
self.data.set(Some(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
TerminalEvent::Input(Event::Key(Key::Backspace))
|
TreeNavResult::Continue
|
||||||
| TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
|
||||||
self.data.set(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ use {
|
||||||
TerminalAtom, TerminalEvent, TerminalStyle, make_label
|
TerminalAtom, TerminalEvent, TerminalStyle, make_label
|
||||||
},
|
},
|
||||||
diagnostics::{Message},
|
diagnostics::{Message},
|
||||||
tree::NestedNode,
|
tree::{NestedNode, TreeNavResult},
|
||||||
commander::Commander
|
commander::ObjCommander
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
std::sync::RwLock,
|
std::sync::RwLock,
|
||||||
|
@ -35,34 +35,34 @@ pub struct DigitEditor {
|
||||||
msg: VecBuffer<Message>,
|
msg: VecBuffer<Message>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commander for DigitEditor {
|
impl ObjCommander for DigitEditor {
|
||||||
type Cmd = TerminalEvent;
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
|
let cmd_obj = cmd_obj.read().unwrap();
|
||||||
|
let cmd_type = cmd_obj.get_type().clone();
|
||||||
|
|
||||||
fn send_cmd(&mut self, event: &TerminalEvent) {
|
let char_type = (&self.ctx, "( Char )").into();
|
||||||
match event {
|
//let _term_event_type = (&ctx, "( TerminalEvent )").into();
|
||||||
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
|
||||||
self.data.set(Some(*c));
|
if cmd_type == char_type {
|
||||||
|
if let Some(cmd_view) = cmd_obj.get_view::<dyn SingletonView<Item = char>>() {
|
||||||
|
let c = cmd_view.get();
|
||||||
|
self.data.set(Some(c));
|
||||||
|
|
||||||
self.msg.clear();
|
self.msg.clear();
|
||||||
if c.to_digit(self.radix).is_none() {
|
if c.to_digit(self.radix).is_none() {
|
||||||
let mut mb = IndexBuffer::new();
|
let mut mb = IndexBuffer::new();
|
||||||
mb.insert_iter(vec![
|
mb.insert_iter(vec![
|
||||||
(Point2::new(1, 0), make_label("invalid digit '")),
|
(Point2::new(1, 0), make_label("invalid digit '")),
|
||||||
(Point2::new(2, 0), make_label(&format!("{}", *c))
|
(Point2::new(2, 0), make_label(&format!("{}", c))
|
||||||
.map_item(|_p,a| a.add_style_back(TerminalStyle::fg_color((140,140,250))))),
|
.map_item(|_p,a| a.add_style_back(TerminalStyle::fg_color((140,140,250))))),
|
||||||
(Point2::new(3, 0), make_label("'"))
|
(Point2::new(3, 0), make_label("'"))
|
||||||
]);
|
]);
|
||||||
self.msg.push(crate::diagnostics::make_error(mb.get_port().flatten()));
|
self.msg.push(crate::diagnostics::make_error(mb.get_port().flatten()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TerminalEvent::Input(Event::Key(Key::Backspace))
|
|
||||||
| TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
|
||||||
self.data.set(None);
|
|
||||||
self.msg.clear();
|
|
||||||
self.msg.push(crate::diagnostics::make_warn(make_label("empty digit")));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,8 +255,8 @@ impl ListEditor {
|
||||||
let prev_node = self.data.get(prev_idx);
|
let prev_node = self.data.get(prev_idx);
|
||||||
|
|
||||||
if let Some(prev_editor) = prev_node.editor.clone() {
|
if let Some(prev_editor) = prev_node.editor.clone() {
|
||||||
let mut prev_editor = prev_editor.downcast::<RwLock<ListEditor>>().unwrap();
|
let prev_editor = prev_editor.downcast::<RwLock<ListEditor>>().unwrap();
|
||||||
let mut prev_editor = prev_editor.write().unwrap();
|
let prev_editor = prev_editor.write().unwrap();
|
||||||
|
|
||||||
if prev_editor.get_data_port().get_view().unwrap().iter()
|
if prev_editor.get_data_port().get_view().unwrap().iter()
|
||||||
.filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0
|
.filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0
|
||||||
|
|
|
@ -7,7 +7,7 @@ use {
|
||||||
type_system::{Context, TypeTerm, ReprTree},
|
type_system::{Context, TypeTerm, ReprTree},
|
||||||
editors::list::*,
|
editors::list::*,
|
||||||
terminal::{TerminalEvent, TerminalView, make_label},
|
terminal::{TerminalEvent, TerminalView, make_label},
|
||||||
tree::{TreeCursor, TreeNav},
|
tree::{TreeCursor, TreeNav, TreeNavResult},
|
||||||
diagnostics::{Diagnostics},
|
diagnostics::{Diagnostics},
|
||||||
tree::NestedNode,
|
tree::NestedNode,
|
||||||
PtySegment
|
PtySegment
|
||||||
|
@ -231,7 +231,7 @@ use r3vi::view::singleton::SingletonView;
|
||||||
use crate::commander::ObjCommander;
|
use crate::commander::ObjCommander;
|
||||||
|
|
||||||
impl ObjCommander for PTYListEditor {
|
impl ObjCommander for PTYListEditor {
|
||||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) {
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
let mut e = self.editor.write().unwrap();
|
let mut e = self.editor.write().unwrap();
|
||||||
let cur = e.cursor.get();
|
let cur = e.cursor.get();
|
||||||
|
|
||||||
|
@ -253,6 +253,8 @@ impl ObjCommander for PTYListEditor {
|
||||||
| TerminalEvent::Input(Event::Key(Key::Insert)) => {
|
| TerminalEvent::Input(Event::Key(Key::Insert)) => {
|
||||||
e.toggle_leaf_mode();
|
e.toggle_leaf_mode();
|
||||||
e.set_leaf_mode(ListCursorMode::Select);
|
e.set_leaf_mode(ListCursorMode::Select);
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(idx) = cur.idx {
|
if let Some(idx) = cur.idx {
|
||||||
|
@ -261,9 +263,11 @@ impl ObjCommander for PTYListEditor {
|
||||||
match event {
|
match event {
|
||||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||||
e.delete_pxev();
|
e.delete_pxev();
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
||||||
e.delete_nexd();
|
e.delete_nexd();
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let mut node = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap();
|
let mut node = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap();
|
||||||
|
@ -281,6 +285,8 @@ impl ObjCommander for PTYListEditor {
|
||||||
if ! remove {
|
if ! remove {
|
||||||
*/
|
*/
|
||||||
e.insert(node);
|
e.insert(node);
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -306,8 +312,9 @@ impl ObjCommander for PTYListEditor {
|
||||||
item.handle_terminal_event(event);
|
item.handle_terminal_event(event);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
TreeNavResult::Continue
|
||||||
} else {
|
} else {
|
||||||
item.send_cmd_obj(cmd_obj);
|
item.send_cmd_obj(cmd_obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
||||||
|
@ -329,31 +336,40 @@ impl ObjCommander for PTYListEditor {
|
||||||
item.handle_terminal_event(event);
|
item.handle_terminal_event(event);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
} else {
|
} else {
|
||||||
item.send_cmd_obj(cmd_obj);
|
item.send_cmd_obj(cmd_obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
||||||
if Some(c) == self.split_char {
|
if Some(c) == self.split_char {
|
||||||
PTYListEditor::split(&mut e);
|
PTYListEditor::split(&mut e);
|
||||||
|
TreeNavResult::Continue
|
||||||
} else {
|
} else {
|
||||||
item.send_cmd_obj(cmd_obj);
|
item.send_cmd_obj(cmd_obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
item.send_cmd_obj(cmd_obj);
|
item.send_cmd_obj(cmd_obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.send_cmd_obj(cmd_obj);
|
item.send_cmd_obj(cmd_obj)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
} else if cmd_type == char_type && cur.mode == ListCursorMode::Select {
|
} else if cmd_type == char_type && cur.mode == ListCursorMode::Select {
|
||||||
if let Some(cmd_view) = co.get_view::<dyn SingletonView<Item = char>>() {
|
if let Some(cmd_view) = co.get_view::<dyn SingletonView<Item = char>>() {
|
||||||
|
@ -362,11 +378,27 @@ impl ObjCommander for PTYListEditor {
|
||||||
|
|
||||||
if Some(c) == self.split_char {
|
if Some(c) == self.split_char {
|
||||||
PTYListEditor::split(&mut e);
|
PTYListEditor::split(&mut e);
|
||||||
|
TreeNavResult::Continue
|
||||||
} else {
|
} else {
|
||||||
if let Some(mut item) = e.get_item_mut() {
|
if let Some(mut item) = e.get_item_mut() {
|
||||||
item.send_cmd_obj(cmd_obj);
|
match item.send_cmd_obj(cmd_obj) {
|
||||||
|
TreeNavResult::Continue => TreeNavResult::Continue,
|
||||||
|
TreeNavResult::Exit => {
|
||||||
|
item.goto(TreeCursor::none());
|
||||||
|
e.cursor.set(ListCursor {
|
||||||
|
mode: ListCursorMode::Insert,
|
||||||
|
idx: Some(cur.idx.unwrap_or(0)+1)
|
||||||
|
});
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
drop(co);
|
drop(co);
|
||||||
|
@ -378,10 +410,14 @@ impl ObjCommander for PTYListEditor {
|
||||||
new_edit.send_cmd_obj(cmd_obj);
|
new_edit.send_cmd_obj(cmd_obj);
|
||||||
|
|
||||||
e.insert(new_edit);
|
e.insert(new_edit);
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
},
|
},
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(mut item) = e.get_item_mut() {
|
if let Some(mut item) = e.get_item_mut() {
|
||||||
item.send_cmd_obj(cmd_obj);
|
item.send_cmd_obj(cmd_obj)
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ use r3vi::view::singleton::SingletonView;
|
||||||
use crate::{commander::ObjCommander, type_system::ReprTree};
|
use crate::{commander::ObjCommander, type_system::ReprTree};
|
||||||
|
|
||||||
impl ObjCommander for ProductEditor {
|
impl ObjCommander for ProductEditor {
|
||||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) {
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
let co = cmd_obj.read().unwrap();
|
let co = cmd_obj.read().unwrap();
|
||||||
let cmd_type = co.get_type().clone();
|
let cmd_type = co.get_type().clone();
|
||||||
let term_event_type = (&self.ctx, "( TerminalEvent )").into();
|
let term_event_type = (&self.ctx, "( TerminalEvent )").into();
|
||||||
|
@ -257,10 +257,14 @@ impl ObjCommander for ProductEditor {
|
||||||
self.update_cur_segment();
|
self.update_cur_segment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TreeNavResult::Continue
|
||||||
} else {
|
} else {
|
||||||
drop(co);
|
drop(co);
|
||||||
if let Some(mut node) = self.get_cur_editor() {
|
if let Some(mut node) = self.get_cur_editor() {
|
||||||
node.send_cmd_obj(cmd_obj);
|
node.send_cmd_obj(cmd_obj)
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,7 @@ use {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
terminal::{
|
terminal::TerminalView,
|
||||||
TerminalEditor, TerminalEditorResult,
|
|
||||||
TerminalEvent, TerminalView
|
|
||||||
},
|
|
||||||
editors::list::ListCursorMode,
|
editors::list::ListCursorMode,
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
tree::{TreeNav, TreeCursor, TreeNavResult},
|
tree::{TreeNav, TreeCursor, TreeNavResult},
|
||||||
|
@ -20,8 +17,7 @@ use {
|
||||||
PtySegment
|
PtySegment
|
||||||
},
|
},
|
||||||
cgmath::{Vector2},
|
cgmath::{Vector2},
|
||||||
std::sync::{Arc, RwLock},
|
std::sync::{Arc, RwLock}
|
||||||
termion::event::{Key}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct SumEditor {
|
pub struct SumEditor {
|
||||||
|
@ -131,7 +127,7 @@ impl PtySegment for SumEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjCommander for SumEditor {
|
impl ObjCommander for SumEditor {
|
||||||
fn send_cmd_obj(&mut self, obj: Arc<RwLock<ReprTree>>) {
|
fn send_cmd_obj(&mut self, obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
self.editors[ self.cur ].send_cmd_obj( obj );
|
self.editors[ self.cur ].send_cmd_obj( obj )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,12 @@ pub struct NestedNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjCommander for NestedNode {
|
impl ObjCommander for NestedNode {
|
||||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) {
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
if let Some(cmd) = self.cmd.as_ref() {
|
if let Some(cmd) = self.cmd.as_ref() {
|
||||||
// todo: filter out tree-nav cmds and send them to tree_nav
|
// todo: filter out tree-nav cmds and send them to tree_nav
|
||||||
cmd.write().unwrap().send_cmd_obj(cmd_obj);
|
cmd.write().unwrap().send_cmd_obj(cmd_obj)
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use {
|
||||||
product::*
|
product::*
|
||||||
},
|
},
|
||||||
tree::{NestedNode},
|
tree::{NestedNode},
|
||||||
terminal::{TerminalEditor},
|
|
||||||
diagnostics::{Diagnostics},
|
diagnostics::{Diagnostics},
|
||||||
type_system::{MorphismTypePattern},
|
type_system::{MorphismTypePattern},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue