Menu

how to know if a new tab is openned read only on beforeopen event

Help
2016-02-26
2016-02-28
  • Michel Sauvard

    Michel Sauvard - 2016-02-26

    I make some analysis on the filebeforeopen event.
    Is there a way to know if the file is openned with the -ro flag.notepad.
    getCommandLine works only from a new session and editor.getReadOnly is not possible because the file is not openned yet.

     
  • CFrank

    CFrank - 2016-02-27

    I think it is only possible when using external modules like win32file.

    import win32file
    
    def callback_FILEBEFOREOPEN(args):
        _file = notepad.getBufferFilename(args['bufferID'])
        fileatt = win32file.GetFileAttributes(_file)
        if fileatt & win32file.FILE_ATTRIBUTE_READONLY == 1:
            console.write('read only\n')
    
    notepad.clearCallbacks([NOTIFICATION.FILEBEFOREOPEN])
    notepad.callback(callback_FILEBEFOREOPEN, [NOTIFICATION.FILEBEFOREOPEN])
    

    Cheers
    Claudia

     
    • Michel Sauvard

      Michel Sauvard - 2016-02-27

      Thanks but that was not what I meant.
      I open the file whith the -ro switch but the file itself is not read only.
      I dont have win32file but I just verified, with os.stat, that the file is not temporarily set RO by notepad

       
  • CFrank

    CFrank - 2016-02-27

    Oh, I see - no, I don't think that you can get these information within the filebeforeloaded callback,
    but you could get it in the bufferactivated callback. I assume there is still enough time to call
    notepad.close before you see the content of the file. As i tested it, there was a flickering but nothing
    what was really annoying, at least for me.

    Cheers
    Claudia

     
    • Michel Sauvard

      Michel Sauvard - 2016-02-28

      Thanks it works.
      I just have to detect that it is the first activation using a global just used between beforeopen and bufferactivated in attempt to avoid concurency

       

Log in to post a comment.