LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Linux Answers > Applications / GUI / Multimedia
User Name
Password

Notices


By MasterPatricko at 2004-11-15 16:42
You can muck up your entire menu if you make any mistakes editing these files. Unless you are comfortable with editing lots of text files by hand, don't try this. Then again, most, if not all, errors should be fixable.

The file locations:

On SuSE 9.1 and KDE 3.3 (They may be in different places on other distributions):

Main file (.menu file) detailing system-wide default menu structure is /etc/xdg/menus/applications.menu

Menu directories (.directory files) are stored in /usr/share/desktop-directories/
System-wide Menu entries (.desktop files) are stored in many places.
Gnome applications: /opt/gnome/share/applications
KDE applications: /opt/kde3/share/applications/kde
or /usr/share/applications/kde
Other Applications: /usr/share/applications

(~ means the home directory of the user - e.g. /home/bubbabob if you are bubbabob)
User-specific applications (.desktop files) are in ~/.local/share/applications
User-specific menu edits (.menu file) are in ~/.config/menus/

If they are not there just search for .desktop / .directory / .menu files on your system and you should be able to find the right folder(s).

Explanation of the Files involved:


.menu files decide the structure of the menu by categorizing .desktop entries into directories. They are based on the Desktop Menu Specification by freedesktop.org. The dtd and specifications sheets can be seen at http://freedesktop.org/Standards/menu-spec.

.desktop files are shortcuts to applications. They are based on the Desktop Entry Specification by freedesktop.org. The specification sheets are at http://freedesktop.org/Standards/desktop-entry-spec.

.directory files are the files that represent the directories that applications are organized into. Really they are only used to assign an icon (picture) to the directory. They are also part of the Desktop Entry Specification.

First of all what is a directory, a menu and an application shortcut.
The main menu that opens up when you click the "K" (or whatever you have in your distro - eg. SuSE has its logo) is the main menu.
The sub-menus are actually .directory files. There can be many menus nested in each other, but each menu or sub-menu or sub-sub-menu is actually a separate .directory file in the desktop-directories folder, eg. 'System --> Terminal' is actually /usr/share/desktop-directories/suse-system-terminal.directory on my computer.
The items that you click to open the application are application shortcuts. They are .desktop files, e.g. Menu --> System Sub-Menu --> Terminal Sub-Menu --> "X Terminal" is actually /usr/share/applications/xterm.desktop which starts up 'xterm'.


Note that you need root permissions to properly create and edit files in any of the system-wide directories. An easy, graphical way to navigate with root permissions with KDE is to use "Konqueror - Super User Mode" - the shortcut to it should be under "System" in your Menu.
To edit the files all you need is a simple text editor.
A way to start the graphical ones with root permissions in KDE:
1. Menu --> Run Command (or Alt-F2)
2. Type in "xedit" or "kate" or whatever program you want to run in the "Command" box.
3. Click "Options". Check "Run as a different User". Type in "root" as the user and your root password as the password.
4. Press "Run".

The editor should open up. Use their "File --> Open" or "Load" to open the file you want to edit.

To add an application to the menu:

Create the .desktop file for it in /usr/share/applications if you want it for all users or ~/.local/share/applications if you want it for only one user. Or you can just copy an existing one, rename it, and change it to what you need.

Open this file in your text editor. Here is a sample .desktop file I created for Mozilla Firefox, in a file called firefox.desktop in /usr/share/applications:

Code:
[Desktop Entry]
Encoding=UTF-8

Type=Application
Exec=/usr/local/firefox/firefox
Icon=firefox

Name=Firefox
GenericName=Web Browser

Categories=Network;X-SuSE-WebBrowser;WebBrowser
And now an explanation of what all the parts are:
Encoding=UTF-8 this will probably UTF-8; use whatever encoding you are using on the rest of your machine.
Type=Application tells the system this is an application. The other type is Type=Directory, which you'll see later.
Exec=/usr/local/firefox tells the command to execute. Its always best to include the full path of the executable (e.g. /bin/chmod , not just chmod ) to prevent any mistakes of the folder not being in $PATH, etc.
Icon=firefox tells the system to use the "firefox" icon which is installed on my system. Default Icons are in /opt/kde3/share/icons/.
Name=Firefox tells the specific name of the program.
GenericName=Web Browser is usually used to show the type of program it is. E.g. 'konsole' has a GenericName=Terminal Program
Categories=Network;X-SuSE-WebBrowser;WebBrowser; Categories are separated by semicolons with no spaces. Be careful not to make spelling mistakes! This is the hard one.

To find out what category to use, Look in your applications.menu file to see the various menus and submenus - see what category the menu you want your application to be in requires.

Then check that category on http://freedesktop.org/Standards/menu-spec/menu-spec-0.8.html#category-r... to see if there are any related categories you should put with it, e.g. in my example I have Firefox as being Network and WebBrowser because they are related.

Example: I want to add Mozilla Firefox to my menu.

In my applications.menu, I saw things like this, all nested within each other:
Code:
<Menu>
    <DontShowIfEmpty/>
    <Name>Web Browser</Name>
    <Directory>suse-network-webbrowser.directory</Directory>
    <Include>
        <Category>WebBrowser</Category>
    </Include>
</Menu>
This is the section of my applications.menu that makes the "Network --> Web Browser" menu. As you can see in the <Category> tags, if I want my new shortcut to be in the "Web Browser" menu, it has to have "WebBrowser" as one of its categories. I check on the menu specification and find Network is related to Web Browser. So my sample 'Mozilla Firefox' shortcut has to have categories "Network;WebBrowser" and will be in this menu.

To remove an item from the menu, there are two ways. One is to just move or delete the application's .desktop file. The other is to use:
Code:
<Exclude>
    <Filename>foo.desktop</Filename>
</Exclude>
in your application.menu in the right place to remove foo.desktop from the menu. More later.

To move an item from one sub-menu to another, first look in your applications.menu and find out what category it has to have. Then open the desktop file and change the "Category=" to what you want. Include any new related categories. Remember to remove the old categories or it will be in both menus!

To create a sub-menu/menu:

First create a .directory file, just like a .desktop file. Here is a sample one. They are even simpler.

Code:
[Desktop Entry]
Encoding=UTF-8
Name=Font Viewer
Icon=fonts
Type=Directory
Name, Encoding, Icon are the same as .desktop files. The Type should be "Directory" for all .directory files.

Then go into your applications.menu file (BACK IT UP FIRST) and add a <Menu> section for your new submenu. This is a very basic example.

Code:
<Menu>
    <DontShowIfEmpty/>
    <Name>FontViewer</Name>
    <Directory>suse-graphics-fontviewer.directory</Directory>
    <Include>
        <Category>FontViewer</Category>
    </Include>
</Menu>
The <Menu> tags start and end the menu. <DontShowIfEmpty/> means if there are no .desktop files that have that category this menu will not be displayed. <Directory> specifies the .directory file to use to get the name and icon. <Name> actually does NOT change the displayed name - the name of the .directory file overrides it. <Include> specifies what categories to include in the menu. You can use <And> to make it have two categories or <Or> to make it have either. You can also use <Not> to not include certain categories. Use <Filename>foo.desktop</Filename> to include just foo.desktop in the menu. There is also another way to stop things from getting in the menu: <Exclude>. It works just like <Include>, using and, or, & not. Nest this section inside the menu you want it in, like the following example which also shows and, not and exclude:

Code:
<Menu>
    <DontShowIfEmpty/>
    <Name>Graphics</Name>
    <Directory>suse-graphics.directory</Directory>
    <Include>
        <Category>X-SuSE-Core-Graphics</Category>
    </Include>
    <Menu>
        <DontShowIfEmpty/>
        <Name>FontViewer</Name>
        <Directory>suse-graphics-fontviewer.directory</Directory>
        <Include>
            <And>            
                <Category>FontViewer</Category>
                <Category>Graphics<Category>
            </And>
        </Include>
        <Exclude>
            <Category>Office</Category>
        </Exclude>
    </Menu>
</Menu>
In that example the first </Menu> ends the Font Viewer menu and the second </Menu> ends the Graphics menu, so the Font Viewer menu is nested inside Graphics. To be in the menu a .desktop file has to have categories of both FontViewer and Graphics. It cannot have, however, a category of Office. Other modifications to the menus can be made in the same way, modifying the applications.menu file. For more info on the tags available look at the Menu-Specification sheet.

To remove a sub-menu just comment out using <!-- and --> in case you need it again or just delete its section. Be sure to remove only that menu's section and not part of its parent menu!

I'm currently working on understanding the user-specific .menu files produced by KMenuEdit (which are an absolute mess) and seeing how I can simplify it so a user can write it by hand.

Summary

KDE Menus are configured in .desktop, .directory, and .menu files. The .directory files are the menus and sub-menus; the .desktop files are the application shortcuts. The .menu file categorizes the .desktop files into the various directories. To add an application, add a .desktop file; to add a directory, create a .directory file and modify the applications.menu file. Other changes must generally be made in the applications.menu file.


  



All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration