From 158186a9c450d1a6ddc04cc89f5a1a5e80b7dce2 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Fri, 14 Jan 2022 19:37:01 +0100 Subject: [PATCH] better WM_DELETE_WINDOW protocol handler in case of multiple windows --- src/paste.c | 2 +- src/xinit.c | 2 +- src/xschem.tcl | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/paste.c b/src/paste.c index fdfa8fa2..67a0a24a 100644 --- a/src/paste.c +++ b/src/paste.c @@ -338,7 +338,7 @@ void merge_file(int selection_load, const char ext[]) if(selection_load==0) { if(!strcmp(ext,"")) { - my_snprintf(tmp, S(tmp), "load_file_dialog {Merge file} {.sch.sym} INITIALLOADDIR", ext); + my_snprintf(tmp, S(tmp), "load_file_dialog {Merge file} {.sch.sym} INITIALLOADDIR"); tcleval(tmp); if(!strcmp(tclresult(),"")) return; my_strncpy(name, (char *)tclresult(), S(name)); diff --git a/src/xinit.c b/src/xinit.c index 5e16f1fc..5d0acf01 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1213,7 +1213,7 @@ static void destroy_window(int *window_count, const char *win_path) savectx = xctx; if(*window_count) { int close = 0; - dbg(1, "new_schematic() destroy {%s}\n", win_path); + dbg(0, "new_schematic() destroy {%s}\n", win_path); if(xctx->modified && has_x) { tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \"" "[get_cell [xschem get schname] 0]" diff --git a/src/xschem.tcl b/src/xschem.tcl index e8cd0a81..53342258 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -4607,14 +4607,19 @@ proc build_widgets { {topwin {} } } { #wm maxsize . 1600 1200 if { $rootwin == {.}} { wm protocol $rootwin WM_DELETE_WINDOW { - if { [xschem get current_win_path] eq {.drw} } { - xschem exit - } else { - xschem new_schematic destroy [xschem get current_win_path] {} - } + set old [xschem get current_win_path] + save_ctx $old + restore_ctx .drw + housekeeping_ctx + xschem new_schematic switch_win .drw + xschem exit + # did not exit ... switch back + restore_ctx $old + housekeeping_ctx + xschem new_schematic switch_win $old } } else { - wm protocol $topwin WM_DELETE_WINDOW "xschem new_schematic destroy $topwin.drw {}" + wm protocol $rootwin WM_DELETE_WINDOW "xschem new_schematic destroy $topwin.drw {}" } frame $topwin.statusbar