mirror of
https://github.com/chylex/Bark-Browser.git
synced 2025-09-15 05:32:13 +02:00
Compare commits
1 Commits
95c12d4f61
...
wip
Author | SHA1 | Date | |
---|---|---|---|
4c5a663f51
|
@@ -1,4 +1,5 @@
|
||||
use crate::component::filesystem::FsLayer;
|
||||
use crate::component::input::InputFieldOverlayLayer;
|
||||
use crate::state::action::{Action, ActionResult};
|
||||
use crate::state::Environment;
|
||||
|
||||
@@ -17,3 +18,13 @@ impl Action<FsLayer> for RedrawScreen {
|
||||
ActionResult::Redraw
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnterCommandMode;
|
||||
|
||||
impl Action<FsLayer> for EnterCommandMode {
|
||||
fn perform(&self, _layer: &mut FsLayer, _environment: &Environment) -> ActionResult {
|
||||
ActionResult::PushLayer(Box::new(InputFieldOverlayLayer::new(":", Box::new(|command| {
|
||||
ActionResult::PopLayer
|
||||
}))))
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ pub struct DeleteSelectedEntry;
|
||||
impl Action<FsLayer> for DeleteSelectedEntry {
|
||||
fn perform(&self, layer: &mut FsLayer, _environment: &Environment) -> ActionResult {
|
||||
if let Some(FileNode { node, entry, path }) = get_selected_file(layer) {
|
||||
ActionResult::PushLayer(Box::new(create_delete_confirmation_dialog(layer, node.node_id(), entry, path.to_owned())))
|
||||
ActionResult::push_layer(create_delete_confirmation_dialog(layer, node.node_id(), entry, path.to_owned()))
|
||||
} else {
|
||||
ActionResult::Nothing
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::component::filesystem::action::application::{Quit, RedrawScreen};
|
||||
use crate::component::filesystem::action::application::{EnterCommandMode, Quit, RedrawScreen};
|
||||
use crate::component::filesystem::action::count::PushCountDigit;
|
||||
use crate::component::filesystem::action::file::{CreateDirectoryInParentOfSelectedEntry, CreateDirectoryInSelectedDirectory, CreateFileInParentOfSelectedEntry, CreateFileInSelectedDirectory, DeleteSelectedEntry, EditSelectedEntry, RenameSelectedEntry};
|
||||
use crate::component::filesystem::action::movement::{CollapseSelectedOr, ExpandSelectedOr, MoveBetweenFirstAndLastSibling, MoveDown, MovementWithCountFactory, MovementWithFallbackFactory, MoveOrTraverseUpParent, MoveToFirst, MoveToLast, MoveToLineOr, MoveToNextSibling, MoveToParent, MoveToPreviousSibling, MoveUp, ScreenHeightRatio};
|
||||
@@ -57,6 +57,7 @@ fn create_action_map() -> ActionKeyMap {
|
||||
map(&mut me, "R", RenameSelectedEntry { prefill: false });
|
||||
|
||||
map(&mut me, "%", MoveBetweenFirstAndLastSibling);
|
||||
map(&mut me, ":", EnterCommandMode);
|
||||
|
||||
map(&mut me, "<Ctrl-B>", MoveUp.with_custom_count(ScreenHeightRatio(1)));
|
||||
map(&mut me, "<Ctrl-C>", Quit);
|
||||
|
@@ -22,4 +22,8 @@ impl ActionResult {
|
||||
Self::Nothing
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_layer<T>(layer: T) -> Self where T: Layer + 'static {
|
||||
Self::PushLayer(Box::new(layer))
|
||||
}
|
||||
}
|
||||
|
32
src/state/event.rs
Normal file
32
src/state/event.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use crate::state::Environment;
|
||||
|
||||
pub trait Event<L> {
|
||||
fn dispatch(&self, layer: &mut L, environment: &Environment) -> EventResult;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub enum EventResult {
|
||||
Nothing,
|
||||
Draw,
|
||||
Redraw,
|
||||
}
|
||||
|
||||
impl EventResult {
|
||||
pub const fn draw_if(condition: bool) -> Self {
|
||||
if condition {
|
||||
Self::Draw
|
||||
} else {
|
||||
Self::Nothing
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(self, other: Self) -> Self {
|
||||
if self == Self::Redraw || other == Self::Redraw {
|
||||
Self::Redraw
|
||||
} else if self == Self::Draw || other == Self::Draw {
|
||||
Self::Draw
|
||||
} else {
|
||||
Self::Nothing
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,6 +10,7 @@ pub use self::environment::Environment;
|
||||
|
||||
mod environment;
|
||||
pub mod action;
|
||||
pub mod event;
|
||||
pub mod layer;
|
||||
pub mod view;
|
||||
|
||||
|
Reference in New Issue
Block a user