From ed611b69bac58e5abb0ed9b0a5ab3f06f3f14570 Mon Sep 17 00:00:00 2001 From: Iulian Radu Date: Tue, 23 Aug 2016 14:46:10 +0300 Subject: properties-grid: Toggle action's enabled state instead of button's sensitivity --- src/ephy-bookmark-properties-grid.c | 21 +++++++++++++++++---- src/resources/gtk/bookmark-properties-grid.ui | 1 - 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ephy-bookmark-properties-grid.c b/src/ephy-bookmark-properties-grid.c index 85b45b8ab..510216d3f 100644 --- a/src/ephy-bookmark-properties-grid.c +++ b/src/ephy-bookmark-properties-grid.c @@ -224,8 +224,10 @@ ephy_bookmarks_properties_grid_actions_add_tag (GSimpleAction *action, widget = ephy_bookmark_properties_grid_create_tag_widget (self, text, TRUE); gtk_flow_box_insert (GTK_FLOW_BOX (self->tags_box), widget, -1); + /* Empty entry and disable button's action until new text is inserted */ gtk_entry_set_text (GTK_ENTRY (self->add_tag_entry), ""); - gtk_widget_set_sensitive (GTK_WIDGET (self->add_tag_button), FALSE); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); + gtk_widget_grab_focus (GTK_WIDGET (self->add_tag_entry)); } @@ -248,16 +250,20 @@ ephy_bookmark_properties_grid_buffer_text_changed_cb (EphyBookmarkPropertiesGrid GParamSpec *pspec, GtkEntryBuffer *buffer) { + GActionGroup *group; + GAction *action; const char *text; g_assert (EPHY_IS_BOOKMARK_PROPERTIES_GRID (self)); g_assert (GTK_IS_ENTRY_BUFFER (buffer)); + group = gtk_widget_get_action_group (GTK_WIDGET (self), "grid"); + action = g_action_map_lookup_action (G_ACTION_MAP (group), "add-tag"); text = gtk_entry_buffer_get_text (buffer); - if (strlen (text) >= 3 && !ephy_bookmarks_manager_tag_exists (self->manager, text)) - gtk_widget_set_sensitive (self->add_tag_button, TRUE); + if (ephy_bookmarks_manager_tag_exists (self->manager, text)) + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); else - gtk_widget_set_sensitive (self->add_tag_button, FALSE); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE); } static void @@ -436,6 +442,7 @@ static void ephy_bookmark_properties_grid_init (EphyBookmarkPropertiesGrid *self) { GSimpleActionGroup *group; + GAction *action; gtk_widget_init_template (GTK_WIDGET (self)); @@ -450,6 +457,12 @@ ephy_bookmark_properties_grid_init (EphyBookmarkPropertiesGrid *self) G_N_ELEMENTS (entries), self); gtk_widget_insert_action_group (GTK_WIDGET (self), "grid", G_ACTION_GROUP (group)); + + /* Disable the "add-tag" action until text is inserted in the corresponding + * entry */ + action = g_action_map_lookup_action (G_ACTION_MAP (group), "add-tag"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); + g_object_unref (group); g_signal_connect_object (gtk_entry_get_buffer (GTK_ENTRY (self->add_tag_entry)), diff --git a/src/resources/gtk/bookmark-properties-grid.ui b/src/resources/gtk/bookmark-properties-grid.ui index efecc6d04..cc60cbda1 100644 --- a/src/resources/gtk/bookmark-properties-grid.ui +++ b/src/resources/gtk/bookmark-properties-grid.ui @@ -147,7 +147,6 @@ _Add grid.add-tag true - false true true -- cgit v1.2.1