[gnome-builder] Add Vala template with GTK 4
- From: Günther Wagner <gwagner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] Add Vala template with GTK 4
- Date: Fri, 5 Nov 2021 20:22:16 +0000 (UTC)
commit 98d341ee2c923f77f134b002e8278c67578879a5
Author: Yotam Nachum <me yotam net>
Date: Fri Nov 5 17:52:45 2021 +0200
Add Vala template with GTK 4
.../meson-templates/meson-templates.gresource.xml | 3 ++
src/plugins/meson-templates/meson_templates.py | 7 ++--
.../resources/src/application-gtk4.vala | 40 ++++++++++++++++++++++
.../meson-templates/resources/src/main-gtk4.vala | 6 ++++
.../resources/src/meson-c-vala.build | 3 ++
.../meson-templates/resources/src/window-gtk4.vala | 13 +++++++
6 files changed, 69 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/meson-templates/meson-templates.gresource.xml
b/src/plugins/meson-templates/meson-templates.gresource.xml
index 328c6699f..adac6ef63 100644
--- a/src/plugins/meson-templates/meson-templates.gresource.xml
+++ b/src/plugins/meson-templates/meson-templates.gresource.xml
@@ -18,6 +18,7 @@
<file compressed="true">resources/src/hello.c</file>
<file compressed="true">resources/src/hello.h</file>
<file compressed="true">resources/src/application.c</file>
+ <file compressed="true">resources/src/application-gtk4.vala</file>
<file compressed="true">resources/src/application.h</file>
<file compressed="true">resources/src/application.rs</file>
<file compressed="true">resources/src/__init__.py</file>
@@ -36,11 +37,13 @@
<file compressed="true">resources/src/window.py</file>
<file compressed="true">resources/src/window-gtk4.py</file>
<file compressed="true">resources/src/window.vala</file>
+ <file compressed="true">resources/src/window-gtk4.vala</file>
<file compressed="true">resources/src/config.rs.in</file>
<file compressed="true">resources/src/config-gtk4.rs.in</file>
<file compressed="true">resources/src/window.rs</file>
<file compressed="true">resources/src/window-gtk4.rs</file>
<file compressed="true">resources/src/main.vala</file>
+ <file compressed="true">resources/src/main-gtk4.vala</file>
<file compressed="true">resources/src/main-cli.vala</file>
<file compressed="true">resources/src/hello.py.in</file>
<file compressed="true">resources/src/main.py</file>
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index 8ce88d509..4d5483578 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -330,7 +330,7 @@ class GnomeGTK4ProjectTemplate(MesonTemplate):
_('GNOME Application'),
'pattern-gnome',
_('Create a GNOME application with GTK 4'),
- ['C', 'Rust', 'Python'],
+ ['C', 'Rust', 'Python', 'Vala'],
0
)
@@ -373,8 +373,9 @@ class GnomeGTK4ProjectTemplate(MesonTemplate):
resource_name = None
window_ui_name = None
elif self.language == 'vala':
- files['resources/src/main.vala'] = 'src/main.vala'
- files['resources/src/window.vala'] = 'src/window.vala'
+ files['resources/src/main-gtk4.vala'] = 'src/main.vala'
+ files['resources/src/window-gtk4.vala'] = 'src/window.vala'
+ files['resources/src/application-gtk4.vala'] = 'src/application.vala'
elif self.language == 'javascript':
files['resources/src/main.js.tmpl'] = 'src/main.js'
files['resources/src/hello.js.in'] = 'src/%(appid)s.in'
diff --git a/src/plugins/meson-templates/resources/src/application-gtk4.vala
b/src/plugins/meson-templates/resources/src/application-gtk4.vala
new file mode 100644
index 000000000..d77d62b7e
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/application-gtk4.vala
@@ -0,0 +1,40 @@
+{{include "license.vala"}}
+
+namespace {{PreFix}} {
+ public class Application : Gtk.Application {
+ private ActionEntry[] APP_ACTIONS = {
+ { "about", on_about_action },
+ { "preferences", on_preferences_action },
+ { "quit", quit }
+ };
+
+
+ public Application () {
+ Object (application_id: "{{appid}}", flags: ApplicationFlags.FLAGS_NONE);
+
+ this.add_action_entries(this.APP_ACTIONS, this);
+ this.set_accels_for_action("app.quit", {"<primary>q"});
+ }
+
+ public override void activate () {
+ base.activate();
+ var win = this.active_window;
+ if (win == null) {
+ win = new {{PreFix}}.Window (this);
+ }
+ win.present ();
+ }
+
+ private void on_about_action () {
+ string[] authors = {"{{author}}"};
+ Gtk.show_about_dialog(this.active_window,
+ "program-name", "{{name}}",
+ "authors", authors,
+ "version", "{{project_version}}");
+ }
+
+ private void on_preferences_action () {
+ message("app.preferences action activated");
+ }
+ }
+}
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.vala
b/src/plugins/meson-templates/resources/src/main-gtk4.vala
new file mode 100644
index 000000000..e8a05c989
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.vala
@@ -0,0 +1,6 @@
+{{include "license.vala"}}
+
+int main (string[] args) {
+ var app = new {{PreFix}}.Application ();
+ return app.run (args);
+}
diff --git a/src/plugins/meson-templates/resources/src/meson-c-vala.build
b/src/plugins/meson-templates/resources/src/meson-c-vala.build
index a9abe1061..013896751 100644
--- a/src/plugins/meson-templates/resources/src/meson-c-vala.build
+++ b/src/plugins/meson-templates/resources/src/meson-c-vala.build
@@ -11,6 +11,9 @@
{{else if language == "vala"}}
'main.vala',
'window.vala',
+ {{if template == "gnome-app-gtk4"}}
+ 'application.vala',
+ {{end}}
{{end}}
]
diff --git a/src/plugins/meson-templates/resources/src/window-gtk4.vala
b/src/plugins/meson-templates/resources/src/window-gtk4.vala
new file mode 100644
index 000000000..7ef3be410
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/window-gtk4.vala
@@ -0,0 +1,13 @@
+{{include "license.vala"}}
+
+namespace {{PreFix}} {
+ [GtkTemplate (ui = "{{appid_path}}/{{ui_file}}")]
+ public class Window : Gtk.ApplicationWindow {
+ [GtkChild]
+ unowned Gtk.Label label;
+
+ public Window (Gtk.Application app) {
+ Object (application: app);
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]