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

@ -3914,6 +3914,14 @@ void HistoryWidget::setTabbedPanel(std::unique_ptr<TabbedPanel> panel) {
}
}
bool HistoryWidget::preventsClose(Fn<void()> &&continueCallback) const {
if (isRecording()) {
_voiceRecordBar->showDiscardRecordingBox(std::move(continueCallback));
return true;
}
return false;
}
void HistoryWidget::toggleTabbedSelectorMode() {
if (!_peer) {
return;

View File

@ -119,6 +119,8 @@ public:
void historyLoaded();
[[nodiscard]] bool preventsClose(Fn<void()> &&continueCallback) const;
// When resizing the widget with top edge moved up or down and we
// want to add this top movement to the scroll position, so inner
// content will not move.

View File

@ -2138,6 +2138,14 @@ bool ComposeControls::isRecording() const {
return _voiceRecordBar->isRecording();
}
bool ComposeControls::preventsClose(Fn<void()> &&continueCallback) const {
if (isRecording()) {
_voiceRecordBar->showDiscardRecordingBox(std::move(continueCallback));
return true;
}
return false;
}
void ComposeControls::updateInlineBotQuery() {
if (!_history) {
return;

View File

@ -135,6 +135,8 @@ public:
[[nodiscard]] bool isEditingMessage() const;
[[nodiscard]] FullMsgId replyingToMessage() const;
[[nodiscard]] bool preventsClose(Fn<void()> &&continueCallback) const;
void showForGrab();
void showStarted();
void showFinished();

View File

@ -1536,9 +1536,10 @@ void VoiceRecordBar::installClickOutsideFilter() {
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
return Type::ShowBox;
} else if (type == QEvent::MouseButtonPress) {
return (noBox && !_inField.current() && !_lock->underMouse())
? Type::ShowBox
: Type::Continue;
return Type::Continue;
// return (noBox && !_inField.current() && !_lock->underMouse())
// ? Type::ShowBox
// : Type::Continue;
}
return Type::Continue;
};
@ -1609,4 +1610,22 @@ void VoiceRecordBar::installListenStateFilter() {
std::move(keyFilter));
}
void VoiceRecordBar::showDiscardRecordingBox(Fn<void()> &&callback) {
if (!isRecording()) {
return;
}
auto sure = [=, callback = std::move(callback)](Fn<void()> &&close) {
hideFast();
close();
if (callback) {
callback();
}
};
Ui::show(Box<ConfirmBox>(
tr::lng_record_lock_cancel_sure(tr::now),
tr::lng_record_lock_discard(tr::now),
st::attentionBoxButton,
std::move(sure)));
}
} // namespace HistoryView::Controls

View File

@ -47,6 +47,8 @@ public:
int recorderHeight);
~VoiceRecordBar();
void showDiscardRecordingBox(Fn<void()> &&callback);
void startRecording();
void finishAnimating();
void hideAnimated();

View File

@ -1315,6 +1315,10 @@ Dialogs::RowDescriptor RepliesWidget::activeChat() const {
};
}
bool RepliesWidget::preventsClose(Fn<void()> &&continueCallback) const {
return _composeControls->preventsClose(std::move(continueCallback));
}
QPixmap RepliesWidget::grabForShowAnimation(const Window::SectionSlideParams &params) {
_topBar->updateControlsVisibility();
if (params.withTopBarShadow) _topBarShadow->hide();

View File

@ -75,6 +75,7 @@ public:
[[nodiscard]] not_null<History*> history() const;
Dialogs::RowDescriptor activeChat() const override;
bool preventsClose(Fn<void()> &&continueCallback) const override;
bool hasTopBarShadow() const override {
return true;

View File

@ -894,6 +894,10 @@ Dialogs::RowDescriptor ScheduledWidget::activeChat() const {
};
}
bool ScheduledWidget::preventsClose(Fn<void()> &&continueCallback) const {
return _composeControls->preventsClose(std::move(continueCallback));
}
QPixmap ScheduledWidget::grabForShowAnimation(const Window::SectionSlideParams &params) {
_topBar->updateControlsVisibility();
if (params.withTopBarShadow) _topBarShadow->hide();

View File

@ -60,6 +60,7 @@ public:
not_null<History*> history() const;
Dialogs::RowDescriptor activeChat() const override;
bool preventsClose(Fn<void()> &&continueCallback) const override;
bool hasTopBarShadow() const override {
return true;

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;
}

View File

@ -274,6 +274,9 @@ private:
std::unique_ptr<Window::SectionMemento> &&memento,
const SectionShow &params);
void dropMainSection(Window::SectionWidget *widget);
bool preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const;
Window::SectionSlideParams prepareThirdSectionAnimation(Window::SectionWidget *section);

View File

@ -129,6 +129,10 @@ public:
return false;
}
virtual bool preventsClose(Fn<void()> &&continueCallback) const {
return false;
}
// Create a memento of that section to store it in the history stack.
// This method may modify the section ("take" heavy items).
virtual std::unique_ptr<SectionMemento> createMemento();