2022-06-19 23:13:21 +02:00
|
|
|
use {
|
2023-02-13 18:39:45 +01:00
|
|
|
r3vi::{
|
|
|
|
view::{
|
|
|
|
OuterViewPort,
|
|
|
|
singleton::*,
|
|
|
|
sequence::*,
|
|
|
|
},
|
|
|
|
buffer::{
|
|
|
|
singleton::SingletonBuffer,
|
|
|
|
vec::VecBuffer
|
|
|
|
},
|
|
|
|
projection::{
|
|
|
|
decorate_sequence::*,
|
|
|
|
}
|
|
|
|
},
|
2023-01-07 04:37:44 +01:00
|
|
|
crate::{
|
2023-02-13 18:39:45 +01:00
|
|
|
editors::list::ListCursorMode,
|
|
|
|
tree::TreeCursor,
|
|
|
|
terminal::{TerminalView, TerminalProjections, make_label}
|
|
|
|
},
|
|
|
|
cgmath::Vector2,
|
2022-06-19 23:13:21 +02:00
|
|
|
};
|
2021-08-23 05:00:57 +02:00
|
|
|
|
2023-11-12 18:07:20 +01:00
|
|
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
2023-09-06 04:33:21 +02:00
|
|
|
pub enum TreeNavResult { Continue, Exit }
|
2023-01-07 04:37:44 +01:00
|
|
|
|
2023-11-12 18:07:20 +01:00
|
|
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
2023-09-06 04:33:21 +02:00
|
|
|
pub enum TreeHeightOp { P, Q, Max }
|
2023-01-07 04:37:44 +01:00
|
|
|
|
2021-08-15 04:27:09 +02:00
|
|
|
pub trait TreeNav {
|
2022-06-19 23:13:21 +02:00
|
|
|
/* CORE
|
|
|
|
*/
|
|
|
|
fn get_cursor(&self) -> TreeCursor {
|
|
|
|
TreeCursor::default()
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 04:37:44 +01:00
|
|
|
fn get_addr_view(&self) -> OuterViewPort<dyn SequenceView<Item = isize>> {
|
|
|
|
VecBuffer::<isize>::new().get_port().to_sequence()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_mode_view(&self) -> OuterViewPort<dyn SingletonView<Item = ListCursorMode>> {
|
|
|
|
SingletonBuffer::new(ListCursorMode::Select).get_port()
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn get_cursor_warp(&self) -> TreeCursor {
|
|
|
|
TreeCursor::default()
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2023-09-06 23:40:32 +02:00
|
|
|
fn get_height(&self, _op: &TreeHeightOp) -> usize {
|
2022-11-13 15:26:25 +01:00
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2022-12-18 01:39:01 +01:00
|
|
|
fn goby(&mut self, _direction: Vector2<isize>) -> TreeNavResult {
|
2021-08-15 04:27:09 +02:00
|
|
|
TreeNavResult::Exit
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn goto(&mut self, _new_cursor: TreeCursor) -> TreeNavResult {
|
2021-08-15 04:27:09 +02:00
|
|
|
TreeNavResult::Exit
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
/* HULL
|
|
|
|
*/
|
|
|
|
fn set_addr(&mut self, addr: isize) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
c.tree_addr[0] = addr;
|
|
|
|
self.goto(c)
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn set_leaf_mode(&mut self, new_leaf_mode: ListCursorMode) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
c.leaf_mode = new_leaf_mode;
|
|
|
|
self.goto(c)
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
|
2023-02-13 18:39:45 +01:00
|
|
|
fn get_leaf_mode(&mut self) -> ListCursorMode {
|
|
|
|
self.get_cursor().leaf_mode
|
|
|
|
}
|
|
|
|
|
|
|
|
fn toggle_leaf_mode(&mut self) -> TreeNavResult {
|
|
|
|
let old_mode = self.get_leaf_mode();
|
|
|
|
self.set_leaf_mode(
|
|
|
|
match old_mode {
|
|
|
|
ListCursorMode::Insert => ListCursorMode::Select,
|
|
|
|
ListCursorMode::Select => ListCursorMode::Insert
|
|
|
|
}
|
|
|
|
);
|
|
|
|
TreeNavResult::Continue
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn up(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(0, -1))
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn dn(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(0, 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pxev(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(-1, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn nexd(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(1, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
fn qpxev(&mut self) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
match c.tree_addr.len() {
|
|
|
|
0 => {
|
|
|
|
self.goto(TreeCursor::home())
|
|
|
|
},
|
|
|
|
depth => {
|
|
|
|
if c.tree_addr[depth-1] != 0 {
|
|
|
|
c.tree_addr[depth-1] = 0;
|
|
|
|
} else {
|
2023-09-06 04:33:21 +02:00
|
|
|
self.pxev();
|
|
|
|
c = self.get_cursor();
|
|
|
|
let d = c.tree_addr.len();
|
|
|
|
if d > 0 {
|
|
|
|
c.tree_addr[d-1] = 0;
|
2022-06-19 23:13:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.goto(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn qnexd(&mut self) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor_warp();
|
|
|
|
match c.tree_addr.len() {
|
|
|
|
0 => {
|
|
|
|
TreeNavResult::Exit
|
|
|
|
},
|
|
|
|
depth => {
|
|
|
|
if c.tree_addr[depth-1] != -1 {
|
|
|
|
c.tree_addr[depth-1] = -1;
|
|
|
|
} else {
|
2023-09-06 04:33:21 +02:00
|
|
|
self.nexd();
|
|
|
|
c = self.get_cursor();
|
|
|
|
let d = c.tree_addr.len();
|
|
|
|
if d > 0 {
|
|
|
|
c.tree_addr[d-1] = -1;
|
2022-06-19 23:13:21 +02:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 04:33:21 +02:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
self.goto(c)
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
}
|
2023-01-07 04:37:44 +01:00
|
|
|
|
|
|
|
fn get_cursor_widget(&self) -> OuterViewPort<dyn TerminalView> {
|
|
|
|
VecBuffer::with_data(
|
|
|
|
vec![
|
|
|
|
make_label("@").with_fg_color((150, 80,230)),
|
|
|
|
self.get_addr_view()
|
|
|
|
.map(|i|
|
|
|
|
make_label(&format!("{}", i)).with_fg_color((0, 100, 20)))
|
|
|
|
.separate(make_label(".").with_fg_color((150, 80,230)))
|
|
|
|
.to_grid_horizontal()
|
|
|
|
.flatten(),
|
|
|
|
make_label(":").with_fg_color((150, 80,230)),
|
|
|
|
self.get_mode_view()
|
|
|
|
.map(|mode| {
|
|
|
|
make_label(
|
|
|
|
match mode {
|
|
|
|
ListCursorMode::Insert => "INSERT",
|
|
|
|
ListCursorMode::Select => "SELECT"
|
|
|
|
})
|
|
|
|
.with_fg_color((200, 200, 20))
|
|
|
|
})
|
|
|
|
.to_grid()
|
|
|
|
.flatten(),
|
|
|
|
make_label(":").with_fg_color((150, 80,230))
|
|
|
|
]
|
|
|
|
).get_port()
|
|
|
|
.to_sequence()
|
|
|
|
.to_grid_horizontal()
|
|
|
|
.flatten()
|
|
|
|
}
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2023-11-11 18:00:47 +01:00
|
|
|
|