add `user_startup_commands` variable that may contain tcl code to be executed after any new window creation. Useful to have custom bindings / menu / buttons in all windows.

This commit is contained in:
stefan schippers 2025-03-13 20:11:18 +01:00
parent 84ca35e6f5
commit e789988b05
3 changed files with 22 additions and 0 deletions

View File

@ -1666,6 +1666,7 @@ static void create_new_window(int *window_count, const char *noconfirm, const ch
tclvareval("set_bindings ", window_path[n], NULL);
tclvareval("set_replace_key_binding ", window_path[n], NULL);
tclvareval("save_ctx ", window_path[n], NULL);
tcleval("eval_user_startup_commands");
/* restore previous context,
* because the Expose event after new window creation does a context switch prev win -> new win
*
@ -2892,6 +2893,7 @@ int Tcl_AppInit(Tcl_Interp *inter)
if(has_x) {
tclsetintvar("tctx::max_new_windows", MAX_NEW_WINDOWS);
tcleval("pack_widgets; set_bindings .drw");
tcleval("eval_user_startup_commands");
}
fs=tclgetintvar("fullscreen");

View File

@ -9355,6 +9355,15 @@ proc source_user_tcl_files {} {
}
}
proc eval_user_startup_commands {} {
global user_startup_commands
if {[info exists user_startup_commands]} {
if {[catch {uplevel #0 $user_startup_commands} res]} {
puts "executing $user_startup_commands:\n\n$res"
}
}
}
proc eval_postinit_commands {} {
global postinit_commands
if {[info exists postinit_commands]} {

View File

@ -540,6 +540,17 @@
# }
# }
###########################################################################
#### TCL COMMANDS TO BE EXECUTED AFTER ANY NEW WINDOW CREATION
###########################################################################
#### this hook is useful to execute user UI code (like event binding,
#### new buttons / menu entries etc).
# set user_startup_commands {
# bind [xschem get current_win_path] <Key-plus> {
# puts Hello
# }
# }
###########################################################################
#### TCL COMMANDS TO BE EXECUTED AFTER GENERATING NETLIST
###########################################################################