Adding Custom Entries To A Create-New-Document Menu

If you look at a file/folder view in various of the common GUI file managers, you should see a contextual menu item with a name like “Create New”, showing a submenu of different document types (e.g. “Text File...”, “Spread Sheet Document...”) that you can create in that location. Select an item, it asks you for a name for the new document, and it creates it under that name, as a copy of the template provided for that document type. You can then click to open the newly-created document in the corresponding app and continue working with it in the usual way. This is an alternative to launching the app, creating a new untitled document, then using its “Save-As” function to name the document file. Of course, you can easily create your own templates. On KDE, when I type kde4-config --path templates to find out where a KDE-based file manager like Dolphin finds these templates, it reports /home/ldo/.kde/share/templates/:/usr/share/templates/ The latter contains templates installed systemwide by repo packages, while the former can contain whatever I like. As to the format of these template files? They are just another variation on the ever-popular text-based .desktop file format, which is used for example to define entries in your application menu, and icons on the desktop (for those who like that sort of thing). Oddly, the official spec for this only briefly mentions <https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html> “Type=Link”, without explaining this option further (that I can find). But some searching found this useful post <https://forum.kde.org/viewtopic.php?f=224&t=119342> on the KDE user forums. For example, if I look at /usr/share/templates/Illustration.desktop on my system, besides all the localized versions of the name to show for this option, there are the lines Type=Link URL=.source/Illustration.odg That “URL” is actually a file path relative to the .desktop file itself, referencing a document template to be copied as the initial state of the new document. Looking in the referenced directory, /usr/share/templates/.source/, I do indeed see the file Illustration.odg, along with many others. The association of the file extension with the app, in this case LibreOffice Draw, is handled through a separate spec, the shared MIME database <https://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/>. This is also widely supported by GUI desktop environments.

I wrote:
On KDE, when I type
kde4-config --path templates
to find out where a KDE-based file manager like Dolphin finds these templates, it reports
/home/ldo/.kde/share/templates/:/usr/share/templates/
I was wondering why KDE might be using a KDE-specific user directory, rather than something more freedesktop.org-generic. The command kf5-config --path templates returns a more standards-compliant-looking answer: /home/ldo/.local/share/templates/:/usr/share/templates/ which makes me wonder why the kde4-config command is still on my system ...
participants (1)
-
Lawrence D'Oliveiro