forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent Handler Demo.py
More file actions
21 lines (16 loc) · 1.13 KB
/
Event Handler Demo.py
File metadata and controls
21 lines (16 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import datetime
# Just in case, we'll clear all the existing callbacks for FILEBEFORESAVE
notepad.clearCallbacks([NOTIFICATION.FILEBEFORESAVE])
# Define the function to call just before the file is saved
def addSaveStamp(args):
if notepad.getBufferFilename(args["bufferID"])[-4:] == '.log':
result = notepad.messageBox("Saving a .log file. Would you like to append a 'File saved on...' message to the file? (This is a Python Script event, click cancel to stop this message appearing)", "Python Script Callback", MESSAGEBOXFLAGS.YESNOCANCEL)
if result == MESSAGEBOXFLAGS.RESULTCANCEL:
notepad.clearCallbacks([NOTIFICATION.FILEBEFORESAVE])
elif result == MESSAGEBOXFLAGS.RESULTYES:
notepad.activateBufferID(args["bufferID"])
editor.appendText("File saved on %s\r\n" % datetime.date.today())
# ... and register the callback
notepad.callback(addSaveStamp, [NOTIFICATION.FILEBEFORESAVE])
# As this is a sample, we'll inform the user
notepad.messageBox("FILEBEFORESAVE notification registered.\n*.log files will now automatically be modified before saving.\nCtrl-Click the script to edit.\n", "Python Script Demo", 0)