ListCmd
This commit is contained in:
parent
b97ba8dedb
commit
6532065928
3 changed files with 66 additions and 23 deletions
|
@ -1,41 +1,80 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
|
r3vi::{
|
||||||
|
view::{singleton::*},
|
||||||
|
buffer::{singleton::*}
|
||||||
|
},
|
||||||
crate::{
|
crate::{
|
||||||
editors::list::ListEditor
|
editors::list::ListEditor,
|
||||||
|
type_system::{Context, ReprTree},
|
||||||
|
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||||
|
commander::{ObjCommander}
|
||||||
},
|
},
|
||||||
std::sync::{Arc, RwLock}
|
std::sync::{Arc, RwLock}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum ListEditorCmd {
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
ItemCmd(Arc<RwLock<ReprTree>>)
|
pub enum ListCmd {
|
||||||
|
DeletePxev,
|
||||||
|
DeleteNexd,
|
||||||
|
JoinNexd,
|
||||||
|
JoinPxev,
|
||||||
Split,
|
Split,
|
||||||
Join
|
Clear,
|
||||||
|
Close,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListCmd {
|
||||||
|
fn into_repr_tree(self, ctx: &Arc<RwLock<Context>>) -> Arc<RwLock<ReprTree>> {
|
||||||
|
let buf = r3vi::buffer::singleton::SingletonBuffer::new(self);
|
||||||
|
ReprTree::new_leaf(
|
||||||
|
(ctx, "( ListCmd )"),
|
||||||
|
buf.get_port().into()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjCommander for ListEditor {
|
impl ObjCommander for ListEditor {
|
||||||
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_repr = cmd_obj.read().unrwap();
|
let cmd_repr = cmd_obj.read().unwrap();
|
||||||
|
if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||||
if let Some(cmd) = cmd_repr.get_view<dyn SingletonView<ListEditorCmd>>() {
|
|
||||||
match cmd.get() {
|
match cmd.get() {
|
||||||
ListEditorCmd::Split => {
|
ListCmd::DeletePxev => {
|
||||||
|
self.delete_pxev();
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
ListEditorCmd::Join => {
|
ListCmd::DeleteNexd => {
|
||||||
|
self.delete_nexd();
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
ListEditorCmd::ItemCmd => {
|
ListCmd::JoinPxev => {
|
||||||
if let Some(cur_item) = self.get_item_mut() {
|
// TODO
|
||||||
drop(cmd);
|
//self.listlist_join_pxev();
|
||||||
drop(cmd_repr);
|
TreeNavResult::Continue
|
||||||
cur_item.send_cmd_obj(cmd_obj);
|
}
|
||||||
}
|
ListCmd::JoinNexd => {
|
||||||
|
// TODO
|
||||||
|
//self.listlist_join_nexd();
|
||||||
|
TreeNavResult::Continue
|
||||||
|
}
|
||||||
|
ListCmd::Split => {
|
||||||
|
self.listlist_split();
|
||||||
|
TreeNavResult::Continue
|
||||||
|
}
|
||||||
|
ListCmd::Clear => {
|
||||||
|
self.clear();
|
||||||
|
TreeNavResult::Continue
|
||||||
|
}
|
||||||
|
ListCmd::Close => {
|
||||||
|
self.goto(TreeCursor::none());
|
||||||
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(cur_item) = self.get_item_mut() {
|
if let Some(cur_item) = self.get_item_mut() {
|
||||||
drop(cmd_repr);
|
drop(cmd_repr);
|
||||||
cur_item.send_cmd_obj(cmd_obj);
|
cur_item.write().unwrap().send_cmd_obj(cmd_obj)
|
||||||
|
} else {
|
||||||
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use {
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, TypeTerm, ReprTree},
|
type_system::{Context, TypeTerm, ReprTree},
|
||||||
editors::list::{ListCursor, ListCursorMode, PTYListController, PTYListStyle},
|
editors::list::{ListCursor, ListCursorMode, commander::ListCmd, PTYListController, PTYListStyle},
|
||||||
tree::{NestedNode, TreeNav, TreeCursor},
|
tree::{NestedNode, TreeNav, TreeCursor},
|
||||||
diagnostics::Diagnostics
|
diagnostics::Diagnostics
|
||||||
},
|
},
|
||||||
|
@ -31,6 +31,8 @@ impl ListEditor {
|
||||||
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
|
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
|
||||||
let mut ctx = ctx.write().unwrap();
|
let mut ctx = ctx.write().unwrap();
|
||||||
|
|
||||||
|
ctx.add_list_typename("ListCmd".into());
|
||||||
|
|
||||||
ctx.add_list_typename("List".into());
|
ctx.add_list_typename("List".into());
|
||||||
ctx.add_node_ctor(
|
ctx.add_node_ctor(
|
||||||
"List", Arc::new(
|
"List", Arc::new(
|
||||||
|
@ -131,7 +133,7 @@ impl ListEditor {
|
||||||
.set_data(data)
|
.set_data(data)
|
||||||
.set_editor(editor.clone())
|
.set_editor(editor.clone())
|
||||||
.set_nav(editor.clone())
|
.set_nav(editor.clone())
|
||||||
//.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_diag(e
|
.set_diag(e
|
||||||
.get_data_port()
|
.get_data_port()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|
|
@ -5,11 +5,13 @@ pub mod editor;
|
||||||
pub mod nav;
|
pub mod nav;
|
||||||
pub mod segment;
|
pub mod segment;
|
||||||
pub mod pty_editor;
|
pub mod pty_editor;
|
||||||
|
pub mod commander;
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
cursor::{ListCursor, ListCursorMode},
|
cursor::{ListCursor, ListCursorMode},
|
||||||
editor::ListEditor,
|
editor::ListEditor,
|
||||||
segment::{ListSegment, ListSegmentSequence},
|
segment::{ListSegment, ListSegmentSequence},
|
||||||
pty_editor::{PTYListStyle, PTYListController}
|
pty_editor::{PTYListStyle, PTYListController},
|
||||||
|
commander::ListCmd
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue