Interact on oppening file



  • Hello,

    I’ve maid a plugin that verify if you can open a file ( you have a message box if an other user has oppened it). It’s ok for this but now I want to propose to the user if he want to open the file in read only or not to pen this file.
    I tried to use :
    unsigned long ret = SendMessage(nppHandle, NPPM_MENUCOMMAND, 0, IDM_EDIT_CLEARREADONLY);
    and
    unsigned long ret = SendMessage(nppHandle, NPPM_MENUCOMMAND, 0, IDM_EDIT_CLEARREADONLY);
    in the NPPN_FILEOPENED procedure but it does noithing
    How can this things works ?



  • Although I don’t have any exact answers, I may be able to provide a few hints to help you. I spent a couple minutes messing around calling some of the menu commands from a script…

    There are 2 “read only” flags you need to keep in mind. There is one that is associated with the Windows operating system (meaning Windows will not allow the file to be overwritten, etc). There is also a “read only” flag within Notepad++, meaning that the file can be overwritten on the actual hard drive, but Notepad++ won’t allow it to be edited in the editor. (See SCI_SETREADONLY for reference.) I’m not sure which flags (maybe both?) get set when calling IDM_EDIT_CLEARREADONLY and IDM_EDIT_SETREADONLY.

    It looks like using IDM_EDIT_SETREADONLY toggles the read only flag (again not sure exactly which flag).

    I’m not 100% sure what IDM_EDIT_CLEARREADONLY does.

    There might a problem setting the read only status during the NPPN_FILEOPENED notification. Notepad++ might mess with the read only flag after it has sent your plugin this notification.



  • Thanks for answering, I’m now able to set readonlyfile (Npp flag only) on a file already open but I can’t do it on openning. I’ve tried to call a function via a thread (I’m in C#) but I have error maybe about static declaration. Is there anyone who use thread or just have been able to set
    Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_EDIT_SETREADONLY); on an oppening file ?.



  • @Yunatane-Gris-Fond

    You are correct that it doesn’t look like using IDM_EDIT_SETREADONLY works for some reason during NPPN_FILEOPENED. For me it partially works but I can’t find any repeatable behavior. I can’t think of another good way to try to fix it.



  • @Yunatane-Gris-Fond

    from what I remember, I once checked this out and hope it is still the status quo, the read only story is the following.
    As dail already pointed out, there are two read only functions which do different things.
    The toggle function set-read-only and the clear-read-only function.
    The first doesn’t change the file attribute where as the latter clears it (but cannot set it).
    Set-read-only just toggles the write state from ui point of view and npp (better scintilla) does or does not allow
    to overwrite the current file.
    Clear-Read-Only can, as the name already suggest, only clear the os file permission flag but cannot set it.

    In regards to your problem, it seems that that the notification is already sent before file has been loaded into
    scintilla buffer completely. I would suggest you use buffer activated notification in addition to set the read-only ui flag.
    From previous testing it looks like that this notification always arrives after buffer has been loaded completely.

    Cheers
    Claudia



  • I would suggest you use buffer activated notification…

    Ah yes! Don’t know why I didn’t think of that (not enough coffee probably) but that would probably be the best in the end anyways.



  • Nice to see that I’m not the only one whose “clear view” depends on coffee consumption :-D
    Just ready for another cup …

    Cheers
    Claudia


Log in to reply