Additional filename validation
Answered
Hi,
I'm developing custom plugin which downloads files into their own packaging structure, allows to modify them, create new ones, and then pushes them to server.
Names of the files follow a specific convention, which I want validate whenever new file is created inside those particular packages. How can I achieve this? The only event that I found is:
VirtualFileListener#fileCreated
but it's post-creation event. I want to prevent file creation when name typed doesn't comply with the convention.
Please sign in to leave a comment.
Hi,
how are files created there? Is it IDEA's normal create file action or some custom one? If it's IDEA's one, then only "io"-based validation is performed. That's ok, as one can want e.g. to move files once created.
I am not sure but looks like you can postpone the error until user tries to push file on server, then you have the full control over the procedure and it would be evident what's going on.
Anna
Thanks for the reply.
I meant creating a file with IDEA create file action, e.g. from the package context menu -> New -> File.
It is important for me to perform such validation as the engine to which the changes are pushed has certain file naming limitations. Also, in some cases, the filenames across the subpackages should not be duplicated, what is allowed in usual package structure (e.g. file some.package.SomeFile shouldn't be created while other.package.SomeFile exists). So there is a couple of custom rules to implement :)
Of course I can postpone it until the push, but there can be a little mess up to that moment, which I would like to avoid by preventing incorrectly named files creation. Eventually, I can warn about the invalid name (and inability to push it later) after the file creation with the event above, but I wanted to do some research before implementing this. Isn't there any way to extend CreateFileAction?
You would need to extend rename & move refactorings to ensure that after creation nobody changed the names. Moreover you would probably need to listen to external changes as people sometimes rename files outside of the IDE. I mean that there are a lot of places where you need to plug if you want to ensure the file name limitations.
Create file doesn't support custom validations currently, sorry.
Anna
I was aware of the consequences and the need to extend other actions and would have also done that if it was possible. For external changes it would be enough to show error at push, as it is rare case. It is only about user feeling, not a strict validation covering all the cases.
Anyway, I understand the complexity of the solution and lack of support. Thanks for help, I will implement the on-push validation.