
#include <gtk/gtk.h>
#include "eggsidebar.h"

static GList *buttons = NULL;

static void
deleted_cb (GtkWidget *button, gpointer blah)
{
	GList *bla = g_list_next (g_list_find (buttons, button));
	gtk_widget_destroy (button);
	if (bla != NULL)
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bla->data), TRUE);
	else
	{
		bla = g_list_previous (g_list_find (buttons, button));
		if (bla != NULL)
			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bla->data), TRUE);

	}
	buttons = g_list_remove (buttons, button);
}

static void
bla_cb (GtkWidget *bla, GtkWidget *sidebar)
{

	EggSidebarButton *button;

	button = egg_sidebar_button_new ("newbutton");
	egg_sidebar_button_set (button, GTK_STOCK_DELETE, "_Gloup", FALSE);
	egg_sidebar_append (EGG_SIDEBAR (sidebar), button);
	g_signal_connect (G_OBJECT (button), "deleted", G_CALLBACK (deleted_cb), NULL);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
	buttons = g_list_append (buttons, button);
}

int
main (int argc, char *argv[])
{
	GtkWidget *window;
	GtkWidget *sidebar, *x, *box;
	EggSidebarButton *button;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (G_OBJECT (window), "destroy", gtk_main_quit, NULL);

	sidebar = egg_sidebar_new ();

	button = egg_sidebar_button_new ("button1");
	egg_sidebar_button_set (button, GTK_STOCK_COPY, "_Copy Time", TRUE);
	egg_sidebar_append (EGG_SIDEBAR (sidebar), button);
	g_signal_connect (G_OBJECT (button), "deleted", G_CALLBACK (deleted_cb), NULL);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
	buttons = g_list_append (buttons, button);

	x = gtk_button_new_with_label ("Goo");
	g_signal_connect (G_OBJECT (x),
			  "clicked",
			  G_CALLBACK (bla_cb),
			  sidebar);
	box = gtk_vbox_new (FALSE, 0);
	gtk_box_pack_start_defaults (GTK_BOX (box), sidebar);
	gtk_box_pack_start_defaults (GTK_BOX (box), x);
	gtk_container_add (GTK_CONTAINER (window), box);
	gtk_widget_show_all (window);

	gtk_main ();
	
	return 0;
}
