examples: More deprecation cleanup

Remove GtkDialog use from bloatpad.
This commit is contained in:
Matthias Clasen 2023-08-04 09:46:54 -04:00
parent 7c8171f069
commit ce4fbcef8e

View File

@ -1,8 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct typedef struct
{ {
GtkApplication parent_instance; GtkApplication parent_instance;
@ -356,8 +354,8 @@ combo_changed (GtkDropDown *combo,
GParamSpec *pspec, GParamSpec *pspec,
gpointer user_data) gpointer user_data)
{ {
GtkDialog *dialog = user_data;
GtkEntry *entry = g_object_get_data (user_data, "entry"); GtkEntry *entry = g_object_get_data (user_data, "entry");
GtkWidget *set_button = g_object_get_data (user_data, "set-button");
const char *action; const char *action;
char **accels; char **accels;
char *str; char *str;
@ -372,7 +370,7 @@ combo_changed (GtkDropDown *combo,
g_strfreev (accels); g_strfreev (accels);
gtk_editable_set_text (GTK_EDITABLE (entry), str); gtk_editable_set_text (GTK_EDITABLE (entry), str);
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_APPLY, FALSE); gtk_widget_set_sensitive (set_button, FALSE);
} }
static void static void
@ -380,15 +378,21 @@ entry_changed (GtkEntry *entry,
GParamSpec *pspec, GParamSpec *pspec,
gpointer user_data) gpointer user_data)
{ {
GtkDialog *dialog = user_data; GtkWidget *set_button = g_object_get_data (user_data, "set-button");
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_APPLY, TRUE); gtk_widget_set_sensitive (set_button, TRUE);
} }
static void static void
response (GtkDialog *dialog, close_clicked (GtkButton *button,
guint response_id, gpointer user_data)
gpointer user_data) {
gtk_window_destroy (GTK_WINDOW (user_data));
}
static void
set_clicked (GtkButton *button,
gpointer user_data)
{ {
GtkEntry *entry = g_object_get_data (user_data, "entry"); GtkEntry *entry = g_object_get_data (user_data, "entry");
GtkDropDown *combo = g_object_get_data (user_data, "combo"); GtkDropDown *combo = g_object_get_data (user_data, "combo");
@ -396,12 +400,6 @@ response (GtkDialog *dialog,
const char *str; const char *str;
char **accels; char **accels;
if (response_id == GTK_RESPONSE_CANCEL)
{
gtk_window_destroy (GTK_WINDOW (dialog));
return;
}
action = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_drop_down_get_selected_item (combo))); action = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_drop_down_get_selected_item (combo)));
if (!action) if (!action)
@ -413,7 +411,7 @@ response (GtkDialog *dialog,
gtk_application_set_accels_for_action (gtk_window_get_application (user_data), action, (const char **) accels); gtk_application_set_accels_for_action (gtk_window_get_application (user_data), action, (const char **) accels);
g_strfreev (accels); g_strfreev (accels);
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_APPLY, FALSE); gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
} }
static void static void
@ -424,32 +422,45 @@ edit_accels (GSimpleAction *action,
GtkApplication *app = user_data; GtkApplication *app = user_data;
GtkWidget *combo; GtkWidget *combo;
GtkWidget *entry; GtkWidget *entry;
GtkWidget *header;
GtkWidget *close_button;
GtkWidget *set_button;
GtkWidget *box;
char **actions; char **actions;
GtkWidget *dialog; GtkWidget *dialog;
int i; int i;
GtkStringList *strings; GtkStringList *strings;
dialog = gtk_dialog_new_with_buttons ("Accelerators", dialog = gtk_window_new ();
NULL, gtk_window_set_title (GTK_WINDOW (dialog), "Accelerators");
GTK_DIALOG_USE_HEADER_BAR,
"Close", GTK_RESPONSE_CANCEL,
"Set", GTK_RESPONSE_APPLY,
NULL);
gtk_window_set_application (GTK_WINDOW (dialog), app); gtk_window_set_application (GTK_WINDOW (dialog), app);
actions = gtk_application_list_action_descriptions (app); actions = gtk_application_list_action_descriptions (app);
strings = gtk_string_list_new (NULL); header = gtk_header_bar_new ();
combo = gtk_drop_down_new (G_LIST_MODEL (strings), NULL); gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
g_object_set (gtk_dialog_get_content_area (GTK_DIALOG (dialog)), close_button = gtk_button_new_with_label ("Close");
g_signal_connect (close_button, "clicked", G_CALLBACK (close_clicked), dialog);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), close_button);
set_button = gtk_button_new_with_label ("Set");
g_signal_connect (set_button, "clicked", G_CALLBACK (set_clicked), dialog);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), set_button);
gtk_window_set_titlebar (GTK_WINDOW (dialog), header);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
g_object_set (box,
"margin-top", 10, "margin-top", 10,
"margin-bottom", 10, "margin-bottom", 10,
"margin-start", 10, "margin-start", 10,
"margin-end", 10, "margin-end", 10,
"spacing", 10,
NULL); NULL);
gtk_window_set_child (GTK_WINDOW (dialog), box);
strings = gtk_string_list_new (NULL);
combo = gtk_drop_down_new (G_LIST_MODEL (strings), NULL);
gtk_box_append (GTK_BOX (box), combo);
gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), combo);
for (i = 0; actions[i]; i++) for (i = 0; actions[i]; i++)
gtk_string_list_append (strings, actions[i]); gtk_string_list_append (strings, actions[i]);
g_signal_connect (combo, "notify::selected", G_CALLBACK (combo_changed), dialog); g_signal_connect (combo, "notify::selected", G_CALLBACK (combo_changed), dialog);
@ -458,10 +469,10 @@ edit_accels (GSimpleAction *action,
gtk_widget_set_hexpand (entry, TRUE); gtk_widget_set_hexpand (entry, TRUE);
g_signal_connect (entry, "notify::text", G_CALLBACK (entry_changed), dialog); g_signal_connect (entry, "notify::text", G_CALLBACK (entry_changed), dialog);
gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), entry); gtk_box_append (GTK_BOX (box), entry);
g_signal_connect (dialog, "response", G_CALLBACK (response), dialog);
g_object_set_data (G_OBJECT (dialog), "combo", combo); g_object_set_data (G_OBJECT (dialog), "combo", combo);
g_object_set_data (G_OBJECT (dialog), "entry", entry); g_object_set_data (G_OBJECT (dialog), "entry", entry);
g_object_set_data (G_OBJECT (dialog), "set-button", set_button);
gtk_drop_down_set_selected (GTK_DROP_DOWN (combo), 0); gtk_drop_down_set_selected (GTK_DROP_DOWN (combo), 0);