[epiphany] PasswordsDialog: Use GActions.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] PasswordsDialog: Use GActions.
- Date: Sun, 1 Nov 2015 16:06:56 +0000 (UTC)
commit e36ef73102127080b9eb314622f37f0ef10abbdd
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Oct 30 09:55:14 2015 +0100
PasswordsDialog: Use GActions.
https://bugzilla.gnome.org/show_bug.cgi?id=757344
src/passwords-dialog.c | 114 +++++++++++++++++++++++--------------
src/resources/passwords-dialog.ui | 18 +++---
2 files changed, 79 insertions(+), 53 deletions(-)
---
diff --git a/src/passwords-dialog.c b/src/passwords-dialog.c
index 88a2ede..1a6d8c1 100644
--- a/src/passwords-dialog.c
+++ b/src/passwords-dialog.c
@@ -52,7 +52,6 @@ struct PasswordsDialogPrivate
GtkWidget *liststore;
GtkWidget *treemodelfilter;
GtkWidget *treemodelsort;
- GtkWidget *remove_button;
GtkWidget *show_passwords_button;
GtkWidget *password_column;
GtkWidget *password_renderer;
@@ -60,6 +59,8 @@ struct PasswordsDialogPrivate
GtkWidget *copy_password_menuitem;
GtkWidget *copy_username_menuitem;
+ GActionGroup *action_group;
+
SecretService *ss;
GCancellable *ss_cancellable;
gboolean filled;
@@ -222,22 +223,21 @@ on_passwords_treeview_key_press_event (GtkWidget *widget,
}
static void
-on_remove_button_clicked (GtkButton *button,
- PasswordsDialog *dialog)
+forget (GSimpleAction *action,
+ GVariant *parameter,
+ PasswordsDialog *dialog)
{
delete_selection (dialog);
-
- /* Restore the focus to the button */
- gtk_widget_grab_focus (GTK_WIDGET (button));
}
static void
-on_show_passwords_button_toggled (GtkToggleButton *button,
- PasswordsDialog *dialog)
+show_passwords (GSimpleAction *action,
+ GVariant *parameter,
+ PasswordsDialog *dialog)
{
gboolean active;
- active = gtk_toggle_button_get_active (button);
+ active = gtk_toggle_button_get_active (dialog->priv->show_passwords_button);
gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (dialog->priv->password_column),
GTK_CELL_RENDERER (dialog->priv->password_renderer),
@@ -247,14 +247,21 @@ on_show_passwords_button_toggled (GtkToggleButton *button,
}
static void
-on_treeview_selection_changed (GtkTreeSelection *selection,
- PasswordsDialog *dialog)
+update_selection_actions (GActionMap *action_map,
+ gboolean has_selection)
{
- gboolean has_selection;
+ GSimpleAction *forget_action;
- has_selection = gtk_tree_selection_count_selected_rows (selection) > 0;
+ forget_action = g_action_map_lookup_action (action_map, "forget");
+ g_simple_action_set_enabled (forget_action, has_selection);
+}
- gtk_widget_set_sensitive (dialog->priv->remove_button, has_selection);
+static void
+on_treeview_selection_changed (GtkTreeSelection *selection,
+ PasswordsDialog *dialog)
+{
+ update_selection_actions (G_ACTION_MAP (dialog->priv->action_group),
+ gtk_tree_selection_count_selected_rows (selection) > 0);
}
static void
@@ -289,14 +296,15 @@ get_selected_item (PasswordsDialog *dialog,
}
static void
-on_copy_password_menuitem_activate (GtkMenuItem *menuitem,
- PasswordsDialog *dialog)
+copy_password (GSimpleAction *action,
+ GVariant *parameter,
+ PasswordsDialog *dialog)
{
char *password;
password = get_selected_item (dialog, COL_PASSWORDS_PASSWORD);
if (password != NULL) {
- gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (menuitem),
+ gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET
(dialog->priv->copy_password_menuitem),
GDK_SELECTION_CLIPBOARD),
password, -1);
}
@@ -304,20 +312,35 @@ on_copy_password_menuitem_activate (GtkMenuItem *menuitem,
}
static void
-on_copy_username_menuitem_activate (GtkMenuItem *menuitem,
- PasswordsDialog *dialog)
+copy_username (GSimpleAction *action,
+ GVariant *parameter,
+ PasswordsDialog *dialog)
{
char *username;
username = get_selected_item (dialog, COL_PASSWORDS_USER);
if (username != NULL) {
- gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (menuitem),
+ gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET
(dialog->priv->copy_username_menuitem),
GDK_SELECTION_CLIPBOARD),
username, -1);
}
g_free (username);
}
+static void
+update_popup_menu_actions (GActionGroup *action_group,
+ gboolean only_one_selected_item)
+{
+ GSimpleAction *copy_password_action;
+ GSimpleAction *copy_username_action;
+
+ copy_password_action = g_action_map_lookup_action (action_group, "copy-password");
+ copy_username_action = g_action_map_lookup_action (action_group, "copy-username");
+
+ g_simple_action_set_enabled (copy_password_action, only_one_selected_item);
+ g_simple_action_set_enabled (copy_username_action, only_one_selected_item);
+}
+
static gboolean
on_passwords_treeview_button_press_event (GtkWidget *widget,
GdkEventButton *event,
@@ -330,8 +353,7 @@ on_passwords_treeview_button_press_event (GtkWidget *widget,
if (n == 0)
return FALSE;
- gtk_widget_set_sensitive (dialog->priv->copy_password_menuitem, (n == 1));
- gtk_widget_set_sensitive (dialog->priv->copy_username_menuitem, (n == 1));
+ update_popup_menu_actions (G_ACTION_MAP (dialog->priv->action_group), (n == 1));
gtk_menu_popup (GTK_MENU (dialog->priv->treeview_popup_menu),
NULL, NULL, NULL, NULL,
@@ -343,19 +365,6 @@ on_passwords_treeview_button_press_event (GtkWidget *widget,
}
static void
-passwords_dialog_response_cb (GtkDialog *widget,
- int response,
- PasswordsDialog *dialog)
-{
- if (response == GTK_RESPONSE_REJECT) {
- delete_all_passwords (dialog);
- return;
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
-static void
passwords_dialog_class_init (PasswordsDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -371,7 +380,6 @@ passwords_dialog_class_init (PasswordsDialogClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, treemodelsort);
gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, passwords_treeview);
gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, tree_selection);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, remove_button);
gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, show_passwords_button);
gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, password_column);
gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, password_renderer);
@@ -382,13 +390,7 @@ passwords_dialog_class_init (PasswordsDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_passwords_treeview_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_passwords_treeview_button_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_treeview_selection_changed);
- gtk_widget_class_bind_template_callback (widget_class, on_remove_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, on_show_passwords_button_toggled);
gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
- gtk_widget_class_bind_template_callback (widget_class, on_copy_password_menuitem_activate);
- gtk_widget_class_bind_template_callback (widget_class, on_copy_username_menuitem_activate);
-
- gtk_widget_class_bind_template_callback (widget_class, passwords_dialog_response_cb);
}
static void
@@ -401,7 +403,9 @@ delete_all_passwords_ready_cb (GObject *source_object,
}
static void
-delete_all_passwords (PasswordsDialog *dialog)
+forget_all (GSimpleAction *action,
+ GVariant *parameter,
+ PasswordsDialog *dialog)
{
GHashTable *attributes;
@@ -514,6 +518,25 @@ row_visible_func (GtkTreeModel *model,
return visible;
}
+static GActionGroup *
+create_action_group (PasswordsDialog *dialog)
+{
+ const GActionEntry entries[] = {
+ { "copy-password", copy_password },
+ { "copy-username", copy_username },
+ { "forget", forget },
+ { "forget-all", forget_all },
+ { "show-passwords", show_passwords }
+ };
+
+ 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
passwords_dialog_init (PasswordsDialog *dialog)
{
@@ -530,4 +553,9 @@ passwords_dialog_init (PasswordsDialog *dialog)
dialog->priv->ss_cancellable,
(GAsyncReadyCallback)secrets_ready_cb,
dialog);
+
+ dialog->priv->action_group = create_action_group (dialog);
+ gtk_widget_insert_action_group (dialog, "passwords", dialog->priv->action_group);
+
+ update_selection_actions (G_ACTION_MAP (dialog->priv->action_group), FALSE);
}
diff --git a/src/resources/passwords-dialog.ui b/src/resources/passwords-dialog.ui
index 86c843e..c5dc151 100644
--- a/src/resources/passwords-dialog.ui
+++ b/src/resources/passwords-dialog.ui
@@ -29,17 +29,17 @@
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
- <signal name="response" handler="passwords_dialog_response_cb"/>
<child internal-child="headerbar">
<object class="GtkHeaderBar">
<property name="title" translatable="yes">Passwords</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">passwords.forget-all</property>
<style>
<class name="destructive-action"/>
<class name="text-button"/>
@@ -145,10 +145,10 @@
<object class="GtkBox">
<property name="visible">True</property>
<child>
- <object class="GtkButton" id="remove_button">
+ <object class="GtkButton">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Forget the selected
passwords</property>
- <signal name="clicked" handler="on_remove_button_clicked"/>
+ <property name="action-name">passwords.forget</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@@ -183,7 +183,7 @@
<object class="GtkToggleButton" id="show_passwords_button">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Reveal all the
passwords</property>
- <signal name="toggled" handler="on_show_passwords_button_toggled"/>
+ <property name="action-name">passwords.show-passwords</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@@ -208,18 +208,16 @@
</child>
</object>
</child>
- <action-widgets>
- <action-widget response="-2">clear_button</action-widget>
- </action-widgets>
</template>
<object class="GtkMenu" id="treeview_popup_menu">
<property name="visible">True</property>
+ <property name="attach-widget">passwords_treeview</property>
<child>
<object class="GtkMenuItem" id="copy_password_menuitem">
<property name="visible">True</property>
<property name="label" translatable="yes">_Copy Password</property>
<property name="use_underline">True</property>
- <signal name="activate" handler="on_copy_password_menuitem_activate"/>
+ <property name="action-name">passwords.copy-password</property>
</object>
</child>
<child>
@@ -227,7 +225,7 @@
<property name="visible">True</property>
<property name="label" translatable="yes">C_opy Username</property>
<property name="use_underline">True</property>
- <signal name="activate" handler="on_copy_username_menuitem_activate"/>
+ <property name="action-name">passwords.copy-username</property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]