module

Tryst::MenuInterceptor

@api private

Live-scan helper for the "menu" CommandInterceptors entry below.

Menu entries are not windows (only the menu itself is one), so they never fire <Destroy>; entry deletion is silent and Tk renumbers the survivors internally. Because of that, entry-level callbacks can't be tracked by index or by any per-entry event - the only sound way to know which callbacks are still needed is to ask Tk what's actually live after every mutating call and release whatever dropped out.

Constants

CALLBACK_SCRIPT_PATTERN = /\Acrystal_callback (\S+)\z/

Anchored to a BARE crystal_callback <id> with nothing after - correct today because tryst never appends %-substitutions to a menu entry's -command (that only happens for App#bind's widget bindings). If substitution support is ever added here, this pattern silently stops matching and those ids leak on rebuild/delete - drop the trailing anchor (match just the leading "crystal_callback <id>") if that changes.

ENTRY_SUBCOMMANDS = ["add", "insert", "entryconfigure", "delete"] of ::String
LIVE_COMMANDS_TCL_PROC = "proc ::tryst_menu_live_commands {path} {\n set result {}\n if {![winfo exists $path]} { return $result }\n set last [$path index end]\n if {$last eq \"none\"} { return $result }\n for {set i 0} {$i <= $last} {incr i} {\n set cmd \"\"\n catch {set cmd [$path entrycget $i -command]}\n lappend result $cmd\n }\n return $result\n}"

Class methods

live_command_ids(app : App, path : String) : Hash(String, String)
Source