1<?xml version="1.0" encoding="utf-8"?>
2<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="aboutdialog.js" xml:lang="gl">
3  <info>
4  <title type="text">AboutDialog (JavaScript)</title>
5    <link type="guide" xref="beginner.js#windows"/>
6    <revision version="0.1" date="2012-05-30" status="draft"/>
7
8    <credit type="author copyright">
9      <name>Taryn Fox</name>
10      <email its:translate="no">jewelfox@fursona.net</email>
11      <years>2012</years>
12    </credit>
13
14    <desc>Mostrar información sobre unha aplicación</desc>
15
16    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
17      <mal:name>Fran Dieguez</mal:name>
18      <mal:email>frandieguez@gnome.org</mal:email>
19      <mal:years>2012-2013.</mal:years>
20    </mal:credit>
21  </info>
22
23  <title>AboutDialog</title>
24  <media type="image" mime="image/png" src="media/aboutdialog_GMenu.png"/>
25  <p>A modal dialog window which shows information about an application and its creators. This one is triggered by clicking "About" in the application's menu, which is normally a good place to put it.</p>
26
27<code mime="application/javascript" style="numbered">#!/usr/bin/gjs
28
29imports.gi.versions.Gtk = '3.0';
30
31const Gio = imports.gi.Gio;
32const GLib = imports.gi.GLib;
33const Gtk = imports.gi.Gtk;
34
35class AboutDialogExample {
36
37    // Create the application itself
38    constructor() {
39        this.application = new Gtk.Application({
40            application_id: 'org.example.jsaboutdialog',
41            flags: Gio.ApplicationFlags.FLAGS_NONE
42        });
43
44        // Connect 'activate' and 'startup' signals to the callback functions
45        this.application.connect('activate', this._onActivate.bind(this));
46        this.application.connect('startup', this._onStartup.bind(this));
47    }
48
49    // Callback function for 'activate' signal presents windows when active
50    _onActivate() {
51        this._window.present();
52    }
53
54    // Callback function for 'startup' signal creates the menu and builds the UI
55    _onStartup() {
56        this._initMenus();
57        this._buildUI();
58    }
59
60    // Build the application's UI
61    _buildUI() {
62        // Create the application window
63        this._window = new Gtk.ApplicationWindow({ application: this.application,
64                                                   window_position: Gtk.WindowPosition.CENTER,
65                                                   title: "AboutDialog Example",
66                                                   default_height: 250,
67                                                   default_width: 350 });
68
69        // Show the window and all child widgets
70        this._window.show_all();
71    }
72
73    // Create the application menu
74    _initMenus() {
75        let menu = new Gio.Menu();
76        menu.append("About", 'app.about');
77        menu.append("Quit",'app.quit');
78        this.application.set_app_menu(menu);
79
80        // Create the "About" menu option and have it call the _showAbout() function
81        let aboutAction = new Gio.SimpleAction({ name: 'about' });
82        aboutAction.connect('activate', () =&gt; { this._showAbout(); });
83        this.application.add_action(aboutAction);
84
85        // Create the "Quit" menu option and have it close the window
86        let quitAction = new Gio.SimpleAction ({ name: 'quit' });
87        quitAction.connect('activate', () =&gt; { this._window.destroy(); });
88        this.application.add_action(quitAction);
89    }
90
91    _showAbout() {
92
93        // String arrays of the names of the people involved in the project
94        var authors = ["GNOME Documentation Team"];
95        var documenters = ["GNOME Documentation Team"];
96
97        // Create the About dialog
98        let aboutDialog = new Gtk.AboutDialog({ title: "AboutDialog Example",
99                                                program_name: "GtkApplication Example",
100                                                copyright: "Copyright \xa9 2012 GNOME Documentation Team",
101                                                authors: authors,
102                                                documenters: documenters,
103                                                website: "http://developer.gnome.org",
104                                                website_label: "GNOME Developer Website" });
105
106        // Attach the About dialog to the window
107        aboutDialog.modal = true;
108        aboutDialog.transient_for = this._window;
109
110        // Show the About dialog
111        aboutDialog.show();
112
113        // Connect the Close button to the destroy signal for the dialog
114        aboutDialog.connect('response', function() {
115            aboutDialog.destroy();
116        });
117    }
118};
119
120// Run the application
121let app = new AboutDialogExample();
122app.application.run(ARGV);
123</code>
124<p>Neste exemplo empregaremos o seguinte:</p>
125<list>
126  <item><p><link href="http://developer.gnome.org/gio/unstable/GMenu.html">GMenu</link></p></item>
127  <item><p><link href="http://developer.gnome.org/gio/stable/GSimpleAction.html">GSimpleAction</link></p></item>
128  <item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.AboutDialog.html">Gtk.AboutDialog</link></p></item>
129  <item><p><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Application.html">Gtk.Application</link></p></item>
130  <item><p><link href="http://developer.gnome.org/gtk3/stable/GtkApplicationWindow.html">Gtk.ApplicationWindow</link></p></item>
131</list>
132</page>
133