Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to open files that are not text #89

Closed
aaronraimist opened this issue Jul 22, 2014 · 1 comment
Closed

Able to open files that are not text #89

aaronraimist opened this issue Jul 22, 2014 · 1 comment

Comments

@aaronraimist
Copy link
Contributor

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

âPNG

IHDR���–���–�����ö8ƒy��
AiCCPICC Profile��H
ùñwTSŸ�áœΩ7Ω–�" %Ù�z   “;H��QâIÄP�ÜÑ&vD�F��)VdT¿�Gá"cE��ÉÇb◊  Ú�P∆¡QDE›åk    Ô≠5Ûfiö˝«YflŸÁ∑◊ŸgÔ}◊∫�P¸Ç�¬tX�Ä4°X�ÓΡ\��Àƒ˜�����X�¿·ff�G¯D�‘¸Ω=ôô®H∆≥ˆÓ.Ädª€,øP&s÷ˇ�ë"7C$��
E’6<~&�Â�îS≥≈�2ˇ� Ùï)2Ü12�°   ¢¨"„ƒØlˆßÊ+ª…òó&‰°�YŒ�º4ûåªPfiö%·£å�°\ò%‡g£|�eΩTIö�˜(””¯úL�0�ô_ÃÁ&°lâ2E��ÓâÚ���îƒ9ºr�ã˘9hû�x¶g‰ä�âIb¶�◊òiÂË»f˙Ò≥S˘b1+î√M·àxLœÙ¥é0�ÄØoñE�%YmôhëÌ≠�ÌÌY÷Êh˘øŸfl�~S˝=»z˚UÒ&ÏœûAåûYfllϨ/Ω��ˆ$Zõ�≥æïU�¥m�@·¨OÔ �Ú��¥fiúÛ�Ül^탂'�ãÏÏls�ük.+Ë7˚üÇo øÜ9˜ôÀÓ˚V;¶�?Å#I�3eE¶߶KDÃÃ�óœd˝˜�ˇ„¿9iÕ…√,úü¿�ÒÖËUQËî  ÑâhªÖ<ÅXê.d
Ñ�’·��6'��~ùk�hu_�}Ö9P∏I�»o=�C#�$n?z�}Î[�1
»æºh≠ëØsè2z˛Á˙��\än·LA"Sʈèdr%¢,�£flÑl¡��ê�t†
4Å.0�,`
�Ä3p�fi �ÑÄH��ñ�.H�i@�≤A>ÿ�
A1ÿ�vÉjp�‘Åz–�NÇ6p�\�W¿

Sublime Text 2 shows output like this:

8950 4e47 0d0a 1a0a 0000 000d 4948 4452
0000 07d0 0000 07d0 0806 0000 009a 38c4
7900 000a 4169 4343 5049 4343 2050 726f
6669 6c65 0000 480d 9d96 7754 53d9 1687
cfbd 37bd d012 2220 25f4 1a7a 0920 d23b
4815 0451 8949 8050 0286 8426 7644 0546
1411 2956 6454 c001 4787 2263 4514 0b83
8262 d709 f210 50c6 c151 4445 e5dd 8c6b
09ef ad35 f3de 9afd c759 dfd9 e7b7 d7d9
67ef 7dd7 ba00 50fc 8204 c274 5801 8034
a158 14ee ebc1 5c12 13cb c4f7 0218 1001
0e58 01c0 e166 6604 47f8 4402 d4fc bd3d
9999 a848 c6b3 f6ee 2e80 64bb db2c bf50
2673 d6ff 7f91 2237 4324 0600 0a45 d536
3c7e 2617 e502 9453 b3c5 1932 ff04 caf4
9529 3286 3132 16a1 09a2 ac22 e3c4 af6c
f6a7 e62b bbc9 9897 26e4 a11a 59ce 19bc
349e 8cbb 50de 9a25 e1a3 8c04 a15c 9825
e067 a37c 0765 bd54 499a 00e5 f728 d3d3
f89c 4c00 3014 995f cce7 26a1 6c89 3245
1419 ee89 f202 0008 94c4 39bc 720e 8bf9
3968 9e00 78a6 67e4 8a04 8949 62a6 11d7
9869 e5e8 c866 faf1 b353 f962 312b 94c3
4de1 8878 4ccf f4b4 0c8e 3017 80af 6f96
4501 2559 6d99 6891 edad 1ced ed59 d6e6
68f9 bfd9 df1e 7e53 fd3d c87a fb55 f126

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.

@uranusjr
Copy link
Member

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?

@uranusjr uranusjr added this to the 0.3 milestone Jul 27, 2014
@uranusjr uranusjr modified the milestones: 0.3, 0.2.4 Aug 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants