Author Topic: Modified lines color, reset on write?  (Read 9780 times)

miffed

  • Community Member
  • Posts: 14
  • Hero Points: 0
Modified lines color, reset on write?
« on: July 30, 2008, 06:36:38 pm »

I turned on color coding for "Modified Lines"
  Tools > Options > Languages > Advanced > Color Coding > Modified Lines

But I cannot find a "Reset on write" option, so the color code never goes away, even after saving the file. As far as I can tell, the only way to remove the color code is to close and re-open the file.

Am I missing something? Is there a way to reset the Modified-line-markings when I save the file?

Thanks.

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Modified lines color, reset on write?
« Reply #1 on: July 30, 2008, 06:41:59 pm »
Tools > Options > File Options > Save > Reset line modify

- Ryan

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Modified lines color, reset on write?
« Reply #2 on: July 30, 2008, 06:47:47 pm »
Also, v13 introduced a handy feature in the Options dialog -- it has a search box at the top left, where you can type something and it filters the treeview to only list stuff that has matches for what you typed.  For example if you type "reset" in there, it filters down to only one match, the one you were looking for.  If you type "modif" in there, it filters down to a lot of matches, but you can go down to the "Search Results" entry in the treeview and scroll through it to see the exact matches and the "Reset line modify" in "File Options > Save" match still stands out as the one you want.

JeffB

  • Senior Community Member
  • Posts: 254
  • Hero Points: 9
Re: Modified lines color, reset on write?
« Reply #3 on: July 30, 2008, 07:15:50 pm »
Psuedo-related...

I just recently started using the "modified lines" functionality, and really like it.  I'm a habitual "CTRL-S" user, so this option doesn't help me.  I would prefer a way to do a reset when I checkin all my files, although I can see how this would be difficult (especially since I don't use SlickEdit to check them in anyway).  Since I couldn't find a "reset all files" function, and haven't had time to write a macro to do it, I started closing and re-opening the workspace after I checkin.  This works ok, but a single function/macro would be nicer :)

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Modified lines color, reset on write?
« Reply #4 on: July 30, 2008, 09:01:51 pm »
Pretty simple macro to reset the modified/inserted line flags:

Code: [Select]
_command void ResetModifiedLines() name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   int flagsMask = MODIFY_LF | INSERTED_LINE_LF;
   typeless p;
   _save_pos2( p );
   top();
   do
   {
      if ( _lineflags() & flagsMask )
         _lineflags( 0, flagsMask );
   }
   while ( !down() );
   _restore_pos2( p );
}

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Modified lines color, reset on write?
« Reply #5 on: July 30, 2008, 10:01:13 pm »
@JeffB: To loop thru all open buffers you can use something like this as starting point:
Code: [Select]
_command void ResetModifiedLinesBuf( boolean allBuffers = false ) name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   if ( _no_child_windows() ) return 0;

   int start_buf_id = p_buf_id;
   typeless p;
   _save_pos2( p );
   do
   {
      ResetModifiedLines();
      _next_buffer('NR');
   } while ( allBuffers && (p_buf_id != start_buf_id) );
   _restore_pos2( p );
}

default: curr. buffer
all buffers: 'ResetModifiedLinesBuf 1' on cmdline

Using GetProjectfiles() you could extend the macro to project scope.

I hope it works - it's NOT tested ;)

HS2

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Modified lines color, reset on write?
« Reply #6 on: July 31, 2008, 01:44:24 am »
It looks good, hs2.  I think it will go into an infinite loop, though, if the initial current buffer is a hidden buffer when the macro is invoked.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Modified lines color, reset on write?
« Reply #7 on: July 31, 2008, 09:00:26 am »
Hmm - I can't see why it'd lifelock at the moment ? So where is the BUG chrisant :)
But you're right - it's maybe better to skip the possibly hidden initial buffer.
Code: [Select]
_command void ResetModifiedLinesBuf( boolean allBuffers = false ) name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   if ( _no_child_windows() ) return;

   int start_buf_id = p_buf_id;

   if ( p_buf_flags & VSBUFFLAG_HIDDEN )  // maybe skip initial hidden buffer
   {
      _next_buffer('NR');
      if ( p_buf_id == start_buf_id ) return;
   }
   
   typeless p;
   _save_pos2( p );
   do
   {
      ResetModifiedLines();
      _next_buffer('NR');
   } while ( allBuffers && (p_buf_id != start_buf_id) );
   _restore_pos2( p );
}

HS2

JeffB

  • Senior Community Member
  • Posts: 254
  • Hero Points: 9
Re: Modified lines color, reset on write?
« Reply #8 on: July 31, 2008, 05:03:57 pm »
Wow...that worked great.  You guys make it seem so easy.

Thanks, Chrisant and HS2.

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Modified lines color, reset on write?
« Reply #9 on: July 31, 2008, 06:01:10 pm »
Oops, I sort of forgot to point it out, didn't I.  :-[  Here is the issue (see the >>>> lines below).

Code: [Select]
_command void ResetModifiedLinesBuf( boolean allBuffers = false ) name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   if ( _no_child_windows() ) return 0;

   int start_buf_id = p_buf_id;
   typeless p;
   _save_pos2( p );
   do
   {
      ResetModifiedLines();
      _next_buffer('NR');
>>>> The while condition breaks when p_buf_id wraps around
>>>> to the original buffer id.  But if the original buffer was
>>>> hidden, then _next_buffer('NR') will skip over the original
>>>> buffer and never reach it, so the loop continues forever.
   } while ( allBuffers && (p_buf_id != start_buf_id) );
   _restore_pos2( p );
}

By the way, the code in autosave.e that recovers an auto-saved file after an abnormal exit has the same bug as above.  I reported it here (with patches) and Lee could reproduce the two problems with auto-recover.  As far as I could tell an official fix didn't make it into 13.0.1, so I'm still using my patches.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Modified lines color, reset on write?
« Reply #10 on: July 31, 2008, 06:43:52 pm »
Ahh - I see. Good catch !
For completeness reasons this should always work (Hope I'm right this time - please review chrisant):
Code: [Select]
_command void ResetModifiedLinesBuf( boolean allBuffers = false ) name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   if ( _no_child_windows() ) return;

   int start_buf_id = p_buf_id;
   typeless p;
   _save_pos2( p );
   do
   {
      if ( (p_buf_flags & VSBUFFLAG_HIDDEN) == 0 ) ResetModifiedLines();
      _next_buffer('HNR');
   } while ( allBuffers && (p_buf_id != start_buf_id) );
   _restore_pos2( p );
}
HS2

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: Modified lines color, reset on write?
« Reply #11 on: July 31, 2008, 08:49:10 pm »
That looks like it should work, hs2.

The patch I made in the autosave code was to hash the visited buffers and exit the loop when any buffer is visited a second time.  I think they have the same effect -- the trade off is that the hashing approach visits the same set of buffers as _next_buffer('nr') [so doesn't alter the basic algorithm] but takes additional memory to store the hash table -- so memory cost is a little higher with a hash table, but runtime will generally be slightly shorter.  I think that in practice there is probably no measurable difference, though.  :)

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Modified lines color, reset on write?
« Reply #12 on: July 31, 2008, 09:22:24 pm »
Hmm - we'll never know until someone profiles both functions or one of the real experts gives a hint ;)
(I won't do the profiling in this case...)
Thanks a lot chrisant, HS2

Dan112123

  • Community Member
  • Posts: 44
  • Hero Points: 2
Re: Modified lines color, reset on write?
« Reply #13 on: July 31, 2008, 11:58:43 pm »
Hmm - we'll never know until someone profiles both functions or one of the real experts gives a hint ;)
(I won't do the profiling in this case...)
Thanks a lot chrisant, HS2


I was thinking of a way to automate it, and usually when you check it it the source code system makes files readonly. You could automate your code by watching the file to see if it's readonly and if it is then reset all the lines. I'm not sure how to do it though since I never figured out how to do times in SE.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Modified lines color, reset on write?
« Reply #14 on: August 01, 2008, 12:36:11 am »
If he uses auto-reload the file should be reloaded after checkin b/c the file has changed externally.
Reload calls the '_buffer_add' callback list.
So all needed is an add user callback like this:
Code: [Select]
void _buffer_add_reset_line_modify( int bid, _str bname, int bflags )
{
   #if __VERSION__<13
   // use ResetModifiedLines by chrisant
   ResetModifiedLines();
   #else
   reset_modified_lines();
   #endif
}
(BTW: I found a stock macro command 'reset_modified_lines' in files.e (SE v13.0.1).)

It sounds like a suitable trigger anyway because confirming a reload discards any changes.

HS2