examples: Take advantage of user_data passed

The last parameter of the signal callback from .ui
is the template's object from which the class is
derived.

And so, we already have access to the window object.
Let's just use it.
This commit is contained in:
Mohammed Sadiq 2018-05-08 18:17:54 +05:30
parent f07b131362
commit 8fcc401e05
4 changed files with 20 additions and 38 deletions

View File

@ -22,9 +22,9 @@ struct _ExampleAppWindow
G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
static void
search_text_changed (GtkEntry *entry)
search_text_changed (GtkEntry *entry,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
const gchar *text;
GtkWidget *tab;
GtkWidget *view;
@ -36,8 +36,6 @@ search_text_changed (GtkEntry *entry)
if (text[0] == '\0')
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@ -154,14 +152,12 @@ update_lines (ExampleAppWindow *win)
static void
visible_child_changed (GObject *stack,
GParamSpec *pspec)
GParamSpec *pspec,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
update_words (win);
update_lines (win);

View File

@ -16,9 +16,9 @@ struct _ExampleAppWindow
G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
static void
search_text_changed (GtkEntry *entry)
search_text_changed (GtkEntry *entry,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
const gchar *text;
GtkWidget *tab;
GtkWidget *view;
@ -30,8 +30,6 @@ search_text_changed (GtkEntry *entry)
if (text[0] == '\0')
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@ -49,15 +47,12 @@ search_text_changed (GtkEntry *entry)
static void
visible_child_changed (GObject *stack,
GParamSpec *pspec)
GParamSpec *pspec,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
}

View File

@ -20,9 +20,9 @@ struct _ExampleAppWindow
G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
static void
search_text_changed (GtkEntry *entry)
search_text_changed (GtkEntry *entry,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
const gchar *text;
GtkWidget *tab;
GtkWidget *view;
@ -34,8 +34,6 @@ search_text_changed (GtkEntry *entry)
if (text[0] == '\0')
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@ -120,15 +118,12 @@ done:
static void
visible_child_changed (GObject *stack,
GParamSpec *pspec)
GParamSpec *pspec,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
update_words (win);
}

View File

@ -22,9 +22,9 @@ struct _ExampleAppWindow
G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
static void
search_text_changed (GtkEntry *entry)
search_text_changed (GtkEntry *entry,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
const gchar *text;
GtkWidget *tab;
GtkWidget *view;
@ -36,8 +36,6 @@ search_text_changed (GtkEntry *entry)
if (text[0] == '\0')
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@ -154,14 +152,12 @@ update_lines (ExampleAppWindow *win)
static void
visible_child_changed (GObject *stack,
GParamSpec *pspec)
GParamSpec *pspec,
ExampleAppWindow *win)
{
ExampleAppWindow *win;
if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
return;
win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
update_words (win);
update_lines (win);