|
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 |
}
|