Added ability to edit contact note with context menu.

This commit is contained in:
23rd
2025-09-26 10:49:02 +03:00
committed by John Preston
parent 0f3ef4b35c
commit e7f6a8a476
4 changed files with 36 additions and 2 deletions
+1
View File
@@ -1605,6 +1605,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_info_birthday_today" = "{emoji} {date}";
"lng_info_notes_label" = "Notes";
"lng_info_notes_private" = "only visible to you";
"lng_edit_note" = "Edit Note";
"lng_delete_note" = "Delete Note";
"lng_info_bio_label" = "Bio";
"lng_info_link_label" = "Link";
@@ -130,7 +130,8 @@ public:
Controller(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> window,
not_null<UserData*> user);
not_null<UserData*> user,
bool focusOnNotes = false);
void prepare();
@@ -162,6 +163,7 @@ private:
not_null<Ui::GenericBox*> _box;
not_null<Window::SessionController*> _window;
not_null<UserData*> _user;
bool _focusOnNotes = false;
Ui::Checkbox *_sharePhone = nullptr;
Ui::InputField *_notesField = nullptr;
Ui::InputField *_firstNameField = nullptr;
@@ -181,10 +183,12 @@ private:
Controller::Controller(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> window,
not_null<UserData*> user)
not_null<UserData*> user,
bool focusOnNotes)
: _box(box)
, _window(window)
, _user(user)
, _focusOnNotes(focusOnNotes)
, _phone(UserPhone(user)) {
}
@@ -261,6 +265,11 @@ void Controller::initNameFields(
_box->setTabOrder(last, first);
}
_focus = [=] {
if (_focusOnNotes && _notesField) {
_notesField->setFocusFast();
_notesField->setCursorPosition(_notesField->getLastText().size());
return;
}
const auto firstValue = getValue(first);
const auto lastValue = getValue(last);
const auto empty = firstValue.isEmpty() && lastValue.isEmpty();
@@ -876,3 +885,15 @@ void EditContactBox(
box->setWidth(st::boxWideWidth);
box->lifetime().make_state<Controller>(box, window, user)->prepare();
}
void EditContactNoteBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> window,
not_null<UserData*> user) {
box->setWidth(st::boxWideWidth);
box->lifetime().make_state<Controller>(
box,
window,
user,
true)->prepare();
}
@@ -19,3 +19,8 @@ void EditContactBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> window,
not_null<UserData*> user);
void EditContactNoteBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> window,
not_null<UserData*> user);
@@ -775,6 +775,13 @@ void DeleteContactNote(
raw->fillContextMenu(request);
const auto addAction = Ui::Menu::CreateAddActionCallback(
request.menu);
addAction({
.text = tr::lng_edit_note(tr::now),
.handler = [=] {
controller->window().show(
Box(EditContactNoteBox, controller, user));
},
});
addAction({
.text = tr::lng_delete_note(tr::now),
.handler = [=] {