mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-22 13:22:28 +00:00
w.i.p. left click confirmation
This commit is contained in:
parent
1190892617
commit
10b1f20562
|
@ -3,7 +3,7 @@ use std::borrow::Cow;
|
||||||
use crate::{float::FloatContent, hint::Shortcut};
|
use crate::{float::FloatContent, hint::Shortcut};
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
crossterm::event::{KeyCode, KeyEvent, MouseEvent, MouseEventKind},
|
crossterm::event::{KeyCode, KeyEvent, MouseButton, MouseEvent, MouseEventKind},
|
||||||
layout::Alignment,
|
layout::Alignment,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
widgets::{Block, Borders, Clear, List},
|
widgets::{Block, Borders, Clear, List},
|
||||||
|
@ -87,16 +87,21 @@ impl FloatContent for ConfirmPrompt {
|
||||||
|
|
||||||
fn handle_mouse_event(&mut self, event: &MouseEvent) -> bool {
|
fn handle_mouse_event(&mut self, event: &MouseEvent) -> bool {
|
||||||
match event.kind {
|
match event.kind {
|
||||||
|
MouseEventKind::Down(MouseButton::Left) => {
|
||||||
|
self.status = ConfirmStatus::Confirm;
|
||||||
|
true
|
||||||
|
}
|
||||||
MouseEventKind::ScrollDown => {
|
MouseEventKind::ScrollDown => {
|
||||||
self.scroll_down();
|
self.scroll_down();
|
||||||
|
false
|
||||||
}
|
}
|
||||||
MouseEventKind::ScrollUp => {
|
MouseEventKind::ScrollUp => {
|
||||||
self.scroll_up();
|
self.scroll_up();
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_key_event(&mut self, key: &KeyEvent) -> bool {
|
fn handle_key_event(&mut self, key: &KeyEvent) -> bool {
|
||||||
use KeyCode::*;
|
use KeyCode::*;
|
||||||
|
|
|
@ -483,7 +483,7 @@ impl AppState {
|
||||||
|
|
||||||
match &mut self.focus {
|
match &mut self.focus {
|
||||||
Focus::FloatingWindow(float) => float.draw(frame, chunks[1]),
|
Focus::FloatingWindow(float) => float.draw(frame, chunks[1]),
|
||||||
Focus::ConfirmationPrompt(prompt) => prompt.draw(frame, chunks[1]),
|
Focus::ConfirmationPrompt(confirm) => confirm.draw(frame, chunks[1]),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,12 +502,25 @@ impl AppState {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Focus::ConfirmationPrompt(prompt) => {
|
Focus::ConfirmationPrompt(confirm) => {
|
||||||
if prompt.handle_mouse_event(event) {
|
if confirm.handle_mouse_event(event) {
|
||||||
|
match confirm.content.status {
|
||||||
|
ConfirmStatus::Abort => {
|
||||||
self.focus = Focus::List;
|
self.focus = Focus::List;
|
||||||
self.selected_commands.clear();
|
if !self.multi_select {
|
||||||
|
self.selected_commands.clear()
|
||||||
|
} else {
|
||||||
|
if let Some(node) = self.get_selected_node() {
|
||||||
|
if !node.multi_select {
|
||||||
|
self.selected_commands.retain(|cmd| cmd.name != node.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ConfirmStatus::Confirm => self.handle_confirm_command(),
|
||||||
|
ConfirmStatus::None => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user