[gnome-devel-docs] Samples: Updates to Window pages.



commit 7bc532cfeedd2a461f7237804f7bc636c20a325b
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Wed May 2 15:11:30 2012 -0400

    Samples: Updates to Window pages.

 platform-demos/C/GtkApplicationWindow.js.page |    3 +-
 platform-demos/C/samples/window.js            |   53 ++++++++++++++++--------
 platform-demos/C/window.c.page                |    4 +-
 platform-demos/C/window.js.page               |   50 +++++++++--------------
 4 files changed, 57 insertions(+), 53 deletions(-)
---
diff --git a/platform-demos/C/GtkApplicationWindow.js.page b/platform-demos/C/GtkApplicationWindow.js.page
index 694456d..c71a5aa 100644
--- a/platform-demos/C/GtkApplicationWindow.js.page
+++ b/platform-demos/C/GtkApplicationWindow.js.page
@@ -20,8 +20,7 @@
   <p>A simple GtkApplicationWindow which can support Menus.</p>
 
 <code mime="text/javascript" style="numbered">
-<xi:include href="samples/GtkApplicationWindow.js" parse="text"><xi:fallback/></xi:include>
-</code>
+<xi:include href="samples/GtkApplicationWindow.js" parse="text"><xi:fallback/></xi:include></code>
 <p>
   In this sample we used the following:
 </p>
diff --git a/platform-demos/C/samples/window.js b/platform-demos/C/samples/window.js
index 3ddabdf..9acf741 100644
--- a/platform-demos/C/samples/window.js
+++ b/platform-demos/C/samples/window.js
@@ -1,25 +1,42 @@
 #!/usr/bin/gjs
 
-var Gtk = imports.gi.Gtk;
-Gtk.init(null, 0);
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
 
-// Create window and give it a name
-// You can't call it "window" as that name is a JavaScript keyword.
-var sampleWindow = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
-sampleWindow.title = "Welcome to GNOME";
+const Application = new Lang.Class ({
+    Name: 'Application',
+   
+    //create the application
+    _init: function () {
+        this.application = new Gtk.Application ({
+            application_id: 'org.example.myapp',
+            flags: Gio.ApplicationFlags.FLAGS_NONE
+        });
 
-/* The "destroy" signal is sent out when you click the X button.
-   Here, we connect that signal to the GTK+ function to close the window. */
-sampleWindow.connect("destroy", function(){Gtk.main_quit()});
+       this.application.connect('activate', Lang.bind(this, this._onActivate));
+    },
 
-/* Here are a few ways we can customize our window.
-   Try uncommenting them or changing their values! */
-// sampleWindow.set_default_size (400,200);
-// sampleWindow.set_has_resize_grip (false);
-// sampleWindow.set_opacity (0.5);
-// sampleWindow.maximize ();
+    //callback function for 'activate' signal
+    _onActivate: function () {
 
-// If the window has widgets in it, you'll want to use show_all() instead.
-sampleWindow.show();
+        MyWindow = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
+        MyWindow.title = "Welcome to GNOME";
 
-Gtk.main();
+       /* Here are a few ways we can customize our window.
+       Try uncommenting them or changing their values! */
+        //MyWindow.set_default_size (400,200);
+        //MyWindow.set_has_resize_grip (false);
+        //MyWindow.set_opacity (0.5);
+        //MyWindow.maximize ();
+
+        //show the window and all child widgets (none in this case)
+        MyWindow.show_all();
+        this.application.add_window(MyWindow);
+    }
+});
+
+//run the application
+let app = new Application ();
+app.application.run (ARGV);
diff --git a/platform-demos/C/window.c.page b/platform-demos/C/window.c.page
index 849a2d1..56e7fec 100644
--- a/platform-demos/C/window.c.page
+++ b/platform-demos/C/window.c.page
@@ -29,14 +29,12 @@
 </table>
 
       <code mime="text/x-csrc" style="numbered">
-<xi:include href="samples/window.c" parse="text"><xi:fallback/></xi:include>
-</code>
+<xi:include href="samples/window.c" parse="text"><xi:fallback/></xi:include></code>
 <p>
   In this sample we used the following:
 </p>
 <list>
   <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html";>GtkApplication</link></p></item>
   <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html";>GtkWindow</link></p></item>
-
 </list>
 </page>
diff --git a/platform-demos/C/window.js.page b/platform-demos/C/window.js.page
index ddd61be..6d6c87e 100644
--- a/platform-demos/C/window.js.page
+++ b/platform-demos/C/window.js.page
@@ -1,4 +1,5 @@
 <page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
       type="guide" style="task"
       id="window.js">
   <info>
@@ -15,36 +16,25 @@
   </info>
 
   <title>Window</title>
-  <media type="image" mime="image/png" src="media/window.png"/>
-  <p>A plain window, without other widgets added to it.</p>
-
-      <code mime="text/javascript" style="numbered"><![CDATA[
-]]>#!/usr/bin/gjs
-
-var Gtk = imports.gi.Gtk;
-Gtk.init(null, 0);
-
-// Create window and give it a name
-// You can't call it "window" as that name is a JavaScript keyword.
-var sampleWindow = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
-sampleWindow.title = "Welcome to GNOME";
-
-/* The "destroy" signal is sent out when you click the X button.
-   Here, we connect that signal to the GTK+ function to close the window. */
-sampleWindow.connect("destroy", function(){Gtk.main_quit()});
-
-/* Here are a few ways we can customize our window.
-   Try uncommenting them or changing their values! */
-// sampleWindow.set_default_size (400,200);
-// sampleWindow.set_has_resize_grip (false);
-// sampleWindow.set_opacity (0.5);
-// sampleWindow.maximize ();
-
-// If the window has widgets in it, you'll want to use show_all() instead.
-sampleWindow.show();
-
-Gtk.main();</code>
+<table>
+  <tr>
+    <td>
+      <media type="image" mime="image/png" src="media/window.png"/>
+      <p>A minimal GtkApplication</p>
+    </td>
+    <td>
+      <p>Use <link href="GtkApplicationWindow.js.page">ApplicationWindow</link> if you need GMenu support.</p>
+    </td>
+  </tr>
+</table>
+      <code mime="text/javascript" style="numbered">
+<xi:include href="samples/window.js" parse="text"><xi:fallback/></xi:include></code>
 <p>
-  In this sample we used the following widget: <link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Window.html";>Gtk.Window</link>
+In this example we used the following:
 </p>
+<list>
+<item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Application.html";>Gtk.Application</link></p></item>
+<item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Window.html";>Gtk.Window</link></p></item>
+</list>
+
 </page>



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