mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Added initial implementation of display sections prevent.
This commit is contained in:
parent
c8643aa1ee
commit
24b8377a2a
13 changed files with 95 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
int recorderHeight);
|
||||
~VoiceRecordBar();
|
||||
|
||||
void showDiscardRecordingBox(Fn<void()> &&callback);
|
||||
|
||||
void startRecording();
|
||||
void finishAnimating();
|
||||
void hideAnimated();
|
||||
|
|
|
@ -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 ¶ms) {
|
||||
_topBar->updateControlsVisibility();
|
||||
if (params.withTopBarShadow) _topBarShadow->hide();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ¶ms) {
|
||||
_topBar->updateControlsVisibility();
|
||||
if (params.withTopBarShadow) _topBarShadow->hide();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1403,6 +1403,7 @@ void MainWidget::ui_showPeerHistory(
|
|||
PeerId peerId,
|
||||
const SectionShow ¶ms,
|
||||
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>(¶ms.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 ¶ms) 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 ¶ms) {
|
||||
|
||||
if (preventsCloseSection([=] { showBackFromStack(params); }, params)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectingPeer()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -274,6 +274,9 @@ private:
|
|||
std::unique_ptr<Window::SectionMemento> &&memento,
|
||||
const SectionShow ¶ms);
|
||||
void dropMainSection(Window::SectionWidget *widget);
|
||||
bool preventsCloseSection(
|
||||
Fn<void()> callback,
|
||||
const SectionShow ¶ms) const;
|
||||
|
||||
Window::SectionSlideParams prepareThirdSectionAnimation(Window::SectionWidget *section);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue