#include <gtk/gtk.h>

int main(int argc, char **argv)
{
  GtkWidget *shortcuts_window;

  GtkWidget *shortcuts_section_a;
  GtkWidget *shortcuts_group_a;
  GtkWidget *shortcuts_shortcut_a1;
  GtkWidget *shortcuts_shortcut_a2;

  GtkWidget *shortcuts_section_b;
  GtkWidget *shortcuts_group_b;
  GtkWidget *shortcuts_shortcut_b;

  gtk_init (&argc, &argv);


  /*
   *  GtkShortcutsShortcut
   */

  shortcuts_shortcut_a1 = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
                                        "accelerator", "<Ctrl>O",
                                        "title", "Open file",
                                        "subtitle", "Use this keyboard shortcut to load a file from disk.",
                                        NULL);
  shortcuts_shortcut_a2 = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
                                        "accelerator", "<Ctrl>S",
                                        "title", "Save file",
                                        "subtitle", "Use this keyboard shortcut to save a file to disk.",
                                        NULL);

  shortcuts_shortcut_b = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
                                       "accelerator", "<Ctrl>R",
                                       "title", "Refresh",
                                       "subtitle", "This shortcut magically refreshes all your Widgets.",
                                       NULL);


  /*
   *  GtkShortcutsGroup
   */

  shortcuts_group_a = g_object_new (GTK_TYPE_SHORTCUTS_GROUP,
                                    "title", "File management",
                                    NULL);
  gtk_container_add (GTK_CONTAINER (shortcuts_group_a), shortcuts_shortcut_a1);
  gtk_container_add (GTK_CONTAINER (shortcuts_group_a), shortcuts_shortcut_a2);

  shortcuts_group_b = g_object_new (GTK_TYPE_SHORTCUTS_GROUP,
                                    "title", "Other shortcuts",
                                    NULL);
  gtk_container_add (GTK_CONTAINER (shortcuts_group_b), shortcuts_shortcut_b);


  /*
   *  GtkShortcutsSection
   */

  shortcuts_section_a = g_object_new (GTK_TYPE_SHORTCUTS_SECTION,
                                      "section-name", "the-section",
                                      "title", "Section A",
                                      NULL);
  /* !!!
   *  Manually show()ing at least 1 Section is mandatory, BEFORE adding to the Window,
   *  because otherwise the Window opens on Search Results with no way out.
   *  GtkShortcutsWindow's show_all() does not suffice, as it excludes Sections.
   */
  gtk_widget_show (shortcuts_section_a);
  gtk_container_add (GTK_CONTAINER (shortcuts_section_a), shortcuts_group_a);

  shortcuts_section_b = g_object_new (GTK_TYPE_SHORTCUTS_SECTION,
                                      "section-name", "another-section",
                                      "title", "Section B",
                                      NULL);
  // N.B. we only need to manually show() one Section; this one doesn't need it!
  gtk_container_add (GTK_CONTAINER (shortcuts_section_b), shortcuts_group_b);


  /*
   *  GtkShortcutsWindow
   */

  shortcuts_window = g_object_new (GTK_TYPE_SHORTCUTS_WINDOW,
                                   "title", "Keyboard shortcuts",
                                   NULL);
  gtk_container_add (GTK_CONTAINER (shortcuts_window), shortcuts_section_a);
  gtk_container_add (GTK_CONTAINER (shortcuts_window), shortcuts_section_b);


  /*
   *  Run
   */

  g_signal_connect (G_OBJECT (shortcuts_window), "delete-event",
                    G_CALLBACK (&gtk_main_quit), NULL);
  /* N.B. warning in !! comment above */
  gtk_widget_show_all (shortcuts_window);
  gtk_main ();
}
