General improvement
[valaterm:valaterm.git] / src / menu-bar.vala
1 /****************************
2 ** Copyright © 2011 Jacques-Pascal Deplaix
3 **
4 ** ValaTerm is free software: you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation, either version 3 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 ****************************/
17
18 public class Menubar : Gtk.MenuBar
19 {
20         private Gtk.ImageMenuItem item_about = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.ABOUT,
21                                                                                                                                                         null);
22         private Gtk.ImageMenuItem item_preferences = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.PREFERENCES,
23                                                                                                                                                                   null);
24         private Gtk.ImageMenuItem item_clear = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.CLEAR,
25                                                                                                                                                         null);
26         private Gtk.ImageMenuItem item_copy = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.COPY,
27                                                                                                                                                    null);
28         private Gtk.ImageMenuItem item_paste = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.PASTE,
29                                                                                                                                                         null);
30         private Gtk.AccelGroup accel_group = new Gtk.AccelGroup();
31
32         public Menubar()
33         {
34                 this.item_clear.label = _("Clear");
35                 this.item_preferences.label = _("Preferences");
36                 this.item_about.label = _("About");
37                 this.item_copy.label = _("Copy");
38                 this.item_paste.label = _("Paste");
39
40                 // Just an exemple:
41                 // this.item.accel_group = this.accel_group;
42
43                 var menu_edit = new Gtk.MenuItem.with_label(_("Edit"));
44                 var submenu_edit = new Gtk.Menu();
45                 menu_edit.set_submenu(submenu_edit);
46                 submenu_edit.append(this.item_copy);
47                 submenu_edit.append(this.item_paste);
48                 submenu_edit.append(new Gtk.SeparatorMenuItem());
49                 submenu_edit.append(this.item_preferences);
50
51                 var menu_tools = new Gtk.MenuItem.with_label(_("Tools"));
52                 var submenu_tools = new Gtk.Menu();
53                 menu_tools.set_submenu(submenu_tools);
54                 submenu_tools.append(this.item_clear);
55
56                 var menu_help = new Gtk.MenuItem.with_label(_("Help"));
57                 var submenu_help = new Gtk.Menu();
58                 menu_help.set_submenu(submenu_help);
59                 submenu_help.append(this.item_about);
60
61                 this.append(menu_edit);
62                 this.append(menu_tools);
63                 this.append(menu_help);
64         }
65
66         public void active_signals(Delegates.AccelGroup add_accel_group,
67                                                            Delegates.Void about,
68                                                            Delegates.Void preferences,
69                                                            Delegates.Void clear,
70                                                            Delegates.Void copy,
71                                                            Delegates.Void paste)
72         {
73                 add_accel_group(this.accel_group);
74
75                 this.item_about.activate.connect(() => about());
76                 this.item_preferences.activate.connect(() => preferences());
77                 this.item_clear.activate.connect(() => clear());
78                 this.item_copy.activate.connect(() => copy());
79                 this.item_paste.activate.connect(() => paste());
80         }
81 }