[gnome-builder] meson-templates: added vala, python and js adwaita templates



commit 8239a5c3073c0dc20da77449a658008c999f2dae
Author: Günther Wagner <info gunibert de>
Date:   Sun Feb 20 21:43:05 2022 +0100

    meson-templates: added vala, python and js adwaita templates

 src/plugins/meson-templates/meson_templates.py     |  2 +-
 .../resources/src/application-gtk4.vala            |  2 +-
 .../resources/src/main-gtk4.js.tmpl                | 28 +++++++++++++++++++++-
 .../meson-templates/resources/src/main-gtk4.py     |  7 ++++--
 .../resources/src/meson-c-vala.build               |  8 +++----
 .../meson-templates/resources/src/meson-js.build   |  2 +-
 6 files changed, 39 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index 34aa2cbff..1eccb0acb 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -413,8 +413,8 @@ class GnomeAdwaitaProjectTemplate(MesonTemplate):
             'gnome-app-adwaita',
             _('GNOME Application'),
             'pattern-gnome',
-            ['C', 'Rust'],
             _('Create a GNOME application'),
+            ['C', 'JavaScript', 'Rust', 'Python', 'Vala'],
             0
          )
 
diff --git a/src/plugins/meson-templates/resources/src/application-gtk4.vala 
b/src/plugins/meson-templates/resources/src/application-gtk4.vala
index d77d62b7e..866f5ebe2 100644
--- a/src/plugins/meson-templates/resources/src/application-gtk4.vala
+++ b/src/plugins/meson-templates/resources/src/application-gtk4.vala
@@ -1,7 +1,7 @@
 {{include "license.vala"}}
 
 namespace {{PreFix}} {
-       public class Application : Gtk.Application {
+       public class Application : {{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application {
                private ActionEntry[] APP_ACTIONS = {
                        { "about", on_about_action },
                        { "preferences", on_preferences_action },
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl 
b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
index c246ec3f6..d1a3feeb6 100644
--- a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
@@ -2,6 +2,9 @@
 
 import Gio from 'gi://Gio';
 import Gtk from 'gi://Gtk?version=4.0';
+{{if is_adwaita}}
+import Adw from 'gi://Adw?version=1';
+{{end}}
 
 import { {{PreFix}}Window } from './window.js';
 
@@ -9,11 +12,34 @@ pkg.initGettext();
 pkg.initFormat();
 
 export function main(argv) {
-    const application = new Gtk.Application({
+    const application = new {{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application({
         application_id: '{{appid}}',
         flags: Gio.ApplicationFlags.FLAGS_NONE,
     });
 
+    const quit_action = new Gio.SimpleAction({name: 'quit'});
+    quit_action.connect('activate', action => {
+      application.quit();
+    });
+    application.add_action(quit_action);
+    application.set_accels_for_action('app.quit', ["<primary>q"]);
+
+    const show_about_action = new Gio.SimpleAction({name: 'about'});
+    show_about_action.connect('activate', action => {
+      let aboutParams = {
+        authors: [
+          '{{author}}'
+        ],
+        version: '{{project_version}}',
+        program_name: '{{name}}',
+        transient_for: application.activeWindow,
+        modal: true
+      };
+      const aboutDialog = new Gtk.AboutDialog(aboutParams);
+      aboutDialog.show();
+    });
+    application.add_action(show_about_action);
+
     application.connect('activate', app => {
         let activeWindow = app.activeWindow;
 
diff --git a/src/plugins/meson-templates/resources/src/main-gtk4.py 
b/src/plugins/meson-templates/resources/src/main-gtk4.py
index 2dbe734bd..cce5dab7a 100755
--- a/src/plugins/meson-templates/resources/src/main-gtk4.py
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.py
@@ -4,13 +4,16 @@ import sys
 import gi
 
 gi.require_version('Gtk', '4.0')
+{{if is_adwaita}}
+gi.require_version('Adw', '1')
+{{end}}
 
-from gi.repository import Gtk, Gio
+from gi.repository import Gtk, Gio{{if is_adwaita}}, Adw{{end}}
 
 from .window import {{PreFix}}Window, AboutDialog
 
 
-class Application(Gtk.Application):
+class Application({{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application):
     """The main application singleton class."""
 
     def __init__(self):
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 33d5656ef..ab73b14de 100644
--- a/src/plugins/meson-templates/resources/src/meson-c-vala.build
+++ b/src/plugins/meson-templates/resources/src/meson-c-vala.build
@@ -2,18 +2,18 @@
 {{if language == "c"}}
   'main.c',
   '{{prefix}}-window.c',
-  {{if (template == "gnome-app-gtk4") || (template == "gnome-app-adwaita")}}
+{{if (template == "gnome-app-gtk4") || (template == "gnome-app-adwaita")}}
   '{{prefix}}-application.c',
-  {{end}}
+{{end}}
 {{else if language == "c++"}}
   'main.cpp',
   '{{prefix}}-window.cpp',
 {{else if language == "vala"}}
   'main.vala',
   'window.vala',
-  {{if template == "gnome-app-gtk4"}}
+{{if (template == "gnome-app-gtk4") || (template == "gnome-app-adwaita")}}
   'application.vala',
-  {{end}}
+{{end}}
 {{end}}
 ]
 
diff --git a/src/plugins/meson-templates/resources/src/meson-js.build 
b/src/plugins/meson-templates/resources/src/meson-js.build
index 5654bf897..6f59e662d 100644
--- a/src/plugins/meson-templates/resources/src/meson-js.build
+++ b/src/plugins/meson-templates/resources/src/meson-js.build
@@ -16,7 +16,7 @@ data_res = gnome.compile_resources('{{appid}}.data',
 )
 
 bin_conf = configuration_data()
-bin_conf.set('GJS', find_program('gjs').path())
+bin_conf.set('GJS', find_program('gjs').full_path())
 bin_conf.set('PACKAGE_VERSION', meson.project_version())
 bin_conf.set('PACKAGE_NAME', meson.project_name())
 bin_conf.set('prefix', get_option('prefix'))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]