[gnome-builder] templates: tweak whitespace in meson templates



commit 63a1f8f6f2a274b1604638f19d6efd96a847a344
Author: Christian Hergert <chergert redhat com>
Date:   Sun Sep 3 16:28:39 2017 -0700

    templates: tweak whitespace in meson templates
    
    We can translate \t to the proper spacing if we do things right. A few
    other stylistic tweaks.

 .../meson_templates/resources/src/main.c           |  100 +++++++++----------
 .../meson_templates/resources/src/window.c         |   10 +-
 .../meson_templates/resources/src/window.h         |    1 +
 .../meson_templates/resources/src/window.ui        |    2 +-
 .../meson_templates/resources/src/window.vala      |    2 +-
 5 files changed, 56 insertions(+), 59 deletions(-)
---
diff --git a/plugins/meson-templates/meson_templates/resources/src/main.c 
b/plugins/meson-templates/meson_templates/resources/src/main.c
index cc20953..329f158 100644
--- a/plugins/meson-templates/meson_templates/resources/src/main.c
+++ b/plugins/meson-templates/meson_templates/resources/src/main.c
@@ -7,74 +7,68 @@
 static void
 on_activate (GtkApplication *app)
 {
-  GtkWindow *window;
+       GtkWindow *window;
 
-  /* It's good practice to check your parameters at the beginning of the
-   * function. It helps catch errors early and in development instead of
-   * by your users.
-   */
-  g_assert (GTK_IS_APPLICATION (app));
+       /* It's good practice to check your parameters at the beginning of the
+        * function. It helps catch errors early and in development instead of
+        * by your users.
+        */
+       g_assert (GTK_IS_APPLICATION (app));
 
-  /*
-   * Get the current window. If there is not one, we will create it.
-   */
-  window = gtk_application_get_active_window (app);
-  if (window == NULL)
-    window = g_object_new ({{PREFIX}}_TYPE_WINDOW,
-                           "application", app,
-                           "default-width", 600,
-                           "default-height", 300,
-                           NULL);
+       /* Get the current window or create one if necessary. */
+       window = gtk_application_get_active_window (app);
+       if (window == NULL)
+               window = g_object_new ({{PREFIX}}_TYPE_WINDOW,
+                                      "application", app,
+                                      "default-width", 600,
+                                      "default-height", 300,
+                                      NULL);
 
-  /*
-   * Ask the window manager/compositor to present the window to the user.
-   */
-  gtk_window_present (window);
+       /* Ask the window manager/compositor to present the window. */
+       gtk_window_present (window);
 }
 
 int
 main (int   argc,
       char *argv[])
 {
-  g_autoptr(GtkApplication) app = NULL;
-  int ret;
+       g_autoptr(GtkApplication) app = NULL;
+       int ret;
 
-  /*
-   * Set up gettext translations.
-   */
+       /* Set up gettext translations */
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);
 
-  /*
-   * Create a new GtkApplication. The application manages our main loop,
-   * application windows, integration with the window manager/compositor, and
-   * desktop features such as file opening and single-instance applications.
-   */
-  app = gtk_application_new ("{{appid}}", G_APPLICATION_FLAGS_NONE);
+       /*
+        * Create a new GtkApplication. The application manages our main loop,
+        * application windows, integration with the window manager/compositor, and
+        * desktop features such as file opening and single-instance applications.
+        */
+       app = gtk_application_new ("{{appid}}", G_APPLICATION_FLAGS_NONE);
 
-  /*
-   * We connect to the activate signal to create a window when the application
-   * has been lauched. Additionally, this signal notifies us when the user
-   * tries to launch a "second instance" of the application. When they try
-   * to do that, we'll just present any existing window.
-   *
-   * Because we can't pass a pointer to any function type, we have to cast
-   * our "on_activate" function to a GCallback.
-   */
-  g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
+       /*
+        * We connect to the activate signal to create a window when the application
+        * has been lauched. Additionally, this signal notifies us when the user
+        * tries to launch a "second instance" of the application. When they try
+        * to do that, we'll just present any existing window.
+        *
+        * Because we can't pass a pointer to any function type, we have to cast
+        * our "on_activate" function to a GCallback.
+        */
+       g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
 
-  /*
-   * Run the application. This function will block until the applicaiton
-   * exits. Upon return, we have our exit code to return to the shell. (This
-   * is the code you see when you do `echo $?` after running a command in a
-   * terminal.
-   *
-   * Since GtkApplication inherits from GApplication, we use the parent class
-   * method "run". But we need to cast, which is what the "G_APPLICATION()"
-   * macro does.
-   */
-  ret = g_application_run (G_APPLICATION (app), argc, argv);
+       /*
+        * Run the application. This function will block until the applicaiton
+        * exits. Upon return, we have our exit code to return to the shell. (This
+        * is the code you see when you do `echo $?` after running a command in a
+        * terminal.
+        *
+        * Since GtkApplication inherits from GApplication, we use the parent class
+        * method "run". But we need to cast, which is what the "G_APPLICATION()"
+        * macro does.
+        */
+       ret = g_application_run (G_APPLICATION (app), argc, argv);
 
-  return ret;
+       return ret;
 }
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.c 
b/plugins/meson-templates/meson_templates/resources/src/window.c
index 25d9609..689d039 100644
--- a/plugins/meson-templates/meson_templates/resources/src/window.c
+++ b/plugins/meson-templates/meson_templates/resources/src/window.c
@@ -1,14 +1,15 @@
 {{include "license.c"}}
 
-#include <gtk/gtk.h>
 #include "{{prefix}}-config.h"
 #include "{{prefix}}-window.h"
 
 struct _{{PreFix}}Window
 {
-  GtkWindow     parent_instance;
-  GtkHeaderBar *header_bar;
-  GtkLabel     *label;
+  GtkApplicationWindow  parent_instance;
+
+  /* Template widgets */
+  GtkHeaderBar        *header_bar;
+  GtkLabel            *label;
 };
 
 G_DEFINE_TYPE ({{PreFix}}Window, {{prefix_}}_window, GTK_TYPE_APPLICATION_WINDOW)
@@ -19,6 +20,7 @@ static void
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   gtk_widget_class_set_template_from_resource (widget_class, "{{appid_path}}/{{ui_file}}");
+  gtk_widget_class_bind_template_child (widget_class, {{PreFix}}Window, header_bar);
   gtk_widget_class_bind_template_child (widget_class, {{PreFix}}Window, label);
 }
 
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.h 
b/plugins/meson-templates/meson_templates/resources/src/window.h
index 890d536..3e757b5 100644
--- a/plugins/meson-templates/meson_templates/resources/src/window.h
+++ b/plugins/meson-templates/meson_templates/resources/src/window.h
@@ -7,6 +7,7 @@
 G_BEGIN_DECLS
 
 #define {{PREFIX}}_TYPE_WINDOW ({{prefix_}}_window_get_type())
+
 G_DECLARE_FINAL_TYPE ({{PreFix}}Window, {{prefix_}}_window, {{PREFIX}}, WINDOW, GtkApplicationWindow)
 
 G_END_DECLS
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.ui 
b/plugins/meson-templates/meson_templates/resources/src/window.ui
index 1937238..cd92863 100644
--- a/plugins/meson-templates/meson_templates/resources/src/window.ui
+++ b/plugins/meson-templates/meson_templates/resources/src/window.ui
@@ -4,7 +4,7 @@
     <property name="default-width">600</property>
     <property name="default-height">300</property>
     <child type="titlebar">
-      <object class="GtkHeaderBar">
+      <object class="GtkHeaderBar" id="header_bar">
         <property name="visible">true</property>
         <property name="show-close-button">true</property>
         <property name="title">Hello, World!</property>
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.vala 
b/plugins/meson-templates/meson_templates/resources/src/window.vala
index 26732a2..26fe751 100644
--- a/plugins/meson-templates/meson_templates/resources/src/window.vala
+++ b/plugins/meson-templates/meson_templates/resources/src/window.vala
@@ -7,7 +7,7 @@ namespace {{PreFix}} {
                Gtk.Label label;
 
                public Window (Gtk.Application app) {
-                       Object(application: app);
+                       Object (application: app);
                }
        }
 }


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