/*
 * Compile me with
 * gcc -o bug ctrlshiftslashbug.c `pkg-config --cflags --libs gtk+-2.0`
 */
#include <gtk/gtk.h>

const gchar *ui = 
	"<ui>"
	"  <menubar>"
	"    <menu action=\"bugging\">"
	"      <menuitem action=\"bug-me\"/>"
	"      <menuitem action=\"dont-bug-me\"/>"
	"    </menu>"
	"  </menubar>"
	"</ui>";

static void
bug_me(GtkAction *action, GtkLabel *label)
{
	gtk_label_set_text(label, "Bug me!");
}

static void
dont_bug_me(GtkAction *action, GtkLabel *label)
{
	gtk_label_set_text(label, "Don't bug me!");
}

int
main(int argc, char **argv)
{
	gtk_init(&argc, &argv);

	/* Create actions */
	GtkAction *actionname = gtk_action_new("bugging", "_Bugging", NULL, NULL);
	GtkAction *action1 = gtk_action_new("bug-me", "_Bug me!", "Bug me by ignoring my accelerator", NULL);
	GtkAction *action2 = gtk_action_new("dont-bug-me", "_Don't bug me", "Behave fine", NULL);
	GtkActionGroup *actiongroup = gtk_action_group_new("group");
	gtk_action_group_add_action(actiongroup, actionname);
	gtk_action_group_add_action_with_accel(actiongroup, action1, "<ctrl><shift>slash");
	gtk_action_group_add_action_with_accel(actiongroup, action2, "<ctrl><alt>slash");
	GtkUIManager *manager = gtk_ui_manager_new();
	gtk_ui_manager_add_ui_from_string(manager, ui, -1, NULL);
	gtk_ui_manager_insert_action_group(manager, actiongroup, 0);

	/* Create widgets */
	GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	GtkWidget *menubar = gtk_ui_manager_get_widget(manager, "/ui/menubar");
	GtkWidget *vbox = gtk_vbox_new(FALSE, 6);
	GtkWidget *label = gtk_label_new("Nothing has happened yet");
	
	/* Set up widgets */
	g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
	g_signal_connect(action1, "activate", G_CALLBACK(bug_me), label);
	g_signal_connect(action2, "activate", G_CALLBACK(dont_bug_me), label);
	gtk_label_set_width_chars(GTK_LABEL(label), 40);
	gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(manager));
	
	/* Put widgets together */
	gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
	gtk_box_pack_end(GTK_BOX(vbox), label, FALSE, FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), vbox);
	
	/* Go */
	gtk_widget_show_all(window);
	gtk_main();
	
	g_object_unref(manager);

	return 0;	
}
