pseakins Posted September 19, 2019 Share Posted September 19, 2019 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 More sharing options...
Developers Jos Posted September 19, 2019 Developers Share Posted September 19, 2019 (edited) 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 September 19, 2019 by Jos FrancescoDiMuro 1 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 More sharing options...
Musashi Posted September 19, 2019 Share Posted September 19, 2019 (edited) 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 ) : 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 September 19, 2019 by Musashi "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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now