Toggle selection by comments button click.

This commit is contained in:
John Preston 2021-02-16 17:50:41 +04:00
parent 467449ac13
commit 48821af475
9 changed files with 57 additions and 31 deletions

View File

@ -1323,10 +1323,8 @@ void HistoryInner::mouseActionFinish(
&& inSelectionMode()
&& button != Qt::RightButton) {
if (const auto view = _mouseActionItem->mainView()) {
if (const auto media = view->media()) {
if (media->toggleSelectionByHandlerClick(activated)) {
activated = nullptr;
}
if (view->toggleSelectionByHandlerClick(activated)) {
activated = nullptr;
}
}
}

View File

@ -1753,9 +1753,6 @@ void HistoryWidget::showHistory(
if (startBot) {
showAtMsgId = ShowAtTheEndMsgId;
}
if (showAtMsgId != ShowForChooseMessagesMsgId) {
_chooseForReport = nullptr;
}
clearHighlightMessages();
hideInfoTooltip(anim::type::instant);
@ -1768,6 +1765,7 @@ void HistoryWidget::showHistory(
showAtMsgId = ShowAtTheEndMsgId;
} else if (showAtMsgId == ShowForChooseMessagesMsgId) {
if (_chooseForReport) {
clearSelected();
_chooseForReport->active = true;
_list->setChooseReportReason(_chooseForReport->reason);
updateControlsVisibility();
@ -1776,7 +1774,6 @@ void HistoryWidget::showHistory(
}
return;
}
_list->clearChooseReportReason();
if (!IsServerMsgId(showAtMsgId)
&& !IsServerMsgId(-showAtMsgId)) {
// To end or to unread.
@ -1939,14 +1936,16 @@ void HistoryWidget::showHistory(
}
_history->setFakeUnreadWhileOpened(true);
refreshTopBarActiveChat();
updateTopBarSelection();
if (showAtMsgId == ShowForChooseMessagesMsgId) {
showAtMsgId = ShowAtUnreadMsgId;
if (_showAtMsgId == ShowForChooseMessagesMsgId) {
_showAtMsgId = ShowAtUnreadMsgId;
if (_chooseForReport) {
_chooseForReport->active = true;
}
} else {
_chooseForReport = nullptr;
}
refreshTopBarActiveChat();
updateTopBarSelection();
if (_channel) {
updateNotifyControls();
@ -2034,6 +2033,7 @@ void HistoryWidget::showHistory(
unreadCountUpdated(); // set _historyDown badge.
showAboutTopPromotion();
} else {
_chooseForReport = nullptr;
refreshTopBarActiveChat();
updateTopBarSelection();
checkMessagesTTL();
@ -3325,9 +3325,13 @@ void HistoryWidget::reportSelectedMessages() {
const auto peer = _peer;
const auto reason = _chooseForReport->reason;
const auto box = std::make_shared<QPointer<Ui::GenericBox>>();
const auto weak = Ui::MakeWeak(_list.data());
const auto send = [=](const QString &text) {
if (weak) {
clearSelected();
controller()->clearChooseReportMessages();
}
HistoryView::SendReport(peer, reason, text, ids);
controller()->clearChooseReportMessages();
if (*box) {
(*box)->closeBox();
}
@ -5514,6 +5518,7 @@ void HistoryWidget::setChooseReportMessagesDetails(
_list->clearChooseReportReason();
}
if (refresh) {
clearSelected();
updateControlsVisibility();
updateControlsGeometry();
updateTopBarChooseForReport();
@ -6260,7 +6265,9 @@ void HistoryWidget::confirmDeleteSelected() {
}
void HistoryWidget::escape() {
if (_nonEmptySelection && _list) {
if (_chooseForReport) {
controller()->clearChooseReportMessages();
} else if (_nonEmptySelection && _list) {
clearSelected();
} else if (_isInlineBot) {
cancelInlineBot();

View File

@ -736,6 +736,11 @@ HistoryMessageReply *Element::displayedReply() const {
return nullptr;
}
bool Element::toggleSelectionByHandlerClick(
const ClickHandlerPtr &handler) const {
return false;
}
bool Element::hasVisibleText() const {
return false;
}

View File

@ -292,6 +292,8 @@ public:
virtual void applyGroupAdminChanges(
const base::flat_set<UserId> &changes) {
}
[[nodiscard]] virtual bool toggleSelectionByHandlerClick(
const ClickHandlerPtr &handler) const;
struct VerticalRepaintRange {
int top = 0;

View File

@ -2184,16 +2184,10 @@ void ListWidget::mouseActionFinish(
repaintItem(pressState.itemId);
const auto toggleByHandler = [&](const ClickHandlerPtr &handler) {
if (_overElement) {
// If we are in selecting items mode perhaps we want to
// toggle selection instead of activating the pressed link.
if (const auto media = _overElement->media()) {
if (media->toggleSelectionByHandlerClick(handler)) {
return true;
}
}
}
return false;
// If we are in selecting items mode perhaps we want to
// toggle selection instead of activating the pressed link.
return _overElement
&& _overElement->toggleSelectionByHandlerClick(handler);
};
auto activated = ClickHandler::unpressed();

View File

@ -2059,6 +2059,18 @@ HistoryMessageReply *Message::displayedReply() const {
return nullptr;
}
bool Message::toggleSelectionByHandlerClick(
const ClickHandlerPtr &handler) const {
if (_comments && _comments->link == handler) {
return true;
} else if (const auto media = this->media()) {
if (media->toggleSelectionByHandlerClick(handler)) {
return true;
}
}
return false;
}
bool Message::displayPinIcon() const {
return data()->isPinned() && !isPinnedContext();
}

View File

@ -105,6 +105,8 @@ public:
bool displayEditedBadge() const override;
TimeId displayedEditDate() const override;
HistoryMessageReply *displayedReply() const override;
bool toggleSelectionByHandlerClick(
const ClickHandlerPtr &handler) const override;
int infoWidth() const override;
VerticalRepaintRange verticalRepaintRange() const override;

View File

@ -1419,7 +1419,10 @@ void MainWidget::showChooseReportMessages(
Ui::ReportReason reason,
Fn<void(MessageIdsList)> done) {
_history->setChooseReportMessagesDetails(reason, std::move(done));
ui_showPeerHistory(peer->id, SectionShow(), ShowForChooseMessagesMsgId);
ui_showPeerHistory(
peer->id,
SectionShow::Way::Forward,
ShowForChooseMessagesMsgId);
}
void MainWidget::clearChooseReportMessages() {

View File

@ -42,7 +42,7 @@ void ReportReasonBox(
const auto add = [&](Reason reason, tr::phrase<> text) {
const auto layout = box->verticalLayout();
const auto button = layout->add(
object_ptr<Ui::SettingsButton>(layout, text()));
object_ptr<SettingsButton>(layout, text()));
button->setClickedCallback([=] {
done(reason);
});
@ -63,7 +63,7 @@ void ReportDetailsBox(
not_null<GenericBox*> box,
Fn<void(QString)> done) {
box->addRow(
object_ptr<Ui::FlatLabel>(
object_ptr<FlatLabel>(
box, // #TODO reports
tr::lng_report_details_about(),
st::boxLabel),
@ -73,20 +73,23 @@ void ReportDetailsBox(
st::boxRowPadding.right(),
st::boxPadding.bottom() });
const auto details = box->addRow(
object_ptr<Ui::InputField>(
object_ptr<InputField>(
box,
st::newGroupDescription,
Ui::InputField::Mode::MultiLine,
InputField::Mode::MultiLine,
tr::lng_report_details(),
QString()));
details->setMaxLength(kReportReasonLengthMax);
box->setFocusCallback([=] {
details->setFocusFast();
});
box->addButton(tr::lng_report_button(), [=] {
const auto submit = [=] {
const auto text = details->getLastText();
done(text);
});
};
QObject::connect(details, &InputField::submitted, submit);
box->addButton(tr::lng_report_button(), submit);
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}