Vala and Custom Widgets

There is a case when you wish to use a custom widget, when you use the same set of widgets to handle data. When you create a Gtk.ListBoxRow you have to attach to it a Gtk.Widget, in that case, should be easiest if you just do

var w = new MyWidget (); = data;

Second line, sets your data to the widget’s data property, so the class initialize the UI with the provided data.

In other case, you have a Widget you can re-use in different parts of the UI, maybe showed up in a popup window. This is the process you can use to create such a widget.

Create a Widget in Glade

Yes, use Glade to create a template UI file for your new widget, for the example, lets start with this simple user interface:

Key aspects is set Composite in order to define it as a Widget class definition, make sure you set Class Name to the same C name of your class, that is include the namespace, in our example the namespace is My so the widget class name is set to MyWidget.

Define your Class

Now, make sure you setup the Widget class to  use the UI  you will use. Name all entries and buttons, or any other UI elements you plan to use in your custom widgets at UI design time; use that name in your source code as follows:

Gtk.Entry evalue1 will be linked to your entry with the Id evalue1 so you can use it as any other variable. To link, use [GtkChild] annotation and [GtkTemplate]  one for the class, setting the attribute uiwith the name of the UI file in the resources file; in this case defined as:

UI file linked to the widget class, should be embedded in your program as a GLib resource. Set prefix to the path for the resource resolution, useful to classify different resources.

If you misspell the UI file or the ChildWidge‘s name you’ll get the following kind of errors:

Make it Interactive

Lets take a view at the bmultiply variable, linked to a Gtk.Button with the id set to, and how above code connect to its clicked signal to perform an operation and set the result to the text of the Gtk.Entry with the Id eresult  just accessing the variables defined as private in the My.Widget.

Base for your Class

Above widget, is a subclass of  Gtk.Box so you should make sure your top level widget in the UI definition is of the same type, as you can see at the Glade screenshot. You can take any other base class, depending on the functionality you want to start from.

GVls 0.14.0 Released

GNOME Vala Language Server, GVls, 0.14.0 has been released!

GVls has been integrated with GNOME Builder and now is its default Vala Language Server!

New features include:

* Completion: implementing filtering on partial words
* SourceView: on completion now provides just the position on code
* onChange: improved UTF-8 handling
* Server: can configure its defaults
* Server: request configuration after ‘initialized’ notification from the client
* Server: can handle configuration changes notifications
* Server: scan for all vala sources in workspace at initialization
* Server: can request configuration from Client
* Server: implemented diagnostics publication
* Server: can response both DocumentSymbol[] or SymbolInformation[] for textDocument/documentSymbol
* Server: search all symbols in a namespace
* Client: can provide build environment server configuration
* Client: expose Vala build settings at server initialization
* Client: can send configuration changes notifications
* Client: notify ‘initialized’ to the server
* Client: notify ‘didChangeConfiguration’ to the server
* ValaConfiguration: new Vala build environment settings object
* General fixes on Variant deserialization
* GNOME Builder: fixes to handle its requests
* API changes due to fixes

Current features will help to integrate GVls with other LSP clients like VSCode, implementing a Client to connect to GVls’s Server.

Now opening for 0.16 release cycle will include a refactoring of the server to share more common VAPI files like glib-2.0 and others.

Memory Footprint

For small projects like GVls or GXml, you have descent 150MB memory footprint and good response time, but for large projects like Vala, that will be increased to 6.9GB!!! unacceptable in my small resources machine, so we need to take action here!

Database driven storage can help on! Store parsed symbols in a database will help to share common used VAPI and reduce footprint on large projects with a possible impact on Server’s response time. My first is to use VDA to get access to simple SQLite or more powerful PostgreSQL servers (may you want to implement any other native or use existing GDA backend), some of the work has been made by Anjuta, so we can share databases or data model or make GVls the server for Anjuta.