[gnome-devel-docs] tutorials <javascript>: Added Gtk.MessageDialog sample and Mallard page
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials <javascript>: Added Gtk.MessageDialog sample and Mallard page
- Date: Mon, 28 May 2012 23:53:10 +0000 (UTC)
commit 9be7ee2d2f454ffce8470394df96fd1c3e440709
Author: Taryn Fox <jewelfox fursona net>
Date: Mon May 28 00:11:18 2012 -0400
tutorials <javascript>: Added Gtk.MessageDialog sample and Mallard page
Many thanks to Tiffany and desrt for helping to figure this out.
platform-demos/C/messagedialog.js.page | 33 ++++++++
platform-demos/C/samples/messagedialog.js | 118 +++++++++++++++++++++++++++++
2 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/messagedialog.js.page b/platform-demos/C/messagedialog.js.page
new file mode 100644
index 0000000..585aa93
--- /dev/null
+++ b/platform-demos/C/messagedialog.js.page
@@ -0,0 +1,33 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ type="guide" style="task"
+ id="messagedialog.js">
+ <info>
+ <link type="guide" xref="beginner.js#windows"/>
+ <revision version="0.1" date="2012-05-28" status="draft"/>
+
+ <credit type="author copyright">
+ <name>Taryn Fox</name>
+ <email>jewelfox fursona net</email>
+ <years>2012</years>
+ </credit>
+
+ <desc>A modal message window</desc>
+ </info>
+
+ <title>MessageDialog</title>
+ <media type="image" mime="image/png" src="media/messagedialog.png"/>
+ <p>A modal message dialog. This one can cause the world to explode.</p>
+
+<code mime="text/javascript" style="numbered"><xi:include href="samples/messagedialog.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>
+ <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://developer.gnome.org/gtk3/stable/GtkApplicationWindow.html">Gtk.ApplicationWindow</link></p></item>
+ <item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.MessageDialog.html">Gtk.MessageDialog</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/messagedialog.js b/platform-demos/C/samples/messagedialog.js
new file mode 100644
index 0000000..e81c6b4
--- /dev/null
+++ b/platform-demos/C/samples/messagedialog.js
@@ -0,0 +1,118 @@
+#!/usr/bin/gjs
+
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const MessageExample = new Lang.Class ({
+ Name: 'Message Example',
+
+ // Create the application itself
+ _init: function () {
+ this.application = new Gtk.Application ({
+ application_id: 'org.example.jsmessagedialog',
+ flags: Gio.ApplicationFlags.FLAGS_NONE
+ });
+
+ // Connect '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));
+ },
+
+ // Callback function for 'activate' signal presents windows when active
+ _onActivate: function () {
+ this._window.present ();
+ },
+
+ // Callback function for 'startup' signal initializes menus and builds the UI
+ _onStartup: function () {
+ this._initMenus();
+ this._buildUI ();
+ },
+
+
+
+ // Build the application menu, including the button that calls the dialog
+ _initMenus: function() {
+ let menu = new Gio.Menu();
+ menu.append("Message",'app.message');
+ menu.append("Quit",'app.quit');
+ this.application.set_app_menu(menu);
+
+ // This pops up a MessageDialog when the menu item is clicked
+ let messageAction = new Gio.SimpleAction ({ name: 'message' });
+ messageAction.connect('activate', Lang.bind(this,
+ function() {
+ this._showMessageDialog();
+ }));
+ this.application.add_action(messageAction);
+
+ let quitAction = new Gio.SimpleAction ({ name: 'quit' });
+ quitAction.connect('activate', Lang.bind(this,
+ function() {
+ this._window.destroy();
+ }));
+ this.application.add_action(quitAction);
+ },
+
+
+
+ // Build the application's UI, including the MessageDialog
+ _buildUI: function () {
+
+ // Create the application window and a "warning message"
+ this._window = new Gtk.ApplicationWindow ({ application: this.application,
+ window_position: Gtk.WindowPosition.CENTER,
+ title: "Gtk.MessageDialog Example",
+ default_height: 200,
+ default_width: 400 });
+
+ this.warningLabel = new Gtk.Label ({label: "This application goes boom! (Not really.)"});
+ this._window.add (this.warningLabel);
+
+ // Show the window and all child widgets
+ this._window.show_all();
+ },
+
+
+
+ _showMessageDialog: function () {
+
+ // Create a modal MessageDialog whose parent is the window
+ this._messageDialog = new Gtk.MessageDialog ({ transient_for: this._window,
+ modal: true,
+ buttons: Gtk.ButtonsType.OK_CANCEL,
+ message_type: Gtk.MessageType.WARNING,
+ text: "This action will cause the universe to stop existing." });
+
+ this._messageDialog.connect ("response", Lang.bind(this, this._response_cb));
+ this._messageDialog.show();
+ },
+
+
+
+ // Callback function (aka signal handler) for the response signal
+ _response_cb: function (messagedialog, response_id) {
+
+ // A simple switch that changes the main window's label
+ switch (response_id) {
+ case Gtk.ResponseType.OK:
+ this.warningLabel.set_label ("*BOOM*\n");
+ break;
+ case Gtk.ResponseType.CANCEL:
+ this.warningLabel.set_label ("Good choice!\n");
+ break;
+ case Gtk.ResponseType.DELETE_EVENT:
+ this.warningLabel.set_label ("Dialog closed or cancelled.\n");
+ break;
+ }
+ this._messageDialog.destroy();
+ }
+
+
+});
+
+// Run the application
+let app = new MessageExample ();
+app.application.run (ARGV);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]