Opening files in the editor.
I keep running into various text files that I would like to open in the editor but the IDE won't do it. The most common example is RST files, but CSV, HELP, etc. etc. also won't open. Is there a way to tell the IDE what file extensions are OK to open?
I notice that scripts like filenav can do it, so it seems to be just configuration.
Unfortunately there's no way to configure what extensions are valid. The fact that filenav can open "invalid" files is because
editor.open_file()skips the extension check. Not all files can be opened in the editor though, when Pythonista attempts to actually open the file it can still fail because of lacking permissions, invalid data or non-displayable characters in the file. Pythonista also has a bad time with abnormally large files, which usually lead to minute-long loading times and a practically stuck forever app. (Open pythonista:// in Safari to escape deadlocks caused by this.)
@dgeIessus - I like the way filenav handles it and love filenav. I use it all the time. I was just beginning to look at adding a feature to have it remember its place in the file system each time it is run. When you execute any Action it exits and you have to re-navigate to the folder you were browsing if you wish to examine a lot of files in a deep structure. Could it record the current path into an environment variable that could be passed in via the command line?
I understand that allowing blind access to a file can be dangerous without some kind of check on the data in the file. The code for doing these kinds of checks is out there. I was able to find a recently updated project called chardet (https://github.com/chardet/chardet) that does it and even detects the language of the text file. It samples the file just enough to determine what encoding is being used. This is way more then just doing text vs binary and seems like a lot of code. I have not looked at any of the MIME type checkers that are out there to see what is available.
There is obviously a big performance hit for doing this kind of check so I think it would be wise to do it only when the user is trying to open or get more info on the file. I think you have done it correctly in filenav's UI by making it a feature of the Info button.