Author Topic: Adding items to KDE "create new ..." menu  (Read 3129 times)

Offline Chris Spackman

  • Jr. Member
  • **
  • Posts: 46
Adding items to KDE "create new ..." menu
« on: October 17, 2009, 04:45:52 PM »
Couldn't find this covered here yet, and thought it might be helpful.

To create a new entry in the "create new" menu, you just need two files in the right places.

Below, typewriter text is used to show a file or directory (folder).

What you need:

1) .desktop file

Desktop files are plain text files that desktop programs use for information and actions. In this case, Konqueror and Dolphin use the desktop files to create the right click menu.

For this tutorial, we will use Main_Document.desktop, "Main_Document" because that is the name of my default template for new OpenOffice.org documents. The code for Main_Document.desktop is below. Just copy it and paste it into a plain text document in Kate or Kwrite, and save as Main_Document.desktop.

Code: [Select]
[Desktop Entry]
Comment=New ODF Document:
Encoding=UTF-8
Icon=openofficeorg3-oasis-text
Name=Main_Document
Name[en_US]=Main_Document
Type=Link
URL[$e]=.source/main.odt

The lines of the file are fairly easy to understand, but don't worry to much about what each line means. The most important one is the URL line. It must show the location of your template file. (more on that below)

Also, some of the information in the desktop file can be changed through the properties dialog in Dolphin or Konqueror. (Right click => Properties, on the .desktop file and look through the tabs. For example, click the icon in the "General" tab to change the icon, then reopen the file in Kate and automagically, the Icon line is updated.)

2) template file

The template file is the "new" file you want to create. It can be any file. The screen shot shows that I added two OpenOffice.org entries (APA_Document and Main_Document) and one LaTeX entry (LaTeX_APA) to my "create new" menu. Each entry has a corresponding template file.

For this tutorial, I will use main.odt, a document created with my main template (in OpenOffice.org) and saved. You can use any file you want. We will talk about how to customize the desktop file for different kinds of files later.

To add your file to the "create new" menu:

Put Main_Document.desktop into ~/.kde4/share/templates
(create the directory templates if it doesn't already exist)

Inside the templates directory, create a hidden directory named .source (notice the period/full stop at the start of the name - that makes it hidden). Put your new file in .source. So, on my machine I put  main.odt into the .source directory.

Maybe you don't want main.odt. Perhaps you need a spreadsheet for monthly expenses. After you set up the spreadsheet once, put a copy in .source and change the URL line in the desktop file to the name of your spreadsheet file. (And you may want to change the icon as well. Your new desktop file might be monthly-expenses.desktop :

Code: [Select]
[Desktop Entry]
Comment=New ODF Spreadsheet:
Encoding=UTF-8
Icon=openofficeorg3-oasis-spreadsheet
Name=Monthly Expenses
Name[en_US]=Monthly Expenses
Type=Link
URL[$e]=.source/monthly-expenses.ods

That is all there is to it.

Misc Tips:

The easiest way to create more entries is to copy the desktop file and rename the copy, and then edit it to point to your new template file. I find Kate easiest, but the Properties GUI works too, especially for changing the icon.

In the desktop files, there is no need for the underscores in the Name fields. I did that originally just to be safe, but you don't need them, spaces are OK.

When you create a new file with the right click menu, don't forget to type the extension for the file type. (Assuming you want one.) The template file might be main.odt, but when you create the file and Dolphin asks for a name, you need to type the .odt (or .txt or .jpg, or whatever) part at the end of the name you give the new file.

This works on KDE 3 and KDE 4, just use the appropriate kde directory.


[attachment deleted by admin]
Chris Spackman
aka Osugi Sakae

"I will not be pushed, filed, stamped, indexed, briefed, debriefed, or Numbered. My life is my own."

musonio

  • Guest
Re: Adding items to KDE "create new ..." menu
« Reply #1 on: October 17, 2009, 04:50:57 PM »
Great contribution. I'll save it for reference.

Murz

  • Guest
Re: Adding items to KDE "create new ..." menu
« Reply #2 on: November 26, 2009, 02:51:53 AM »
How I can add those items per user?
In Gnome I see the ~/Templates folder in each user homepage.
I want to add some templates only for be, but not to other users.

Offline Chris Spackman

  • Jr. Member
  • **
  • Posts: 46
Re: Adding items to KDE "create new ..." menu
« Reply #3 on: November 26, 2009, 09:15:45 AM »
How I can add those items per user?
In Gnome I see the ~/Templates folder in each user homepage.
I want to add some templates only for be, but not to other users.

Sorry, I do not know how to do this for Gnome. The directions above are personal, not system wide. Have you tried following the directions here, but putting the desktop files and templates into the Gnome ~/Template folder?

Chris Spackman
aka Osugi Sakae

"I will not be pushed, filed, stamped, indexed, briefed, debriefed, or Numbered. My life is my own."

daveleh

  • Guest
Re: Adding items to KDE "create new ..." menu
« Reply #4 on: November 26, 2009, 01:13:09 PM »
Thanks, I'll study that later

Regards

Murz

  • Guest
Re: Adding items to KDE "create new ..." menu
« Reply #5 on: November 27, 2009, 12:06:33 AM »
Sorry, I didn't see tilda in your folder address :)
Thank's for info, but I think that KDE must do an easilly GUI interface for this process.