Mime Type Editing

Gnome 2.10 still does not have a mime type editor but it is fairly easy to make a system wide addition to the mime type database. Gnome 2.10 has adopted the FreeDesktop.org approach to setting mime types. To illustrate, I'll use the mathematics application Maple which I installed in
  /usr/local/maple9.5

To add a mime type for Maple, as root I edited the XML file

  /usr/share/mime/packages/freedesktop.org.xml

by adding the lines

  <mime-type type="application/maple">
<comment xml:lang="en">Maple Worksheet</comment>
<glob pattern="*.mws"/>
</mime-type>

and then I executed the command

  update-mime-database /usr/share/mime

Icon Association. Gnome 2.10 still does not have an editor that can make a system wide addition to the icons associated with different mime types. Again, this is fairly easy to do my hand. To add an icon for Maple worksheets, as root I did

  cp /usr/local/maple9.5/cmaple.png /usr/share/icons/
gnome/48x48/mimetypes/
gnome-mime-application-maple.png

chmod 644 /usr/share/icons/gnome/48x48/mimetypes/
gnome-mime-application-maple.png

gtk-update-icon-cache /usr/share/icons/gnome

Menu Editing. Gnome 2.10 does not yet have a menu editor but because the FreeDesktop.org approach to menus is now being used by Gnome and KDE, menus are easily edited by hand. Gnome and KDE desktop menus are controlled by three types of files

  Menu files (*.menu)

System: /etc/xdg/menus
User: ~/.config/menus
  Directory files (*.directory)

System: /usr/share/desktop-directories
User: ~/.gnome/share/desktop-directories (Gnome)
User: ~/.local/share/desktop-directories (KDE)
  Desktop files (*.desktop)

System: /usr/share/applications (Gnome and KDE)
System: /usr/share/applications/kde (KDE)
System: /usr/share/applnk (KDE)
System: /etc/X11/applnk (Gnome and KDE)
User: ~/.gnome/share/applications (Gnome)
User: ~/.local/share/applications (KDE

To add a menu item we must first create a desktop file. To add a menu item for Maple to the Programming submenu, as root I created a maple.desktop file containing the following lines and then modified its permissions.

  /usr/share/applications/maple.desktop

[Desktop Entry]
Exec=xmaple -cw
Icon=/usr/local/maple9.5/cmaple.png
MimeType=application/maple
Name=Maple Classic
StartupNotify=true
Terminal=false
Type=Application
Categories=Development

chmod 644 /usr/share/applications/maple.desktop

Note that this desktop file contains a Categories key which, in general, will have a semicolon separated list as its value. In this case, Maple has been put in the Development category.

Examining the menu file

  /etc/xdg/menus/applications.menu

we find the XML segment

  <!-- Development Tools -->
<Menu>
<Name>Development</Name>
<Directory>Development.directory</Directory>
<Include>
<And>
<Category>Development</Category>
<Not>
<Category>KDE</Category>
</Not>
</And>
</Include>
</Menu> <!-- End Development Tools -->

Maple is in the Development category but it shows up in the Programming menu. What gives? This is where the directory files come into play. We find

  /usr/share/desktop-directories/Development.directory

[Desktop Entry]
Name=Programming
...
Icon=redhat-programming.png
Type=Directory

This directory file converts the Development category into the Programming submenu item. Note that the icon referred to here is in /usr/share/pixmaps. Also, note that I added the 'not category KDE code' to the menu file to keep KDE applications from displaying in the Gnome Programming submenu. This works because KDE applications generally have KDE in their Categories list. As an alternative, the line

  OnlyShowIn=KDE

inserted in a desktop file will insure that the corresponding application menu item only shows up in a KDE submenu and not in a Gnome submenu.

Next, I added a submenu to the applications menu by adding the following XML code to the applications.menu file.

  /etc/xdg/menus/applications.menu

<!-- Viewers -->
<Menu>
<Name>Viewers</Name>
<Directory>Viewers.directory</Directory>
<Include>
<And>
<Category>Viewers</Category>
<Not>
<Category>KDE</Category>
</Not>
</And>
</Include>
</Menu> <!-- End Viewers -->

I edited the Categories line in the files

  AdobeReader.desktop
gnome-ggv.desktop
net-xpdf.desktop
gnome-gpdf.desktop

Categories=Viewers

so that these applications would show up in the Viewers submenu. To commit these menu changes, as root issue the command

  update-desktop-database -v

File Association. At the top of the context menu for a file in Nautilus is found the 'Open with "Preferred Application" menu item. Next, is found the 'Open with' menu item, which lists all other applications which can open the file. These menu items are controlled respectively by the following files:

  /usr/share/applications/defaults.list
/usr/share/applications/mimeinfo.cache

Each line in defaults.list contains a desktop file followed by a mimetype. For example, the line

  application/postscript=evince.desktop

shows that Evince is the preferred application for opening postscript files. Each line in mimeinfo.cache contains a desktop file followed by a list of mimetypes. For example, the line

  image/gif=gthumb.desktop;gimp-2.2.desktop;
gnome-eog.desktop;

shows the list of applications available for opening gif files. Gnome constructs the mimeinfo.cache file by processing the mimetypes recorded in the desktop files. Gnome comes with a pre-built system-wide defaults.list. At the user level there are parallel files

  ~/.local/applications/defaults.list
~/.local/applications/mimeinfo.cache

Users can add lines to these files as follows.

  In a Nautilus window, right click on a file
Select Properties
Select the 'Open With' tab
To add to the current 'Open With' list
Hit Add and select an application
Hit Add again
Select the preferred application radio button

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值