parent
4e9aedd34c
commit
f531886255
@ -241,6 +241,7 @@ impl<'a> Component for App<'a> {
|
|||||||
};
|
};
|
||||||
match action {
|
match action {
|
||||||
Action::Quit | Action::Handled => return Ok(action),
|
Action::Quit | Action::Handled => return Ok(action),
|
||||||
|
Action::Save => self.editor.save()?,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
|
use crate::tui::component::Action::Pass;
|
||||||
use crate::tui::component::{Action, Component, ComponentState};
|
use crate::tui::component::{Action, Component, ComponentState};
|
||||||
|
use crate::tui::title_bar::MenuBarItemOption::{
|
||||||
|
About, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
||||||
|
};
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
@ -16,6 +20,29 @@ enum MenuBarItem {
|
|||||||
Help,
|
Help,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter)]
|
||||||
|
enum MenuBarItemOption {
|
||||||
|
Save,
|
||||||
|
Reload,
|
||||||
|
Exit,
|
||||||
|
ShowHideExplorer,
|
||||||
|
ShowHideLogger,
|
||||||
|
About,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MenuBarItemOption {
|
||||||
|
fn id(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
MenuBarItemOption::Save => "Save",
|
||||||
|
MenuBarItemOption::Reload => "Reload",
|
||||||
|
MenuBarItemOption::Exit => "Exit",
|
||||||
|
MenuBarItemOption::ShowHideExplorer => "Show / hide explorer",
|
||||||
|
MenuBarItemOption::ShowHideLogger => "Show / hide logger",
|
||||||
|
MenuBarItemOption::About => "About",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MenuBarItem {
|
impl MenuBarItem {
|
||||||
pub fn next(self) -> Self {
|
pub fn next(self) -> Self {
|
||||||
let cur = self as usize;
|
let cur = self as usize;
|
||||||
@ -37,11 +64,11 @@ impl MenuBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn options(&self) -> &[&str] {
|
pub fn options(&self) -> &[MenuBarItemOption] {
|
||||||
match self {
|
match self {
|
||||||
MenuBarItem::File => &["Save", "Reload"],
|
MenuBarItem::File => &[Save, Reload, Exit],
|
||||||
MenuBarItem::View => &["Show/hide explorer", "Show/hide logger"],
|
MenuBarItem::View => &[ShowHideExplorer, ShowHideLogger],
|
||||||
MenuBarItem::Help => &["About"],
|
MenuBarItem::Help => &[About],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +118,7 @@ impl MenuBar {
|
|||||||
) {
|
) {
|
||||||
let popup_area = Self::rect_under_option(title_bar_anchor, area, 40, 10);
|
let popup_area = Self::rect_under_option(title_bar_anchor, area, 40, 10);
|
||||||
Clear::default().render(popup_area, buf);
|
Clear::default().render(popup_area, buf);
|
||||||
let options = opened.options().iter().map(|i| ListItem::new(*i));
|
let options = opened.options().iter().map(|i| ListItem::new(i.id()));
|
||||||
StatefulWidget::render(
|
StatefulWidget::render(
|
||||||
List::new(options)
|
List::new(options)
|
||||||
.block(Block::bordered().title(self.selected.id()))
|
.block(Block::bordered().title(self.selected.id()))
|
||||||
@ -149,8 +176,18 @@ impl Component for MenuBar {
|
|||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
// TODO: Handle action for the item.
|
if let Some(selected) = self.list_state.selected() {
|
||||||
Ok(Action::Handled)
|
let seletion = self.selected.options()[selected];
|
||||||
|
return match seletion {
|
||||||
|
Save => Ok(Action::Save),
|
||||||
|
Exit => Ok(Action::Quit),
|
||||||
|
Reload => Ok(Action::Noop), // TODO
|
||||||
|
ShowHideExplorer => Ok(Action::Noop), // TODO
|
||||||
|
ShowHideLogger => Ok(Action::Noop), // TODO
|
||||||
|
About => Ok(Action::Noop), // TODO
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
KeyCode::Esc | KeyCode::Char('q') => {
|
KeyCode::Esc | KeyCode::Char('q') => {
|
||||||
self.opened = None;
|
self.opened = None;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user