Closed aaronraimist closed 10 years ago
This is pretty tricky. Originally MacDown was implemented to be able to open text files only, but I found out that many text editors out there doesn’t really handle UTI (which OS X application uses to identify file formats) well, and due to numerous requests (#7, #12, #15, #54, etc.) I decided that it’s better to just be able to open everything. And to take care of this issue MacDown needs to keep being able to open them in the future. But obviously the current behaviour when opening non-text document is not ideal. Something needs to be done.
The second solution (convert to link) you mentioned feels counter-intuitive to me because it doesn’t really open the original document, but creates another one. The first one (what Atom and Sublime Text 2 do) requires us to implement a separate document class (NSDocument
subclass) for files we don’t really do anything about, and seems, although fine, an overkill to me.
Another way I can think of is to add extra checks in -readFromData:ofType:error:(NSError **)
, and if the data can’t be converted to string with UTF-8 (i.e. when -initWithData:encoding:
returns nil
, which results in an empty document) we just refuse to open it (maybe raise an error dialog as you mentioned). This won’t handle extreme edge cases in which arbitrary data happen to be valid UTF-8, but should stop most hazard with minimal work.
Thoughts?
You are able to open videos and images with FIle > Open. In a Apple app other file types would be grayed out. In TextEdit though it does allow you to open images and videos but just produces an output like this
Sublime Text 2 shows output like this:
Both Atom and MacDown allow you to open images and videos but show no output in the editor or preview windows.
I think either you should not be able to open these files, because they are grayed out or a warning message appears telling you that is a file MacDown doesn't support, or a new text file should be created with that image or video linked. Something like
![FILENAME](/Users/aaronraimist/Pictures/...)
EDIT: GitHub messed up the first time I wrote this so if you got an email with only half of this message that is why.