/* vim: set noexpandtab tabstop=4 shiftwidth=4 nowrap textwidth=100
*
* Echo Media Player
* Copyright (C) 2008 Shane O'Connell
*
* [ The original file includes a copyright header in this location describing
* the file as being released under the terms of the GNU General Public
* License. It has been removed in order to display the file as part of the
* archive. ]
*/
using Echo.Core;
using Echo.Database;
using Echo.Interfaces;
using Echo.UI.Tabs;
public class Echo.UI.Widgets.TabPane : Gtk.Notebook
{
private Gee.ArrayList<ITab> _tabs;
private Gee.ReadOnlyList<ITab> _read_only_tabs;
public signal void tab_removed();
public Gee.List<ITab> tabs
{
get {
_tabs.clear();
for (int i = 0; i < this.get_n_pages(); i++) {
if (this.get_nth_page(i) is ITab)
_tabs.add((ITab)this.get_nth_page(i));
}
return _read_only_tabs;
}
}
public TabPane()
{
_tabs = new Gee.ArrayList<ITab>();
_read_only_tabs = new Gee.ReadOnlyList<ITab>(_tabs);
this.popup_enable();
this.set_scrollable(true);
}
public void add_tab(ITab tab)
{
Gtk.HBox label = new Gtk.HBox(false, 5);
Gtk.HBox menu_label = new Gtk.HBox(false, 5);
Gtk.Image icon = new Gtk.Image.from_icon_name(tab.get_icon(), Gtk.IconSize.MENU);
Gtk.Image menu_icon = new Gtk.Image.from_icon_name(tab.get_icon(), Gtk.IconSize.MENU);
label.pack_start(icon, false, false, 0);
label.pack_start(new Gtk.Label(tab.get_name()), false, false, 0);
label.show_all();
//var menu_item = new Gtk.ImageMenuItem.with_label(tab.get_name());
//menu_item.set_image(new Gtk.Image.from_icon_name(tab.get_icon(), Gtk.IconSize.MENU));
menu_label.pack_start(menu_icon, false, false, 0);
menu_label.pack_start(new Gtk.Label(tab.get_name()), false, false, 0);
menu_label.show_all();
var event_box = new Gtk.EventBox();
event_box.set_visible_window(false);
event_box.button_press_event += this.on_tab_button_press;
event_box.add(label);
this.append_page_menu(tab, event_box, menu_label);
this.set_tab_reorderable(tab, true);
tab.show_all();
this.set_current_page(Gtk.NotebookPage.num(this, tab));
}
public void switch_to_tab(ITab tab)
{
int page_num = Gtk.NotebookPage.num(this, tab);
assert(page_num >= 0);
this.set_current_page(page_num);
}
private bool on_tab_button_press(Gtk.EventBox tab_label, Gdk.EventButton event)
{
if (event.button == 2) {
for (int i = 0; i < this.get_n_pages(); i++) {
if ((Gtk.Widget)tab_label == this.get_tab_label(this.get_nth_page(i))) {
this.remove_page(i);
tab_removed();
}
}
return true;
}
return false;
}
}