From 6d08202a5d6db09e45e5f52a1575281e9c032416 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sun, 4 Jun 2023 10:16:17 +0200 Subject: [PATCH] save (ctrl-s function) normally does not save if no changes are made. However if file timestamp has changed since opening (by someone else) prompt user to decide what to do (save or not) --- src/actions.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/actions.c b/src/actions.c index ce5aed32..cec6ccc2 100644 --- a/src/actions.c +++ b/src/actions.c @@ -450,18 +450,29 @@ const char *get_file_path(char *f) */ int save(int confirm) { - if(xctx->modified) - { - if(confirm) { - tcleval("ask_save"); - if(!strcmp(tclresult(), "") ) return -1; /* user clicks "Cancel" */ - else if(!strcmp(tclresult(), "yes") ) return save_schematic(xctx->sch[xctx->currsch]); - else return 0; /* user clicks "no" */ - } else { - return save_schematic(xctx->sch[xctx->currsch]); - } - } - return 1; /* circuit not changed: always succeeed */ + struct stat buf; + char *name = xctx->sch[xctx->currsch]; + int force = 0; + + if(!stat(name, &buf)) { + if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) { + force = 1; + confirm = 0; + } + } + + if(force || xctx->modified) + { + if(confirm) { + tcleval("ask_save"); + if(!strcmp(tclresult(), "") ) return -1; /* user clicks "Cancel" */ + else if(!strcmp(tclresult(), "yes") ) return save_schematic(xctx->sch[xctx->currsch]); + else return 0; /* user clicks "no" */ + } else { + return save_schematic(xctx->sch[xctx->currsch]); + } + } + return 1; /* circuit not changed: always succeeed */ } void saveas(const char *f, int type) /* changed name from ask_save_file to saveas 20121201 */