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(
const QString &query) const -> SearchQuery {
Expects(_key.peer() != nullptr);

View File

@ -212,6 +212,8 @@ public:
void showBackFromStack(
const Window::SectionShow &params = Window::SectionShow()) override;
void removeFromStack(const std::vector<Section> &sections) const;
rpl::lifetime &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);
}
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 {
// This was done for tabs support.
//

View File

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

View File

@ -59,6 +59,16 @@ Widget::Widget(
controller->showBackFromStack();
}, _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) {
_inner->widthValue(
) | rpl::start_with_next([=](int w) {
@ -104,6 +114,9 @@ void Widget::saveChanges(FnMut<void()> done) {
void Widget::showFinished() {
_inner->showFinished();
_inner->removeFromStack(
) | rpl::start_to_stream(_removesFromStack, lifetime());
}
void Widget::setInnerFocus() {

View File

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

View File

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