2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Added initial implementation of display sections prevent.

This commit is contained in:
23rd
2020-11-22 02:18:58 +03:00
committed by John Preston
parent c8643aa1ee
commit 24b8377a2a
13 changed files with 95 additions and 4 deletions

View File

@@ -1403,6 +1403,7 @@ void MainWidget::ui_showPeerHistory(
PeerId peerId,
const SectionShow &params,
MsgId showAtMsgId) {
if (auto peer = session().data().peerLoaded(peerId)) {
if (peer->migrateTo()) {
peer = peer->migrateTo();
@@ -1423,6 +1424,13 @@ void MainWidget::ui_showPeerHistory(
return;
}
if (!(_history->peer() && _history->peer()->id == peerId)
&& preventsCloseSection(
[=] { ui_showPeerHistory(peerId, params, showAtMsgId); },
params)) {
return;
}
using OriginMessage = SectionShow::OriginMessage;
if (const auto origin = std::get_if<OriginMessage>(&params.origin)) {
if (const auto returnTo = session().data().message(origin->id)) {
@@ -1618,13 +1626,22 @@ void MainWidget::showSection(
// return;
}
using MementoPtr = std::unique_ptr<Window::SectionMemento>;
const auto sharedMemento = std::make_shared<MementoPtr>(
std::move(memento));
if (preventsCloseSection(
[=] { showSection(base::take(*sharedMemento), params); },
params)) {
return;
}
// If the window was not resized, but we've enabled
// tabbedSelectorSectionEnabled or thirdSectionInfoEnabled
// we need to update adaptive layout to Adaptive::ThirdColumn().
updateColumnLayout();
showNewSection(
std::move(memento),
std::move(*sharedMemento),
params);
}
@@ -1880,8 +1897,24 @@ bool MainWidget::stackIsEmpty() const {
return _stack.empty();
}
bool MainWidget::preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const {
if (params.thirdColumn || Core::App().passcodeLocked()) {
return false;
}
auto copy = callback;
return (_mainSection && _mainSection->preventsClose(std::move(copy)))
|| (_history && _history->preventsClose(std::move(callback)));
}
void MainWidget::showBackFromStack(
const SectionShow &params) {
if (preventsCloseSection([=] { showBackFromStack(params); }, params)) {
return;
}
if (selectingPeer()) {
return;
}