[gnome-builder] Update JavaScript/GJS Meson template to ES6. - Fix some deviations from GJS style guidelines. - Make



commit e885d1e6f1a4a0386dabeb4b9e8e790950219c09
Author: rockon999 <noreply evanwelsh com>
Date:   Mon Jul 30 16:36:09 2018 -0500

    Update JavaScript/GJS Meson template to ES6.
    - Fix some deviations from GJS style guidelines.
    - Make UI template compatible with newer GTK+ widgets.

 .../meson-templates/resources/src/main.js.tmpl     | 37 +++++++++++-----------
 .../meson-templates/resources/src/window.js.tmpl   | 24 +++++++-------
 .../meson-templates/resources/src/window.ui        |  9 ++++--
 3 files changed, 36 insertions(+), 34 deletions(-)
---
diff --git a/src/plugins/meson-templates/resources/src/main.js.tmpl 
b/src/plugins/meson-templates/resources/src/main.js.tmpl
index 99296a87a..547889f82 100644
--- a/src/plugins/meson-templates/resources/src/main.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/main.js.tmpl
@@ -7,26 +7,25 @@ pkg.require({
   'Gtk': '3.0'
 });
 
-const Gio = imports.gi.Gio;
-const Gtk = imports.gi.Gtk;
+const { Gio, Gtk } = imports.gi;
 
-const Window = imports.window;
+const { {{PreFix}}Window } = imports.window;
 
 function main(argv) {
-
-  let app = new Gtk.Application({
-      application_id: '{{appid}}',
-      flags: Gio.ApplicationFlags.FLAGS_NONE,
-  });
-
-  app.connect('activate', app => {
-      let win = app.active_window;
-
-      if (!win)
-          win = new Window.{{PreFix}}Window(app);
-
-      win.present();
-  });
-
-  return app.run(argv);
+    const application = new Gtk.Application({
+        application_id: '{{appid}}',
+        flags: Gio.ApplicationFlags.FLAGS_NONE,
+    });
+
+    application.connect('activate', app => {
+        let window = app.get_active_window();
+        
+        if(!window) {
+            window = new {{PreFix}}Window(app);
+        }
+
+        window.present();
+    });
+
+    return application.run(argv);
 }
diff --git a/src/plugins/meson-templates/resources/src/window.js.tmpl 
b/src/plugins/meson-templates/resources/src/window.js.tmpl
index c5f3352ff..8251ddf98 100644
--- a/src/plugins/meson-templates/resources/src/window.js.tmpl
+++ b/src/plugins/meson-templates/resources/src/window.js.tmpl
@@ -1,19 +1,17 @@
 {{include "license.js"}}
 
-const Gtk = imports.gi.Gtk;
+const { GObject, Gtk } = imports.gi;
 const Lang = imports.lang;
 
-var {{PreFix}}Window = new Lang.Class({
-    Name: '{{PreFix}}Window',
-    GTypeName: '{{PreFix}}Window',
-    Extends: Gtk.ApplicationWindow,
-    Template: 'resource://{{appid_path}}/{{ui_file}}',
-    InternalChildren: ['label'],
-
-    _init(application) {
-        this.parent({
-            application,
-        });
+var {{PreFix}}Window = GObject.registerClass({
+        GTypeName: '{{PreFix}}Window',
+        Template: 'resource://{{appid_path}}/{{ui_file}}',
+        InternalChildren: ['label']
     },
-});
+    class {{PreFix}}Window extends Gtk.ApplicationWindow {
+        _init(application) {
+            super._init({ application });
+        }
+    }
+);
 
diff --git a/src/plugins/meson-templates/resources/src/window.ui 
b/src/plugins/meson-templates/resources/src/window.ui
index 3478b2b72..0aac2a867 100644
--- a/src/plugins/meson-templates/resources/src/window.ui
+++ b/src/plugins/meson-templates/resources/src/window.ui
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
+  <requires lib="gtk+" version="3.20"/>
 {{if language == "c++"}}
   <object class="GtkHeaderBar" id="headerbar">
     <property name="can_focus">False</property>
@@ -19,8 +20,12 @@
     <property name="default-width">600</property>
     <property name="default-height">300</property>
     <child type="titlebar">
-      <object class="GtkHeaderBar" id="header_bar">
-        <property name="visible">True</property>
+    {{if language == "javascript"}}
+  <object class="GtkHeaderBar" id="headerBar">
+    {{else}}
+  <object class="GtkHeaderBar" id="header_bar">
+    {{end}}
+    <property name="visible">True</property>
         <property name="show-close-button">True</property>
         <property name="title">Hello, World!</property>
       </object>


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