use super::{
rules::{Check, first_failure},
state::CommandState,
};
use crate::MainWindow;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Category {
File,
Edit,
View,
Tiers,
Solve,
Tools,
Help,
}
impl Category {
#[must_use]
pub const fn label(self) -> &'static str {
match self {
Self::File => "File",
Self::Edit => "Edit",
Self::View => "View",
Self::Tiers => "Tiers",
Self::Solve => "Solve",
Self::Tools => "Tools",
Self::Help => "Help",
}
}
}
pub struct Command {
pub id: &'static str,
pub title: &'static str,
pub category: Category,
pub keywords: &'static str,
pub shortcut: Option<&'static str>,
pub requires: &'static [Check],
pub run: fn(&MainWindow),
}
impl Command {
pub fn availability(&self, state: &CommandState) -> Result<(), &'static str> {
first_failure(self.requires, state)
}
}
#[must_use]
pub const fn command(
id: &'static str,
title: &'static str,
category: Category,
keywords: &'static str,
shortcut: Option<&'static str>,
requires: &'static [Check],
run: fn(&MainWindow),
) -> Command {
Command {
id,
title,
category,
keywords,
shortcut,
requires,
run,
}
}