From f9610851e88f7e586d2ccb7f899c7ff9fdff36c6 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 3 Jun 2023 11:37:37 +0200 Subject: [PATCH] cleanup exit procedures: tcl exit command will cleanly delete additional tabs/windows data structures before closing --- src/options.c | 3 ++- src/xinit.c | 14 ++++++++------ src/xschem.tcl | 28 +++++++--------------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/options.c b/src/options.c index 95974776..06b926ab 100644 --- a/src/options.c +++ b/src/options.c @@ -158,7 +158,8 @@ static void check_opt(char *opt, char *optval, int type) } else if( (type == SHORT && *opt == 'h') || (type == LONG && !strcmp("help", opt)) ) { help=1; - + quit=1; + has_x=0; } else { fprintf(errfp, "Unknown option: %s\n", opt); } diff --git a/src/xinit.c b/src/xinit.c index 9c32717f..7426de6e 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -850,6 +850,8 @@ static void xwin_exit(void) return; } tcleval("catch { ngspice::resetdata }"); /* remove ngspice annotation data if any */ + /* "1" parameter means to force exit even if there are modified tabs/windows */ + if(has_x) new_schematic("destroy_all", "1", NULL); delete_schematic_data(1); if(has_x) { Tk_DestroyWindow(mainwindow); @@ -1602,7 +1604,7 @@ static void destroy_tab(int *window_count, const char *win_path) } } -static void destroy_all_windows(int *window_count) +static void destroy_all_windows(int *window_count, int force) { int i; Xschem_ctx *savectx; @@ -1619,7 +1621,7 @@ static void destroy_all_windows(int *window_count) xctx = save_xctx[i]; close = 0; /* reset old focused window so callback() will force repaint on expose events */ - if(xctx->modified && has_x) { + if(!force && xctx->modified && has_x) { tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \"" "[get_cell [xschem get schname] 0]" ": UNSAVED data: want to exit?\""); @@ -1651,7 +1653,7 @@ static void destroy_all_windows(int *window_count) } } -static void destroy_all_tabs(int *window_count) +static void destroy_all_tabs(int *window_count, int force) { int i; Xschem_ctx *savectx; @@ -1664,7 +1666,7 @@ static void destroy_all_tabs(int *window_count) xctx = save_xctx[i]; close = 0; /* reset old focused window so callback() will force repaint on expose events */ - if(xctx->modified && has_x) { + if(!force && xctx->modified && has_x) { tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \"" "[get_cell [xschem get schname] 0]" ": UNSAVED data: want to exit?\""); @@ -1726,9 +1728,9 @@ int new_schematic(const char *what, const char *win_path, const char *fname) } } else if(!strcmp(what, "destroy_all")) { if(!tabbed_interface) { - destroy_all_windows(&window_count); + destroy_all_windows(&window_count, win_path ? 1 : 0); } else { - destroy_all_tabs(&window_count); + destroy_all_tabs(&window_count, win_path ? 1 : 0); } } else if(!strcmp(what, "switch_win")) { switch_window(&window_count, win_path); /* see comments in switch_window() */ diff --git a/src/xschem.tcl b/src/xschem.tcl index 362fd87c..639e22f0 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -138,15 +138,14 @@ proc inutile_translate {f} { proc inutile { {filename {}}} { global XSCHEM_SHAREDIR retval netlist_dir + if { ![string compare $filename ""] } then { + tk_messageBox -type ok -message "Please give a file name as argument" + return + } toplevel .inutile wm title .inutile "(IN)UTILE (Stefan Schippers, sschippe)" wm iconname .inutile "(IN)UTILE" set utile_path $XSCHEM_SHAREDIR/utile - if { ![string compare $filename ""] } then { - wm withdraw .inutile - tk_messageBox -type ok -message "Please give a file name as argument" - exit - } set retval {} frame .inutile.buttons pack .inutile.buttons -side bottom -fill x -pady 2m @@ -5242,11 +5241,7 @@ proc setup_tabbed_interface {} { # update tabbed window close (X) function if {$tabbed_interface} { wm protocol . WM_DELETE_WINDOW { - if { [xschem get current_win_path] eq {.drw} } { - xschem exit - } else { - xschem new_schematic destroy [xschem get current_win_path] {} - } + xschem exit } # restore non tabbed window close function for main window } else { @@ -5826,11 +5821,7 @@ proc build_widgets { {topwin {} } } { $topwin.menubar.file.menu add command -label "SVG Export" -command "xschem print svg" -accelerator {Alt+*} $topwin.menubar.file.menu add separator $topwin.menubar.file.menu add command -label "Exit" -accelerator {Ctrl+Q} -command { - if {[xschem get current_win_path] eq {.drw} } { - xschem exit - } else { - xschem new_schematic destroy [xschem get current_win_path] {} - } + xschem exit } $topwin.menubar.option.menu add checkbutton -label "Color Postscript/SVG" -variable color_ps \ -command { @@ -6249,11 +6240,7 @@ tclcommand=\"xschem raw_read \$netlist_dir/[file tail [file rootname [xschem get #wm maxsize . 1600 1200 if {$tabbed_interface && $rootwin eq {.}} { 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] {} - } + xschem exit } } elseif { $rootwin == {.}} { wm protocol $rootwin WM_DELETE_WINDOW { @@ -6343,7 +6330,6 @@ proc print_help_and_exit {} { set helpfile [read $fd] puts $helpfile close $fd - exit } }