|
Packit |
1470ea |
|
|
Packit |
1470ea |
<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="de">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">AboutDialog (JavaScript)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.js#windows"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-30" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Taryn Fox</name>
|
|
Packit |
1470ea |
<email its:translate="no">jewelfox@fursona.net</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Informationen zur Anwendung anzeigen</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Mario Blättermann</mal:name>
|
|
Packit |
1470ea |
<mal:email>mario.blaettermann@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011, 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>AboutDialog</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/aboutdialog_GMenu.png"/>
|
|
Packit |
1470ea |
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.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#!/usr/bin/gjs
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
imports.gi.versions.Gtk = '3.0';
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
const Gio = imports.gi.Gio;
|
|
Packit |
1470ea |
const GLib = imports.gi.GLib;
|
|
Packit |
1470ea |
const Gtk = imports.gi.Gtk;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class AboutDialogExample {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application itself
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application({
|
|
Packit |
1470ea |
application_id: 'org.example.jsaboutdialog',
|
|
Packit |
1470ea |
flags: Gio.ApplicationFlags.FLAGS_NONE
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect 'activate' and 'startup' signals to the callback functions
|
|
Packit |
1470ea |
this.application.connect('activate', this._onActivate.bind(this));
|
|
Packit |
1470ea |
this.application.connect('startup', this._onStartup.bind(this));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'activate' signal presents windows when active
|
|
Packit |
1470ea |
_onActivate() {
|
|
Packit |
1470ea |
this._window.present();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'startup' signal creates the menu and builds the UI
|
|
Packit |
1470ea |
_onStartup() {
|
|
Packit |
1470ea |
this._initMenus();
|
|
Packit |
1470ea |
this._buildUI();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Build the application's UI
|
|
Packit |
1470ea |
_buildUI() {
|
|
Packit |
1470ea |
// Create the application window
|
|
Packit |
1470ea |
this._window = new Gtk.ApplicationWindow({ application: this.application,
|
|
Packit |
1470ea |
window_position: Gtk.WindowPosition.CENTER,
|
|
Packit |
1470ea |
title: "AboutDialog Example",
|
|
Packit |
1470ea |
default_height: 250,
|
|
Packit |
1470ea |
default_width: 350 });
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the window and all child widgets
|
|
Packit |
1470ea |
this._window.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application menu
|
|
Packit |
1470ea |
_initMenus() {
|
|
Packit |
1470ea |
let menu = new Gio.Menu();
|
|
Packit |
1470ea |
menu.append("About", 'app.about');
|
|
Packit |
1470ea |
menu.append("Quit",'app.quit');
|
|
Packit |
1470ea |
this.application.set_app_menu(menu);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the "About" menu option and have it call the _showAbout() function
|
|
Packit |
1470ea |
let aboutAction = new Gio.SimpleAction({ name: 'about' });
|
|
Packit |
1470ea |
aboutAction.connect('activate', () => { this._showAbout(); });
|
|
Packit |
1470ea |
this.application.add_action(aboutAction);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the "Quit" menu option and have it close the window
|
|
Packit |
1470ea |
let quitAction = new Gio.SimpleAction ({ name: 'quit' });
|
|
Packit |
1470ea |
quitAction.connect('activate', () => { this._window.destroy(); });
|
|
Packit |
1470ea |
this.application.add_action(quitAction);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_showAbout() {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// String arrays of the names of the people involved in the project
|
|
Packit |
1470ea |
var authors = ["GNOME Documentation Team"];
|
|
Packit |
1470ea |
var documenters = ["GNOME Documentation Team"];
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the About dialog
|
|
Packit |
1470ea |
let aboutDialog = new Gtk.AboutDialog({ title: "AboutDialog Example",
|
|
Packit |
1470ea |
program_name: "GtkApplication Example",
|
|
Packit |
1470ea |
copyright: "Copyright \xa9 2012 GNOME Documentation Team",
|
|
Packit |
1470ea |
authors: authors,
|
|
Packit |
1470ea |
documenters: documenters,
|
|
Packit |
1470ea |
website: "http://developer.gnome.org",
|
|
Packit |
1470ea |
website_label: "GNOME Developer Website" });
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Attach the About dialog to the window
|
|
Packit |
1470ea |
aboutDialog.modal = true;
|
|
Packit |
1470ea |
aboutDialog.transient_for = this._window;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the About dialog
|
|
Packit |
1470ea |
aboutDialog.show();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect the Close button to the destroy signal for the dialog
|
|
Packit |
1470ea |
aboutDialog.connect('response', function() {
|
|
Packit |
1470ea |
aboutDialog.destroy();
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Run the application
|
|
Packit |
1470ea |
let app = new AboutDialogExample();
|
|
Packit |
1470ea |
app.application.run(ARGV);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gio/unstable/GMenu.html">GMenu</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gio/stable/GSimpleAction.html">GSimpleAction</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.AboutDialog.html">Gtk.AboutDialog</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/Gtk.Application.html">Gtk.Application</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkApplicationWindow.html">Gtk.ApplicationWindow</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|