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
This commit is contained in:
Ryan Lortie 2014-01-04 02:52:12 -05:00
parent 2112af719a
commit 2bcb4fc354

View File

@ -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>"