From 41b143cb7e2bb1f1c81cd4e7a02d47fd9ece3fc5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 29 Nov 2017 00:01:00 +0400 Subject: [PATCH] Fix and improve back navigation with three columns. --- Telegram/SourceFiles/info/info_top_bar.h | 4 ++ .../SourceFiles/info/info_wrap_widget.cpp | 1 + Telegram/SourceFiles/mainwidget.cpp | 64 +++++++++++++++---- Telegram/SourceFiles/mainwidget.h | 4 ++ 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/info/info_top_bar.h b/Telegram/SourceFiles/info/info_top_bar.h index 002e0ef63..1156128f0 100644 --- a/Telegram/SourceFiles/info/info_top_bar.h +++ b/Telegram/SourceFiles/info/info_top_bar.h @@ -76,6 +76,10 @@ public: rpl::producer<> cancelSelectionRequests() const; + void finishAnimating() { + updateControlsVisibility(anim::type::instant); + } + protected: int resizeGetHeight(int newWidth) override; void paintEvent(QPaintEvent *e) override; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 45e00db5c..ad831b9f6 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -336,6 +336,7 @@ void WrapWidget::createTopBar() { _topBar->lower(); _topBar->resizeToWidth(width()); + _topBar->finishAnimating(); _topBar->show(); } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 48d35301f..26ee595ea 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -41,6 +41,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/resize_area.h" #include "chat_helpers/message_field.h" #include "chat_helpers/stickers.h" +#include "info/info_memento.h" #include "observer_peer.h" #include "apiwrap.h" #include "dialogs/dialogs_widget.h" @@ -123,8 +124,15 @@ public: void setThirdSectionMemento( std::unique_ptr &&memento); - Window::SectionMemento *thirdSectionMemento() const { - return _thirdSectionMemento.get(); + std::unique_ptr takeThirdSectionMemento() { + return std::move(_thirdSectionMemento); + } + + void setThirdSectionWeak(QPointer section) { + _thirdSectionWeak = section; + } + QPointer thirdSectionWeak() const { + return _thirdSectionWeak; } virtual StackItemType type() const = 0; @@ -132,6 +140,7 @@ public: private: PeerData *_peer = nullptr; + QPointer _thirdSectionWeak; std::unique_ptr _thirdSectionMemento; }; @@ -2541,6 +2550,7 @@ void MainWidget::saveSectionInStack() { if (auto memento = _mainSection->createMemento()) { _stack.push_back(std::make_unique( std::move(memento))); + _stack.back()->setThirdSectionWeak(_thirdSection.data()); } } else if (_history->peer()) { _peerInStack = _history->peer(); @@ -2549,6 +2559,7 @@ void MainWidget::saveSectionInStack() { _peerInStack, _msgIdInStack, _history->replyReturns())); + _stack.back()->setThirdSectionWeak(_thirdSection.data()); } } @@ -2875,6 +2886,7 @@ void MainWidget::showBackFromStack( if (auto currentHistoryPeer = _history->peer()) { clearBotStartToken(currentHistoryPeer); } + _thirdSectionFromStack = item->takeThirdSectionMemento(); if (item->type() == HistoryStackItem) { dlgUpdated(); _peerInStack = nullptr; @@ -2900,15 +2912,14 @@ void MainWidget::showBackFromStack( std::move(*sectionItem->memento()), params.withWay(SectionShow::Way::Backward)); } - if (auto memento = item->thirdSectionMemento()) { - if (_thirdSection) { - _controller->showSection( - std::move(*memento), - SectionShow( - SectionShow::Way::ClearStack, - anim::type::instant, - anim::activation::background)); - } + if (_thirdSectionFromStack && _thirdSection) { + _controller->showSection( + std::move(*base::take(_thirdSectionFromStack)), + SectionShow( + SectionShow::Way::ClearStack, + anim::type::instant, + anim::activation::background)); + } } @@ -3432,11 +3443,26 @@ void MainWidget::updateDialogsWidthAnimated() { } } +bool MainWidget::saveThirdSectionToStackBack() const { + return !_stack.empty() + && _thirdSection != nullptr + && _stack.back()->thirdSectionWeak() == _thirdSection.data(); +} + +auto MainWidget::thirdSectionForCurrentMainSection( + not_null peer) +-> std::unique_ptr { + if (_thirdSectionFromStack) { + return std::move(_thirdSectionFromStack); + } + return std::make_unique(peer->id); +} + void MainWidget::updateThirdColumnToCurrentPeer( PeerData *peer, bool canWrite) { auto saveOldThirdSection = [&] { - if (!_stack.empty() && _thirdSection) { + if (saveThirdSectionToStackBack()) { _stack.back()->setThirdSectionMemento( _thirdSection->createMemento()); _thirdSection.destroy(); @@ -3448,7 +3474,19 @@ void MainWidget::updateThirdColumnToCurrentPeer( anim::activation::background); auto switchInfoFast = [&] { saveOldThirdSection(); - _controller->showPeerInfo(peer, params); + + // + // Like in _controller->showPeerInfo() + // + if (Adaptive::ThreeColumn() + && !Auth().data().thirdSectionInfoEnabled()) { + Auth().data().setThirdSectionInfoEnabled(true); + Auth().saveDataDelayed(); + } + + _controller->showSection( + std::move(*thirdSectionForCurrentMainSection(peer)), + params); }; auto switchTabbedFast = [&] { saveOldThirdSection(); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index f8cc317ba..3e5616d7a 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -437,6 +437,9 @@ private: void updateThirdColumnToCurrentPeer( PeerData *peer, bool canWrite); + [[nodiscard]] bool saveThirdSectionToStackBack() const; + [[nodiscard]] auto thirdSectionForCurrentMainSection( + not_null peer) -> std::unique_ptr; void createPlayer(); void switchToPanelPlayer(); @@ -578,6 +581,7 @@ private: object_ptr _history; object_ptr _mainSection = { nullptr }; object_ptr _thirdSection = { nullptr }; + std::unique_ptr _thirdSectionFromStack; base::weak_unique_ptr _currentCall; object_ptr> _callTopBar = { nullptr };