sort commands in quickbar

This commit is contained in:
Stephan Dilly 2020-04-02 18:33:34 +02:00
parent 6c7c155cef
commit 25883f6070
3 changed files with 50 additions and 35 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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,