<commit_before>#include <stdlib.h>
#include <gtk/gtk.h>

static void
new_window (GApplication *app,
            GFile        *file)
{
  GtkWidget *window, *scrolled, *view, *overlay;
  GtkSettings *settings;
  gboolean appmenu;

  window = gtk_application_window_new (GTK_APPLICATION (app));
  gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE);
  gtk_window_set_default_size ((GtkWindow*)window, 640, 480);
  gtk_window_set_title (GTK_WINDOW (window), "Sunny");

  overlay = gtk_overlay_new ();
  gtk_container_add (GTK_CONTAINER (window), overlay);

  settings = gtk_settings_get_default ();
  g_object_get (settings, "gtk-shell-shows-app-menu", &appmenu, NULL);
  if (!appmenu)
    {
      GMenuModel *model;
      GtkWidget *menu;
      GtkWidget *image;

      model = gtk_application_get_app_menu (GTK_APPLICATION (app));
      menu = gtk_menu_button_new ();
      gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu), model);
      gtk_widget_set_halign (menu, GTK_ALIGN_END);
      gtk_widget_set_valign (menu, GTK_ALIGN_START);
      image = gtk_image_new ();
      gtk_image_set_from_icon_name (GTK_IMAGE (image),
                                    "sunny",
                                    GTK_ICON_SIZE_MENU);
      gtk_button_set_image (GTK_BUTTON (menu), image);
      gtk_overlay_add_overlay (GTK_OVERLAY (overlay), menu);
    }

  scrolled = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_hexpand (scrolled, TRUE);
  gtk_widget_set_vexpand (scrolled, TRUE);
  view = gtk_text_view_new ();

  gtk_container_add (GTK_CONTAINER (scrolled), view);
  gtk_container_add (GTK_CONTAINER (overlay), scrolled);

  if (file != NULL)
    {
      gchar *contents;
      gsize length;

      if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
        {
          GtkTextBuffer *buffer;

          buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
          gtk_text_buffer_set_text (buffer, contents, length);
          g_free (contents);
        }
    }

  gtk_widget_show_all (GTK_WIDGET (window));
}

static void
activate (GApplication *application)
{
  new_window (application, NULL);
}

static void
open (GApplication  *application,
      GFile        **files,
      gint           n_files,
      const gchar   *hint)
{
  gint i;

  for (i = 0; i < n_files; i++)
    new_window (application, files[i]);
}

typedef GtkApplication MenuButton;
typedef GtkApplicationClass MenuButtonClass;

G_DEFINE_TYPE (MenuButton, menu_button, GTK_TYPE_APPLICATION)

static void
show_about (GSimpleAction *action,
            GVariant      *parameter,
            gpointer       user_data)
{
  gtk_show_about_dialog (NULL,
                         "program-name", "Sunny",
                         "title", "About Sunny",
                         "logo-icon-name", "sunny",
                         "comments", "A cheap Bloatpad clone.",
                         NULL);
}


static void
quit_app (GSimpleAction *action,
          GVariant      *parameter,
          gpointer       user_data)
{
  GList *list, *next;
  GtkWindow *win;

  g_print ("Going down...\n");

  list = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
  while (list)
    {
      win = list->data;
      next = list->next;

      gtk_widget_destroy (GTK_WIDGET (win));

      list = next;
    }
}

static void
new_activated (GSimpleAction *action,
               GVariant      *parameter,
               gpointer       user_data)
{
  GApplication *app = user_data;

  g_application_activate (app);
}

static GActionEntry app_entries[] = {
  { "about", show_about, NULL, NULL, NULL },
  { "quit", quit_app, NULL, NULL, NULL },
  { "new", new_activated, NULL, NULL, NULL }
};

static void
startup (GApplication *application)
{
  GtkBuilder *builder;

  G_APPLICATION_CLASS (menu_button_parent_class)->startup (application);

  g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), application);

  builder = gtk_builder_new ();
  gtk_builder_add_from_string (builder,
                               "<interface>"
                               "  <menu id='app-menu'>"
                               "    <section>"
                               "      <item>"
                               "        <attribute name='label' translatable='yes'>_New Window</attribute>"
                               "        <attribute name='action'>app.new</attribute>"
                               "      </item>"
                               "      <item>"
                               "        <attribute name='label' translatable='yes'>_About Sunny</attribute>"
                               "        <attribute name='action'>app.about</attribute>"
                               "      </item>"
                               "      <item>"
                               "        <attribute name='label' translatable='yes'>_Quit</attribute>"
                               "        <attribute name='action'>app.quit</attribute>"
                               "        <attribute name='accel'>&lt;Primary&gt;q</attribute>"
                               "      </item>"
                               "    </section>"
                               "  </menu>"
                               "</interface>", -1, NULL);<commit_msg>Test headerbar app menu fallback<commit_after>#include <stdlib.h>
#include <gtk/gtk.h>

static void
new_window (GApplication *app,
            GFile        *file)
{
  GtkWidget *window, *scrolled, *view, *overlay;
  GtkWidget *header;

  window = gtk_application_window_new (GTK_APPLICATION (app));
  gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE);
  gtk_window_set_default_size ((GtkWindow*)window, 640, 480);
  gtk_window_set_title (GTK_WINDOW (window), "Sunny");
  gtk_window_set_icon_name (GTK_WINDOW (window), "sunny");

  header = gtk_header_bar_new ();
  gtk_widget_show (header);
  gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Sunny");
  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header), TRUE);
  gtk_header_bar_set_show_fallback_app_menu (GTK_HEADER_BAR (header), TRUE);
  gtk_window_set_titlebar (GTK_WINDOW (window), header);

  overlay = gtk_overlay_new ();
  gtk_container_add (GTK_CONTAINER (window), overlay);

  scrolled = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_hexpand (scrolled, TRUE);
  gtk_widget_set_vexpand (scrolled, TRUE);
  view = gtk_text_view_new ();

  gtk_container_add (GTK_CONTAINER (scrolled), view);
  gtk_container_add (GTK_CONTAINER (overlay), scrolled);

  if (file != NULL)
    {
      gchar *contents;
      gsize length;

      if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
        {
          GtkTextBuffer *buffer;

          buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
          gtk_text_buffer_set_text (buffer, contents, length);
          g_free (contents);
        }
    }

  gtk_widget_show_all (GTK_WIDGET (window));
}

static void
activate (GApplication *application)
{
  new_window (application, NULL);
}

static void
open (GApplication  *application,
      GFile        **files,
      gint           n_files,
      const gchar   *hint)
{
  gint i;

  for (i = 0; i < n_files; i++)
    new_window (application, files[i]);
}

typedef GtkApplication MenuButton;
typedef GtkApplicationClass MenuButtonClass;

G_DEFINE_TYPE (MenuButton, menu_button, GTK_TYPE_APPLICATION)

static void
show_about (GSimpleAction *action,
            GVariant      *parameter,
            gpointer       user_data)
{
  gtk_show_about_dialog (NULL,
                         "program-name", "Sunny",
                         "title", "About Sunny",
                         "logo-icon-name", "sunny",
                         "comments", "A cheap Bloatpad clone.",
                         NULL);
}


static void
quit_app (GSimpleAction *action,
          GVariant      *parameter,
          gpointer       user_data)
{
  GList *list, *next;
  GtkWindow *win;

  g_print ("Going down...\n");

  list = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
  while (list)
    {
      win = list->data;
      next = list->next;

      gtk_widget_destroy (GTK_WIDGET (win));

      list = next;
    }
}

static void
new_activated (GSimpleAction *action,
               GVariant      *parameter,
               gpointer       user_data)
{
  GApplication *app = user_data;

  g_application_activate (app);
}

static GActionEntry app_entries[] = {
  { "about", show_about, NULL, NULL, NULL },
  { "quit", quit_app, NULL, NULL, NULL },
  { "new", new_activated, NULL, NULL, NULL }
};

static void
startup (GApplication *application)
{
  GtkBuilder *builder;

  G_APPLICATION_CLASS (menu_button_parent_class)->startup (application);

  g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), application);

  if (g_getenv ("APP_MENU_FALLBACK"))
    g_object_set (gtk_settings_get_default (), "gtk-shell-shows-app-menu", FALSE, NULL);
 
  builder = gtk_builder_new ();
  gtk_builder_add_from_string (builder,
                               "<interface>"
                               "  <menu id='app-menu'>"
                               "    <section>"
                               "      <item>"
                               "        <attribute name='label' translatable='yes'>_New Window</attribute>"
                               "        <attribute name='action'>app.new</attribute>"
                               "      </item>"
                               "      <item>"
                               "        <attribute name='label' translatable='yes'>_About Sunny</attribute>"
                               "        <attribute name='action'>app.about</attribute>"
                               "      </item>"
                               "      <item>"
                               "        <attribute name='label' translatable='yes'>_Quit</attribute>"
                               "        <attribute name='action'>app.quit</attribute>"
                               "        <attribute name='accel'>&lt;Primary&gt;q</attribute>"
                               "      </item>"
                               "    </section>"
                               "  </menu>"
                               "</interface>", -1, NULL);
{'fraction_non_alphanumeric': 0.10846968238691049, 'fraction_numerical': 0.0015399422521655437, 'mean_word_length': 2.0670011806375443, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5239027', 'n_tokens_mistral': 3259, 'n_tokens_neox': 3095, 'n_words': 631}