[epiphany] CookiesDialog: Use GActions.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] CookiesDialog: Use GActions.
- Date: Sun, 1 Nov 2015 15:52:12 +0000 (UTC)
commit 1b7f558101ed8bbc7a3bbbe18afbc69f401cc7db
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Oct 31 06:36:45 2015 +0100
CookiesDialog: Use GActions.
https://bugzilla.gnome.org/show_bug.cgi?id=757401
src/cookies-dialog.c | 66 ++++++++++++++++++++++++--------------
src/resources/cookies-dialog.ui | 11 ++----
2 files changed, 46 insertions(+), 31 deletions(-)
---
diff --git a/src/cookies-dialog.c b/src/cookies-dialog.c
index 678cd17..3b0fa61 100644
--- a/src/cookies-dialog.c
+++ b/src/cookies-dialog.c
@@ -46,7 +46,8 @@ struct CookiesDialogPrivate
GtkWidget *liststore;
GtkWidget *treemodelfilter;
GtkWidget *treemodelsort;
- GtkWidget *remove_toolbutton;
+
+ GActionGroup *action_group;
WebKitCookieManager *cookie_manager;
gboolean filled;
@@ -217,24 +218,29 @@ on_cookies_treeview_key_press_event (GtkWidget *widget,
}
static void
-on_remove_toolbutton_clicked (GtkToolButton *toolbutton,
- CookiesDialog *dialog)
+forget (GSimpleAction *action,
+ GVariant *parameter,
+ CookiesDialog *dialog)
{
delete_selection (dialog);
+}
+
+static void
+update_selection_actions (GActionMap *action_map,
+ gboolean has_selection)
+{
+ GSimpleAction *forget_action;
- /* Restore the focus to the button */
- gtk_widget_grab_focus (GTK_WIDGET (toolbutton));
+ forget_action = g_action_map_lookup_action (action_map, "forget");
+ g_simple_action_set_enabled (forget_action, has_selection);
}
static void
on_treeview_selection_changed (GtkTreeSelection *selection,
CookiesDialog *dialog)
{
- gboolean has_selection;
-
- has_selection = gtk_tree_selection_count_selected_rows (selection) > 0;
-
- gtk_widget_set_sensitive (dialog->priv->remove_toolbutton, has_selection);
+ update_selection_actions (G_ACTION_MAP (dialog->priv->action_group),
+ gtk_tree_selection_count_selected_rows (selection) > 0);
}
static void
@@ -250,17 +256,12 @@ on_search_entry_changed (GtkSearchEntry *entry,
}
static void
-cookies_dialog_response_cb (GtkDialog *widget,
- int response,
- CookiesDialog *dialog)
+forget_all (GSimpleAction *action,
+ GVariant *parameter,
+ CookiesDialog *dialog)
{
- if (response == GTK_RESPONSE_REJECT) {
- webkit_cookie_manager_delete_all_cookies (dialog->priv->cookie_manager);
- reload_model (dialog);
- return;
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ webkit_cookie_manager_delete_all_cookies (dialog->priv->cookie_manager);
+ reload_model (dialog);
}
static void
@@ -280,14 +281,10 @@ cookies_dialog_class_init (CookiesDialogClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, treemodelsort);
gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, cookies_treeview);
gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, tree_selection);
- gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, remove_toolbutton);
gtk_widget_class_bind_template_callback (widget_class, on_cookies_treeview_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_treeview_selection_changed);
- gtk_widget_class_bind_template_callback (widget_class, on_remove_toolbutton_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
-
- gtk_widget_class_bind_template_callback (widget_class, cookies_dialog_response_cb);
}
static gboolean
@@ -445,6 +442,22 @@ setup_page (CookiesDialog *dialog)
populate_model (dialog);
}
+static GActionGroup *
+create_action_group (CookiesDialog *dialog)
+{
+ const GActionEntry entries[] = {
+ { "forget", forget },
+ { "forget-all", forget_all }
+ };
+
+ GSimpleActionGroup *group;
+
+ group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (group), entries, G_N_ELEMENTS (entries), dialog);
+
+ return G_ACTION_GROUP (group);
+}
+
static void
cookies_dialog_init (CookiesDialog *dialog)
{
@@ -463,4 +476,9 @@ cookies_dialog_init (CookiesDialog *dialog)
dialog->priv->cookie_manager = webkit_web_context_get_cookie_manager (web_context);
setup_page (dialog);
+
+ dialog->priv->action_group = create_action_group (dialog);
+ gtk_widget_insert_action_group (dialog, "cookies", dialog->priv->action_group);
+
+ update_selection_actions (G_ACTION_MAP (dialog->priv->action_group), FALSE);
}
diff --git a/src/resources/cookies-dialog.ui b/src/resources/cookies-dialog.ui
index d338fe7..8a4f81e 100644
--- a/src/resources/cookies-dialog.ui
+++ b/src/resources/cookies-dialog.ui
@@ -25,17 +25,17 @@
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
- <signal name="response" handler="cookies_dialog_response_cb"/>
<child internal-child="headerbar">
<object class="GtkHeaderBar">
<property name="title" translatable="yes">Cookies</property>
<property name="show-close-button">True</property>
<child>
- <object class="GtkButton" id="clear_button">
+ <object class="GtkButton">
<property name="label" translatable="yes">C_lear All</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="valign">center</property>
+ <property name="action-name">cookies.forget-all</property>
<style>
<class name="destructive-action"/>
<class name="text-button"/>
@@ -115,12 +115,12 @@
<object class="GtkBox">
<property name="visible">True</property>
<child>
- <object class="GtkButton" id="remove_toolbutton">
+ <object class="GtkButton">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="tooltip_text" translatable="yes">Delete the selected
cookies</property>
<property name="label" translatable="yes">Remove</property> <!-- TODO conflicts
with the image -->
- <signal name="clicked" handler="on_remove_toolbutton_clicked"/>
+ <property name="action-name">cookies.forget</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@@ -142,8 +142,5 @@
</child>
</object>
</child>
- <action-widgets>
- <action-widget response="-2">clear_button</action-widget>
- </action-widgets>
</template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]