summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2014-01-04 02:52:12 -0500
committerRyan Lortie <desrt@desrt.ca>2014-01-08 14:21:19 -0500
commit2bcb4fc354231f6e8a8fe93a1d2aacf62702ded9 (patch)
tree710b513e195452d0ba2be201ac3000064d1e4ac1 /examples
parent2112af719a22a395e97b31164a3de246c7cb447e (diff)
downloadgtk+-2bcb4fc354231f6e8a8fe93a1d2aacf62702ded9.tar.gz
bloatpad: test hidden-when=''
Cook up some silly cases to test out the hidden-when='' attribute. - make sure hidden-when='action-missing' shows/hides items based on actions being created and destroyed - make sure hidden-when='action-disabled' shows/hides items based on actions being enabled and disabled - make sure hidden-when='action-missing' doesn't hide items when the action is merely disabled https://bugzilla.gnome.org/show_bug.cgi?id=688421
Diffstat (limited to 'examples')
-rw-r--r--examples/bloatpad.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/examples/bloatpad.c b/examples/bloatpad.c
index 90e9f33afd..840bdc6747 100644
--- a/examples/bloatpad.c
+++ b/examples/bloatpad.c
@@ -151,10 +151,14 @@ activate_clear_all (GSimpleAction *action,
static void
text_buffer_changed_cb (GtkTextBuffer *buffer,
- BloatPad *app)
+ gpointer user_data)
{
+ GtkWindow *window = user_data;
+ BloatPad *app;
gint old_n, n;
+ app = (BloatPad *) gtk_window_get_application (window);
+
n = gtk_text_buffer_get_char_count (buffer);
if (n > 0)
{
@@ -173,6 +177,17 @@ text_buffer_changed_cb (GtkTextBuffer *buffer,
}
}
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (window), "clear")), n > 0);
+
+ if (n > 0)
+ {
+ GSimpleAction *spellcheck;
+ spellcheck = g_simple_action_new ("spell-check", NULL);
+ g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (spellcheck));
+ }
+ else
+ g_action_map_remove_action (G_ACTION_MAP (window), "spell-check");
+
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));
@@ -274,7 +289,8 @@ new_window (GApplication *app,
}
}
g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)), "changed",
- G_CALLBACK (text_buffer_changed_cb), app);
+ G_CALLBACK (text_buffer_changed_cb), window);
+ text_buffer_changed_cb (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)), window);
gtk_widget_show_all (GTK_WIDGET (window));
}
@@ -545,6 +561,24 @@ bloat_pad_startup (GApplication *application)
" </section>"
" <section>"
" <item>"
+ " <attribute name='label'>Clear (always shown)</attribute>"
+ " <attribute name='action'>win.clear</attribute>"
+ /* action should never be missing (so always shown) */
+ " <attribute name='hidden-when'>action-missing</attribute>"
+ " </item>"
+ " <item>"
+ " <attribute name='label'>Clear (hidden when no text)</attribute>"
+ " <attribute name='hidden-when'>action-disabled</attribute>"
+ " <attribute name='action'>win.clear</attribute>"
+ " </item>"
+ " <item>"
+ " <attribute name='label'>Spell check (does nothing, hides)</attribute>"
+ " <attribute name='hidden-when'>action-missing</attribute>"
+ " <attribute name='action'>win.spell-check</attribute>"
+ " </item>"
+ " </section>"
+ " <section>"
+ " <item>"
" <attribute name='label' translatable='yes'>Accelerators...</attribute>"
" <attribute name='action'>app.edit-accels</attribute>"
" </item>"