mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/telegramdesktop/tdesktop
synced 2026-09-20 08:03:45 +08:00
Fixed profile about copy and translate including peer id.
This commit is contained in:
@@ -1458,16 +1458,18 @@ Section DetailsFiller::makeInfo() {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto addTranslateToMenu = [&,
|
const auto setupAboutContextMenu = [&,
|
||||||
peer = _peer.get(),
|
peer = _peer.get(),
|
||||||
controller = _controller->parentController()](
|
controller = _controller->parentController()](
|
||||||
not_null<Ui::FlatLabel*> label,
|
not_null<Ui::FlatLabel*> label,
|
||||||
rpl::producer<TextWithEntities> &&text) {
|
rpl::producer<TextWithEntities> &&text) {
|
||||||
struct State {
|
struct State {
|
||||||
rpl::variable<TextWithEntities> labelText;
|
rpl::variable<TextWithEntities> labelText;
|
||||||
|
rpl::variable<TextWithEntities> aboutText;
|
||||||
};
|
};
|
||||||
const auto state = label->lifetime().make_state<State>();
|
const auto state = label->lifetime().make_state<State>();
|
||||||
state->labelText = std::move(text);
|
state->labelText = std::move(text);
|
||||||
|
state->aboutText = AboutValue(peer);
|
||||||
label->setContextMenuHook([=](
|
label->setContextMenuHook([=](
|
||||||
Ui::FlatLabel::ContextMenuRequest request) {
|
Ui::FlatLabel::ContextMenuRequest request) {
|
||||||
if (request.link) {
|
if (request.link) {
|
||||||
@@ -1484,24 +1486,49 @@ Section DetailsFiller::makeInfo() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
label->fillContextMenu(request);
|
const auto selected = !request.selection.empty();
|
||||||
if (Ui::SkipTranslate(state->labelText.current())) {
|
const auto full = state->labelText.current();
|
||||||
|
const auto about = state->aboutText.current();
|
||||||
|
const auto advanced = (about.text.size() < full.text.size());
|
||||||
|
if (selected || !advanced) {
|
||||||
|
label->fillContextMenu(request);
|
||||||
|
} else {
|
||||||
|
if (!about.empty()) {
|
||||||
|
request.menu->addAction(
|
||||||
|
tr::lng_context_copy_text(tr::now),
|
||||||
|
[=] {
|
||||||
|
TextUtilities::SetClipboardText(
|
||||||
|
TextForMimeData::WithExpandedLinks(about));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (const auto link = request.link) {
|
||||||
|
const auto copy = link->copyToClipboardContextItemText();
|
||||||
|
if (!copy.isEmpty()) {
|
||||||
|
request.menu->addAction(
|
||||||
|
copy,
|
||||||
|
[text = link->copyToClipboardText()] {
|
||||||
|
TextUtilities::SetClipboardText({ text });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Ui::SkipTranslate(selected ? full : about)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto item = (request.selection.empty()
|
auto item = (selected
|
||||||
? tr::lng_context_translate
|
? tr::lng_context_translate_selected
|
||||||
: tr::lng_context_translate_selected)(tr::now);
|
: tr::lng_context_translate)(tr::now);
|
||||||
request.menu->addAction(std::move(item), [=] {
|
request.menu->addAction(std::move(item), [=] {
|
||||||
controller->window().show(Box(
|
controller->window().show(Box(
|
||||||
Ui::TranslateBox,
|
Ui::TranslateBox,
|
||||||
peer,
|
peer,
|
||||||
MsgId(),
|
MsgId(),
|
||||||
request.selection.empty()
|
(selected
|
||||||
? state->labelText.current()
|
? Ui::Text::Mid(
|
||||||
: Ui::Text::Mid(
|
full,
|
||||||
state->labelText.current(),
|
|
||||||
request.selection.from,
|
request.selection.from,
|
||||||
request.selection.to - request.selection.from),
|
request.selection.to - request.selection.from)
|
||||||
|
: about),
|
||||||
false));
|
false));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1681,7 +1708,7 @@ Section DetailsFiller::makeInfo() {
|
|||||||
const auto about = addInfoLine(
|
const auto about = addInfoLine(
|
||||||
std::move(label),
|
std::move(label),
|
||||||
AboutWithAdvancedValue(user));
|
AboutWithAdvancedValue(user));
|
||||||
addTranslateToMenu(about.text, AboutWithAdvancedValue(user));
|
setupAboutContextMenu(about.text, AboutWithAdvancedValue(user));
|
||||||
SetupAboutPeerIdDrag(about.text, user);
|
SetupAboutPeerIdDrag(about.text, user);
|
||||||
|
|
||||||
const auto usernameLine = addInfoOneLine(
|
const auto usernameLine = addInfoOneLine(
|
||||||
@@ -1846,7 +1873,7 @@ Section DetailsFiller::makeInfo() {
|
|||||||
? rpl::single(TextWithEntities())
|
? rpl::single(TextWithEntities())
|
||||||
: AboutWithAdvancedValue(_peer));
|
: AboutWithAdvancedValue(_peer));
|
||||||
if (!_topic) {
|
if (!_topic) {
|
||||||
addTranslateToMenu(about.text, AboutWithAdvancedValue(_peer));
|
setupAboutContextMenu(about.text, AboutWithAdvancedValue(_peer));
|
||||||
SetupAboutPeerIdDrag(about.text, _peer);
|
SetupAboutPeerIdDrag(about.text, _peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user