Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: HOWTO: set fyle/MIME types & icons

  1. #1
    Join Date
    Mar 2006
    Beans
    14

    HOWTO: set fyle/MIME types & icons

    This HOWTO describes how to set the File and MIME type of files manually and also how to associated MIME icons to specific types of files.

    In this HOWTO I'm setting the MIME type 'text/x-R' which corresponds to the file extension '.R'. I'm using this file type because it is a script language recognized by Gedit and it is not automatically set when the package R is installed (R is a powerful program which is a environment and a language for statistical and graphical analysis, see http://www.r-project.org/). In the end we will also set a customized icon to the new File/MIME type. The advantage of doing this setting is that Gedit will automatically associated the correct highlighting mode for the script language and we will have a nicer looking to the R script files.

    HOWTO:

    1. Create or choose a customized icon for your file type. In my case I created the icon 'gnome-mime-text-R.png'.

    Click image for larger version. 

Name:	gnome-mime-text-x-R.png 
Views:	113 
Size:	17.6 KB 
ID:	7627

    2. Create a file to test the HOWTO. I created the file 'test.txt', in the Desktop directory, with the following content:

    # short example of R script with vector manipulation and plotting

    x <- c(2,3,4,5,6,9)
    y <- c(7,5,4,3,2,1)
    plot(x, y, pch=19)

    a = 2*x - 2*y
    a
    plot(a)
    The actual Type and MIME type of this file are 'plain text' and 'text/plain', respectively. The icon is the default text icon used by the current icon theme. If you open the 'test.txt' file with the Gedit program you will see that the text looks like a normal text and not a highlighted language. The same would be true for a .R file.

    3. Create the information of the new MIME type in the file that store the the MIME types:

    sudo cp /usr/share/mime/packages/freedesktop.org.xml /usr/share/mime/packages/freedesktop.org.xml_backup
    sudo gedit /usr/share/mime/packages/freedesktop.org.xml

    In the opened file, add the following information that contains the mime-type as 'text/x-R' and the name of the file type (R code):

    <mime-type type="text/x-R">
    <sub-class-of type="text/plain"/>
    <comment>R code</comment>
    <comment xml:lang="az">R kodu</comment>
    <comment xml:lang="bg">Код на R</comment>
    <comment xml:lang="cs">Kód R</comment>
    <comment xml:lang="cy">Côd R</comment>
    <comment xml:lang="de">R-Befehle</comment>
    <comment xml:lang="el">κώδικας R</comment>
    <comment xml:lang="eo">R-kodo</comment>
    <comment xml:lang="es">Código R</comment>
    <comment xml:lang="eu">R kodea</comment>
    <comment xml:lang="fi">R-koodi</comment>
    <comment xml:lang="fr">code R</comment>
    <comment xml:lang="hu">R-kód</comment>
    <comment xml:lang="it">Codice R</comment>
    <comment xml:lang="ja">R コード</comment>
    <comment xml:lang="ko">R 코드</comment>
    <comment xml:lang="ms">Kod R</comment>
    <comment xml:lang="nb">R-kildekode</comment>
    <comment xml:lang="nl">R-code</comment>
    <comment xml:lang="nn">R-kode</comment>
    <comment xml:lang="no">R-kildekode</comment>
    <comment xml:lang="pl">Kod R</comment>
    <comment xml:lang="pt">código R</comment>
    <comment xml:lang="pt_BR">Código R</comment>
    <comment xml:lang="sq">Kod R</comment>
    <comment xml:lang="sr">R ко̂д</comment>
    <comment xml:lang="sv">R-kod</comment>
    <comment xml:lang="uk">Код R</comment>
    <comment xml:lang="zh_CN">R 代码</comment>
    <glob pattern="*.R"/>
    </mime-type>
    between the information of two other MIME files as in the example bellow:
    ...
    <glob pattern="*.py"/>
    </mime-type>
    insert here -->
    <mime-type type="text/x-readme">
    <sub-class-of type="text/plain"/>
    <comment>README document</comment>
    ...
    Save and close the file.

    4. Update the MIME database with the command:

    sudo update-mime-database /usr/share/mime/

    and now the new file and MIME types for the *.R files will be 'R code' and 'text/x-R', respectively.

    4.a. If you see a error in the parsing of the .xml file, this is because you edited wrong the freedesktop.org.xml file, so go back and adjust the file or restore the back up with the command:

    sudo mv -f /usr/share/mime/packages/freedesktop.org.xml_backup /usr/share/mime/packages/freedesktop.org.xml

    and go back to step 3 of this HOWTO.

    5. Now, let's associate the icon with the new file/MIME type. Put the icon into the directory /usr/share/icons/name_of_the_icon_theme_used/mime.types/. Please, note that this will put the icon in a place that can be used by all users of the cumputer. Important: If you keep your icons in your home directory, replace /usr/share/icons by /home/.icons/ in the next steps.

    sudo mv -i path/to/file/gnome-mime-text-R.png /usr/share/icons/name_of_the_icon_theme_used/scalable/mimetypes/

    Obs: if you already has a file with this name, choose 'no' and give another name to you file. If you don't have a file with the same name you will not be asked anything.

    6. Edit the file with the icons' information:

    UPDATED Feb 10, 2007: The "mime-support" package recommends the creation of a .mime-types in the home directory instead of editing the file present in the system installation.

    sudo cp /usr/share/icons/name_of_the_icon_theme_used/mime.types /usr/share/icons/name_of_the_icon_theme_used/mime.types_backup
    sudo gedit /usr/share/icons/name_of_the_icon_theme_used/mime.types

    Add the following line to the mime-types file:

    text/x-R R
    Save and close the file.

    To do this with other files, just replace the file and MIME type information. To associate specific programs to open your new file and MIME types follow the nautilus instructions of "open with"...

    7. Test the files and your environment to see if everything is fine:

    sudo cp path/to/file/test.txt path/to/file/test.R

    Now the file test.R will appear with the customized icon. If you open this file with Gedit it will appear highlighted with the R script language.

    Obs: check if your Gedit is set to show syntax highlighting by using the menu EDIT -> PREFERENCES -> SYNTAX HIGHLIGHTING and see if the box 'Enable syntax highlighting' is checked. You can also customize the highlighting colors used by Gedit...

    8. If there is no any problem in your system or files, you can now remove the back-up files:

    sudo rm /usr/share/mime/packages/freedesktop.org.xml_backup
    sudo rm /usr/share/mime/globs_backup
    sudo rm /usr/share/icons/name_of_the_icon_theme_used/mime.types_backup

    otherwise restore them as described in 4.a., but changing the appropriated names and paths.

    and that is it.
    Last edited by andbelo; February 13th, 2007 at 04:00 AM.

  2. #2
    Join Date
    Dec 2006
    Beans
    3

    Re: HOWTO: set fyle/MIME types & icons

    Tanks a lot four your Howto

    The only problem I have is with step 8, I dont have such a file.. :/

  3. #3
    Join Date
    Mar 2006
    Beans
    14

    Re: HOWTO: set fyle/MIME types & icons

    I'm happy you liked but I gave up making these manual adjusts because every time that the system is upgraded you end up loosing your work.

    For the files, it depends on the icon theme, but the mimetypes folder is usually inside a 'scalable' or 'size x size' folder, e.g. /usr/share/icons/name_of_the_icon_theme_used/128x128/mimetypes

  4. #4
    Join Date
    Dec 2006
    Beans
    3

    Re: HOWTO: set fyle/MIME types & icons

    Quote Originally Posted by andbelo View Post
    I'm happy you liked but I gave up making these manual adjusts because every time that the system is upgraded you end up loosing your work.

    For the files, it depends on the icon theme, but the mimetypes folder is usually inside a 'scalable' or 'size x size' folder, e.g. /usr/share/icons/name_of_the_icon_theme_used/128x128/mimetypes
    Well I'll see what happens at the next upgrade

    But I do have the flder mimetypes, I even replaced the php icon and it worked, but I dont have the file mime.types...
    I'm looking at human to see if it's because I'm using Tango..

    PS: Are you talking about "/etc/mime.types" ?

  5. #5
    Join Date
    Mar 2006
    Beans
    14

    Re: HOWTO: set fyle/MIME types & icons

    Sorry by the confusion. Yes, the file is the "/etc/mime.types" at least in my current version: edgy. Interestingly, now it shows a comment suggesting the creation of a ".mime.type" file in the home directory. Well, good luck.

  6. #6
    Join Date
    Nov 2006
    Location
    Zrenjanin, Serbia
    Beans
    64
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: set fyle/MIME types & icons

    This is a very usable HOWTO! Thanks a lot!
    Nevertheless, I need to ask this small community of R+gedit users, have you tried to comment lines in xxx.R files. My gedit crashes everytime I try to do that. Does anoyine knows why? And a hint to fix that, maybe?

    Best,
    Petar M

  7. #7
    Join Date
    Mar 2006
    Beans
    14

    Re: HOWTO: set fyle/MIME types & icons

    For me it works fine when I comment a line in .R files. I cannot see any reason for Gedit to crash.

  8. #8
    Join Date
    Nov 2006
    Location
    Zrenjanin, Serbia
    Beans
    64
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: set fyle/MIME types & icons

    Yes, I managed to fix that. However, I still wonder if it is possible to slecet few lines and comment them at once?

    Best,
    Petar M

  9. #9
    Join Date
    Mar 2006
    Beans
    14

    Re: HOWTO: set fyle/MIME types & icons

    Petar, I'm not aware of such a comment in gedit. However, a quick and dirt way of doing this is using the replace tool and replace "\n" by "\n#". The bad news is that it will replace the first occurrence under the cursor or all of them. For several lines one could press Replace untill all the desired lines are commented.

    I'm currently using vim for editing R files. It works fine and has the advantage of being able to send the R commands directly to a R window (vim-r-plugin).

  10. #10
    Join Date
    Nov 2006
    Location
    Zrenjanin, Serbia
    Beans
    64
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: set fyle/MIME types & icons

    ANDBELO, Although I am not a newbie in statistics, I am one in Linux. I have asked about the best editor, but I got so different answers and quarrels: Gvim vs Emacs. Emacs looks too much to me, and I start using vim (nice latex-suite and rest that I need), but some told me not to - bad idea. I am confused, I must admit. That is why I started using gedit as a part of gnome. Although I realized is not as powerful as vim and Emacs.

    Best,
    Petar

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •