This commit is contained in:
Michael Sippel 2023-08-11 19:23:00 +02:00
parent b97ba8dedb
commit 6532065928
Signed by: senvas
GPG key ID: F96CF119C34B64A6
3 changed files with 66 additions and 23 deletions

View file

@ -1,41 +1,80 @@
use {
r3vi::{
view::{singleton::*},
buffer::{singleton::*}
},
crate::{
editors::list::ListEditor
editors::list::ListEditor,
type_system::{Context, ReprTree},
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
commander::{ObjCommander}
},
std::sync::{Arc, RwLock}
};
pub enum ListEditorCmd {
ItemCmd(Arc<RwLock<ReprTree>>)
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum ListCmd {
DeletePxev,
DeleteNexd,
JoinNexd,
JoinPxev,
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 {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) {
let cmd_repr = cmd_obj.read().unrwap();
if let Some(cmd) = cmd_repr.get_view<dyn SingletonView<ListEditorCmd>>() {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
let cmd_repr = cmd_obj.read().unwrap();
if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
match cmd.get() {
ListEditorCmd::Split => {
ListCmd::DeletePxev => {
self.delete_pxev();
TreeNavResult::Continue
}
ListEditorCmd::Join => {
ListCmd::DeleteNexd => {
self.delete_nexd();
TreeNavResult::Continue
}
ListEditorCmd::ItemCmd => {
if let Some(cur_item) = self.get_item_mut() {
drop(cmd);
drop(cmd_repr);
cur_item.send_cmd_obj(cmd_obj);
ListCmd::JoinPxev => {
// TODO
//self.listlist_join_pxev();
TreeNavResult::Continue
}
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 {
if let Some(cur_item) = self.get_item_mut() {
drop(cmd_repr);
cur_item.send_cmd_obj(cmd_obj);
cur_item.write().unwrap().send_cmd_obj(cmd_obj)
} else {
TreeNavResult::Continue
}
}
}

View file

@ -5,7 +5,7 @@ use {
},
crate::{
type_system::{Context, TypeTerm, ReprTree},
editors::list::{ListCursor, ListCursorMode, PTYListController, PTYListStyle},
editors::list::{ListCursor, ListCursorMode, commander::ListCmd, PTYListController, PTYListStyle},
tree::{NestedNode, TreeNav, TreeCursor},
diagnostics::Diagnostics
},
@ -31,6 +31,8 @@ impl ListEditor {
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
let mut ctx = ctx.write().unwrap();
ctx.add_list_typename("ListCmd".into());
ctx.add_list_typename("List".into());
ctx.add_node_ctor(
"List", Arc::new(
@ -131,7 +133,7 @@ impl ListEditor {
.set_data(data)
.set_editor(editor.clone())
.set_nav(editor.clone())
//.set_cmd(editor.clone())
.set_cmd(editor.clone())
.set_diag(e
.get_data_port()
.enumerate()

View file

@ -5,11 +5,13 @@ pub mod editor;
pub mod nav;
pub mod segment;
pub mod pty_editor;
pub mod commander;
pub use {
cursor::{ListCursor, ListCursorMode},
editor::ListEditor,
segment::{ListSegment, ListSegmentSequence},
pty_editor::{PTYListStyle, PTYListController}
pty_editor::{PTYListStyle, PTYListController},
commander::ListCmd
};