[gnome-devel-docs] Samples Javascript: GMenu with SimpleActions



commit 1e16b4596d071e54a2c47f6be4b974aa092035af
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Wed May 2 17:41:27 2012 -0400

    Samples Javascript: GMenu with SimpleActions

 platform-demos/C/gmenu.js.page      |   30 ++++++++++++
 platform-demos/C/media/gmenu.js.png |  Bin 0 -> 20730 bytes
 platform-demos/C/samples/gmenu.js   |   89 +++++++++++++++++++++++++++++++++++
 platform-demos/Makefile.am          |    3 +
 4 files changed, 122 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/gmenu.js.page b/platform-demos/C/gmenu.js.page
new file mode 100644
index 0000000..47fa14c
--- /dev/null
+++ b/platform-demos/C/gmenu.js.page
@@ -0,0 +1,30 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="gmenu.js">
+  <info>
+    <link type="guide" xref="beginner.js#menu-combo-toolbar"/>
+    <revision version="0.1" date="2012-04-07" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Tiffany Antopolski</name>
+      <email>tiffany antopolski gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A simple implementation of GMenuModel</desc>
+  </info>
+
+  <title>GMenu</title>
+  <media type="image" mime="image/png" src="media/gmenu.js.png"/>
+  <p>A GtkApplication with a simple GMenu and SimpleActions</p>
+
+      <code mime="text/javascript" style="numbered"><xi:include href="samples/gmenu.js" 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/gio/unstable/GMenu.html";>GMenu</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gio/stable/GSimpleAction.html";>GSimpleAction</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/media/gmenu.js.png b/platform-demos/C/media/gmenu.js.png
new file mode 100644
index 0000000..fa5d96e
Binary files /dev/null and b/platform-demos/C/media/gmenu.js.png differ
diff --git a/platform-demos/C/samples/gmenu.js b/platform-demos/C/samples/gmenu.js
new file mode 100644
index 0000000..ad3531e
--- /dev/null
+++ b/platform-demos/C/samples/gmenu.js
@@ -0,0 +1,89 @@
+#!/usr/bin/gjs
+
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+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
+        });
+       
+       //connect to 'activate' and 'startup' signals to the callback functions
+       this.application.connect('activate', Lang.bind(this, this._onActivate));
+       this.application.connect('startup', Lang.bind(this, this._onStartup));
+    },
+
+    //create the UI (in this case it's just the ApplicationWindow
+    _buildUI: function() {
+        this._window = new Gtk.ApplicationWindow  ({ application: this.application,
+                                                   window_position: Gtk.WindowPosition.CENTER,
+                                                   title: "Welcome to GNOME" });
+
+        //uncommenting the line below will change the window size
+        //this._window.set_size_request(600, 400);
+
+        //show the window and all child widgets (none in this case)
+        this._window.show_all();
+    },
+
+    _showNew: function() {
+	print ("This doesn't do anything. It is only a demonstration.");
+    },
+
+    _showAbout: function() {
+        print ("No AboutDialog here.  This is only a demonstration.");
+    },
+ 
+    //create the menu items and connect the signals to the callback functions.
+    _initMenus: function() {
+        let menu = new Gio.Menu();
+        menu.append("New",'app.new');
+        menu.append("About", 'app.about');
+        menu.append("Quit",'app.quit');
+        this.application.set_app_menu(menu);
+ 
+        let newAction = new Gio.SimpleAction ({ name: 'new' });
+        newAction.connect('activate', Lang.bind(this,
+            function() {
+                this._showNew();
+            }));
+        this.application.add_action(newAction);
+
+        let aboutAction = new Gio.SimpleAction ({ name: 'about' });
+        aboutAction.connect('activate', Lang.bind(this,
+            function() {
+                this._showAbout();
+            }));
+        this.application.add_action(aboutAction);
+
+        let quitAction = new Gio.SimpleAction ({ name: 'quit' });
+        quitAction.connect('activate', Lang.bind(this,
+            function() {
+                this._window.destroy();
+            }));
+         this.application.add_action(quitAction);
+    },
+
+    //callback function for 'activate' signal
+    _onActivate: function() {
+        this._window.present();
+    },
+
+    //callback function for 'startup' signal
+    _onStartup: function() {
+        //You must call _initMenus() before calling _buildUI().
+        this._initMenus();
+        this._buildUI();
+    }
+});
+
+//run the application
+let app = new Application ();
+app.application.run (ARGV);
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 9db216c..253381c 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -25,6 +25,7 @@ demo_sources = \
 	samples/button.vala			\
 	samples/dialog.vala			\
 	samples/gmenu.c				\
+	samples/gmenu.js			\
 	samples/gmenu.py			\
 	samples/grid.py				\
 	samples/GtkApplicationWindow.c		\
@@ -46,6 +47,7 @@ DOC_FIGURES = \
 	media/fedora.png			\
 	media/opensuse.png			\
 	media/gmenu.c.png			\
+	media/gmenu.js.png			\
 	media/gmenu.py.png			\
 	media/gmenu.vala.png			\
 	media/grid.png				\
@@ -86,6 +88,7 @@ DOC_PAGES =				\
 	getting-ready.page		\
 	grid.js.page			\
 	gmenu.c.page			\
+	gmenu.js.page			\
 	gmenu.py.page			\
 	gmenu.vala.page			\
 	grid.py.page			\



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