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