use crate::i18n::{Key, Lang};
use iced::widget::text_editor;
use std::collections::BTreeSet;
use std::sync::Arc;
mod dialog;
pub(crate) mod markdown;
mod search;
#[cfg(test)]
mod tests;
pub(crate) use markdown::{
HelpMarkdownHighlight, HelpMarkdownHighlighter, HelpMarkdownLine, parse_help_markdown_line,
};
pub(crate) use search::{HelpSearchResponse, HelpSearchResult, run_help_search};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum HelpNode {
CatIntroduction,
TopicAbout,
TopicFeatures,
CatSystemComposition,
TopicSystemComponents,
CatCpuArchitecture,
TopicArchitecture,
TopicRegisters,
TopicFlagsRegister,
TopicMemoryIoSpaces,
CatInstructionSet,
TopicDataTransferCommands,
TopicLogicalCommands,
TopicArithmeticCommands,
TopicControlTransferCommands,
TopicProcessorControlCommands,
TopicIoCommands,
TopicStackCommands,
CatProgramInterface,
TopicMainWindow,
CatMainMenu,
TopicMenuFile,
TopicMenuMpSystem,
TopicMenuHelp,
TopicSchematic,
TopicRamTable,
CatExternalDevices,
TopicMonitor,
TopicFloppy,
TopicHdd,
TopicNetwork,
TopicPrinter,
TopicRamEditing,
TopicRegisterEditing,
TopicResetButtons,
TopicCommandPanel,
TopicRunButtons,
CatFilesExport,
TopicSaveLoad,
TopicImport,
TopicExport,
TopicFileFormats,
CatSettings,
TopicGeneralSettings,
TopicAppearance,
CatWorkflow,
TopicGeneralPrinciples,
TopicMemorySearch,
TopicRegisterEdit,
TopicDeviceWorkflow,
CatCommandReference,
TopicCommandSummary,
CatShortcuts,
TopicShortcuts,
}
impl HelpNode {
pub(crate) const ROOTS: [Self; 12] = [
Self::CatIntroduction,
Self::CatSystemComposition,
Self::CatCpuArchitecture,
Self::CatInstructionSet,
Self::CatProgramInterface,
Self::CatMainMenu,
Self::CatExternalDevices,
Self::CatFilesExport,
Self::CatSettings,
Self::CatWorkflow,
Self::CatCommandReference,
Self::CatShortcuts,
];
pub(crate) fn children(self) -> &'static [Self] {
match self {
Self::CatIntroduction => &[Self::TopicAbout, Self::TopicFeatures],
Self::CatSystemComposition => &[Self::TopicSystemComponents],
Self::CatCpuArchitecture => &[
Self::TopicArchitecture,
Self::TopicRegisters,
Self::TopicFlagsRegister,
Self::TopicMemoryIoSpaces,
],
Self::CatInstructionSet => &[
Self::TopicDataTransferCommands,
Self::TopicLogicalCommands,
Self::TopicArithmeticCommands,
Self::TopicControlTransferCommands,
Self::TopicProcessorControlCommands,
Self::TopicIoCommands,
Self::TopicStackCommands,
],
Self::CatProgramInterface => &[
Self::TopicMainWindow,
Self::TopicSchematic,
Self::TopicRamTable,
Self::TopicRamEditing,
Self::TopicRegisterEditing,
Self::TopicResetButtons,
Self::TopicCommandPanel,
Self::TopicRunButtons,
],
Self::CatMainMenu => &[
Self::TopicMenuFile,
Self::TopicMenuMpSystem,
Self::TopicMenuHelp,
],
Self::CatExternalDevices => &[
Self::TopicMonitor,
Self::TopicFloppy,
Self::TopicHdd,
Self::TopicNetwork,
Self::TopicPrinter,
],
Self::CatFilesExport => &[
Self::TopicSaveLoad,
Self::TopicImport,
Self::TopicExport,
Self::TopicFileFormats,
],
Self::CatSettings => &[Self::TopicGeneralSettings, Self::TopicAppearance],
Self::CatWorkflow => &[
Self::TopicGeneralPrinciples,
Self::TopicMemorySearch,
Self::TopicRegisterEdit,
Self::TopicDeviceWorkflow,
],
Self::CatCommandReference => &[Self::TopicCommandSummary],
Self::CatShortcuts => &[Self::TopicShortcuts],
_ => &[],
}
}
pub(crate) fn is_category(self) -> bool {
!self.children().is_empty()
}
pub(crate) fn label_key(self) -> Key {
match self {
Self::CatIntroduction => Key::HnIntroduction,
Self::TopicAbout => Key::HnAbout,
Self::TopicFeatures => Key::HnFeatures,
Self::CatSystemComposition => Key::HnSystemComposition,
Self::TopicSystemComponents => Key::HnSystemComponents,
Self::CatCpuArchitecture => Key::HnCpuArchitecture,
Self::TopicArchitecture => Key::HnArchitecture,
Self::TopicRegisters => Key::HnRegisters,
Self::TopicFlagsRegister => Key::HnFlagsRegister,
Self::TopicMemoryIoSpaces => Key::HnMemoryIoSpaces,
Self::CatInstructionSet => Key::HnInstructionSet,
Self::TopicDataTransferCommands => Key::HnDataTransferCommands,
Self::TopicLogicalCommands => Key::HnLogicalCommands,
Self::TopicArithmeticCommands => Key::HnArithmeticCommands,
Self::TopicControlTransferCommands => Key::HnControlTransferCommands,
Self::TopicProcessorControlCommands => Key::HnProcessorControlCommands,
Self::TopicIoCommands => Key::HnIoCommands,
Self::TopicStackCommands => Key::HnStackCommands,
Self::CatProgramInterface => Key::HnProgramInterface,
Self::TopicMainWindow => Key::HnMainWindow,
Self::CatMainMenu => Key::HnMainMenu,
Self::TopicMenuFile => Key::HnMenuFile,
Self::TopicMenuMpSystem => Key::HnMenuMpSystem,
Self::TopicMenuHelp => Key::HnMenuHelp,
Self::TopicSchematic => Key::HnSchematic,
Self::TopicRamTable => Key::HnRamTable,
Self::CatExternalDevices => Key::HnExternalDevices,
Self::TopicMonitor => Key::HnMonitor,
Self::TopicFloppy => Key::HnFloppy,
Self::TopicHdd => Key::HnHdd,
Self::TopicNetwork => Key::HnNetwork,
Self::TopicPrinter => Key::HnPrinter,
Self::TopicRamEditing => Key::HnRamEditing,
Self::TopicRegisterEditing => Key::HnRegisterEditing,
Self::TopicResetButtons => Key::HnResetButtons,
Self::TopicCommandPanel => Key::HnCommandPanel,
Self::TopicRunButtons => Key::HnRunButtons,
Self::CatFilesExport => Key::HnFilesExport,
Self::TopicSaveLoad => Key::HnSaveLoad,
Self::TopicImport => Key::HnImport,
Self::TopicExport => Key::HnExport,
Self::TopicFileFormats => Key::HnFileFormats,
Self::CatSettings => Key::HnSettings,
Self::TopicGeneralSettings => Key::HnGeneralSettings,
Self::TopicAppearance => Key::HnAppearance,
Self::CatWorkflow => Key::HnWorkflow,
Self::TopicGeneralPrinciples => Key::HnGeneralPrinciples,
Self::TopicMemorySearch => Key::HnMemorySearch,
Self::TopicRegisterEdit => Key::HnRegisterEdit,
Self::TopicDeviceWorkflow => Key::HnDeviceWorkflow,
Self::CatCommandReference => Key::HnCommandReference,
Self::TopicCommandSummary => Key::HnCommandSummary,
Self::CatShortcuts => Key::HnShortcuts,
Self::TopicShortcuts => Key::HnTopicShortcuts,
}
}
pub(crate) fn content_key(self) -> Key {
match self {
Self::TopicAbout => Key::HcAbout,
Self::TopicFeatures => Key::HcFeatures,
Self::TopicSystemComponents => Key::HcSystemComponents,
Self::TopicArchitecture => Key::HcArchitecture,
Self::TopicRegisters => Key::HcRegisters,
Self::TopicFlagsRegister => Key::HcFlagsRegister,
Self::TopicMemoryIoSpaces => Key::HcMemoryIoSpaces,
Self::TopicDataTransferCommands => Key::HcDataTransferCommands,
Self::TopicLogicalCommands => Key::HcLogicalCommands,
Self::TopicArithmeticCommands => Key::HcArithmeticCommands,
Self::TopicControlTransferCommands => Key::HcControlTransferCommands,
Self::TopicProcessorControlCommands => Key::HcProcessorControlCommands,
Self::TopicIoCommands => Key::HcIoCommands,
Self::TopicStackCommands => Key::HcStackCommands,
Self::TopicMainWindow => Key::HcMainWindow,
Self::TopicMenuFile => Key::HcMenuFile,
Self::TopicMenuMpSystem => Key::HcMenuMpSystem,
Self::TopicMenuHelp => Key::HcMenuHelp,
Self::TopicSchematic => Key::HcSchematic,
Self::TopicRamTable => Key::HcRamTable,
Self::TopicMonitor => Key::HcMonitor,
Self::TopicFloppy => Key::HcFloppy,
Self::TopicHdd => Key::HcHdd,
Self::TopicNetwork => Key::HcNetwork,
Self::TopicPrinter => Key::HcPrinter,
Self::TopicRamEditing => Key::HcRamEditing,
Self::TopicRegisterEditing => Key::HcRegisterEditing,
Self::TopicResetButtons => Key::HcResetButtons,
Self::TopicCommandPanel => Key::HcCommandPanel,
Self::TopicRunButtons => Key::HcRunButtons,
Self::TopicSaveLoad => Key::HcSaveLoad,
Self::TopicImport => Key::HcImport,
Self::TopicExport => Key::HcExport,
Self::TopicFileFormats => Key::HcFileFormats,
Self::TopicGeneralSettings => Key::HcGeneralSettings,
Self::TopicAppearance => Key::HcAppearance,
Self::TopicGeneralPrinciples => Key::HcGeneralPrinciples,
Self::TopicMemorySearch => Key::HcMemorySearch,
Self::TopicRegisterEdit => Key::HcRegisterEdit,
Self::TopicDeviceWorkflow => Key::HcDeviceWorkflow,
Self::TopicCommandSummary => Key::HcCommandSummary,
Self::TopicShortcuts => Key::HcShortcuts,
_ => Key::HcAbout,
}
}
}
#[derive(Clone)]
pub(crate) struct HelpDialog {
pub(crate) selected: HelpNode,
pub(crate) expanded: BTreeSet<HelpNode>,
pub(crate) search: String,
pub(crate) article_content: text_editor::Content,
pub(crate) article_highlights: markdown::HelpMarkdownHighlights,
article_content_node: HelpNode,
article_content_lang: Lang,
search_index: Arc<search::HelpSearchIndex>,
search_generation: u64,
pending_search: Option<dialog::PendingHelpSearch>,
search_results_query: String,
search_matches: BTreeSet<HelpNode>,
search_results: Vec<HelpSearchResult>,
}