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

struct {
    GtkWidget *web_view;
    GtkWidget *address_label;
    GtkWidget *address_entry;
    GtkWidget *scripts_label;
} ui;

void enable_scripts(gboolean enable){
    g_object_set(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(ui.web_view)), "enable-scripts", enable, NULL);
    gtk_widget_set_visible(ui.scripts_label, enable);
}

void show_address_label(){
    gtk_widget_hide(ui.address_entry);
    gtk_widget_show(ui.address_label);
}

void go(){
    webkit_web_view_load_uri(WEBKIT_WEB_VIEW(ui.web_view), gtk_entry_get_text(GTK_ENTRY(ui.address_entry)));
    show_address_label();
}

void update_address_label(){
    if(webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(ui.web_view)) == WEBKIT_LOAD_COMMITTED)
        gtk_label_set_text(GTK_LABEL(ui.address_label), webkit_web_view_get_uri(WEBKIT_WEB_VIEW(ui.web_view)));
}

void show_address_entry(){
    const gchar *uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(ui.web_view));
    gtk_entry_set_text(GTK_ENTRY(ui.address_entry), uri ? uri : "");
    gtk_widget_hide(ui.address_label);
    gtk_widget_show(ui.address_entry);
    gtk_widget_grab_focus(ui.address_entry);
}

bool on_key_press(GtkWidget *widget, GdkEventKey *event){
    if(gtk_widget_get_visible(ui.address_entry)){
        if(event->keyval == GDK_KEY_Escape){
            show_address_label();
            return TRUE;
        }
        else return FALSE;
    }
    switch(event->keyval){
        case GDK_KEY_u: show_address_entry();  return TRUE;
        case GDK_KEY_j: enable_scripts(FALSE); return TRUE;
        case GDK_KEY_J: enable_scripts(TRUE);  return TRUE;
    }
    return FALSE;
}

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

    // Window

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_add_events(window, GDK_KEY_PRESS_MASK);
    gtk_window_set_has_resize_grip(GTK_WINDOW(window), FALSE);
    g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);

    GtkWidget *layout = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_widget_show(layout);

    // Web view

    ui.web_view = webkit_web_view_new();
    g_signal_connect(ui.web_view, "notify::load-status", G_CALLBACK(update_address_label), NULL);<commit_msg>reload key: r<commit_after>#include <gtk/gtk.h>
#include <webkit/webkit.h>

struct {
    GtkWidget *web_view;
    GtkWidget *address_label;
    GtkWidget *address_entry;
    GtkWidget *scripts_label;
} ui;

void enable_scripts(gboolean enable){
    g_object_set(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(ui.web_view)), "enable-scripts", enable, NULL);
    gtk_widget_set_visible(ui.scripts_label, enable);
}

void show_address_label(){
    gtk_widget_hide(ui.address_entry);
    gtk_widget_show(ui.address_label);
}

void go(){
    webkit_web_view_load_uri(WEBKIT_WEB_VIEW(ui.web_view), gtk_entry_get_text(GTK_ENTRY(ui.address_entry)));
    show_address_label();
}

void update_address_label(){
    if(webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(ui.web_view)) == WEBKIT_LOAD_COMMITTED)
        gtk_label_set_text(GTK_LABEL(ui.address_label), webkit_web_view_get_uri(WEBKIT_WEB_VIEW(ui.web_view)));
}

void show_address_entry(){
    const gchar *uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(ui.web_view));
    gtk_entry_set_text(GTK_ENTRY(ui.address_entry), uri ? uri : "");
    gtk_widget_hide(ui.address_label);
    gtk_widget_show(ui.address_entry);
    gtk_widget_grab_focus(ui.address_entry);
}

bool on_key_press(GtkWidget *widget, GdkEventKey *event){
    if(gtk_widget_get_visible(ui.address_entry)){
        if(event->keyval == GDK_KEY_Escape){
            show_address_label();
            return TRUE;
        }
        else return FALSE;
    }
    switch(event->keyval){
        case GDK_KEY_u: show_address_entry();  return TRUE;
        case GDK_KEY_j: enable_scripts(FALSE); return TRUE;
        case GDK_KEY_J: enable_scripts(TRUE);  return TRUE;
        case GDK_KEY_r: webkit_web_view_reload(WEBKIT_WEB_VIEW(ui.web_view)); return TRUE;
        case GDK_KEY_R: webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(ui.web_view)); return TRUE;
    }
    return FALSE;
}

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

    // Window

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_add_events(window, GDK_KEY_PRESS_MASK);
    gtk_window_set_has_resize_grip(GTK_WINDOW(window), FALSE);
    g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);

    GtkWidget *layout = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_widget_show(layout);

    // Web view

    ui.web_view = webkit_web_view_new();
    g_signal_connect(ui.web_view, "notify::load-status", G_CALLBACK(update_address_label), NULL);
{'fraction_non_alphanumeric': 0.11269035532994924, 'fraction_numerical': 0.0004060913705583756, 'mean_word_length': 4.9564691656590085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1402913', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1834, 'n_words': 247}