mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Make dialogs filter onfocused by default.
This commit is contained in:
parent
dc438cff23
commit
2f03b9aa29
3 changed files with 89 additions and 78 deletions
|
@ -214,8 +214,8 @@ Widget::Widget(
|
|||
st::dialogsMenuToggle),
|
||||
.under = object_ptr<Ui::AbstractButton>(_searchControls),
|
||||
})
|
||||
, _searchForNarrowFilters(_searchControls, st::dialogsSearchForNarrowFilters)
|
||||
, _filter(_searchControls, st::dialogsFilter, tr::lng_dlg_filter())
|
||||
, _searchForNarrowLayout(_searchControls, st::dialogsSearchForNarrowFilters)
|
||||
, _search(_searchControls, st::dialogsFilter, tr::lng_dlg_filter())
|
||||
, _chooseFromUser(
|
||||
_searchControls,
|
||||
object_ptr<Ui::IconButton>(this, st::dialogsSearchFrom))
|
||||
|
@ -321,7 +321,7 @@ Widget::Widget(
|
|||
}, lifetime());
|
||||
_inner->refreshHashtagsRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
filterCursorMoved();
|
||||
searchCursorMoved();
|
||||
}, lifetime());
|
||||
_inner->cancelSearchFromUserRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
|
@ -330,7 +330,7 @@ Widget::Widget(
|
|||
: _searchInChat.sublist()
|
||||
? Key(session().data().history(session().user()))
|
||||
: _searchInChat, nullptr);
|
||||
applyFilterUpdate(true);
|
||||
applySearchUpdate(true);
|
||||
}, lifetime());
|
||||
_inner->chosenRow(
|
||||
) | rpl::start_with_next([=](const ChosenRow &row) {
|
||||
|
@ -353,17 +353,17 @@ Widget::Widget(
|
|||
Ui::PostponeCall(this, [=] { listScrollUpdated(); });
|
||||
}, lifetime());
|
||||
|
||||
_filter->changes(
|
||||
_search->changes(
|
||||
) | rpl::start_with_next([=] {
|
||||
applyFilterUpdate();
|
||||
}, _filter->lifetime());
|
||||
_filter->submits(
|
||||
) | rpl::start_with_next([=] { submit(); }, _filter->lifetime());
|
||||
applySearchUpdate();
|
||||
}, _search->lifetime());
|
||||
_search->submits(
|
||||
) | rpl::start_with_next([=] { submit(); }, _search->lifetime());
|
||||
QObject::connect(
|
||||
_filter->rawTextEdit().get(),
|
||||
_search->rawTextEdit().get(),
|
||||
&QTextEdit::cursorPositionChanged,
|
||||
this,
|
||||
[=] { filterCursorMoved(); },
|
||||
[=] { searchCursorMoved(); },
|
||||
Qt::QueuedConnection); // So getLastText() works already.
|
||||
|
||||
if (!Core::UpdaterDisabled()) {
|
||||
|
@ -401,8 +401,8 @@ Widget::Widget(
|
|||
setupStories();
|
||||
}
|
||||
|
||||
_searchForNarrowFilters->setClickedCallback([=] {
|
||||
_filter->setFocusFast();
|
||||
_searchForNarrowLayout->setClickedCallback([=] {
|
||||
_search->setFocusFast();
|
||||
if (_childList) {
|
||||
controller->closeForum();
|
||||
}
|
||||
|
@ -440,8 +440,8 @@ Widget::Widget(
|
|||
loadMoreBlockedByDate();
|
||||
}, lifetime());
|
||||
|
||||
_filter->setFocusPolicy(Qt::StrongFocus);
|
||||
_filter->customUpDown(true);
|
||||
_search->setFocusPolicy(Qt::StrongFocus);
|
||||
_search->customUpDown(true);
|
||||
|
||||
updateJumpToDateVisibility(true);
|
||||
updateSearchFromVisibility(true);
|
||||
|
@ -492,7 +492,7 @@ Widget::Widget(
|
|||
) | rpl::start_with_next([=](float64 shown) {
|
||||
const auto color = (shown > 0.) ? &st::dialogsRippleBg : nullptr;
|
||||
_mainMenu.toggle->setRippleColorOverride(color);
|
||||
_searchForNarrowFilters->setRippleColorOverride(color);
|
||||
_searchForNarrowLayout->setRippleColorOverride(color);
|
||||
}, lifetime());
|
||||
|
||||
setupMoreChatsBar();
|
||||
|
@ -806,7 +806,7 @@ void Widget::setupMainMenuToggle() {
|
|||
const auto filtersHidden = !controller()->filtersWidth();
|
||||
_mainMenu.toggle->setVisible(filtersHidden);
|
||||
_mainMenu.under->setVisible(filtersHidden);
|
||||
_searchForNarrowFilters->setVisible(!filtersHidden);
|
||||
_searchForNarrowLayout->setVisible(!filtersHidden);
|
||||
updateControlsGeometry();
|
||||
}, lifetime());
|
||||
|
||||
|
@ -1014,7 +1014,7 @@ void Widget::updateControlsVisibility(bool fast) {
|
|||
updateLoadMoreChatsVisibility();
|
||||
_scroll->show();
|
||||
updateStoriesVisibility();
|
||||
if ((_openedFolder || _openedForum) && _filter->hasFocus()) {
|
||||
if ((_openedFolder || _openedForum) && _search->hasFocus()) {
|
||||
setInnerFocus();
|
||||
}
|
||||
if (_updateTelegram) {
|
||||
|
@ -1039,9 +1039,6 @@ void Widget::updateControlsVisibility(bool fast) {
|
|||
_forumReportBar->show();
|
||||
}
|
||||
} else {
|
||||
if (hasFocus() && !_childList) {
|
||||
_filter->setFocusFast();
|
||||
}
|
||||
updateLockUnlockVisibility();
|
||||
updateJumpToDateVisibility(fast);
|
||||
updateSearchFromVisibility(fast);
|
||||
|
@ -1056,7 +1053,7 @@ void Widget::updateControlsVisibility(bool fast) {
|
|||
if (_hideChildListCanvas) {
|
||||
_hideChildListCanvas->show();
|
||||
}
|
||||
if (_childList && _filter->hasFocus()) {
|
||||
if (_childList && _search->hasFocus()) {
|
||||
setInnerFocus();
|
||||
}
|
||||
updateLockUnlockPosition();
|
||||
|
@ -1069,7 +1066,7 @@ void Widget::updateLockUnlockPosition() {
|
|||
const auto stories = (_stories && !_stories->isHidden())
|
||||
? _stories->collapsedGeometryCurrent()
|
||||
: Stories::List::CollapsedGeometry();
|
||||
const auto simple = _filter->x() + _filter->width();
|
||||
const auto simple = _search->x() + _search->width();
|
||||
const auto right = stories.geometry.isEmpty()
|
||||
? simple
|
||||
: anim::interpolate(stories.geometry.x(), simple, stories.expanded);
|
||||
|
@ -1215,7 +1212,7 @@ void Widget::refreshTopBars() {
|
|||
}, _subsectionTopBar->lifetime());
|
||||
_subsectionTopBar->searchQuery(
|
||||
) | rpl::start_with_next([=](QString query) {
|
||||
applyFilterUpdate();
|
||||
applySearchUpdate();
|
||||
}, _subsectionTopBar->lifetime());
|
||||
_subsectionTopBar->jumpToDateRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
|
@ -1381,9 +1378,12 @@ void Widget::checkUpdateStatus() {
|
|||
void Widget::setInnerFocus() {
|
||||
if (_childList) {
|
||||
_childList->setInnerFocus();
|
||||
} else if (!_openedFolder && !_openedForum) {
|
||||
_filter->setFocus();
|
||||
} else if (!_subsectionTopBar->searchSetFocus()) {
|
||||
} else if ((_openedFolder || _openedForum)
|
||||
&& _subsectionTopBar->searchSetFocus()) {
|
||||
return;
|
||||
} else if (!_search->getLastText().isEmpty() || _searchInChat) {
|
||||
_search->setFocus();
|
||||
} else {
|
||||
setFocus();
|
||||
}
|
||||
}
|
||||
|
@ -1514,7 +1514,7 @@ void Widget::updateStoriesVisibility() {
|
|||
|| _openedForum
|
||||
|| !_widthAnimationCache.isNull()
|
||||
|| _childList
|
||||
|| !_filter->getLastText().isEmpty()
|
||||
|| !_search->getLastText().isEmpty()
|
||||
|| _searchInChat
|
||||
|| _stories->empty();
|
||||
if (_stories->isHidden() != hidden) {
|
||||
|
@ -1631,7 +1631,7 @@ void Widget::slideFinished() {
|
|||
_shownProgressValue = 1.;
|
||||
updateControlsVisibility(true);
|
||||
if ((!_subsectionTopBar || !_subsectionTopBar->searchHasFocus())
|
||||
&& !_filter->hasFocus()) {
|
||||
&& !_search->hasFocus()) {
|
||||
controller()->widget()->setInnerFocus();
|
||||
}
|
||||
}
|
||||
|
@ -1963,7 +1963,7 @@ void Widget::searchMessages(QString query, Key inChat) {
|
|||
setSearchInChat(inChat, nullptr, tags);
|
||||
}
|
||||
setSearchQuery(query);
|
||||
applyFilterUpdate(true);
|
||||
applySearchUpdate(true);
|
||||
_searchTimer.cancel();
|
||||
searchMessages();
|
||||
|
||||
|
@ -2433,7 +2433,7 @@ void Widget::listScrollUpdated() {
|
|||
_scrollToTop->update();
|
||||
}
|
||||
|
||||
void Widget::applyFilterUpdate(bool force) {
|
||||
void Widget::applySearchUpdate(bool force) {
|
||||
if (_showAnimation && !force) {
|
||||
return;
|
||||
}
|
||||
|
@ -2462,13 +2462,13 @@ void Widget::applyFilterUpdate(bool force) {
|
|||
|| _searchFromAuthor
|
||||
|| !_searchTags.empty()) {
|
||||
auto switchToChooseFrom = HistoryView::SwitchToChooseFromQuery();
|
||||
if (_lastFilterText != switchToChooseFrom
|
||||
&& switchToChooseFrom.startsWith(_lastFilterText)
|
||||
if (_lastSearchText != switchToChooseFrom
|
||||
&& switchToChooseFrom.startsWith(_lastSearchText)
|
||||
&& filterText == switchToChooseFrom) {
|
||||
showSearchFrom();
|
||||
}
|
||||
}
|
||||
_lastFilterText = filterText;
|
||||
_lastSearchText = filterText;
|
||||
}
|
||||
|
||||
void Widget::showForum(
|
||||
|
@ -2574,7 +2574,7 @@ void Widget::closeChildList(anim::type animated) {
|
|||
_childListShown = 0.;
|
||||
if (hasFocus()) {
|
||||
setInnerFocus();
|
||||
_filter->finishAnimating();
|
||||
_search->finishAnimating();
|
||||
}
|
||||
if (animated == anim::type::normal) {
|
||||
_hideChildListCanvas->hide();
|
||||
|
@ -2673,7 +2673,7 @@ bool Widget::setSearchInChat(
|
|||
clearSearchCache();
|
||||
_searchTags = std::move(list);
|
||||
if (_searchTags.empty()) {
|
||||
applyFilterUpdate(true);
|
||||
applySearchUpdate(true);
|
||||
} else {
|
||||
searchMessages();
|
||||
}
|
||||
|
@ -2684,10 +2684,14 @@ bool Widget::setSearchInChat(
|
|||
_openedForum && _searchInChat);
|
||||
}
|
||||
if (_searchFromAuthor
|
||||
&& _lastFilterText == HistoryView::SwitchToChooseFromQuery()) {
|
||||
&& _lastSearchText == HistoryView::SwitchToChooseFromQuery()) {
|
||||
cancelSearch();
|
||||
}
|
||||
_filter->setFocus();
|
||||
if (_searchInChat) {
|
||||
_search->setFocus();
|
||||
} else {
|
||||
setFocus();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2735,18 +2739,18 @@ void Widget::showSearchFrom() {
|
|||
} else if (const auto strong = weak.get()) {
|
||||
setSearchInChat(strong, from);
|
||||
}
|
||||
applyFilterUpdate(true);
|
||||
applySearchUpdate(true);
|
||||
}),
|
||||
crl::guard(this, [=] { _filter->setFocus(); }));
|
||||
crl::guard(this, [=] { _search->setFocus(); }));
|
||||
if (box) {
|
||||
controller()->show(std::move(box));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::filterCursorMoved() {
|
||||
const auto to = _filter->textCursor().position();
|
||||
const auto text = _filter->getLastText();
|
||||
void Widget::searchCursorMoved() {
|
||||
const auto to = _search->textCursor().position();
|
||||
const auto text = _search->getLastText();
|
||||
auto hashtag = QStringView();
|
||||
for (int start = to; start > 0;) {
|
||||
--start;
|
||||
|
@ -2765,8 +2769,8 @@ void Widget::filterCursorMoved() {
|
|||
}
|
||||
|
||||
void Widget::completeHashtag(QString tag) {
|
||||
const auto t = _filter->getLastText();
|
||||
auto cur = _filter->textCursor().position();
|
||||
const auto t = _search->getLastText();
|
||||
auto cur = _search->textCursor().position();
|
||||
auto hashtag = QString();
|
||||
for (int start = cur; start > 0;) {
|
||||
--start;
|
||||
|
@ -2781,9 +2785,9 @@ void Widget::completeHashtag(QString tag) {
|
|||
}
|
||||
if (cur - start - 1 == tag.size() && cur < t.size() && t.at(cur) == ' ') ++cur;
|
||||
hashtag = t.mid(0, start + 1) + tag + ' ' + t.mid(cur);
|
||||
_filter->setText(hashtag);
|
||||
_filter->setCursorPosition(start + 1 + tag.size() + 1);
|
||||
applyFilterUpdate(true);
|
||||
_search->setText(hashtag);
|
||||
_search->setCursorPosition(start + 1 + tag.size() + 1);
|
||||
applySearchUpdate(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -2791,9 +2795,9 @@ void Widget::completeHashtag(QString tag) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
_filter->setText(t.mid(0, cur) + '#' + tag + ' ' + t.mid(cur));
|
||||
_filter->setCursorPosition(cur + 1 + tag.size() + 1);
|
||||
applyFilterUpdate(true);
|
||||
_search->setText(t.mid(0, cur) + '#' + tag + ' ' + t.mid(cur));
|
||||
_search->setCursorPosition(cur + 1 + tag.size() + 1);
|
||||
applySearchUpdate(true);
|
||||
}
|
||||
|
||||
void Widget::resizeEvent(QResizeEvent *e) {
|
||||
|
@ -2809,7 +2813,7 @@ void Widget::updateLockUnlockVisibility(anim::type animated) {
|
|||
|| _openedForum
|
||||
|| !_widthAnimationCache.isNull()
|
||||
|| _childList
|
||||
|| !_filter->getLastText().isEmpty()
|
||||
|| !_search->getLastText().isEmpty()
|
||||
|| _searchInChat;
|
||||
if (_lockUnlock->toggled() == hidden) {
|
||||
const auto stories = _stories && !_stories->empty();
|
||||
|
@ -2842,7 +2846,7 @@ void Widget::updateJumpToDateVisibility(bool fast) {
|
|||
}
|
||||
|
||||
_jumpToDate->toggle(
|
||||
(_searchInChat && _filter->getLastText().isEmpty()),
|
||||
(_searchInChat && _search->getLastText().isEmpty()),
|
||||
fast ? anim::type::instant : anim::type::normal);
|
||||
}
|
||||
|
||||
|
@ -2864,7 +2868,7 @@ void Widget::updateSearchFromVisibility(bool fast) {
|
|||
if (visible) {
|
||||
additional.setRight(_chooseFromUser->width());
|
||||
}
|
||||
_filter->setAdditionalMargins(additional);
|
||||
_search->setAdditionalMargins(additional);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2898,9 +2902,9 @@ void Widget::updateControlsGeometry() {
|
|||
narrowRatio);
|
||||
}
|
||||
|
||||
auto filterTop = (filterAreaHeight - _filter->height()) / 2;
|
||||
auto filterTop = (filterAreaHeight - _search->height()) / 2;
|
||||
filterLeft = anim::interpolate(filterLeft, _narrowWidth, narrowRatio);
|
||||
_filter->setGeometryToLeft(filterLeft, filterTop, filterWidth, _filter->height());
|
||||
_search->setGeometryToLeft(filterLeft, filterTop, filterWidth, _search->height());
|
||||
|
||||
auto mainMenuLeft = anim::interpolate(
|
||||
st::dialogsFilterPadding.x(),
|
||||
|
@ -2915,15 +2919,15 @@ void Widget::updateControlsGeometry() {
|
|||
+ _mainMenu.toggle->height()
|
||||
+ st::dialogsFilterPadding.y());
|
||||
const auto searchLeft = anim::interpolate(
|
||||
-_searchForNarrowFilters->width(),
|
||||
(_narrowWidth - _searchForNarrowFilters->width()) / 2,
|
||||
-_searchForNarrowLayout->width(),
|
||||
(_narrowWidth - _searchForNarrowLayout->width()) / 2,
|
||||
narrowRatio);
|
||||
_searchForNarrowFilters->moveToLeft(searchLeft, st::dialogsFilterPadding.y());
|
||||
_searchForNarrowLayout->moveToLeft(searchLeft, st::dialogsFilterPadding.y());
|
||||
|
||||
auto right = filterLeft + filterWidth;
|
||||
_cancelSearch->moveToLeft(right - _cancelSearch->width(), _filter->y());
|
||||
right -= _jumpToDate->width(); _jumpToDate->moveToLeft(right, _filter->y());
|
||||
right -= _chooseFromUser->width(); _chooseFromUser->moveToLeft(right, _filter->y());
|
||||
_cancelSearch->moveToLeft(right - _cancelSearch->width(), _search->y());
|
||||
right -= _jumpToDate->width(); _jumpToDate->moveToLeft(right, _search->y());
|
||||
right -= _chooseFromUser->width(); _chooseFromUser->moveToLeft(right, _search->y());
|
||||
|
||||
const auto barw = width();
|
||||
const auto expandedStoriesTop = filterAreaTop + filterAreaHeight;
|
||||
|
@ -3066,6 +3070,14 @@ void Widget::keyPressEvent(QKeyEvent *e) {
|
|||
_inner->selectSkipPage(_scroll->height(), 1);
|
||||
} else if (e->key() == Qt::Key_PageUp) {
|
||||
_inner->selectSkipPage(_scroll->height(), -1);
|
||||
} else if (!(e->modifiers() & ~Qt::ShiftModifier)
|
||||
&& e->key() != Qt::Key_Shift
|
||||
&& !_openedFolder
|
||||
&& !_openedForum
|
||||
&& _search->isVisible()
|
||||
&& !e->text().isEmpty()) {
|
||||
_search->setFocusFast();
|
||||
QCoreApplication::sendEvent(_search->rawTextEdit(), e);
|
||||
} else {
|
||||
e->ignore();
|
||||
}
|
||||
|
@ -3132,14 +3144,14 @@ Data::ForumTopic *Widget::searchInTopic() const {
|
|||
QString Widget::currentSearchQuery() const {
|
||||
return _subsectionTopBar
|
||||
? _subsectionTopBar->searchQueryCurrent()
|
||||
: _filter->getLastText();
|
||||
: _search->getLastText();
|
||||
}
|
||||
|
||||
void Widget::clearSearchField() {
|
||||
if (_subsectionTopBar) {
|
||||
_subsectionTopBar->searchClear();
|
||||
} else {
|
||||
_filter->clear();
|
||||
_search->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3147,7 +3159,7 @@ void Widget::setSearchQuery(const QString &query) {
|
|||
if (_subsectionTopBar) {
|
||||
_subsectionTopBar->searchSetText(query);
|
||||
} else {
|
||||
_filter->setText(query);
|
||||
_search->setText(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3176,7 +3188,10 @@ bool Widget::cancelSearch() {
|
|||
_lastSearchId = _lastSearchMigratedId = 0;
|
||||
_inner->clearFilter();
|
||||
clearSearchField();
|
||||
applyFilterUpdate();
|
||||
applySearchUpdate();
|
||||
if (!_searchInChat && _search->hasFocus()) {
|
||||
setFocus();
|
||||
}
|
||||
return clearingQuery || clearingInChat;
|
||||
}
|
||||
|
||||
|
@ -3193,7 +3208,7 @@ void Widget::cancelSearchInChat() {
|
|||
}
|
||||
setSearchInChat(Key());
|
||||
}
|
||||
applyFilterUpdate(true);
|
||||
applySearchUpdate(true);
|
||||
if (!isOneColumn) {
|
||||
controller()->content()->dialogsCancelled();
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ private:
|
|||
void chosenRow(const ChosenRow &row);
|
||||
void listScrollUpdated();
|
||||
void cancelSearchInChat();
|
||||
void filterCursorMoved();
|
||||
void searchCursorMoved();
|
||||
void completeHashtag(QString tag);
|
||||
|
||||
[[nodiscard]] QString currentSearchQuery() const;
|
||||
|
@ -223,7 +223,7 @@ private:
|
|||
void closeChildList(anim::type animated);
|
||||
|
||||
void fullSearchRefreshOn(rpl::producer<> events);
|
||||
void applyFilterUpdate(bool force = false);
|
||||
void applySearchUpdate(bool force = false);
|
||||
void refreshLoadMoreButton(bool mayBlock, bool isBlocked);
|
||||
void loadMoreBlockedByDate();
|
||||
|
||||
|
@ -255,8 +255,8 @@ private:
|
|||
object_ptr<Ui::IconButton> toggle;
|
||||
object_ptr<Ui::AbstractButton> under;
|
||||
} _mainMenu;
|
||||
object_ptr<Ui::IconButton> _searchForNarrowFilters;
|
||||
object_ptr<Ui::InputField> _filter;
|
||||
object_ptr<Ui::IconButton> _searchForNarrowLayout;
|
||||
object_ptr<Ui::InputField> _search;
|
||||
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _chooseFromUser;
|
||||
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _jumpToDate;
|
||||
object_ptr<Ui::CrossButton> _cancelSearch;
|
||||
|
@ -294,7 +294,7 @@ private:
|
|||
PeerData *_searchFromAuthor = nullptr;
|
||||
std::vector<Data::ReactionId> _searchTags;
|
||||
rpl::lifetime _searchTagsLifetime;
|
||||
QString _lastFilterText;
|
||||
QString _lastSearchText;
|
||||
|
||||
rpl::event_stream<rpl::producer<Stories::Content>> _storiesContents;
|
||||
base::flat_map<PeerId, Ui::PeerUserpicView> _storiesUserpicsViewsHidden;
|
||||
|
|
|
@ -1893,12 +1893,8 @@ int SessionController::minimalThreeColumnWidth() const {
|
|||
}
|
||||
|
||||
bool SessionController::forceWideDialogs() const {
|
||||
if (_dialogsListDisplayForced.current()) {
|
||||
return true;
|
||||
} else if (_dialogsListFocused.current()) {
|
||||
return true;
|
||||
}
|
||||
return !content()->isMainSectionShown();
|
||||
return _dialogsListDisplayForced.current()
|
||||
|| _dialogsListFocused.current();
|
||||
}
|
||||
|
||||
auto SessionController::computeColumnLayout() const -> ColumnLayout {
|
||||
|
|
Loading…
Add table
Reference in a new issue