From bea7edf90e83cece2a7a085a510110ff897c4b56 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Thu, 27 May 2021 09:39:50 +0200 Subject: [PATCH] reorder --- src/components/commit.rs | 250 +++++++++++++++++++-------------------- 1 file changed, 125 insertions(+), 125 deletions(-) diff --git a/src/components/commit.rs b/src/components/commit.rs index c89d9c28..8498a1fc 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -49,131 +49,6 @@ pub struct CommitComponent { const FIRST_LINE_LIMIT: usize = 50; -impl DrawableComponent for CommitComponent { - fn draw( - &self, - f: &mut Frame, - rect: Rect, - ) -> Result<()> { - if self.is_visible() { - self.input.draw(f, rect)?; - self.draw_branch_name(f); - self.draw_warnings(f); - } - - Ok(()) - } -} - -impl Component for CommitComponent { - fn commands( - &self, - out: &mut Vec, - force_all: bool, - ) -> CommandBlocking { - self.input.commands(out, force_all); - - if self.is_visible() || force_all { - out.push(CommandInfo::new( - strings::commands::commit_enter(&self.key_config), - self.can_commit(), - true, - )); - - out.push(CommandInfo::new( - strings::commands::commit_amend(&self.key_config), - self.can_amend(), - true, - )); - - out.push(CommandInfo::new( - strings::commands::commit_open_editor( - &self.key_config, - ), - true, - true, - )); - } - - visibility_blocking(self) - } - - fn event(&mut self, ev: Event) -> Result { - if self.is_visible() { - if self.input.event(ev)?.is_consumed() { - return Ok(EventState::Consumed); - } - - if let Event::Key(e) = ev { - if e == self.key_config.enter && self.can_commit() { - try_or_popup!( - self, - "commit error:", - self.commit() - ); - } else if e == self.key_config.commit_amend - && self.can_amend() - { - self.amend()?; - } else if e == self.key_config.open_commit_editor { - self.queue.borrow_mut().push_back( - InternalEvent::OpenExternalEditor(None), - ); - self.hide(); - } else { - } - // stop key event propagation - return Ok(EventState::Consumed); - } - } - - Ok(EventState::NotConsumed) - } - - fn is_visible(&self) -> bool { - self.input.is_visible() - } - - fn hide(&mut self) { - self.input.hide() - } - - fn show(&mut self) -> Result<()> { - //only clear text if it was not a normal commit dlg before, so to preserve old commit msg that was edited - if !matches!(self.mode, Mode::Normal) { - self.input.clear(); - } - - self.mode = Mode::Normal; - - self.mode = if sync::repo_state(CWD)? == RepoState::Merge { - let ids = sync::mergehead_ids(CWD)?; - self.input.set_title(strings::commit_title_merge()); - self.input.set_text(sync::merge_msg(CWD)?); - Mode::Merge(ids) - } else { - self.commit_template = - get_config_string(CWD, "commit.template") - .ok() - .flatten() - .and_then(|path| read_to_string(path).ok()); - - if self.is_empty() { - if let Some(s) = &self.commit_template { - self.input.set_text(s.clone()); - } - } - - self.input.set_title(strings::commit_title()); - Mode::Normal - }; - - self.input.show()?; - - Ok(()) - } -} - impl CommitComponent { /// pub fn new( @@ -409,3 +284,128 @@ impl CommitComponent { Ok(()) } } + +impl DrawableComponent for CommitComponent { + fn draw( + &self, + f: &mut Frame, + rect: Rect, + ) -> Result<()> { + if self.is_visible() { + self.input.draw(f, rect)?; + self.draw_branch_name(f); + self.draw_warnings(f); + } + + Ok(()) + } +} + +impl Component for CommitComponent { + fn commands( + &self, + out: &mut Vec, + force_all: bool, + ) -> CommandBlocking { + self.input.commands(out, force_all); + + if self.is_visible() || force_all { + out.push(CommandInfo::new( + strings::commands::commit_enter(&self.key_config), + self.can_commit(), + true, + )); + + out.push(CommandInfo::new( + strings::commands::commit_amend(&self.key_config), + self.can_amend(), + true, + )); + + out.push(CommandInfo::new( + strings::commands::commit_open_editor( + &self.key_config, + ), + true, + true, + )); + } + + visibility_blocking(self) + } + + fn event(&mut self, ev: Event) -> Result { + if self.is_visible() { + if self.input.event(ev)?.is_consumed() { + return Ok(EventState::Consumed); + } + + if let Event::Key(e) = ev { + if e == self.key_config.enter && self.can_commit() { + try_or_popup!( + self, + "commit error:", + self.commit() + ); + } else if e == self.key_config.commit_amend + && self.can_amend() + { + self.amend()?; + } else if e == self.key_config.open_commit_editor { + self.queue.borrow_mut().push_back( + InternalEvent::OpenExternalEditor(None), + ); + self.hide(); + } else { + } + // stop key event propagation + return Ok(EventState::Consumed); + } + } + + Ok(EventState::NotConsumed) + } + + fn is_visible(&self) -> bool { + self.input.is_visible() + } + + fn hide(&mut self) { + self.input.hide() + } + + fn show(&mut self) -> Result<()> { + //only clear text if it was not a normal commit dlg before, so to preserve old commit msg that was edited + if !matches!(self.mode, Mode::Normal) { + self.input.clear(); + } + + self.mode = Mode::Normal; + + self.mode = if sync::repo_state(CWD)? == RepoState::Merge { + let ids = sync::mergehead_ids(CWD)?; + self.input.set_title(strings::commit_title_merge()); + self.input.set_text(sync::merge_msg(CWD)?); + Mode::Merge(ids) + } else { + self.commit_template = + get_config_string(CWD, "commit.template") + .ok() + .flatten() + .and_then(|path| read_to_string(path).ok()); + + if self.is_empty() { + if let Some(s) = &self.commit_template { + self.input.set_text(s.clone()); + } + } + + self.input.set_title(strings::commit_title()); + Mode::Normal + }; + + self.input.show()?; + + Ok(()) + } +}