Respected copy restriction on translate box.

This commit is contained in:
23rd 2022-11-27 16:12:30 +03:00
parent 3fdb807a1e
commit 6695d7d503
4 changed files with 21 additions and 9 deletions

View File

@ -140,7 +140,8 @@ void TranslateBox(
not_null<Ui::GenericBox*> box,
not_null<PeerData*> peer,
MsgId msgId,
TextWithEntities text) {
TextWithEntities text,
bool hasCopyRestriction) {
box->setWidth(st::boxWideWidth);
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
const auto container = box->verticalLayout();
@ -182,6 +183,10 @@ void TranslateBox(
box,
object_ptr<FlatLabel>(box, stLabel)));
{
if (hasCopyRestriction) {
original->entity()->setContextMenuHook([](auto&&) {
});
}
original->entity()->setMarkedText(text);
original->setMinimalHeight(lineHeight);
original->hide(anim::type::instant);
@ -232,7 +237,7 @@ void TranslateBox(
const auto translated = box->addRow(object_ptr<SlideWrap<FlatLabel>>(
box,
object_ptr<FlatLabel>(box, stLabel)));
translated->entity()->setSelectable(true);
translated->entity()->setSelectable(!hasCopyRestriction);
translated->hide(anim::type::instant);
constexpr auto kMaxLines = 3;

View File

@ -19,7 +19,8 @@ void TranslateBox(
not_null<Ui::GenericBox*> box,
not_null<PeerData*> peer,
MsgId msgId,
TextWithEntities text);
TextWithEntities text,
bool hasCopyRestriction);
[[nodiscard]] bool SkipTranslate(TextWithEntities textWithEntities);

View File

@ -2276,7 +2276,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
Ui::TranslateBox,
item->history()->peer,
MsgId(),
getSelectedText().rich));
getSelectedText().rich,
hasCopyRestrictionForSelected()));
}, &st::menuIconTranslate);
}
}
@ -2376,7 +2377,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
Ui::TranslateBox,
item->history()->peer,
MsgId(),
getSelectedText().rich));
getSelectedText().rich,
hasCopyRestrictionForSelected()));
}, &st::menuIconTranslate);
}
addItemActions(item, item);
@ -2446,7 +2448,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
Ui::TranslateBox,
item->history()->peer,
item->fullId().msg,
item->originalText()));
item->originalText(),
hasCopyRestriction(item)));
}, &st::menuIconTranslate);
}
}

View File

@ -1014,7 +1014,8 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
Ui::TranslateBox,
item->history()->peer,
MsgId(),
list->getSelectedText().rich));
list->getSelectedText().rich,
list->hasCopyRestrictionForSelected()));
}
}, &st::menuIconTranslate);
}
@ -1061,7 +1062,8 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
Ui::TranslateBox,
item->history()->peer,
item->fullId().msg,
item->originalText()));
item->originalText(),
list->hasCopyRestriction(view->data())));
}
}, &st::menuIconTranslate);
}
@ -1143,7 +1145,8 @@ void AddPollActions(
Ui::TranslateBox,
item->history()->peer,
MsgId(),
TextWithEntities{ .text = text }));
TextWithEntities{ .text = text },
item->forbidsForward()));
}, &st::menuIconTranslate);
}
}