[gnome-builder/ebassi/js-template] templates: Refresh the GNOME JavaScript project




commit d0cc10349a0be25902ca5a8bbf009ec63519bedf
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Mar 1 11:28:12 2022 +0000

    templates: Refresh the GNOME JavaScript project
    
    The JavaScript template is completely different from the templates for
    other languages, which makes it harder to document.
    
    Let's make it easier to transfer knowledge by having templates with a
    similar structure.

 .../resources/src/main-gtk4.js.tmpl                | 78 ++++++++++++----------
 1 file changed, 41 insertions(+), 37 deletions(-)
---
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 d1a3feeb6..f12678b17 100644
--- a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
@@ -11,43 +11,47 @@ import { {{PreFix}}Window } from './window.js';
 pkg.initGettext();
 pkg.initFormat();
 
-export function main(argv) {
-    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;
-
-        if (!activeWindow)
-            activeWindow = new {{PreFix}}Window(app);
-
-        activeWindow.present();
-    });
+export const {{PreFix}}Application = GObject.registerClass(
+    class {{PreFix}}Application extends {{if is_adwaita}}Adw{{else}}Gtk{{end}}.Application {
+        constructor() {
+            super({application_id: '{{appid}}', flags: Gio.ApplicationFlags.FLAGS_NONE});
+
+            const quit_action = new Gio.SimpleAction({name: 'quit'});
+                quit_action.connect('activate', action => {
+                this.quit();
+            });
+            this.add_action(quit_action);
+            this.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: this.active_window,
+                    modal: true,
+                };
+                const aboutDialog = new Gtk.AboutDialog(aboutParams);
+                aboutDialog.present();
+            });
+            this.add_action(show_about_action);
+        }
+
+        vfunc_activate() {
+            let {active_window} = this;
+
+            if (!active_window)
+                active_window = new {{PreFix}}Window(this);
+
+            active_window.present();
+        }
+    }
+);
 
+export function main(argv) {
+    const application = new {{PreFix}}Application();
     return application.run(argv);
 }


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