diff options
author | Canop <cano.petrole@gmail.com> | 2021-04-17 10:26:26 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-04-17 10:26:26 +0200 |
commit | ccce368ea81ea1aa070557ff984a04b6c1449960 (patch) | |
tree | f9c7f6d3d84274fa0755009a310fb5fe2b10ea62 | |
parent | f925993a6bbacbf92befdf1d825de982ba094fdf (diff) |
:open_staging_area and :close_staging_area
-rw-r--r-- | src/app/app.rs | 1 | ||||
-rw-r--r-- | src/app/panel_state.rs | 23 | ||||
-rw-r--r-- | src/path/common.rs | 2 | ||||
-rw-r--r-- | src/stage/stage_state.rs | 11 | ||||
-rw-r--r-- | src/verb/builtin.rs | 2 | ||||
-rw-r--r-- | src/verb/internal.rs | 2 |
6 files changed, 37 insertions, 4 deletions
diff --git a/src/app/app.rs b/src/app/app.rs index 951a02c..e8f14ce 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -9,7 +9,6 @@ use { file_sum, git, launchable::Launchable, skin::*, - stage::StageState, task_sync::{Dam, Either}, verb::Internal, }, diff --git a/src/app/panel_state.rs b/src/app/panel_state.rs index 808ef19..71da555 100644 --- a/src/app/panel_state.rs +++ b/src/app/panel_state.rs @@ -323,6 +323,27 @@ pub trait PanelState { Internal::stage => self.stage(app_state, cc, con), Internal::unstage => self.unstage(app_state, cc, con), Internal::toggle_stage => self.toggle_stage(app_state, cc, con), + Internal::close_staging_area => { + if let Some(id) = cc.app.stage_panel { + CmdResult::ClosePanel { + validate_purpose: false, + panel_ref: PanelReference::Id(id), + } + } else { + CmdResult::Keep + } + } + Internal::open_staging_area => { + if cc.app.stage_panel.is_none() { + CmdResult::NewPanel { + state: Box::new(StageState::new(self.tree_options(), con)), + purpose: PanelPurpose::None, + direction: HDir::Right, + } + } else { + CmdResult::Keep + } + } Internal::print_path => { if let Some(path) = self.selected_path() { print::print_path(path, con)? @@ -371,7 +392,7 @@ pub trait PanelState { &self, app_state: &mut AppState, cc: &CmdContext, - con: &AppContext, + _con: &AppContext, ) -> CmdResult { if let Some(path) = self.selected_path() { if app_state.stage.remove(path) && app_state.stage.is_empty() { diff --git a/src/path/common.rs b/src/path/common.rs index a88a5cf..4c75faa 100644 --- a/src/path/common.rs +++ b/src/path/common.rs @@ -7,7 +7,7 @@ pub fn longest_common_ancestor(paths: &[PathBuf]) -> PathBuf { 0 => PathBuf::new(), // empty 1 => paths[0].clone(), _ => { - let mut cs0 = paths[0].components(); + let cs0 = paths[0].components(); let mut csi: Vec<Components> = paths .iter() .skip(1) diff --git a/src/stage/stage_state.rs b/src/stage/stage_state.rs index 5e78c1e..f3208d5 100644 --- a/src/stage/stage_state.rs +++ b/src/stage/stage_state.rs @@ -79,6 +79,7 @@ impl PanelState for StageState { in_new_panel: bool, con: &AppContext, ) -> CmdResult { + // FIXME we must register the options, at least // TODO implement: sorting, etc. CmdResult::Keep } @@ -264,7 +265,15 @@ impl PanelState for StageState { Ok(if refresh { CmdResult::RefreshState { clear_cache: true } } else { - CmdResult::Keep + app_state.stage.refresh(); + if app_state.stage.is_empty() { + CmdResult::ClosePanel { + validate_purpose: false, + panel_ref: PanelReference::Active, + } + } else { + CmdResult::Keep + } }) } } diff --git a/src/verb/builtin.rs b/src/verb/builtin.rs index 1fe54fe..00dd2fe 100644 --- a/src/verb/builtin.rs +++ b/src/verb/builtin.rs @@ -184,6 +184,8 @@ pub fn builtin_verbs() -> Vec<Verb> { internal(stage), internal(unstage), internal(toggle_stage), + internal(open_staging_area), + internal(close_staging_area), internal(sort_by_count).with_shortcut("sc"), internal(sort_by_date).with_shortcut("sd"), internal(sort_by_size).with_shortcut("ss"), diff --git a/src/verb/internal.rs b/src/verb/internal.rs index 3eb3eb8..b96a79b 100644 --- a/src/verb/internal.rs +++ b/src/verb/internal.rs @@ -112,6 +112,8 @@ Internals! { clear_stage: "empty the staging area" false, stage: "add selection to staging area" true, unstage: "remove selection from staging area" true, + open_staging_area: "open the staging area" false, + close_staging_area: "close the sting area panel" false, toggle_stage: "add or remove selection to staging area" true, toggle_counts: "toggle showing number of files in directories" false, toggle_dates: "toggle showing last modified dates" false, |