Added ability to remove previous sections from stack in info widget.

This commit is contained in:
23rd 2022-05-03 07:02:51 +03:00
parent 549d7c77e5
commit 972666440e
7 changed files with 46 additions and 1 deletions

View file

@ -290,6 +290,10 @@ void Controller::showBackFromStack(const Window::SectionShow &params) {
} }
} }
void Controller::removeFromStack(const std::vector<Section> &sections) const {
_widget->removeFromStack(sections);
}
auto Controller::produceSearchQuery( auto Controller::produceSearchQuery(
const QString &query) const -> SearchQuery { const QString &query) const -> SearchQuery {
Expects(_key.peer() != nullptr); Expects(_key.peer() != nullptr);

View file

@ -212,6 +212,8 @@ public:
void showBackFromStack( void showBackFromStack(
const Window::SectionShow &params = Window::SectionShow()) override; const Window::SectionShow &params = Window::SectionShow()) override;
void removeFromStack(const std::vector<Section> &sections) const;
rpl::lifetime &lifetime() { rpl::lifetime &lifetime() {
return _lifetime; return _lifetime;
} }
@ -240,4 +242,4 @@ private:
}; };
} // namespace Info } // namespace Info

View file

@ -596,6 +596,26 @@ bool WrapWidget::showBackFromStackInternal(
return (wrap() == Wrap::Layer); return (wrap() == Wrap::Layer);
} }
void WrapWidget::removeFromStack(const std::vector<Section> &sections) {
for (const auto &section : sections) {
const auto it = ranges::find_if(_historyStack, [&](
const StackItem &item) {
const auto &s = item.section->section();
if (s.type() != section.type()) {
return false;
} else if (s.type() == Section::Type::Media) {
return (s.mediaType() == section.mediaType());
} else if (s.type() == Section::Type::Settings) {
return (s.settingsType() == section.settingsType());
}
return false;
});
if (it != end(_historyStack)) {
_historyStack.erase(it);
}
}
}
not_null<Ui::RpWidget*> WrapWidget::topWidget() const { not_null<Ui::RpWidget*> WrapWidget::topWidget() const {
// This was done for tabs support. // This was done for tabs support.
// //

View file

@ -106,6 +106,7 @@ public:
not_null<Window::SectionMemento*> memento, not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) override; const Window::SectionShow &params) override;
bool showBackFromStackInternal(const Window::SectionShow &params); bool showBackFromStackInternal(const Window::SectionShow &params);
void removeFromStack(const std::vector<Section> &sections);
std::shared_ptr<Window::SectionMemento> createMemento() override; std::shared_ptr<Window::SectionMemento> createMemento() override;
rpl::producer<int> desiredHeightValue() const override; rpl::producer<int> desiredHeightValue() const override;

View file

@ -59,6 +59,16 @@ Widget::Widget(
controller->showBackFromStack(); controller->showBackFromStack();
}, _inner->lifetime()); }, _inner->lifetime());
_removesFromStack.events(
) | rpl::start_with_next([=](const std::vector<Type> &types) {
const auto sections = ranges::views::all(
types
) | ranges::views::transform([](Type type) {
return Section(type);
}) | ranges::to_vector;
controller->removeFromStack(sections);
}, _inner->lifetime());
if (_pinnedToTop) { if (_pinnedToTop) {
_inner->widthValue( _inner->widthValue(
) | rpl::start_with_next([=](int w) { ) | rpl::start_with_next([=](int w) {
@ -104,6 +114,9 @@ void Widget::saveChanges(FnMut<void()> done) {
void Widget::showFinished() { void Widget::showFinished() {
_inner->showFinished(); _inner->showFinished();
_inner->removeFromStack(
) | rpl::start_to_stream(_removesFromStack, lifetime());
} }
void Widget::setInnerFocus() { void Widget::setInnerFocus() {

View file

@ -84,6 +84,8 @@ private:
not_null<::Settings::AbstractSection*> _inner; not_null<::Settings::AbstractSection*> _inner;
QPointer<Ui::RpWidget> _pinnedToTop; QPointer<Ui::RpWidget> _pinnedToTop;
rpl::event_stream<std::vector<Type>> _removesFromStack;
}; };
} // namespace Settings } // namespace Settings

View file

@ -81,6 +81,9 @@ public:
[[nodiscard]] virtual rpl::producer<> sectionShowBack() { [[nodiscard]] virtual rpl::producer<> sectionShowBack() {
return nullptr; return nullptr;
} }
[[nodiscard]] virtual rpl::producer<std::vector<Type>> removeFromStack() {
return nullptr;
}
[[nodiscard]] virtual rpl::producer<QString> title() = 0; [[nodiscard]] virtual rpl::producer<QString> title() = 0;
virtual void sectionSaveChanges(FnMut<void()> done) { virtual void sectionSaveChanges(FnMut<void()> done) {
done(); done();