From c44966c1a9d8ed6cd46c69fba50566740effa92c Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Tue, 12 May 2020 14:05:38 +0200 Subject: [PATCH] cleanup --- src/app.rs | 9 +-------- src/components/changes.rs | 26 ++++++++++++++++++++++---- src/queue.rs | 2 ++ src/strings.rs | 4 ++-- src/tabs/status.rs | 17 ----------------- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/app.rs b/src/app.rs index d7e0f1ed..f0123f4d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -108,14 +108,6 @@ impl App { flags.insert(NeedsUpdate::COMMANDS); } else if let Event::Key(k) = ev { let new_flags = match k { - //TODO: move into status tab - keys::OPEN_COMMIT - if self.status_tab.offer_open_commit_cmd() => - { - self.commit.show(); - NeedsUpdate::COMMANDS - } - keys::TAB_TOGGLE => { self.toggle_tabs(); NeedsUpdate::COMMANDS @@ -265,6 +257,7 @@ impl App { flags.insert(NeedsUpdate::ALL); } InternalEvent::Update(u) => flags.insert(u), + InternalEvent::OpenCommit => self.commit.show(), }; flags diff --git a/src/components/changes.rs b/src/components/changes.rs index 8c8a229d..6b79eaeb 100644 --- a/src/components/changes.rs +++ b/src/components/changes.rs @@ -302,7 +302,7 @@ impl Component for ChangesComponent { fn commands( &self, out: &mut Vec, - _force_all: bool, + force_all: bool, ) -> CommandBlocking { let some_selection = self.selection().is_some(); @@ -323,6 +323,14 @@ impl Component for ChangesComponent { some_selection, self.focused, )); + out.push( + CommandInfo::new( + commands::COMMIT_OPEN, + !self.is_empty(), + self.focused || force_all, + ) + .order(-1), + ); } out.push(CommandInfo::new( @@ -338,6 +346,15 @@ impl Component for ChangesComponent { if self.focused { if let Event::Key(e) = ev { return match e { + keys::OPEN_COMMIT + if !self.is_working_dir + && !self.is_empty() => + { + self.queue + .borrow_mut() + .push_back(InternalEvent::OpenCommit); + true + } keys::STATUS_STAGE_FILE => { if self.index_add_remove() { self.queue.borrow_mut().push_back( @@ -348,9 +365,10 @@ impl Component for ChangesComponent { } true } - keys::STATUS_RESET_FILE => { - self.is_working_dir - && self.dispatch_reset_workdir() + keys::STATUS_RESET_FILE + if self.is_working_dir => + { + self.dispatch_reset_workdir() } keys::MOVE_DOWN => { self.move_selection(MoveSelection::Down) diff --git a/src/queue.rs b/src/queue.rs index 7351d136..0deb2186 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -33,6 +33,8 @@ pub enum InternalEvent { ShowMsg(String), /// Update(NeedsUpdate), + /// + OpenCommit, } /// diff --git a/src/strings.rs b/src/strings.rs index 11ce73dc..cd7e08e3 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -14,7 +14,7 @@ pub static COMMIT_MSG: &str = "type commit message.."; pub static RESET_TITLE: &str = "Reset"; pub static RESET_MSG: &str = "confirm file reset?"; -pub static HELP_TITLE: &str = "Help"; +pub static HELP_TITLE: &str = "Help: all commands"; pub mod commands { use crate::components::CommandText; @@ -100,7 +100,7 @@ pub mod commands { /// pub static COMMIT_OPEN: CommandText = CommandText::new( "Commit [c]", - "open commit view (available in non-empty stage)", + "open commit popup (available in non-empty stage)", CMD_GROUP_COMMIT, ); /// diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 7a4f7fcf..97bf3bb1 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -130,13 +130,6 @@ impl Status { } } - //TODO: unpub - pub fn offer_open_commit_cmd(&self) -> bool { - self.visible - && self.diff_target == DiffTarget::Stage - && !self.index.is_empty() - } - fn switch_focus(&mut self, f: Focus) -> bool { if self.focus != f { self.focus = f; @@ -273,16 +266,6 @@ impl Component for Status { )); } - out.push( - CommandInfo::new( - commands::COMMIT_OPEN, - !self.index.is_empty(), - (self.visible && self.offer_open_commit_cmd()) - || force_all, - ) - .order(-1), - ); - out.push( CommandInfo::new( commands::SELECT_STATUS,