diff --git a/src/app.rs b/src/app.rs index 1a7fe59d..1e243334 100644 --- a/src/app.rs +++ b/src/app.rs @@ -239,6 +239,7 @@ impl App { fn update_commands(&mut self) { self.help.set_cmds(self.commands(true)); self.current_commands = self.commands(false); + self.current_commands.sort_by_key(|e| e.order); } fn update_status(&mut self) { @@ -269,20 +270,26 @@ impl App { { let focus_on_stage = self.focus == Focus::Stage; let focus_not_diff = self.focus != Focus::Diff; - res.push(CommandInfo::new_hidden( - strings::CMD_STATUS_FOCUS_UNSTAGED, - true, - main_cmds_available - && focus_on_stage - && !focus_not_diff, - )); - res.push(CommandInfo::new_hidden( - strings::CMD_STATUS_FOCUS_STAGED, - true, - main_cmds_available - && !focus_on_stage - && !focus_not_diff, - )); + res.push( + CommandInfo::new( + strings::CMD_STATUS_FOCUS_UNSTAGED, + true, + main_cmds_available + && focus_on_stage + && !focus_not_diff, + ) + .hidden(), + ); + res.push( + CommandInfo::new( + strings::CMD_STATUS_FOCUS_STAGED, + true, + main_cmds_available + && !focus_on_stage + && !focus_not_diff, + ) + .hidden(), + ); } { let focus_on_diff = self.focus == Focus::Diff; @@ -298,11 +305,14 @@ impl App { )); } - res.push(CommandInfo::new( - strings::CMD_STATUS_QUIT, - true, - main_cmds_available, - )); + res.push( + CommandInfo::new( + strings::CMD_STATUS_QUIT, + true, + main_cmds_available, + ) + .order(100), + ); } res diff --git a/src/components/command.rs b/src/components/command.rs index 7c352a71..047a3609 100644 --- a/src/components/command.rs +++ b/src/components/command.rs @@ -10,6 +10,8 @@ pub struct CommandInfo { pub quick_bar: bool, /// available in current app state pub available: bool, + /// used to order commands in quickbar + pub order: i8, } impl CommandInfo { @@ -20,20 +22,20 @@ impl CommandInfo { enabled, quick_bar: true, available, + order: 0, } } /// - pub fn new_hidden( - name: &str, - enabled: bool, - available: bool, - ) -> Self { - Self { - name: name.to_string(), - enabled, - quick_bar: false, - available, - } + pub fn order(self, order: i8) -> Self { + let mut res = self; + res.order = order; + res + } + /// + pub fn hidden(self) -> Self { + let mut res = self; + res.quick_bar = false; + res } /// pub fn print(&self, out: &mut String) { diff --git a/src/components/help.rs b/src/components/help.rs index f1ed0525..14f5b0c9 100644 --- a/src/components/help.rs +++ b/src/components/help.rs @@ -56,11 +56,14 @@ impl Component for HelpComponent { out.clear(); } - out.push(CommandInfo::new( - strings::CMD_STATUS_HELP, - true, - !self.visible, - )); + out.push( + CommandInfo::new( + strings::CMD_STATUS_HELP, + true, + !self.visible, + ) + .order(99), + ); out.push(CommandInfo::new( strings::COMMIT_CMD_CLOSE,