1
0
mirror of https://github.com/chylex/Bark-Browser.git synced 2025-09-15 14:32:12 +02:00

Compare commits

1 Commits

Author SHA1 Message Date
4c5a663f51 WIP 2023-08-07 04:51:49 +02:00
6 changed files with 51 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
use crate::component::filesystem::FsLayer; use crate::component::filesystem::FsLayer;
use crate::component::input::InputFieldOverlayLayer;
use crate::state::action::{Action, ActionResult}; use crate::state::action::{Action, ActionResult};
use crate::state::Environment; use crate::state::Environment;
@@ -17,3 +18,13 @@ impl Action<FsLayer> for RedrawScreen {
ActionResult::Redraw 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
}))))
}
}

View File

@@ -20,7 +20,7 @@ pub struct DeleteSelectedEntry;
impl Action<FsLayer> for DeleteSelectedEntry { impl Action<FsLayer> for DeleteSelectedEntry {
fn perform(&self, layer: &mut FsLayer, _environment: &Environment) -> ActionResult { fn perform(&self, layer: &mut FsLayer, _environment: &Environment) -> ActionResult {
if let Some(FileNode { node, entry, path }) = get_selected_file(layer) { 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 { } else {
ActionResult::Nothing ActionResult::Nothing
} }

View File

@@ -1,6 +1,6 @@
use lazy_static::lazy_static; 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::count::PushCountDigit;
use crate::component::filesystem::action::file::{CreateDirectoryInParentOfSelectedEntry, CreateDirectoryInSelectedDirectory, CreateFileInParentOfSelectedEntry, CreateFileInSelectedDirectory, DeleteSelectedEntry, EditSelectedEntry, RenameSelectedEntry}; 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}; 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, "R", RenameSelectedEntry { prefill: false });
map(&mut me, "%", MoveBetweenFirstAndLastSibling); map(&mut me, "%", MoveBetweenFirstAndLastSibling);
map(&mut me, ":", EnterCommandMode);
map(&mut me, "<Ctrl-B>", MoveUp.with_custom_count(ScreenHeightRatio(1))); map(&mut me, "<Ctrl-B>", MoveUp.with_custom_count(ScreenHeightRatio(1)));
map(&mut me, "<Ctrl-C>", Quit); map(&mut me, "<Ctrl-C>", Quit);

View File

@@ -22,4 +22,8 @@ impl ActionResult {
Self::Nothing 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
View 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
}
}
}

View File

@@ -10,6 +10,7 @@ pub use self::environment::Environment;
mod environment; mod environment;
pub mod action; pub mod action;
pub mod event;
pub mod layer; pub mod layer;
pub mod view; pub mod view;