|||
在为一个应用程序制作RPM安装包时,有时候会想在系统的菜单项里增加一个菜单项,那如何做呢?
首先,列出需要学习的材料:
[1] Desktop Menu Specificationl, http://standards.freedesktop.org/menu-spec/menu-spec-1.0.html
[2] Desktop Entry Specification, http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
[3] Icon Theme Specification, http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
[4] Red Hat Desktop: Deployment Guide: Chapter 3. Menu Editing and Configuration, https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Desktop_Deployment_Guide/ch-ddg-menus.html
根据参考[1],摘录其中的例子如下:
Example
The company ShinyThings Inc. has developed an application namedWebMirror 1.0 and would like to add its own submenu to the system menus consisting of a WebMirrormenu item and a WebMirror Admin Toolmenu item. The company will use "shinythings" as its vendor id. For the purpose of this example all menu items will be available in two languages, English and Dutch. The language code for Dutch is nl.
First the company needs to create two .desktop files that describe the two menu items:
datadir/applications/shinythings-webmirror.desktop:
[Desktop Entry]
Encoding=UTF-8
Type=Application
Exec=webmirror
Icon=webmirror
Name=WebMirror
Name[nl]=WebSpiegel
and
datadir/applications/shinythings-webmirror-admin.desktop:
[Desktop Entry]
Encoding=UTF-8
Type=Application
Exec=webmirror-admintool
Icon=webmirror-admintool
Name=WebMirror Admin Tool
Name[nl]=WebSpiegel Administratie Tool
A .directory file needs to be installed to provide a title and icon for the sub-menu itself:
datadir/desktop-directories/shinythings-webmirror.directory:
[Desktop Entry]
Encoding=UTF-8
Icon=webmirror Name=WebMirror
Name[nl]=WebSpiegel
And finally, a .menu file needs to be provided that links it all togther:
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" "http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">这时,有朋友就会问icon的目录是如何寻找的,根据参考[3],知道会递归遍历/usr/share/icons/hicolor目录,但是有朋友又会问,为什么我把图片拷贝到其中的一个目录(例如/usr/share/icons/hicolor/32x32/apps/)了,为什么菜单项里的图标还是没有?这时你还需执行命令:
<Menu>
<Name>Applications</Name>
<Menu>
<Name>WebMirror</Name>
<Directory>shinythings-webmirror.directory</Directory>
<Include>
<Filename>shinythings-webmirror.desktop</Filename>
<Filename>shinythings-webmirror-admin.desktop</Filename>
</Include>
</Menu>
</Menu>
gtk-update-icon-cache /usr/share/icons/hicolor
以更新icons的cache,才能生效。
加我私人微信,交流技术。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-24 15:23
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社