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() { void HistoryWidget::toggleTabbedSelectorMode() {
if (!_peer) { if (!_peer) {
return; return;

View file

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

View file

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

View file

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

View file

@ -1536,9 +1536,10 @@ void VoiceRecordBar::installClickOutsideFilter() {
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) { } else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
return Type::ShowBox; return Type::ShowBox;
} else if (type == QEvent::MouseButtonPress) { } else if (type == QEvent::MouseButtonPress) {
return (noBox && !_inField.current() && !_lock->underMouse()) return Type::Continue;
? Type::ShowBox // return (noBox && !_inField.current() && !_lock->underMouse())
: Type::Continue; // ? Type::ShowBox
// : Type::Continue;
} }
return Type::Continue; return Type::Continue;
}; };
@ -1609,4 +1610,22 @@ void VoiceRecordBar::installListenStateFilter() {
std::move(keyFilter)); 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 } // namespace HistoryView::Controls

View file

@ -47,6 +47,8 @@ public:
int recorderHeight); int recorderHeight);
~VoiceRecordBar(); ~VoiceRecordBar();
void showDiscardRecordingBox(Fn<void()> &&callback);
void startRecording(); void startRecording();
void finishAnimating(); void finishAnimating();
void hideAnimated(); 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) { QPixmap RepliesWidget::grabForShowAnimation(const Window::SectionSlideParams &params) {
_topBar->updateControlsVisibility(); _topBar->updateControlsVisibility();
if (params.withTopBarShadow) _topBarShadow->hide(); if (params.withTopBarShadow) _topBarShadow->hide();

View file

@ -75,6 +75,7 @@ public:
[[nodiscard]] not_null<History*> history() const; [[nodiscard]] not_null<History*> history() const;
Dialogs::RowDescriptor activeChat() const override; Dialogs::RowDescriptor activeChat() const override;
bool preventsClose(Fn<void()> &&continueCallback) const override;
bool hasTopBarShadow() const override { bool hasTopBarShadow() const override {
return true; 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) { QPixmap ScheduledWidget::grabForShowAnimation(const Window::SectionSlideParams &params) {
_topBar->updateControlsVisibility(); _topBar->updateControlsVisibility();
if (params.withTopBarShadow) _topBarShadow->hide(); if (params.withTopBarShadow) _topBarShadow->hide();

View file

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

View file

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

View file

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

View file

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