xdg-desktop-menu won't add submenu SOLVED

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
wb8zvv

xdg-desktop-menu won't add submenu SOLVED

Post by wb8zvv »

Running Mate of Mint 17.1 on 32 bit hardware. I am attempting to add a submenu under which I can place some of my homebrew programs. According to what I can glean from assorted web sources, a submenu to be created is specified with

[Desktop Entry]
Encoding=UTF-8
Type=Directory
Name=My Stuff
Icon=folder

and then, for an application to appear under the submenu, the application specification would resemble

[Desktop Entry]
Encoding=UTF-8
Name=Trimtext
Type=Application
Terminal=false
Exec=/home/clean/MyStuff/trimtext
Icon=/home/clean/MyStuff/Trimtext/trimtext-22.png
Icon[en_US]=/home/clean/MyStuff/Trimtext/trimtext-22.png

with the subdirectory and application entry being created with

Code: Select all

#!/bin/sh
XDG_UTILS_DEBUG_LEVEL=9
export XDG_UTILS_DEBUG_LEVEL
xdg-desktop-menu install ./mystuff-menu.directory \
                                    ./mystuff-trimtext.desktop
echo "install: $?"
(including debugging info).

For testing, I created a clean account (/home/clean), confirmed that the paths are correct, and that the files exist and are appropriately protected (executable trimtext is 755 and mystuff-menu.directory, mystuff-trimtext.desktop, and
trimtext-22.png are 644). When the script is run, an "Other" submenu appears with "trimtext" appearing under "Other". The expected files appear in the expected subdirectories as follows:

Code: Select all

        Subdirectory                                                         File
        ~/.config/menus/applications-merged                      user-mystuff-menu.menu
        ~/.local/share/applications                                     mystuff-trimtext.desktop
        ~/.local/share/desktop-directories                           mystuff-menu.directory
The "MyStuff" submenu does NOT appear in the menu and neither the exit code (0) nor the XDG debugging suggests any problem.

Copying all necessary files to a "clean" account on another 32 bit machine running Ubuntu 10.04 LTS I get the desired result of

Code: Select all

    Menu ("Applications" if Ubuntu)
        MyStuff
            trimtext
The "MyStuff" subdirectory would ultimately have other entries.

The only difference which I have been able to determine is that Ubuntu 10.04 is running xdg-desktop-menu version 1.0.1 while Mint Mate is using a newer version (1.0.2). Otherwise, the files (and insofar as I can make them, the accounts) are identical. A solution or additional things to try would be appreciated.

Thanks.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
roblm
Level 15
Level 15
Posts: 5939
Joined: Sun Feb 24, 2013 2:41 pm

Re: xdg-desktop-menu won't add submenu

Post by roblm »

When you say "submenu", I assume you mean a menu within another category? Look at the XFCE Applications Menu below. A submenu has been created within the Games category. You will have to add the Main MATE Menu to the panel and remove the mintMenu (Advanced Menu). Then the configuration file "/etc/xdg/menus/mate-applications.menu" or "/etc/xdg/menus/mate-settings.menu" will have to be edited:
mate sub-menu.png
wb8zvv

Re: xdg-desktop-menu won't add submenu SOLVED

Post by wb8zvv »

"roblm" thanks for your response. Your menu image is exactly what I was wanting to create (and have under Ubuntu). You might want to look at the "xdg-desktop-menu" manpage. Creating a "directory" and "desktop" files should allow you to create/add/remove your own entries from the menu without doing any editing of the XML files. Apparently, there is a known bug and a workaround as described in
https://github.com/mate-desktop/mate-menus/issues/2
that resolves the issue. I tried the "ln" fix and it appears to work. I can live with that until a legitimate fix is provided.
User avatar
roblm
Level 15
Level 15
Posts: 5939
Joined: Sun Feb 24, 2013 2:41 pm

Re: xdg-desktop-menu won't add submenu SOLVED

Post by roblm »

Is Trimtext an application you installed? What category was it added to, was it Office?

Why not just create a category in the Menu named MyStuff, similar to the Favorites category I created in this post, under the section:
10. Create a Favorites category already listing all the applications.
http://forums.linuxmint.com/viewtopic.p ... 52#p966575

These lines were added to the configuration file /etc/xdg/menus/mate-settings.menu

Code: Select all

<Menu>
    <Name>Favorites</Name>
    <Directory>mate-favorites.directory</Directory>
    <Include>
       <Category>Settings</Category> 
       <Category>System</Category>
       <Category>Office</Category>
       <Category>AudioVideo</Category>
       <Category>Network</Category>
       <Category>Game</Category>
       <Category>Graphics</Category>
       <Category>Utility</Category>   
       <Category>Development</Category>
    </Include>
</Menu>
It's like an All category, so every category is included, except Other, and any app that is installed will go into one of those categories. You would not need to include all of them. Suppose the apps you installed are added only to the Office category. Then you would only need these lines:

Code: Select all

<Menu>
    <Name>My Stuff</Name>
    <Directory>mate-my-stuff.directory</Directory>
    <Include>
       <Category>Office</Category>
    </Include>
</Menu>
wb8zvv

Re: xdg-desktop-menu won't add submenu SOLVED

Post by wb8zvv »

Your "Favorites" looks quite interesting but I am trying to work with the provided utility (xdg-desktop-menu) to create menus for an individual account rather than globally. I have a bunch of homebrew programs that I would like to organize within the menu. So I create "MyStuff" as the location for those programs that I have written. As a further level of organization, I would create a "Utilities" menu under "MyStuff" for miscellaneous utilities, perhaps a "Ham Radio" directory for programs relating to that hobby, etc. Then under the appropriate menu, I would have the utilities, ham radio programs, etc.

The link fix (cited in previous post) allows an xdg-desktop-menu created "MyStuff" to be created (and show in "Menu"). However, although the appropriate XML files are created for "Utilities" and "Ham Radio", all programs appear under the "MyStuff" menu. "Utilities" and "Ham Radio" menus do not appear. (My use of the term "appropriate" is based on a comparison of the XML files created under Mate with those created under Ubuntu by xdg-desktop-menu.) Thus I should probably have noted that the problem is partially solved.

I also explored using the built-in menu editor. (Right click on "Menu", then click on "Edit menu".) This provides a GUI allowing creation of menu entries (either new menus or new items). The GUI shows the structure that I am trying to create ("Utilities" and "Ham Radio" under "MyStuff" and "trimtext" plus other programs under "Utilities). However, when "Menu" is invoked, only "MyStuff" appears with all items appearing under "MyStuff" rather than organized into menus of related programs.

So whether a menu entry is created with xdg-desktop-menu or through Mozo (Mate Menu Editor), the resulting XML files are not being appropriately interpreted so as to generate the desired editor for a user.

And, to answer your specific question as to the function of "trimtext", this utility will accept text files (Microsoft, Linux, or Mac formats), convert tab characters to the appropriate number of spaces, trim excess spaces from the end of the line, and write text file either in the same format or one of the other two formats. Might be more appropriate to place under "Office" I find it more convenient to organize my programs under my own menu.

I will have to take a closer look at your code as I can concieve of applications where that might be very useful. Again, thank you for your response. Having a different perspective on a problem often helps.
User avatar
roblm
Level 15
Level 15
Posts: 5939
Joined: Sun Feb 24, 2013 2:41 pm

Re: xdg-desktop-menu won't add submenu SOLVED

Post by roblm »

If you want to create a Menu category named My Stuff and then add subcategories (submenus) to it named Utilities and Ham Radio, which other apps can be added to, then the Menu Editor can't be used. You will have to edit the configuration file
/etc/xdg/menus/mate-applications.menu for the categories to appear in the upper part of the Menu, or edit
/etc/xdg/menus/mate-settings.menu for the categories to appear under the System category, as a subcategory.
As I said in my first post, the Main MATE Menu will have to be used, not the mintMenu (Advanced Menu). This is what I did in the menu on the right in the picture below. The menu on the left is the mintMenu, where only the My Stuff category is displayed and not it's subcategories, and any apps added to Utilities and Ham Radio are displayed in My Stuff, just like you experienced:
my stuff menu.png
To do this, three categories were created named My Stuff, Utilities, and Ham Radio:

Code: Select all

<Menu>
    <Name>My Stuff</Name>
    <Directory>mate-my-stuff.directory</Directory>
</Menu>

<Menu>
    <Name>Utilities</Name>
    <Directory>mate-utilities.directory</Directory>
    <Include>
           <Filename>gimp.desktop</Filename>
    </Include>       
</Menu>

<Menu>
     <Name>Ham Radio</Name>
     <Directory>mate-ham-radio.directory</Directory>
     <Include>
           <Filename>gimp.desktop</Filename>
     </Include>       
 </Menu>
The line <Filename>gimp.desktop</Filename> was added, as an example, to the Utilities and Ham Radio categories because at least one app has to be added before the category will be displayed. Once you've added Trimtext or another app, then that line can be removed.
(I renamed GIMP to Trimtext in the Menu Editor. That's why it is displayed as Trimtext in the Menu).
Then the Utilities and Ham Radio categories were added to the My Stuff category:

Code: Select all

<Menu>
    <Name>My Stuff</Name>
    <Directory>mate-my-stuff.directory</Directory>
       
    <Menu>
           <Name>Utilities</Name>
           <Directory>mate-utilities.directory</Directory>
           <Include>
               <Filename>gimp.desktop</Filename>
           </Include>       
      </Menu>
       
      <Menu>
          <Name>Ham Radio</Name>
          <Directory>mate-ham-radio.directory</Directory>
          <Include>
              <Filename>gimp.desktop</Filename>
          </Include>       
      </Menu>

</Menu>
Then the lines of code were added to the /etc/xdg/menus/mate-applications.menu file.

Then these three files were created in /usr/share/mate/desktop-directories

1. mate-my-stuff.directory

Which contains these lines:

Code: Select all

[Desktop Entry]
Name=My Stuff
Comment=
Icon=
Type=Directory
2. mate-utilities.directory

Which contains these lines:

Code: Select all

[Desktop Entry]
Name=Utilities
Comment=
Icon=
Type=Directory
3. mate-ham-radio.directory

Which contains these lines:

Code: Select all

[Desktop Entry]
Name=Ham Radio
Comment=
Icon=
Type=Directory
Now the 3 new categories will appear in the Menu Editor. If you desire, the default folder icons can be changed.

To add the Trimtext app or any other app to Utilities or Ham Radio, then add the <application>.desktop name between the two Include code tags, such as:

Code: Select all

<Include>
       <Filename>trimtext.desktop</Filename>
</Include>
wb8zvv

Re: xdg-desktop-menu won't add submenu SOLVED

Post by wb8zvv »

roblm, you have an interesting approach to the problem. However, for my configuration, I would like to be able to have different menus for different logins. (Yes, still a single user machine but different purposes for the different logins.) Using the xdg-desktop-menu software I should (and can under the old Ubuntu installation) create menus for each login rather than having global menus. Also, I do not need to edit system files.

As per xdg-desktop-menu, to create "My Stuff" with a subordinate directory of "Utilities" that will contain application "Trimtext", I create three files (shown as one listing for convenience):

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Value=1.0
Type=Directory
Name=My Stuff
Icon=folder

[Desktop Entry]
Encoding=UTF-8
Value=1.0
Type=Directory
Name=Utilities
Icon=folder

[Desktop Entry]
Encoding=UTF-8
Value=1.0
Name=Trimtext
Type=Application
Terminal=false
Exec=/home/clean/MyStuff/trimtext
Icon=/home/clean/MyStuff/Trimtext/trimtext-32.png
The three files are passed as arguments to xdg-desktop-menu with something similar to

Code: Select all

#!/bin/sh
xdg-desktop-menu install ./mystuff-menu.directory \
                         ./mystuff-utilities.directory \
                         ./mystuff-trimtext.desktop

echo "install: $?"
Using the "Edit menu" capability (strictly to look), I see the "My Stuff" folder under "Applications" (between "Internet" and "Office"). Slightly indented under "My Stuff" is the expected "Utilities" folder. However, just clicking on "Menu" to access the applications shows only "My Stuff" and, if I click on "My Stuff" I see only "Trimtext" -- no sign of the "Utilities" folder. The expected files are created in ~/.config/menus/applications-merged, ~/.local/share/desktop-directories, and ~/.local/share/applications-merged. (As previously mentioned, a soft link

Code: Select all

ln -s ~/.config/menus/applications-merged ~/.config/menus/mate-applications-merged
needs to be created or all of the applications will be placed under "Other".)

If the above code (and supporting files such as the icon and application executable) are copied to the Ubuntu system, the "Utilities" folder appears with "Trimtext" an entry within that folder. (Obviously, the soft link is NOT needed under Ubuntu.) So I am still of the opinion that what I am experiencing is a bug (or maybe a new feature? :D )

I suspect (but do NOT know) that other OS that use xdg-desktop-menu would work the same. As the configuration files are for a user (AKA "login"), each can have a different menu. Your technique would provide a mechanism for global (all users) menu modifications which would remove the necessity of doing an installation for each login.
User avatar
roblm
Level 15
Level 15
Posts: 5939
Joined: Sun Feb 24, 2013 2:41 pm

Re: xdg-desktop-menu won't add submenu SOLVED

Post by roblm »

You're trying to get the subcategories Ham Radio and Utilities to appear in the mintMenu (Advanced Menu) but it appears that this menu was not designed to display subcategories. Hopefully everything displays and functions correctly in the Main MATE Menu. To add it, right click on the panel and select Add to Panel. Or you can try using Mint XFCE and it's Applications Menu, which I showed in my first post.

If you ever decide to use the method I discussed in my last post, then add these lines to the Ham Radio and Utilities directories sections:

Code: Select all

<OnlyUnallocated/>
<Include>
    <And>
      <Not><Category>Core</Category></Not>
      <Not><Category>Settings</Category></Not>
      <Not><Category>Screensaver</Category></Not>
    </And>
</Include>
So those sections will now look like this:

Code: Select all

<Menu>
    <Name>My Stuff</Name>
    <Directory>mate-my-stuff.directory</Directory>
       
      <Menu>
        <Name>Utilities</Name>
        <Directory>mate-utilities.directory</Directory>
        <OnlyUnallocated/>
        <Include>
            <And>
               <Not><Category>Core</Category></Not>
               <Not><Category>Settings</Category></Not>
               <Not><Category>Screensaver</Category></Not>
            </And>
         </Include>     
      </Menu>
       
      <Menu>
          <Name>Ham Radio</Name>
          <Directory>mate-ham-radio.directory</Directory>
          <OnlyUnallocated/>
          <Include>
              <And>
                  <Not><Category>Core</Category></Not>
                  <Not><Category>Settings</Category></Not>
                  <Not><Category>Screensaver</Category></Not>
             </And>
          </Include>      
      </Menu>
</Menu>
Now any app that you create, that would usually go into the "Other" category, will automatically be added to both the Ham Radio and Utilities categories, after it's <application-name>.directory file is added to /usr/share/applications. Then the Menu Editor will have to be opened to select which category the app will be displayed in. Those code lines are from the "Other" category section in the
/etc/xdg/menus/mate-applications.menu file.
Locked

Return to “MATE”