mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Fixed Escape hotkey in info sections with search field.
This commit is contained in:
parent
bd084f9181
commit
683c3c4f36
9 changed files with 56 additions and 16 deletions
|
@ -289,6 +289,18 @@ void ContentWidget::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
|
|||
addAction);
|
||||
}
|
||||
|
||||
void ContentWidget::checkBeforeCloseByEscape(Fn<void()> close) {
|
||||
if (_searchField) {
|
||||
if (!_searchField->empty()) {
|
||||
_searchField->setText({});
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<SelectedItems> ContentWidget::selectedListValue() const {
|
||||
return rpl::single(SelectedItems(Storage::SharedMediaType::Photo));
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ public:
|
|||
virtual void checkBeforeClose(Fn<void()> close) {
|
||||
close();
|
||||
}
|
||||
virtual void checkBeforeCloseByEscape(Fn<void()> close);
|
||||
[[nodiscard]] virtual rpl::producer<QString> title() = 0;
|
||||
[[nodiscard]] virtual rpl::producer<QString> subtitle() {
|
||||
return nullptr;
|
||||
|
|
|
@ -216,6 +216,19 @@ void TopBar::clearSearchField() {
|
|||
_searchView = nullptr;
|
||||
}
|
||||
|
||||
void TopBar::checkBeforeCloseByEscape(Fn<void()> close) {
|
||||
if (_searchModeEnabled) {
|
||||
if (_searchField && !_searchField->empty()) {
|
||||
_searchField->setText({});
|
||||
} else {
|
||||
_searchModeEnabled = false;
|
||||
updateControlsVisibility(anim::type::normal);
|
||||
}
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void TopBar::createSearchView(
|
||||
not_null<Ui::InputField*> field,
|
||||
rpl::producer<bool> &&shown,
|
||||
|
@ -269,18 +282,14 @@ void TopBar::createSearchView(
|
|||
return !selectionMode() && searchMode();
|
||||
});
|
||||
|
||||
auto cancelSearch = [=] {
|
||||
cancel->addClickHandler([=] {
|
||||
if (!field->getLastText().isEmpty()) {
|
||||
field->setText(QString());
|
||||
} else {
|
||||
_searchModeEnabled = false;
|
||||
updateControlsVisibility(anim::type::normal);
|
||||
}
|
||||
};
|
||||
|
||||
cancel->addClickHandler(cancelSearch);
|
||||
field->cancelled(
|
||||
) | rpl::start_with_next(cancelSearch, field->lifetime());
|
||||
});
|
||||
|
||||
wrap->widthValue(
|
||||
) | rpl::start_with_next([=](int newWidth) {
|
||||
|
|
|
@ -103,6 +103,8 @@ public:
|
|||
|
||||
void showSearch();
|
||||
|
||||
void checkBeforeCloseByEscape(Fn<void()> close);
|
||||
|
||||
protected:
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
|
|
@ -439,6 +439,20 @@ void WrapWidget::checkBeforeClose(Fn<void()> close) {
|
|||
}));
|
||||
}
|
||||
|
||||
void WrapWidget::checkBeforeCloseByEscape(Fn<void()> close) {
|
||||
if (_topBar) {
|
||||
_topBar->checkBeforeCloseByEscape([&] {
|
||||
_content->checkBeforeCloseByEscape(crl::guard(this, [=] {
|
||||
WrapWidget::checkBeforeClose(close);
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
_content->checkBeforeCloseByEscape(crl::guard(this, [=] {
|
||||
WrapWidget::checkBeforeClose(close);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
void WrapWidget::addTopBarMenuButton() {
|
||||
Expects(_topBar != nullptr);
|
||||
Expects(_content != nullptr);
|
||||
|
@ -895,13 +909,11 @@ void WrapWidget::resizeEvent(QResizeEvent *e) {
|
|||
|
||||
void WrapWidget::keyPressEvent(QKeyEvent *e) {
|
||||
if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Back) {
|
||||
if (hasStackHistory() || wrap() != Wrap::Layer) {
|
||||
checkBeforeClose([=] { _controller->showBackFromStack(); });
|
||||
} else {
|
||||
checkBeforeClose([=] {
|
||||
checkBeforeCloseByEscape((hasStackHistory() || wrap() != Wrap::Layer)
|
||||
? Fn<void()>([=] { _controller->showBackFromStack(); })
|
||||
: Fn<void()>([=] {
|
||||
_controller->parentController()->hideSpecialLayer();
|
||||
});
|
||||
}
|
||||
}));
|
||||
return;
|
||||
}
|
||||
SectionWidget::keyPressEvent(e);
|
||||
|
|
|
@ -161,6 +161,7 @@ private:
|
|||
void injectActiveProfileMemento(
|
||||
std::shared_ptr<ContentMemento> memento);
|
||||
void checkBeforeClose(Fn<void()> close);
|
||||
void checkBeforeCloseByEscape(Fn<void()> close);
|
||||
void restoreHistoryStack(
|
||||
std::vector<std::shared_ptr<ContentMemento>> stack);
|
||||
bool hasStackHistory() const {
|
||||
|
|
|
@ -240,6 +240,12 @@ void Widget::checkBeforeClose(Fn<void()> close) {
|
|||
_inner->checkBeforeClose(std::move(close));
|
||||
}
|
||||
|
||||
void Widget::checkBeforeCloseByEscape(Fn<void()> close) {
|
||||
ContentWidget::checkBeforeCloseByEscape([&] {
|
||||
_inner->checkBeforeClose(std::move(close));
|
||||
});
|
||||
}
|
||||
|
||||
rpl::producer<QString> Widget::title() {
|
||||
return _inner->title();
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
|
||||
bool closeByOutsideClick() const override;
|
||||
void checkBeforeClose(Fn<void()> close) override;
|
||||
void checkBeforeCloseByEscape(Fn<void()> close) override;
|
||||
rpl::producer<QString> title() override;
|
||||
|
||||
void enableBackButton() override;
|
||||
|
|
|
@ -30,10 +30,6 @@ auto SearchFieldController::createRowView(
|
|||
|
||||
auto field = createField(wrap, st.field).release();
|
||||
field->show();
|
||||
field->cancelled(
|
||||
) | rpl::start_with_next([=] {
|
||||
field->setText(QString());
|
||||
}, field->lifetime());
|
||||
|
||||
auto cancel = CreateChild<Ui::CrossButton>(
|
||||
wrap,
|
||||
|
|
Loading…
Add table
Reference in a new issue