mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
generalise command gathering
This commit is contained in:
parent
572be62b5f
commit
21cbc3b136
3 changed files with 34 additions and 20 deletions
|
|
@ -48,6 +48,7 @@ macro_rules! accessors {
|
|||
};
|
||||
}
|
||||
|
||||
/// returns `true` if event was consumed
|
||||
pub fn event_pump(
|
||||
ev: Event,
|
||||
components: &mut [&mut dyn Component],
|
||||
|
|
@ -61,6 +62,23 @@ pub fn event_pump(
|
|||
false
|
||||
}
|
||||
|
||||
/// helper fn to simplify delegating command
|
||||
/// gathering down into child components
|
||||
/// see `event_pump`,`accessors`
|
||||
pub fn command_pump(
|
||||
out: &mut Vec<CommandInfo>,
|
||||
force_all: bool,
|
||||
components: &[&dyn Component],
|
||||
) {
|
||||
for c in components {
|
||||
if c.commands(out, force_all) != CommandBlocking::PassingOn
|
||||
&& !force_all
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum ScrollType {
|
||||
Up,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use crate::{
|
||||
accessors,
|
||||
components::{
|
||||
CommandBlocking, CommandInfo, Component, DrawableComponent,
|
||||
FileTreeComponent,
|
||||
command_pump, event_pump, CommandBlocking, CommandInfo,
|
||||
Component, DrawableComponent, FileTreeComponent,
|
||||
},
|
||||
keys,
|
||||
queue::{InternalEvent, NeedsUpdate, Queue},
|
||||
|
|
@ -36,6 +37,8 @@ pub struct Stashing {
|
|||
}
|
||||
|
||||
impl Stashing {
|
||||
accessors!(self, [index]);
|
||||
|
||||
///
|
||||
pub fn new(
|
||||
sender: &Sender<AsyncNotification>,
|
||||
|
|
@ -162,7 +165,7 @@ impl Component for Stashing {
|
|||
out: &mut Vec<CommandInfo>,
|
||||
force_all: bool,
|
||||
) -> CommandBlocking {
|
||||
self.index.commands(out, force_all);
|
||||
command_pump(out, force_all, self.components().as_slice());
|
||||
|
||||
out.push(CommandInfo::new(
|
||||
commands::STASHING_SAVE,
|
||||
|
|
@ -189,9 +192,7 @@ impl Component for Stashing {
|
|||
|
||||
fn event(&mut self, ev: crossterm::event::Event) -> bool {
|
||||
if self.visible {
|
||||
let conusmed = self.index.event(ev);
|
||||
|
||||
if conusmed {
|
||||
if event_pump(ev, self.components_mut().as_mut_slice()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
accessors,
|
||||
components::{
|
||||
event_pump, ChangesComponent, CommandBlocking, CommandInfo,
|
||||
Component, DiffComponent, DrawableComponent,
|
||||
self, event_pump, ChangesComponent, CommandBlocking,
|
||||
CommandInfo, Component, DiffComponent, DrawableComponent,
|
||||
FileTreeItemKind,
|
||||
},
|
||||
keys,
|
||||
|
|
@ -14,6 +14,7 @@ use asyncgit::{
|
|||
sync::status::StatusType, AsyncDiff, AsyncNotification,
|
||||
AsyncStatus, DiffParams, StatusParams,
|
||||
};
|
||||
use components::command_pump;
|
||||
use crossbeam_channel::Sender;
|
||||
use crossterm::event::Event;
|
||||
use strings::commands;
|
||||
|
|
@ -262,14 +263,11 @@ impl Component for Status {
|
|||
force_all: bool,
|
||||
) -> CommandBlocking {
|
||||
if self.visible {
|
||||
for c in self.components() {
|
||||
if c.commands(out, force_all)
|
||||
!= CommandBlocking::PassingOn
|
||||
&& !force_all
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
command_pump(
|
||||
out,
|
||||
force_all,
|
||||
self.components().as_slice(),
|
||||
);
|
||||
|
||||
{
|
||||
let focus_on_diff = self.focus == Focus::Diff;
|
||||
|
|
@ -325,10 +323,7 @@ impl Component for Status {
|
|||
|
||||
fn event(&mut self, ev: crossterm::event::Event) -> bool {
|
||||
if self.visible {
|
||||
let conusmed =
|
||||
event_pump(ev, self.components_mut().as_mut_slice());
|
||||
|
||||
if conusmed {
|
||||
if event_pump(ev, self.components_mut().as_mut_slice()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue