Jump to content

Scite ctrl+s saves even when file not changed


pseakins
 Share

Recommended Posts

Many programmer's text editors disable the (CTRL-S) menu option File/Save if the file is not dirty by greying out the menu selection and disabling (CTRL-S). Zeus and TextPad are two examples. Even Microsoft Word will not rewrite the file if there has been no change made in the editor.

Scite however, does not behave this way. This, I believe, is due to a 2012 user request, and the "feature" was implemented in Scite release 3.0.4 according to https://www.scintilla.org/ScintillaHistory.html - "SciTE allows saving file even when file unchanged. Feature #3486654".

I would like to change MY Scite's behaviour by modifying my copy of AutoItTools.lua function AutoItTools:OnBeforeSave(). To do this I need access to the dirty/clean status of the file being saved.

I'm hoping someone can identify a global variable that I can access, or perhaps a configuration item.

Phil Seakins

Link to comment
Share on other sites

  • Developers

I use the standard available PersonalTools.lua file for personal scripts and something like this should work..  ;) 

function PersonalTools:OnBeforeSave(fpath)
    print("FileSave requested for file ",fpath)
    if editor.Modify  then
        print("File was changed so saving file:" .. fpath)
    else
        print("File was not changed so cancel saving operation" )
        return true
    end
end

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

3 hours ago, Jos said:

I use the standard available PersonalTools.lua file for personal scripts and something like this should work..  ;) 

Yes, it does 🙂

Here is a brief description of how I proceeded (to help people who are new to LUA - at least newer than myself :lol: ) :

The default version of PersonalTools.lua is located in SCITE_USERHOME. You can find the setting for SCITE_USERHOME in the first lines of the SciTE console when running a script (F5), for example : SCITE_USERHOME => C:\Users\[Username]\AppData\Local\AutoIt v3\SciTE

Change to the specified folder. I have made a backup of the current file -> PersonalTools_default.lua (just in case).

Open PersonalTools.lua with your preferred editor (or SciTE itself). Please note, that LUA doesn't seem to like 'UTF-8 with BOM' encoding.

The following line should already exist :

PersonalTools = EventClass:new(Common)

Now insert the function :

--------------------------------------------------------------------------------
-- OnBeforeSave(fpath)
--------------------------------------------------------------------------------
function PersonalTools:OnBeforeSave(fpath)
    print("FileSave requested for file ",fpath)
    if editor.Modify  then
        print("File was changed so saving file:" .. fpath)
    else
        print("File was not changed so cancel saving operation" )
        return true
    end
end

Save the file and restart SciTE (PersonalTools.lua will be started automatically by SciTEStartup.lua).

If you now save a file via the menu, the icon or CTRL+S, a message appears in the console :

(file was not changed) :
FileSave requested for file     C:\XXX\Test\Mainscript.au3
File was not changed so cancel saving operation

(file was changed) :
FileSave requested for file     C:\XXX\Test\Mainscript.au3
File was changed so saving file:C:\XXX\Test\Mainscript.au3

To get rid of these messages, simply restore the default PersonalTools.lua file.

@Jos : Graying out the menu item and the save icon seems to be a lot harder, right ?

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...