[fractal] account-settings: Use AdwEntryRow
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] account-settings: Use AdwEntryRow
- Date: Wed, 28 Sep 2022 13:51:24 +0000 (UTC)
commit 0b9519e370fa4b3d201ce903468cdd5d63f9e2bb
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Wed Sep 28 15:25:21 2022 +0200
account-settings: Use AdwEntryRow
.../account-settings-deactivate-account-subpage.ui | 4 +-
data/resources/ui/account-settings-user-page.ui | 10 +++-
.../user_page/deactivate_account_subpage.rs | 11 ++--
src/session/account_settings/user_page/mod.rs | 63 ++++++++++------------
4 files changed, 41 insertions(+), 47 deletions(-)
---
diff --git a/data/resources/ui/account-settings-deactivate-account-subpage.ui
b/data/resources/ui/account-settings-deactivate-account-subpage.ui
index d27f6e0a3..728211aec 100644
--- a/data/resources/ui/account-settings-deactivate-account-subpage.ui
+++ b/data/resources/ui/account-settings-deactivate-account-subpage.ui
@@ -75,9 +75,7 @@
<child>
<object class="AdwPreferencesGroup">
<child>
- <object class="ComponentsEntryRow" id="confirmation">
- <property name="title" translatable="yes">Matrix User ID</property>
- </object>
+ <object class="AdwEntryRow" id="confirmation"/>
</child>
</object>
</child>
diff --git a/data/resources/ui/account-settings-user-page.ui b/data/resources/ui/account-settings-user-page.ui
index 1e04fd524..2ffcfe2f0 100644
--- a/data/resources/ui/account-settings-user-page.ui
+++ b/data/resources/ui/account-settings-user-page.ui
@@ -34,7 +34,7 @@
<child>
<object class="AdwPreferencesGroup">
<child>
- <object class="ComponentsEntryRow" id="display_name">
+ <object class="AdwEntryRow" id="display_name">
<property name="title" translatable="yes">Name</property>
<binding name="text">
<lookup name="display-name">
@@ -43,6 +43,14 @@
</lookup>
</lookup>
</binding>
+ <signal name="entry-activated" handler="handle_change_display_name" swapped="yes"/>
+ <child type="suffix">
+ <object class="ComponentsActionButton" id="display_name_button">
+ <property name="visible">False</property>
+ <property name="state">confirm</property>
+ <signal name="clicked" handler="handle_change_display_name" swapped="yes"/>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/session/account_settings/user_page/deactivate_account_subpage.rs
b/src/session/account_settings/user_page/deactivate_account_subpage.rs
index 8974d0b80..457d0a467 100644
--- a/src/session/account_settings/user_page/deactivate_account_subpage.rs
+++ b/src/session/account_settings/user_page/deactivate_account_subpage.rs
@@ -8,7 +8,7 @@ use log::error;
use matrix_sdk::ruma::{api::client::account::deactivate, assign};
use crate::{
- components::{AuthDialog, EntryRow, SpinnerButton},
+ components::{AuthDialog, SpinnerButton},
session::{Session, UserExt},
spawn, toast,
};
@@ -24,7 +24,7 @@ mod imp {
pub struct DeactivateAccountSubpage {
pub session: OnceCell<WeakRef<Session>>,
#[template_child]
- pub confirmation: TemplateChild<EntryRow>,
+ pub confirmation: TemplateChild<adw::EntryRow>,
#[template_child]
pub button: TemplateChild<SpinnerButton>,
}
@@ -36,7 +36,6 @@ mod imp {
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
- EntryRow::static_type();
Self::bind_template(klass);
}
@@ -85,7 +84,7 @@ mod imp {
self.parent_constructed(obj);
self.confirmation
- .connect_activated(clone!(@weak obj => move|_| {
+ .connect_entry_activated(clone!(@weak obj => move|_| {
spawn!(
clone!(@weak obj => async move {
obj.deactivate_account().await;
@@ -134,9 +133,7 @@ impl DeactivateAccountSubpage {
if let Some(session) = session {
let priv_ = self.imp();
priv_.session.set(session.downgrade()).unwrap();
- priv_
- .confirmation
- .set_placeholder_text(Some(&self.user_id()));
+ priv_.confirmation.set_title(&self.user_id());
}
}
diff --git a/src/session/account_settings/user_page/mod.rs b/src/session/account_settings/user_page/mod.rs
index b796d63e6..6794b0a0e 100644
--- a/src/session/account_settings/user_page/mod.rs
+++ b/src/session/account_settings/user_page/mod.rs
@@ -17,7 +17,7 @@ use change_password_subpage::ChangePasswordSubpage;
use deactivate_account_subpage::DeactivateAccountSubpage;
use crate::{
- components::{ActionState, ButtonRow, EditableAvatar, EntryRow},
+ components::{ActionButton, ActionState, ButtonRow, EditableAvatar},
session::{Session, User, UserExt},
spawn, spawn_tokio, toast,
utils::TemplateCallbacks,
@@ -37,7 +37,9 @@ mod imp {
#[template_child]
pub avatar: TemplateChild<EditableAvatar>,
#[template_child]
- pub display_name: TemplateChild<EntryRow>,
+ pub display_name: TemplateChild<adw::EntryRow>,
+ #[template_child]
+ pub display_name_button: TemplateChild<ActionButton>,
#[template_child]
pub change_password_group: TemplateChild<adw::PreferencesGroup>,
#[template_child]
@@ -63,7 +65,6 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
EditableAvatar::static_type();
- EntryRow::static_type();
ButtonRow::static_type();
ChangePasswordSubpage::static_type();
DeactivateAccountSubpage::static_type();
@@ -342,31 +343,17 @@ impl UserPage {
}
fn init_display_name(&self) {
- let entry = &*self.imp().display_name;
- entry.connect_focused(clone!(@weak self as obj => move|entry, focused| {
- if entry.entry_sensitive() {
- if focused {
- entry.set_action_state(ActionState::Confirm);
- } else if entry.text() == obj.user().display_name() {
- entry.set_action_state(ActionState::Default);
- }
- }
- }));
- entry.connect_activated(clone!(@weak self as obj => move|_| {
- spawn!(
- clone!(@weak obj => async move {
- obj.change_display_name().await;
- })
- );
- }));
- entry.connect_cancel(clone!(@weak self as obj => move|entry| {
- entry.set_text(&obj.user().display_name());
+ let priv_ = self.imp();
+ let entry = &priv_.display_name;
+ entry.connect_changed(clone!(@weak self as obj => move|entry| {
+ obj.imp().display_name_button.set_visible(entry.text() != obj.user().display_name());
}));
}
fn display_name_changed(&self, name: &str) {
let priv_ = self.imp();
- let entry = &*priv_.display_name;
+ let entry = &priv_.display_name;
+ let button = &priv_.display_name_button;
let to_display_name = priv_
.changing_display_name_to
@@ -376,23 +363,20 @@ impl UserPage {
if to_display_name == name {
priv_.changing_display_name_to.take();
entry.remove_css_class("error");
- entry.set_action_state(ActionState::Success);
- entry.set_entry_sensitive(true);
+ entry.set_sensitive(true);
+ button.hide();
+ button.set_state(ActionState::Confirm);
toast!(self, gettext("Name changed successfully"));
- glib::timeout_add_local_once(
- Duration::from_secs(2),
- clone!(@weak entry => move || {
- entry.set_action_state(ActionState::Default);
- }),
- );
}
}
async fn change_display_name(&self) {
let priv_ = self.imp();
- let entry = &*priv_.display_name;
- entry.set_action_state(ActionState::Loading);
- entry.set_entry_sensitive(false);
+ let entry = &priv_.display_name;
+ let button = &priv_.display_name_button;
+
+ entry.set_sensitive(false);
+ button.set_state(ActionState::Loading);
let display_name = entry.text();
priv_
@@ -415,9 +399,9 @@ impl UserPage {
Err(err) => {
error!("Couldn’t change user display name: {}", err);
toast!(self, gettext("Could not change display name"));
- entry.set_action_state(ActionState::Retry);
+ button.set_state(ActionState::Retry);
entry.add_css_class("error");
- entry.set_entry_sensitive(true);
+ entry.set_sensitive(true);
}
}
}
@@ -442,6 +426,13 @@ impl UserPage {
);
}
+ #[template_callback]
+ fn handle_change_display_name(&self) {
+ spawn!(clone!(@weak self as obj => async move {
+ obj.change_display_name().await;
+ }));
+ }
+
#[template_callback]
fn show_change_password(&self) {
self.root()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]