diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-12-14 21:36:27 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2013-12-16 13:51:22 -0500 |
commit | 2841c0ec542262218fd805443aaa5ca3cca6d6a0 (patch) | |
tree | 266be43893d058ccfb99dc74d8dd3808327f5e94 /examples | |
parent | 8bdc3ab4c50f57b71777a2bc64970afe61c0bb3e (diff) | |
download | gtk+-2841c0ec542262218fd805443aaa5ca3cca6d6a0.tar.gz |
bloatpad: test inhibit
Add an inhibit for logout when there is context in the text buffer.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bloatpad.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/examples/bloatpad.c b/examples/bloatpad.c index 5ed5e7b475..66ae90daa9 100644 --- a/examples/bloatpad.c +++ b/examples/bloatpad.c @@ -1,6 +1,19 @@ #include <stdlib.h> #include <gtk/gtk.h> +typedef struct +{ + GtkApplication parent_instance; + + guint quit_inhibit; + GMenu *time; + guint timeout; +} BloatPad; + +typedef GtkApplicationClass BloatPadClass; + +G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION) + static void activate_toggle (GSimpleAction *action, GVariant *parameter, @@ -126,10 +139,28 @@ activate_clear (GSimpleAction *action, static void text_buffer_changed_cb (GtkTextBuffer *buffer, - GApplication *app) + BloatPad *app) { gint old_n, n; + n = gtk_text_buffer_get_char_count (buffer); + if (n > 0) + { + if (!app->quit_inhibit) + app->quit_inhibit = gtk_application_inhibit (GTK_APPLICATION (app), + gtk_application_get_active_window (GTK_APPLICATION (app)), + GTK_APPLICATION_INHIBIT_LOGOUT, + "bloatpad can't save, so you can't logout; erase your text"); + } + else + { + if (app->quit_inhibit) + { + gtk_application_uninhibit (GTK_APPLICATION (app), app->quit_inhibit); + app->quit_inhibit = 0; + } + } + old_n = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (buffer), "line-count")); n = gtk_text_buffer_get_line_count (buffer); g_object_set_data (G_OBJECT (buffer), "line-count", GINT_TO_POINTER (n)); @@ -140,7 +171,7 @@ text_buffer_changed_cb (GtkTextBuffer *buffer, n = g_notification_new ("Three lines of text"); g_notification_set_body (n, "Keep up the good work!"); g_notification_add_button (n, "Start over", "app.clear"); - g_application_send_notification (app, "three-lines", n); + g_application_send_notification (G_APPLICATION (app), "three-lines", n); g_object_unref (n); } } @@ -254,18 +285,6 @@ bloat_pad_open (GApplication *application, new_window (application, files[i]); } -typedef struct -{ - GtkApplication parent_instance; - - GMenu *time; - guint timeout; -} BloatPad; - -typedef GtkApplicationClass BloatPadClass; - -G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION) - static void bloat_pad_finalize (GObject *object) { |