From 6532065928c344e96b50a5923bf726557f12ba78 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 11 Aug 2023 19:23:00 +0200 Subject: [PATCH] ListCmd --- nested/src/editors/list/commander.rs | 79 +++++++++++++++++++++------- nested/src/editors/list/editor.rs | 6 ++- nested/src/editors/list/mod.rs | 4 +- 3 files changed, 66 insertions(+), 23 deletions(-) diff --git a/nested/src/editors/list/commander.rs b/nested/src/editors/list/commander.rs index be4cca2..438283e 100644 --- a/nested/src/editors/list/commander.rs +++ b/nested/src/editors/list/commander.rs @@ -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>) +#[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>) -> Arc> { + 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>) { - let cmd_repr = cmd_obj.read().unrwap(); - - if let Some(cmd) = cmd_repr.get_view>() { + fn send_cmd_obj(&mut self, cmd_obj: Arc>) -> TreeNavResult { + let cmd_repr = cmd_obj.read().unwrap(); + if let Some(cmd) = cmd_repr.get_view::>() { 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 } } } diff --git a/nested/src/editors/list/editor.rs b/nested/src/editors/list/editor.rs index 6e14178..ca36f42 100644 --- a/nested/src/editors/list/editor.rs +++ b/nested/src/editors/list/editor.rs @@ -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>) { 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() diff --git a/nested/src/editors/list/mod.rs b/nested/src/editors/list/mod.rs index a6b51fe..8494856 100644 --- a/nested/src/editors/list/mod.rs +++ b/nested/src/editors/list/mod.rs @@ -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 };