[gnome-control-center/wip/feborges/user-accounts-ui-improvements: 6/9] user-accounts: Make the full_name_entry and editable widget
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/feborges/user-accounts-ui-improvements: 6/9] user-accounts: Make the full_name_entry and editable widget
- Date: Mon, 27 Jan 2020 14:59:14 +0000 (UTC)
commit 6fc45142843a640b7ce72117ed711b9ae75506ba
Author: Felipe Borges <felipeborges gnome org>
Date: Mon Jan 13 12:34:22 2020 +0100
user-accounts: Make the full_name_entry and editable widget
According to the mockups at
https://gitlab.gnome.org/Teams/Design/settings-mockups/blob/master/users/users.png
Fixes #771
panels/user-accounts/cc-user-panel.c | 62 +++++++++++++++++++++++------------
panels/user-accounts/cc-user-panel.ui | 55 +++++++++++++++++++++++++++----
2 files changed, 90 insertions(+), 27 deletions(-)
---
diff --git a/panels/user-accounts/cc-user-panel.c b/panels/user-accounts/cc-user-panel.c
index 157e1d492..21f905d16 100644
--- a/panels/user-accounts/cc-user-panel.c
+++ b/panels/user-accounts/cc-user-panel.c
@@ -76,6 +76,9 @@ struct _CcUserPanel {
CcCarousel *carousel;
GtkButton *fingerprint_button;
GtkLabel *fingerprint_label;
+ GtkStack *full_name_stack;
+ GtkLabel *full_name_label;
+ GtkToggleButton *full_name_edit_button;
GtkEntry *full_name_entry;
GtkButton *language_button;
GtkLabel *language_button_label;
@@ -792,6 +795,7 @@ get_autologin_possible (ActUser *user)
}
static void on_permission_changed (CcUserPanel *self);
+static void change_name_done (CcUserPanel *self);
static void
show_user (ActUser *user, CcUserPanel *self)
@@ -807,8 +811,14 @@ show_user (ActUser *user, CcUserPanel *self)
cc_avatar_chooser_set_user (self->avatar_chooser, user);
+ gtk_label_set_label (self->full_name_label, act_user_get_real_name (user));
gtk_entry_set_text (self->full_name_entry, act_user_get_real_name (user));
- gtk_widget_set_tooltip_text (GTK_WIDGET (self->full_name_entry), act_user_get_user_name (user));
+ gtk_widget_set_tooltip_text (GTK_WIDGET (self->full_name_label), act_user_get_user_name (user));
+
+ g_signal_handlers_block_by_func (self->full_name_edit_button, change_name_done, self);
+ gtk_stack_set_visible_child (self->full_name_stack, GTK_WIDGET (self->full_name_label));
+ gtk_toggle_button_set_active (self->full_name_edit_button, FALSE);
+ g_signal_handlers_unblock_by_func (self->full_name_edit_button, change_name_done, self);
if (act_user_get_account_type (user) == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->account_type_admin_button), TRUE);
@@ -881,24 +891,31 @@ show_user (ActUser *user, CcUserPanel *self)
}
static void
-change_name_done (CcUserPanel *self)
+full_name_entry_activate (CcUserPanel *self)
{
- const gchar *text;
- ActUser *user;
-
- user = get_selected_user (self);
-
- text = gtk_entry_get_text (self->full_name_entry);
- if (g_strcmp0 (text, act_user_get_real_name (user)) != 0 &&
- is_valid_name (text)) {
- act_user_set_real_name (user, text);
- }
+ gtk_toggle_button_set_active (self->full_name_edit_button, FALSE);
}
static void
-change_name_focus_out (CcUserPanel *self)
+change_name_done (CcUserPanel *self)
{
- change_name_done (self);
+ if (gtk_stack_get_visible_child (self->full_name_stack) == GTK_WIDGET (self->full_name_label)) {
+ gtk_stack_set_visible_child (self->full_name_stack, GTK_WIDGET (self->full_name_entry));
+
+ gtk_widget_grab_focus (GTK_WIDGET (self->full_name_entry));
+ } else {
+ const gchar *text;
+ ActUser *user;
+
+ gtk_stack_set_visible_child (self->full_name_stack, GTK_WIDGET (self->full_name_label));
+
+ user = get_selected_user (self);
+ text = gtk_entry_get_text (self->full_name_entry);
+ if (g_strcmp0 (text, act_user_get_real_name (user)) != 0 &&
+ is_valid_name (text)) {
+ act_user_set_real_name (user, text);
+ }
+ }
}
static void
@@ -1264,16 +1281,16 @@ on_permission_changed (CcUserPanel *self)
/* The full name entry: insensitive if remote or not authorized and not self */
if (!act_user_is_local_account (user)) {
- gtk_widget_set_sensitive (GTK_WIDGET (self->full_name_entry), FALSE);
- remove_unlock_tooltip (GTK_WIDGET (self->full_name_entry));
+ gtk_widget_set_sensitive (GTK_WIDGET (self->full_name_edit_button), FALSE);
+ remove_unlock_tooltip (GTK_WIDGET (self->full_name_stack));
} else if (is_authorized || self_selected) {
- gtk_widget_set_sensitive (GTK_WIDGET (self->full_name_entry), TRUE);
- remove_unlock_tooltip (GTK_WIDGET (self->full_name_entry));
+ gtk_widget_set_sensitive (GTK_WIDGET (self->full_name_edit_button), TRUE);
+ remove_unlock_tooltip (GTK_WIDGET (self->full_name_stack));
} else {
- gtk_widget_set_sensitive (GTK_WIDGET (self->full_name_entry), FALSE);
- add_unlock_tooltip (GTK_WIDGET (self->full_name_entry));
+ gtk_widget_set_sensitive (GTK_WIDGET (self->full_name_edit_button), FALSE);
+ add_unlock_tooltip (GTK_WIDGET (self->full_name_stack));
}
if (is_authorized || self_selected) {
@@ -1466,6 +1483,9 @@ cc_user_panel_class_init (CcUserPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcUserPanel, carousel);
gtk_widget_class_bind_template_child (widget_class, CcUserPanel, fingerprint_button);
gtk_widget_class_bind_template_child (widget_class, CcUserPanel, fingerprint_label);
+ gtk_widget_class_bind_template_child (widget_class, CcUserPanel, full_name_stack);
+ gtk_widget_class_bind_template_child (widget_class, CcUserPanel, full_name_label);
+ gtk_widget_class_bind_template_child (widget_class, CcUserPanel, full_name_edit_button);
gtk_widget_class_bind_template_child (widget_class, CcUserPanel, full_name_entry);
gtk_widget_class_bind_template_child (widget_class, CcUserPanel, language_button);
gtk_widget_class_bind_template_child (widget_class, CcUserPanel, language_button_label);
@@ -1492,7 +1512,7 @@ cc_user_panel_class_init (CcUserPanelClass *klass)
gtk_widget_class_bind_template_callback (widget_class, change_fingerprint);
gtk_widget_class_bind_template_callback (widget_class, change_language);
gtk_widget_class_bind_template_callback (widget_class, change_name_done);
- gtk_widget_class_bind_template_callback (widget_class, change_name_focus_out);
+ gtk_widget_class_bind_template_callback (widget_class, full_name_entry_activate);
gtk_widget_class_bind_template_callback (widget_class, change_password);
gtk_widget_class_bind_template_callback (widget_class, delete_user);
gtk_widget_class_bind_template_callback (widget_class, dismiss_notification);
diff --git a/panels/user-accounts/cc-user-panel.ui b/panels/user-accounts/cc-user-panel.ui
index 8aa64cd72..0ceaaab56 100644
--- a/panels/user-accounts/cc-user-panel.ui
+++ b/panels/user-accounts/cc-user-panel.ui
@@ -181,14 +181,57 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="full_name_entry">
+ <object class="GtkBox">
<property name="visible">True</property>
- <property name="max-length">255</property>
- <property name="width-chars">18</property>
- <property name="max-width-chars">30</property>
<property name="valign">GTK_ALIGN_CENTER</property>
- <signal name="activate" handler="change_name_done" object="CcUserPanel"
swapped="yes"/>
- <signal name="focus-out-event" handler="change_name_focus_out" object="CcUserPanel"
swapped="yes"/>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkStack" id="full_name_stack">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="full_name_label">
+ <property name="visible">True</property>
+ <property name="halign">GTK_ALIGN_START</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+ <property name="width-chars">18</property>
+ <property name="max-width-chars">30</property>
+ <attributes>
+ <attribute name="scale" value="1.2"/>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkEntry" id="full_name_entry">
+ <property name="visible">True</property>
+ <property name="max-length">255</property>
+ <property name="width-chars">18</property>
+ <property name="max-width-chars">30</property>
+ <property name="valign">GTK_ALIGN_CENTER</property>
+ <signal name="activate" handler="full_name_entry_activate"
object="CcUserPanel" swapped="yes"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="full_name_edit_button">
+ <property name="visible">True</property>
+ <signal name="toggled" handler="change_name_done" object="CcUserPanel"
swapped="yes"/>
+ <style>
+ <class name="circular"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="margin">5</property>
+ <property name="icon-name">document-edit-symbolic</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]