So, I’ve been working on KDevelop for two weeks now, and it’s time to show some results. My summer project revolves around templates, not in the sense of C++ angle-bracket templates, but templates for source code files. The goal is to auto-generate the boilerplate code.
Sharing Application Templates
KDevelop already had a basic template support. When you create a new project, it gives you a choice of all templates installed by KAppTemplate and a couple of its own. However, those only come from official sources, and while it’s possible to install new ones, there is no GUI way to do it.
So I started by implementing both downloading with GHNS and loading local files.
Loading from file works for .zip or. tar.bz2 compressed archives, in which case it simply copies to the directory where all templates are stored. You can also load .kdevtemplate files, the program automatically archives its containing directory and stores it.
Downloading more templates works pretty much as expected, currently there are only three templates available for download, but I plan to make some more.
It is also possible to share template right from KDevelop. I have added a new configuration modules, where all different types of templates are listed. From there, you can import, download or upload template files. So far, there are only project templates, but they will soon be joined by class template and possibly others.
The project creation logic works exactly as it did before, the same variables are accepted, so all old templates work. The only exception is that now folder names can have placeholders as well.
Seeing as the current class generator in KDevelop is not very configurable, I wrote a new system that uses templates. However, contrary to creating a project skeleton, classes usually have variable numbers of members, and function signatures look different in every language. To allow loops and other complex constructs in templates, I used the Grantlee template engine, written in Qt by Stephen Kelly. I will add some custom functions (filters) for it, but even without it basic use cases are covered.
To allow this, I modified the “Create Class” assistant a little. The most user-visible change is allowing an arbitrary number of output files, not just two. The following is for a template with a private class declared in a separate header, useful for shared d-pointers.
The template engine already handles most of the properties class functions can have. It is possible to group class members according to their access, have slots and signals declared together, handle constructors and destructors separately, etc. What’s missing is a simple way to declare members before creating the class. Currently, only functions which can be overloaded are offered, but no data members.