From ee0de61220ca17303e94de4465678946dda4c6c0 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 4 Jan 2025 12:24:22 +0100 Subject: [PATCH] add `2` and `3` argument to set_modify (do only clear/set modified flag), save() -> save_schematic(): do not update title/tab names if saving with same name. --- doc/xschem_man/developer_info.html | 12 ++++++++++-- src/actions.c | 15 ++++++++++----- src/save.c | 5 ++++- src/scheduler.c | 12 ++++++++++-- src/xschem.tcl | 2 +- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index f079f211..90222099 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -1452,8 +1452,15 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
  • set_different_tok str new_str old_str
  •     Return string 'str' replacing/adding/removing tokens that are
        different between 'new_str' and 'old_str' 
    -
  • set_modify
  • -   Force modify status on current schematic 
    +
  • set_modify [n]
  • +   Force modify status on current schematic
    +   integer 'n':
    +   0 : clear modified flag, update title and tab names, upd. simulation button colors.
    +   1 : set modified flag, update title and tab names, upd. simulation button colors, rst floater caches.
    +   2 : clear modified flag, do nothing else.
    +   3 : set modified flag, do nothing else.
    +  -1 : set title, rst floater caches.
    +  -2 : rst floater caches, update simulation button colors (Simulate, Waves, Netlist).
  • setprop instance|symbol|text|rect ref tok [val] [fast]
  •        
            setprop instance inst [tok] [val] [fast]
    @@ -1685,6 +1692,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
     
     
     
    +
     
     
      
    diff --git a/src/actions.c b/src/actions.c
    index 7621ee7c..1d52d0b5 100644
    --- a/src/actions.c
    +++ b/src/actions.c
    @@ -140,9 +140,14 @@ const char *get_text_floater(int i)
       return txt_ptr;
     } 
     
    -/* mod=-1 used to force set title 
    - * mod=-2 used to reset floaters cache 
    - * if floaters are present set_modify(1) (after a modify opration) must be done before draw()
    +/* mod:
    + *   0 : clear modified flag, update title and tab names, upd. simulation button colors.
    + *   1 : set modified flag, update title and tab names, upd. simulation button colors, rst floater caches.
    + *   2 : clear modified flag, do nothing else.
    + *   3 : set modified flag, do nothing else.
    + *  -1 : set title, rst floater caches.
    + *  -2 : rst floater caches, update simulation button colors (Simulate, Waves, Netlist).
    + * If floaters are present set_modify(1) (after a modify operation) must be done before draw()
      * to invalidate cached floater string values  before redrawing
      * return 1 if floaters are found (mod==-2 or mod == 1 or mod == -1) */
     int set_modify(int mod)
    @@ -152,8 +157,8 @@ int set_modify(int mod)
       dbg(1, "set_modify(): %d, prev_set_modify=%d\n", mod, xctx->prev_set_modify);
     
       /* set modify state */
    -  if(mod == 0 || mod == 1) {
    -    xctx->modified = mod;
    +  if(mod == 0 || mod == 1 || mod == 2 || mod == 3) {
    +    xctx->modified = (mod & 1);
       }
       if(mod == 1 || (mod == 0  && xctx->prev_set_modify) || mod == -2) {
         /*                Do not configure buttons if displaying in preview window */
    diff --git a/src/save.c b/src/save.c
    index df57a7c8..24e38d02 100644
    --- a/src/save.c
    +++ b/src/save.c
    @@ -3322,6 +3322,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */
       xRect *rect;
       int rects;
       char msg[PATH_MAX + 100];
    +  int same_name = 0;
     
       if(!schname || !strcmp(schname, "")) return 0;
     
    @@ -3337,6 +3338,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */
         set_modify(-1); /* set title to new filename */
       }
       else { /* user asks to save to same filename */
    +    same_name = 1;
         if(!stat(xctx->sch[xctx->currsch], &buf)) {
           if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) {
             tclvareval("ask_save_optional \"Schematic file: ", xctx->sch[xctx->currsch],
    @@ -3372,7 +3374,8 @@ int save_schematic(const char *schname) /* 20171020 added return value */
        * xctx->prep_hash_wires=0;
        */
       if(!strstr(xctx->sch[xctx->currsch], ".xschem_embedded_")) {
    -     set_modify(0);
    +     if(same_name) set_modify(2); /* clear only modified flag, do not set window title etc */
    +     else set_modify(0);
       }
       tclvareval(xctx->top_path, ".menubar entryconfigure Simulate -background $simulate_bg", NULL);
       tclvareval("set tctx::", xctx->current_win_path, "_simulate $simulate_bg", NULL);
    diff --git a/src/scheduler.c b/src/scheduler.c
    index 81ad5732..ea7d1a69 100644
    --- a/src/scheduler.c
    +++ b/src/scheduler.c
    @@ -5179,8 +5179,16 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
           my_free(_ALLOC_ID_, &s);
         }
     
    -    /* set_modify
    -     *   Force modify status on current schematic */
    +    /* set_modify [n]
    +     *   Force modify status on current schematic
    +     *   integer 'n':
    +     *   0 : clear modified flag, update title and tab names, upd. simulation button colors.
    +     *   1 : set modified flag, update title and tab names, upd. simulation button colors, rst floater caches.
    +     *   2 : clear modified flag, do nothing else.
    +     *   3 : set modified flag, do nothing else.
    +     *  -1 : set title, rst floater caches.
    +     *  -2 : rst floater caches, update simulation button colors (Simulate, Waves, Netlist).
    +     */
         else if(!strcmp(argv[1], "set_modify"))
         {
           if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
    diff --git a/src/xschem.tcl b/src/xschem.tcl
    index 0a501574..97d47a1b 100644
    --- a/src/xschem.tcl
    +++ b/src/xschem.tcl
    @@ -1901,7 +1901,7 @@ proc traversal_setlabels {w parent_sch instname inst_sch sym_sch default_sch ins
           } else {
             xschem setprop instance $instname schematic [$w get] fast ;# set schematic attr on instance
           } 
    -      xschem set_modify 1
    +      xschem set_modify 3 ;# set only modified flag to force a save, do not update window/tab titles
           xschem save
           set inst_sch [$w get]
           puts "inst_sch set to: $inst_sch"