Author Topic: Open certain files in RO mode always... or not lock them at least  (Read 10360 times)

CrowLegs

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
First let me say how much I love Slick Edit..... I use Eclipse when I have to, but Slick is my primary tool-of-choice.

Now, on to the question.

My application, like many others, generated a log/output file. I open this file in Slick when developing and debugging. Some times, Slick puts a lock on this file. I am not sure why or when this happens, but if it does, the application will not restart properly until I close the file. I cannot remove the file from the command line, either. Windows reports it as 'in use by another application'.

I'd like to use a macro or something to force this file (any file ending in .out would be ok) to be read-only, thinking that this might prevent any lock. I found the "read_only_mode_toggle" command, but I can't see where I can automatically trigger anything when a file gets opened.

Any suggestions? Any other options? My Slick version is 9.0.

Thanks

Scott Carpenter

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Open certain files in RO mode always... or not lock them at least
« Reply #1 on: August 22, 2006, 09:50:11 PM »
This should work:
Code: [Select]
_switchbuf_CrowLegs (...)
{
   _str ext=get_extension( p_buf_name, false);
   if ( ext == "out" ) read_only_mode('');
}
Slick to automatically calls all macros w/ _switchbuf_ prefix when switching buffers (internally built callback list)

HS2

CrowLegs

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
Re: Open certain files in RO mode always... or not lock them at least
« Reply #2 on: August 23, 2006, 12:28:56 PM »
OK, that works really well    :)..... BUT, there are a couple of cases where it could be better.

If I drag-and-drop a .out file, it doesn't run that macro until I switch to another buffer then back to the .out. I can see the RW status at the bottom of the screen change to RO when I go back to the .out buffer. I see the same behavior if I double-click the .out file from Windows Explorer. If I use the Slick Edit Open dialog, or pick it from the MRU list under File... it works as desired.

Any more thoughts?

Scott

CrowLegs

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
Re: Open certain files in RO mode always... or not lock them at least
« Reply #3 on: August 23, 2006, 01:03:07 PM »
OK, I figured it out.... Instead of read_only_mode(' '), I had to change it to read_only_mode('1'). This send the logic in stdcmds.e into a different branch that seems to have better timing for drag-n-drop and double-click opens.

Thanks for the help! In 10 years of using Slick Edit (from AIX to now), I have rarely taken the time to really look at the macro stuff... It's way cool.... 8)

Scott

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Open certain files in RO mode always... or not lock them at least
« Reply #4 on: August 23, 2006, 03:23:03 PM »
Congrats !
And thanks for the hint w/ read_only_mode('1');, which is certainly better.
Missed that somehow :(

HS2

Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: Open certain files in RO mode always... or not lock them at least
« Reply #5 on: August 28, 2006, 03:03:08 PM »
The address when SlickEdit locks a file and when it doesn't, this is controlled by your load options (Tools > Options > File Options).  If you increase the amount for "Load Partial...", you can prevent SlickEdit from needing to lock some larger files.

The caveat to this setting is performance.  If you set "Load Partial..." really high, SlickEdit will obey and use that much memory and make you wait while it reads in the large file.  Typically, that is pretty fast, but it can be noticable compared to the quickness of load partial.

--Dennis

cdouble

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: Open certain files in RO mode always... or not lock them at least
« Reply #6 on: October 01, 2006, 03:27:26 PM »
Coming in a bit late to this thread. I have had Slick lock my log files too. My "File locking" option is turned off. Is this a bug?

Thanks,

CD

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Open certain files in RO mode always... or not lock them at least
« Reply #7 on: October 10, 2006, 02:25:43 PM »
No, "File locking" option is to detect that another user has the file open and is sure to free the file handle after loading the file.  The issue you are having is that the file is large so the editor is doing partial load and keeping the file handle open.  You could increase the "Load partial if larger than" size, or when you open the file check "Preload file" so that the entire file is loaded intially and then the file handle will be released (and the file unlocked).

jbezem

  • Community Member
  • Posts: 87
  • Hero Points: 8
Re: Open certain files in RO mode always... or not lock them at least
« Reply #8 on: October 13, 2006, 09:31:28 AM »
Instead of read_only_mode(' '), I had to change it to read_only_mode('1').

For my setup, this changed the read-only attribute on disk as well, making it impossible for my Lint application to touch its output file.
I had to change the command into
Code: [Select]
/* Make sure to load all error files with extension 'out'
 * as read-only */
_switchbuf_readonly_out (...)
{
   _str ext = get_extension(p_buf_name, false);
   if (ext == "out") _set_read_only(true, true, false, false);
}
But thanks for the valuable hints!

Johan