Add 'Copy Username' context menu to usernames in profiles.

This commit is contained in:
John Preston 2022-11-29 13:41:40 +04:00
parent 05524c3f6c
commit c39b9e9635
2 changed files with 28 additions and 1 deletions

View file

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/labels.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/box_content_divider.h"
#include "ui/widgets/popup_menu.h"
#include "ui/boxes/report_box.h"
#include "ui/boxes/confirm_box.h"
#include "ui/layers/generic_box.h"
@ -386,8 +387,34 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
_peer,
Window::Show(controller),
QString());
const auto hook = [=](Ui::FlatLabel::ContextMenuRequest request) {
if (!request.link) {
return;
}
const auto text = request.link->copyToClipboardContextItemText();
if (text.isEmpty()) {
return;
}
const auto link = request.link->copyToClipboardText();
request.menu->addAction(
text,
[=] { QGuiApplication::clipboard()->setText(link); });
const auto last = link.lastIndexOf('/');
if (last < 0) {
return;
}
const auto mention = '@' + link.mid(last + 1);
if (mention.size() < 2) {
return;
}
request.menu->addAction(
tr::lng_context_copy_mention(tr::now),
[=] { QGuiApplication::clipboard()->setText(mention); });
};
usernameLine.text->overrideLinkClickHandler(callback);
usernameLine.subtext->overrideLinkClickHandler(callback);
usernameLine.text->setContextMenuHook(hook);
usernameLine.subtext->setContextMenuHook(hook);
const auto usernameLabel = usernameLine.text;
if (user->isBot()) {
const auto copyUsername = Ui::CreateChild<Ui::IconButton>(

@ -1 +1 @@
Subproject commit e6064719dfb885910b73e0e90da8a66afa98f75a
Subproject commit 0937ac0ad0feaf3cbccf009e0e1f2a04cc0ef9f8