个人工具
登录
查看“UbuntuHelp:AddingMimeTypes”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:AddingMimeTypes”的源代码
来自Ubuntu中文
←
UbuntuHelp:AddingMimeTypes
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{From|https://help.ubuntu.com/community/AddingMimeTypes}} {{Languages|UbuntuHelp:AddingMimeTypes}} === Introduction === MIME types are a sort of identification card for files on Ubuntu. A file's MIME type is usually determined by the extension of its filename; for example, a text file may end in .txt, and image file might end in .png or .jpg. This tells Ubuntu what icon should be used to represent it and what programs should open it by default. Unfortunately, the obvious options for editing MIME types in Ubuntu are shallow. You can teach Ubuntu to open a certain file extension with a certain program using the Properties window, but you cannot set an icon for that extension as a whole: only for the individual file. This can be annoying if you are say, a Python programmer. Ubuntu does not include a special icon for Python files, and it is hard to visually differentiate .py and .pyc files. This guide will both teach you to add new MIME types and to associate icons with existing types. We will use .py files as an example. === Adding a MIME Type === To start out, we must be assure that the MIME type for our file extension does not already exist. Open a command line and enter the line below, replacing the letters py with your extension. <pre><nowiki> grep 'py' /etc/mime.types </nowiki></pre> ==== Analysing results ==== This particular command will output two lines. If your extension does not output any lines, or if the lines outputed do not include your extension, you must create a new MIME type. Otherwise, look at the right side of this output, find your file extension, and copy the corresponding text to the far right. For 'py', we must copy down 'text/x-python'. <pre><nowiki> application/x-python-code pyc pyo text/x-python py </nowiki></pre> ==== Creating the MIME type, if needed ==== If there was no output, or the output given did not include your extension, we must add a MIME type. <pre><nowiki> gksudo gedit /etc/mime.types </nowiki></pre> Modify the following text so that the word "extension" is replaced with your file extension (no period mark), add the line to the end of the mime.types file, and save. <pre><nowiki> text/extension extension </nowiki></pre> And copy the modified 'text/extension' part. === Adding an Icon === Now we need to associate an icon with the MIME type. Get an SVG icon and name it "text/extension .svg", or whatever your modified MIME type is named; this will be the icon to represent all instances of the MIME type on your system. For our python example, [http://upload.wikimedia.org/wikipedia/commons/8/82/Text-x-python.svg this] is a good choice. Rename the .svg file so that the it matches "text/x-python.svg" (or "insertYourMIMEtype.svg") so that the slashes are replaced with "-" and there are no capital letters. Then simply run the following command, with 'text/x-python' replaced with your MIME type. <pre><nowiki> sudo cp text-x-python.svg /usr/share/icons/gnome/scalable/mimetypes </nowiki></pre> Relogin and all files ending in the MIME extension will display with that icon. [[category:UbuntuHelp]]
该页面使用的模板:
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
返回至
UbuntuHelp:AddingMimeTypes
。