#include <gtk/gtk.h>

typedef struct
{
  GtkWindow parent_instance;

  GtkUIManager *manager;
  GtkActionGroup *group;
} CrashyWindow;

typedef GtkWindowClass CrashyWindowClass;

G_DEFINE_TYPE (CrashyWindow, crashy_window, GTK_TYPE_WINDOW)

void
quit_callback (GtkAction   *action,
               CrashyWindow *window)
{
  gtk_widget_destroy (GTK_WIDGET (window));
}

static const GtkActionEntry action_entries[] =
{
  { "File", NULL, "_File" },
  { "FileQuit", GTK_STOCK_QUIT, NULL, "<control>Q", "Quit the program", G_CALLBACK (quit_callback) }
};

/* separate group, should be sensitive even when there are no tabs */
static const GtkActionEntry crashy_quit_menu_entries[] =
{
};

static void
crashy_window_dispose (GObject *object)
{
  CrashyWindow *window = (CrashyWindow *) object;

  g_clear_object (&window->manager);
  g_clear_object (&window->group);

  G_OBJECT_CLASS (crashy_window_parent_class)->dispose (object);
}

static void
crashy_window_class_init (CrashyWindowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = crashy_window_dispose;
}

static void
crashy_window_init (CrashyWindow *window)
{
  window->manager = gtk_ui_manager_new ();

  gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (window->manager));

  window->group = gtk_action_group_new ("Actions");
  gtk_action_group_add_actions (window->group, action_entries, G_N_ELEMENTS (action_entries), window);
  gtk_ui_manager_insert_action_group (window->manager, window->group, 0);

  gtk_ui_manager_add_ui_from_string (window->manager,
                                     "<ui>"
                                       "<menubar name='MenuBar'>"
                                        "<menu name='FileMenu' action='File'>"
                                         "<menuitem name='FileQuitMenu' action='FileQuit'/>"
                                        "</menu>"
                                       "</menubar>"
                                      "</ui>", -1, NULL);
}

int
main (void)
{
  gtk_init (0, 0);
  gtk_widget_show (g_object_new (crashy_window_get_type (), NULL));
  gtk_main ();
}
