This is a pretty old issue afaik.
xdg-templates directory
There is the strange xdg-templates directory (aka. ~/Templates
) but placing files there doesnt do anything.
Is there any work in progress on making that directory work? Afaik on GNOME if you place files there, they will be recommended.
Distros need to pre-populate that, and the Libreoffice Dolphin Extension does not exist for Libreoffice Flatpak.
creating desktop entries
There was an extension for Plasma5, to create “Create new…” entries
I used the second one and it worked pretty well.
It placed .desktop entries in ~/.local/share/kservices5/ServiceMenus
which is to my knowledge now replaced with ~/.local/share/kio/servicemenus
(just the Dolphin context menus, not the templates).
Plasma 6 Template Manager
At least porting it to Plasma6 could be done, but even better, automatically converting every file in xdg-templates to such a desktop entry.
The issue is that the desktop entries have a name (which could be the filename), a Comment (which could be empty) and a link.
An extension could also just convert any file to a template, like “KDE5 Template Manager” does it.
Issue
How to use xdg-user-dirs in shell scripts and desktop entries??
I couldnt find enough info about this, and for some reason they are not aliased in bash on Fedora.
Okay I found it.
- In ~/Templates create some subdirectory like “sources”
- Place a file you want there
- in ~/Templates create a desktop entry like “Table.desktop”
[Desktop Entry]
Name=Table
Comment=Create a table
Icon=libreoffice-calc
Type=Link
URL=./sources/Table.ods
The problem is, I have no idea how to reference the xdg directory, ${XDG_TEMPLATES_DIR}/Table.ods
does not work.
If I use my localized $HOME/Vorlagen/sources/Table.desktop
it works.
Workaround: just use ./sources/name.fileext
that works.
Now, I would like to automate this:
- Monitor the directory
~/Templates
for changes
- If a file is placed there, open a KDialog and prompt for name, Icon, etc.
- Move the file to
./sources/
and create the desktop entry
[Desktop Entry]
Name=a
Comment=b
Type=Link
Icon=someicon
URL=
This thread discussed about getting these dirs
A solution could be $(systemd-path user-templates)
but that would cause a systemd dependency
This is really strange…
>> cat ~/.config/user-dirs.dirs
...
But this is not loaded in my shell or anywhere. Using something like
cat > ~/.local/bin/xdg-user-dirs.sh <<EOF
#!/usr/bin/sh
EOF
cat ~/.config/user-dirs.dirs >> ~/.local/bin/xdg-user-dirs.sh
chmod +x ~/.local/bin/xdg-user-dirs.sh
cat >> ~/.bashrc <<EOF
. $HOME/.local/bin/xdg-user-dirs.sh
EOF
Fish compatibility
# add "set", output to fish script
sed '/^#/! s/^/set /' ~/.local/bin/xdg-user-dirs.sh > ~/.local/bin/xdg-user-dirs.fish
# replace "=" with " " inline
sed -i 's/=/ /g' ~/.local/bin/xdg-user-dirs.fish
# load in fish config
cat >> ~/.config/fish/config.fish <<EOF
. ~/.local/bin/xdg-user-dirs.fish
EOF
Would fix this possibly. But that is hacky, isnt this done at the system level?
The xdg-user-dirs package (xdg-user-dirs), can return requested directories (e.g. xdg-user-dir TEMPLATES
), as well as sets up and manages all the XDG folders, including with translations afaik, so it may be worth looking into? It could help with the systemd dep, but it may not be what you’re looking for.
This is a very old issue: 191632 – It should be easier to add a template to "Create New..." menu (e.g. look into ~/Templates)
So old in fact that its main original difficulty (the lack of a Qt API to easily access ~/Templates) no longer applies, there’s QStandardPaths::TemplatesLocation now.
We just need someone that wants to implement this, but nobody else stepped up in six years.
1 Like
What would be involved in implementing it? I wouldn’t be opposed to taking a crack at it, but I know none of the specifics to do so.
1 Like
I suppose this would need integration in either Dolphin or kio?
In KIO’s knewfilemenu, based on the class description and the fact the previous attempt from six years ago also changed that file (on Phabricator you need to get down after the comments section to see the diff).
1 Like