|
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="toolbar.vala" xml:lang="es">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Barra de herramientas (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#menu-combo-toolbar"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.vala"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-08" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Una barra de botones</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Daniel Mustieles</mal:name>
|
|
Packit |
1470ea |
<mal:email>daniel.mustieles@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011 - 2017</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Nicolás Satragno</mal:name>
|
|
Packit |
1470ea |
<mal:email>nsatragno@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012 - 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Jorge González</mal:name>
|
|
Packit |
1470ea |
<mal:email>jorgegonz@svn.gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Barra de herramientas</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/toolbar.png"/>
|
|
Packit |
1470ea |
La barra de herramientas puede contener texto o iconos del almacén. En este ejemplo se usan iconos del almacén. Este ejemplo funciona a pantalla completa.
|
|
Packit |
1470ea |
Este ejemplo usa SimpleActions (ventana y aplicación). Las acciones de la aplicación se pueden añadir fácilmente al menú de la aplicación.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the Window */
|
|
Packit |
1470ea |
class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Instance variables belonging to the window */
|
|
Packit |
1470ea |
Gtk.Toolbar toolbar;
|
|
Packit |
1470ea |
Gtk.ToolButton new_button;
|
|
Packit |
1470ea |
Gtk.ToolButton open_button;
|
|
Packit |
1470ea |
Gtk.ToolButton undo_button;
|
|
Packit |
1470ea |
Gtk.ToolButton fullscreen_button;
|
|
Packit |
1470ea |
Gtk.ToolButton leave_fullscreen_button;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Constructor */
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "Toolbar Example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.set_default_size (400, 200);
|
|
Packit |
1470ea |
var grid = new Gtk.Grid ();
|
|
Packit |
1470ea |
this.add (grid);
|
|
Packit |
1470ea |
grid.show ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
create_toolbar ();
|
|
Packit |
1470ea |
toolbar.set_hexpand (true);
|
|
Packit |
1470ea |
grid.attach (toolbar, 0, 0, 1, 1);
|
|
Packit |
1470ea |
toolbar.show ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* create the "undo" window action action */
|
|
Packit |
1470ea |
var undo_action = new SimpleAction ("undo", null);
|
|
Packit |
1470ea |
undo_action.activate.connect (undo_callback);
|
|
Packit |
1470ea |
this.add_action (undo_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* create the "fullscreen" window action */
|
|
Packit |
1470ea |
var fullscreen_action = new SimpleAction ("fullscreen", null);
|
|
Packit |
1470ea |
fullscreen_action.activate.connect (fullscreen_callback);
|
|
Packit |
1470ea |
this.add_action (fullscreen_action);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This function creates the toolbar, its ToolButtons,
|
|
Packit |
1470ea |
* and assigns the actions names to the ToolButtons.*/
|
|
Packit |
1470ea |
void create_toolbar () {
|
|
Packit |
1470ea |
toolbar = new Gtk.Toolbar ();
|
|
Packit |
1470ea |
toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
new_button = new Gtk.ToolButton.from_stock (Gtk.Stock.NEW);
|
|
Packit |
1470ea |
new_button.is_important = true; //decides whether to show the label
|
|
Packit |
1470ea |
toolbar.add (new_button);
|
|
Packit |
1470ea |
new_button.show ();
|
|
Packit |
1470ea |
new_button.action_name = "app.new";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
open_button = new Gtk.ToolButton.from_stock (Gtk.Stock.OPEN);
|
|
Packit |
1470ea |
open_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (open_button);
|
|
Packit |
1470ea |
open_button.show ();
|
|
Packit |
1470ea |
open_button.action_name = "app.open";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
undo_button = new Gtk.ToolButton.from_stock (Gtk.Stock.UNDO);
|
|
Packit |
1470ea |
undo_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (undo_button);
|
|
Packit |
1470ea |
undo_button.show ();
|
|
Packit |
1470ea |
undo_button.action_name = "win.undo";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
fullscreen_button = new Gtk.ToolButton.from_stock (Gtk.Stock.FULLSCREEN);
|
|
Packit |
1470ea |
fullscreen_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (fullscreen_button);
|
|
Packit |
1470ea |
fullscreen_button.show ();
|
|
Packit |
1470ea |
fullscreen_button.action_name = "win.fullscreen";
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
leave_fullscreen_button = new Gtk.ToolButton.from_stock (Gtk.Stock.LEAVE_FULLSCREEN)
|
|
Packit |
1470ea |
;
|
|
Packit |
1470ea |
leave_fullscreen_button.is_important = true;
|
|
Packit |
1470ea |
toolbar.add (leave_fullscreen_button);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
leave_fullscreen_button.action_name = "win.fullscreen";
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void undo_callback (SimpleAction simple, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"Undo\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void fullscreen_callback (SimpleAction simple, Variant? parameter) {
|
|
Packit |
1470ea |
if ((this.get_window ().get_state () & Gdk.WindowState.FULLSCREEN) != 0) {
|
|
Packit |
1470ea |
this.unfullscreen ();
|
|
Packit |
1470ea |
leave_fullscreen_button.hide ();
|
|
Packit |
1470ea |
fullscreen_button.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
else {
|
|
Packit |
1470ea |
this.fullscreen ();
|
|
Packit |
1470ea |
fullscreen_button.hide ();
|
|
Packit |
1470ea |
leave_fullscreen_button.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the application */
|
|
Packit |
1470ea |
class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
protected override void startup () {
|
|
Packit |
1470ea |
base.startup ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the "new" action and add it to the app*/
|
|
Packit |
1470ea |
var new_action = new SimpleAction ("new", null);
|
|
Packit |
1470ea |
new_action.activate.connect (new_callback);
|
|
Packit |
1470ea |
this.add_action (new_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the "open" action, and add it to the app */
|
|
Packit |
1470ea |
var open_action = new SimpleAction ("open", null);
|
|
Packit |
1470ea |
open_action.activate.connect (open_callback);
|
|
Packit |
1470ea |
this.add_action (open_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* You could also add the action to the app menu
|
|
Packit |
1470ea |
* if you wanted to.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
//var menu = new Menu ();
|
|
Packit |
1470ea |
//menu.append ("New", "app.new");
|
|
Packit |
1470ea |
//this.app_menu = menu;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void new_callback (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"New\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void open_callback (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"Open\".\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The main function creates the application and runs it. */
|
|
Packit |
1470ea |
int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
En este ejemplo se usa lo siguiente:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.Toolbar.html">Gtk.Toolbar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.ToolButton.html">Gtk.Toolbutton</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.Stock.html">Gtk.Stock</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</page>
|