' Context-sensitive help via menu item selection
#COMPILE EXE
#DIM ALL

%ID_HELP_TOPICS    = 100
%ID_HELP_KEYBOARD  = 101
%ID_HELP_MENU      = 102
%ID_HELP_TOOLBAR   = 103
%ID_HELP_COMMANDS  = 104
%ID_HELP_TIPS      = 105
%ID_HELP_TROUBLE   = 106
%ID_HELP_ABOUT     = 107
%ID_HELP_SEARCH    = 108
%ID_HELP_INDEX     = 109

SUB ShowTopic(BYVAL id AS LONG, BYVAL title AS STRING, BYVAL content AS STRING)
    PRINT "=== "; title; " ==="
    PRINT content
    PRINT "---"
END SUB

SUB ShowTopicWithParent(BYVAL id AS LONG, BYVAL title AS STRING, BYVAL content AS STRING, BYVAL parent AS STRING)
    PRINT "=== "; title; " ==="
    PRINT content
    IF LEN(parent) > 0 THEN PRINT "Parent: "; parent
    PRINT "---"
END SUB

SUB BuildHelpSystem()
    PRINT "Help system (9 topics):"
    PRINT "  - Help Topics (ID 100)"
    PRINT "    - Keyboard Shortcuts (ID 101)"
    PRINT "    - Using Menus (ID 102)"
    PRINT "    - Toolbar Reference (ID 103)"
    PRINT "    - Command Reference (ID 104)"
    PRINT "    - Tips and Tricks (ID 105)"
    PRINT "    - Troubleshooting (ID 106)"
    PRINT "  - About (ID 107)"
    PRINT "  - Search (ID 108)"
    PRINT "  - Index (ID 109)"
END SUB

SUB ShowMenuHelp(BYVAL id AS LONG)
    PRINT ""
    IF id = %ID_HELP_TOPICS THEN ShowTopic(id, "Help Topics", "Welcome to the help system. Select a topic from the list.")
    IF id = %ID_HELP_KEYBOARD THEN ShowTopicWithParent(id, "Keyboard Shortcuts", "Ctrl+N: New, Ctrl+O: Open, Ctrl+S: Save", "Help Topics")
    IF id = %ID_HELP_MENU THEN ShowTopicWithParent(id, "Using Menus", "Menus provide access to all application features and functions.", "Help Topics")
    IF id = %ID_HELP_TOOLBAR THEN ShowTopicWithParent(id, "Toolbar Reference", "The toolbar gives one-click access to common commands.", "Help Topics")
    IF id = %ID_HELP_ABOUT THEN ShowTopic(id, "About", "PBXB64 Context Help Demo v1.0")
    IF id = %ID_HELP_COMMANDS THEN ShowTopicWithParent(id, "Command Reference", "Full list of all commands and their keyboard shortcuts.", "Help Topics")
    IF id = %ID_HELP_TIPS THEN ShowTopicWithParent(id, "Tips and Tricks", "Save time with these productivity tips.", "Help Topics")
    IF id = %ID_HELP_TROUBLE THEN ShowTopicWithParent(id, "Troubleshooting", "Common issues: file not found, access denied, network timeout.", "Help Topics")
END SUB

SUB MenuHelpSimulation()
    BuildHelpSystem()
    PRINT ""
    ShowMenuHelp(%ID_HELP_KEYBOARD)
    ShowMenuHelp(%ID_HELP_ABOUT)
    ShowMenuHelp(%ID_HELP_TROUBLE)
END SUB

SUB F1ContextHelp(BYVAL menuId AS LONG)
    PRINT ""
    PRINT "F1 Help for menu item #"; menuId; ":"
    ShowMenuHelp(menuId)
END SUB

SUB PrintHelpTree(BYVAL indent AS LONG)
    LOCAL i  AS LONG
    LOCAL j  AS LONG
    FOR i = 0 TO 8
        LOCAL sp AS STRING
        sp = ""
        FOR j = 1 TO indent
            sp = sp + "  "
        NEXT j
        IF i = 0 THEN PRINT sp; "- Help Topics"
        IF i = 1 THEN PRINT sp; "  - Keyboard Shortcuts"
        IF i = 2 THEN PRINT sp; "  - Using Menus"
        IF i = 3 THEN PRINT sp; "  - Toolbar Reference"
        IF i = 4 THEN PRINT sp; "  - Command Reference"
        IF i = 5 THEN PRINT sp; "  - Tips and Tricks"
        IF i = 6 THEN PRINT sp; "  - Troubleshooting"
        IF i = 7 THEN PRINT sp; "- About"
        IF i = 8 THEN PRINT sp; "- Search"
    NEXT i
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Context Help Demo ==="
    PRINT "Help system with topic hierarchy"
    MenuHelpSimulation()
    PRINT ""
    PRINT "Help tree:"
    PrintHelpTree(0)
    F1ContextHelp(%ID_HELP_KEYBOARD)
    F1ContextHelp(%ID_HELP_ABOUT)
    PRINT "=== End Context Help ==="
    FUNCTION = 0
END FUNCTION
