[gnome-builder/ebassi/js-template] templates: Refresh the GNOME JavaScript project
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/ebassi/js-template] templates: Refresh the GNOME JavaScript project
- Date: Fri, 4 Mar 2022 20:53:25 +0000 (UTC)
commit 98ee97b79c43b8ac7a29adbe79a6e7784e0c982c
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 | 79 ++++++++++++----------
1 file changed, 42 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..13ad322e8 100644
--- a/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/main-gtk4.js.tmpl
@@ -1,5 +1,6 @@
{{include "license.js"}}
+import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk?version=4.0';
{{if is_adwaita}}
@@ -11,43 +12,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]