mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allow clearing search results.
This commit is contained in:
parent
2a6ff9203b
commit
051ca51d3b
5 changed files with 141 additions and 36 deletions
|
@ -1453,13 +1453,19 @@ void Widget::setInnerFocus() {
|
||||||
} else if ((_openedFolder || _openedForum)
|
} else if ((_openedFolder || _openedForum)
|
||||||
&& _subsectionTopBar->searchSetFocus()) {
|
&& _subsectionTopBar->searchSetFocus()) {
|
||||||
return;
|
return;
|
||||||
} else if (!_search->getLastText().isEmpty() || _searchInChat) {
|
} else if (!_search->getLastText().isEmpty()
|
||||||
|
|| _searchInChat
|
||||||
|
|| _searchHasFocus) {
|
||||||
_search->setFocus();
|
_search->setFocus();
|
||||||
} else {
|
} else {
|
||||||
setFocus();
|
setFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Widget::searchHasFocus() const {
|
||||||
|
return _searchHasFocus;
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::jumpToTop(bool belowPinned) {
|
void Widget::jumpToTop(bool belowPinned) {
|
||||||
if (session().supportMode()) {
|
if (session().supportMode()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -100,6 +100,7 @@ public:
|
||||||
const Window::SectionShow ¶ms);
|
const Window::SectionShow ¶ms);
|
||||||
void searchInChat(Key chat);
|
void searchInChat(Key chat);
|
||||||
void setInnerFocus();
|
void setInnerFocus();
|
||||||
|
[[nodiscard]] bool searchHasFocus() const;
|
||||||
|
|
||||||
void jumpToTop(bool belowPinned = false);
|
void jumpToTop(bool belowPinned = false);
|
||||||
void raiseWithTooltip();
|
void raiseWithTooltip();
|
||||||
|
|
|
@ -21,9 +21,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/elastic_scroll.h"
|
#include "ui/widgets/elastic_scroll.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/delayed_activation.h"
|
#include "ui/delayed_activation.h"
|
||||||
|
@ -70,10 +72,12 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RecentsController final : public PeerListController {
|
class RecentsController final
|
||||||
|
: public PeerListController
|
||||||
|
, public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
RecentsController(
|
RecentsController(
|
||||||
not_null<Main::Session*> session,
|
not_null<Window::SessionController*> window,
|
||||||
RecentPeersList list);
|
RecentPeersList list);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<int> count() const {
|
[[nodiscard]] rpl::producer<int> count() const {
|
||||||
|
@ -95,8 +99,9 @@ public:
|
||||||
private:
|
private:
|
||||||
void setupDivider();
|
void setupDivider();
|
||||||
void subscribeToEvents();
|
void subscribeToEvents();
|
||||||
|
[[nodiscard]] Fn<void()> removeAllCallback();
|
||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Window::SessionController*> _window;
|
||||||
RecentPeersList _recent;
|
RecentPeersList _recent;
|
||||||
rpl::variable<int> _count;
|
rpl::variable<int> _count;
|
||||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||||
|
@ -105,14 +110,33 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void FillTopPeerMenu(
|
struct EntryMenuDescriptor {
|
||||||
|
not_null<Window::SessionController*> controller;
|
||||||
|
not_null<PeerData*> peer;
|
||||||
|
QString removeOneText;
|
||||||
|
Fn<void()> removeOne;
|
||||||
|
QString removeAllText;
|
||||||
|
QString removeAllConfirm;
|
||||||
|
Fn<void()> removeAll;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] Fn<void()> RemoveAllConfirm(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const ShowTopPeerMenuRequest &request,
|
QString removeAllConfirm,
|
||||||
Fn<void(not_null<PeerData*>)> remove,
|
Fn<void()> removeAll) {
|
||||||
Fn<void()> hideAll) {
|
return [=] {
|
||||||
const auto owner = &controller->session().data();
|
controller->show(Ui::MakeConfirmBox({
|
||||||
const auto peer = owner->peer(PeerId(request.id));
|
.text = removeAllConfirm,
|
||||||
const auto &add = request.callback;
|
.confirmed = [=](Fn<void()> close) { removeAll(); close(); }
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void FillEntryMenu(
|
||||||
|
const Ui::Menu::MenuCallback &add,
|
||||||
|
EntryMenuDescriptor &&descriptor) {
|
||||||
|
const auto peer = descriptor.peer;
|
||||||
|
const auto controller = descriptor.controller;
|
||||||
const auto group = peer->isMegagroup();
|
const auto group = peer->isMegagroup();
|
||||||
const auto channel = peer->isChannel();
|
const auto channel = peer->isChannel();
|
||||||
|
|
||||||
|
@ -143,21 +167,18 @@ void FillTopPeerMenu(
|
||||||
add({ .separatorSt = &st::expandedMenuSeparator });
|
add({ .separatorSt = &st::expandedMenuSeparator });
|
||||||
|
|
||||||
add({
|
add({
|
||||||
.text = tr::lng_recent_remove(tr::now),
|
.text = descriptor.removeOneText,
|
||||||
.handler = [=] { remove(peer); },
|
.handler = descriptor.removeOne,
|
||||||
.icon = &st::menuIconDeleteAttention,
|
.icon = &st::menuIconDeleteAttention,
|
||||||
.isAttention = true,
|
.isAttention = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto hideAllConfirmed = [=] {
|
|
||||||
controller->show(Ui::MakeConfirmBox({
|
|
||||||
.text = tr::lng_recent_hide_sure(),
|
|
||||||
.confirmed = [=](Fn<void()> close) { hideAll(); close(); }
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
add({
|
add({
|
||||||
.text = tr::lng_recent_hide_top(tr::now).replace('&', u"&&"_q),
|
.text = descriptor.removeAllText,
|
||||||
.handler = hideAllConfirmed,
|
.handler = RemoveAllConfirm(
|
||||||
|
descriptor.controller,
|
||||||
|
descriptor.removeAllConfirm,
|
||||||
|
descriptor.removeAll),
|
||||||
.icon = &st::menuIconCancelAttention,
|
.icon = &st::menuIconCancelAttention,
|
||||||
.isAttention = true,
|
.isAttention = true,
|
||||||
});
|
});
|
||||||
|
@ -257,9 +278,9 @@ QPoint RecentRow::computeNamePosition(const style::PeerListItem &st) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
RecentsController::RecentsController(
|
RecentsController::RecentsController(
|
||||||
not_null<Main::Session*> session,
|
not_null<Window::SessionController*> window,
|
||||||
RecentPeersList list)
|
RecentPeersList list)
|
||||||
: _session(session)
|
: _window(window)
|
||||||
, _recent(std::move(list)) {
|
, _recent(std::move(list)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,14 +300,55 @@ void RecentsController::rowClicked(not_null<PeerListRow*> row) {
|
||||||
_chosen.fire(row->peer());
|
_chosen.fire(row->peer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fn<void()> RecentsController::removeAllCallback() {
|
||||||
|
const auto weak = base::make_weak(this);
|
||||||
|
const auto session = &_window->session();
|
||||||
|
return crl::guard(session, [=] {
|
||||||
|
if (weak) {
|
||||||
|
_count = 0;
|
||||||
|
while (delegate()->peerListFullRowsCount() > 0) {
|
||||||
|
delegate()->peerListRemoveRow(delegate()->peerListRowAt(0));
|
||||||
|
}
|
||||||
|
delegate()->peerListRefreshRows();
|
||||||
|
}
|
||||||
|
session->recentPeers().clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
base::unique_qptr<Ui::PopupMenu> RecentsController::rowContextMenu(
|
base::unique_qptr<Ui::PopupMenu> RecentsController::rowContextMenu(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<PeerListRow*> row) {
|
not_null<PeerListRow*> row) {
|
||||||
return nullptr;
|
auto result = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
parent,
|
||||||
|
st::popupMenuWithIcons);
|
||||||
|
const auto peer = row->peer();
|
||||||
|
const auto weak = base::make_weak(this);
|
||||||
|
const auto session = &_window->session();
|
||||||
|
const auto removeOne = crl::guard(session, [=] {
|
||||||
|
if (weak) {
|
||||||
|
const auto rowId = peer->id.value;
|
||||||
|
if (const auto row = delegate()->peerListFindRow(rowId)) {
|
||||||
|
_count = std::max(0, _count.current() - 1);
|
||||||
|
delegate()->peerListRemoveRow(row);
|
||||||
|
delegate()->peerListRefreshRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session->recentPeers().remove(peer);
|
||||||
|
});
|
||||||
|
FillEntryMenu(Ui::Menu::CreateAddActionCallback(result), {
|
||||||
|
.controller = _window,
|
||||||
|
.peer = peer,
|
||||||
|
.removeOneText = tr::lng_recent_remove(tr::now),
|
||||||
|
.removeOne = removeOne,
|
||||||
|
.removeAllText = tr::lng_recent_clear_all(tr::now),
|
||||||
|
.removeAllConfirm = tr::lng_recent_clear_sure(tr::now),
|
||||||
|
.removeAll = removeAllCallback(),
|
||||||
|
});
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::Session &RecentsController::session() const {
|
Main::Session &RecentsController::session() const {
|
||||||
return *_session;
|
return _window->session();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RecentsController::savedMessagesChatStatus() const {
|
QString RecentsController::savedMessagesChatStatus() const {
|
||||||
|
@ -306,6 +368,10 @@ void RecentsController::setupDivider() {
|
||||||
raw,
|
raw,
|
||||||
tr::lng_recent_clear(tr::now),
|
tr::lng_recent_clear(tr::now),
|
||||||
st::searchedBarLink);
|
st::searchedBarLink);
|
||||||
|
clear->setClickedCallback(RemoveAllConfirm(
|
||||||
|
_window,
|
||||||
|
tr::lng_recent_clear_sure(tr::now),
|
||||||
|
removeAllCallback()));
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
raw->sizeValue(),
|
raw->sizeValue(),
|
||||||
clear->widthValue()
|
clear->widthValue()
|
||||||
|
@ -325,7 +391,7 @@ void RecentsController::setupDivider() {
|
||||||
|
|
||||||
void RecentsController::subscribeToEvents() {
|
void RecentsController::subscribeToEvents() {
|
||||||
using Flag = Data::PeerUpdate::Flag;
|
using Flag = Data::PeerUpdate::Flag;
|
||||||
_session->changes().peerUpdates(
|
session().changes().peerUpdates(
|
||||||
Flag::Notifications
|
Flag::Notifications
|
||||||
| Flag::OnlineStatus
|
| Flag::OnlineStatus
|
||||||
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
||||||
|
@ -349,7 +415,7 @@ void RecentsController::subscribeToEvents() {
|
||||||
}
|
}
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
_session->data().unreadBadgeChanges(
|
session().data().unreadBadgeChanges(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
for (auto i = 0; i != _count.current(); ++i) {
|
for (auto i = 0; i != _count.current(); ++i) {
|
||||||
const auto row = delegate()->peerListRowAt(i);
|
const auto row = delegate()->peerListRowAt(i);
|
||||||
|
@ -395,20 +461,31 @@ Suggestions::Suggestions(
|
||||||
_topPeers->showMenuRequests(
|
_topPeers->showMenuRequests(
|
||||||
) | rpl::start_with_next([=](const ShowTopPeerMenuRequest &request) {
|
) | rpl::start_with_next([=](const ShowTopPeerMenuRequest &request) {
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(this);
|
||||||
const auto remove = [=](not_null<PeerData*> peer) {
|
const auto owner = &controller->session().data();
|
||||||
|
const auto peer = owner->peer(PeerId(request.id));
|
||||||
|
const auto removeOne = [=] {
|
||||||
peer->session().topPeers().remove(peer);
|
peer->session().topPeers().remove(peer);
|
||||||
if (weak) {
|
if (weak) {
|
||||||
_topPeers->removeLocally(peer->id.value);
|
_topPeers->removeLocally(peer->id.value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
const auto hideAll = crl::guard(session, [=] {
|
const auto removeAll = crl::guard(session, [=] {
|
||||||
session->topPeers().toggleDisabled(true);
|
session->topPeers().toggleDisabled(true);
|
||||||
if (weak) {
|
if (weak) {
|
||||||
_topPeers->removeLocally();
|
_topPeers->removeLocally();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
FillTopPeerMenu(controller, request, remove, hideAll);
|
FillEntryMenu(request.callback, {
|
||||||
|
.controller = controller,
|
||||||
|
.peer = peer,
|
||||||
|
.removeOneText = tr::lng_recent_remove(tr::now),
|
||||||
|
.removeOne = removeOne,
|
||||||
|
.removeAllText = tr::lng_recent_hide_top(
|
||||||
|
tr::now).replace('&', u"&&"_q),
|
||||||
|
.removeAllConfirm = tr::lng_recent_hide_sure(tr::now),
|
||||||
|
.removeAll = removeAll,
|
||||||
|
});
|
||||||
}, _topPeers->lifetime());
|
}, _topPeers->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,7 +546,7 @@ object_ptr<Ui::SlideWrap<>> Suggestions::setupRecentPeers(
|
||||||
PeerListContentDelegateSimple
|
PeerListContentDelegateSimple
|
||||||
>();
|
>();
|
||||||
const auto controller = lifetime.make_state<RecentsController>(
|
const auto controller = lifetime.make_state<RecentsController>(
|
||||||
&window->session(),
|
window,
|
||||||
std::move(recentPeers));
|
std::move(recentPeers));
|
||||||
controller->setStyleOverrides(&st::recentPeersList);
|
controller->setStyleOverrides(&st::recentPeersList);
|
||||||
|
|
||||||
|
|
|
@ -1167,7 +1167,9 @@ Image *MainWidget::newBackgroundThumb() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::setInnerFocus() {
|
void MainWidget::setInnerFocus() {
|
||||||
if (_hider || !_history->peer()) {
|
if (_dialogs && _dialogs->searchHasFocus()) {
|
||||||
|
_dialogs->setInnerFocus();
|
||||||
|
} else if (_hider || !_history->peer()) {
|
||||||
if (!_hider && _mainSection) {
|
if (!_hider && _mainSection) {
|
||||||
_mainSection->setInnerFocus();
|
_mainSection->setInnerFocus();
|
||||||
} else if (!_hider && _thirdSection) {
|
} else if (!_hider && _thirdSection) {
|
||||||
|
@ -2620,12 +2622,29 @@ void MainWidget::returnTabbedSelector() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainWidget::relevantForDialogsFocus(not_null<QWidget*> widget) const {
|
||||||
|
if (!_dialogs || widget->window() != window()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
if (widget.get() == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const auto parent = widget->parentWidget();
|
||||||
|
if (!parent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
widget = parent;
|
||||||
|
}
|
||||||
|
Unexpected("Should never be here.");
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWidget::eventFilter(QObject *o, QEvent *e) {
|
bool MainWidget::eventFilter(QObject *o, QEvent *e) {
|
||||||
const auto widget = o->isWidgetType()
|
const auto widget = o->isWidgetType()
|
||||||
? static_cast<QWidget*>(o)
|
? static_cast<QWidget*>(o)
|
||||||
: nullptr;
|
: nullptr;
|
||||||
if (e->type() == QEvent::FocusIn) {
|
if (e->type() == QEvent::FocusIn) {
|
||||||
if (widget && _dialogs && widget->window() == window()) {
|
if (widget && relevantForDialogsFocus(widget)) {
|
||||||
_dialogs->updateHasFocus(widget);
|
_dialogs->updateHasFocus(widget);
|
||||||
}
|
}
|
||||||
} else if (e->type() == QEvent::MouseButtonPress) {
|
} else if (e->type() == QEvent::MouseButtonPress) {
|
||||||
|
|
|
@ -108,7 +108,7 @@ class ItemBase;
|
||||||
} // namespace Layout
|
} // namespace Layout
|
||||||
} // namespace InlineBots
|
} // namespace InlineBots
|
||||||
|
|
||||||
class MainWidget
|
class MainWidget final
|
||||||
: public Ui::RpWidget
|
: public Ui::RpWidget
|
||||||
, private Media::Player::FloatDelegate {
|
, private Media::Player::FloatDelegate {
|
||||||
public:
|
public:
|
||||||
|
@ -236,12 +236,14 @@ public:
|
||||||
|
|
||||||
void dialogsCancelled();
|
void dialogsCancelled();
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
bool eventFilter(QObject *o, QEvent *e) override;
|
bool eventFilter(QObject *o, QEvent *e) override;
|
||||||
|
|
||||||
private:
|
[[nodiscard]] bool relevantForDialogsFocus(
|
||||||
|
not_null<QWidget*> widget) const;
|
||||||
|
|
||||||
void showFinished();
|
void showFinished();
|
||||||
void handleAdaptiveLayoutUpdate();
|
void handleAdaptiveLayoutUpdate();
|
||||||
void updateWindowAdaptiveLayout();
|
void updateWindowAdaptiveLayout();
|
||||||
|
|
Loading…
Add table
Reference in a new issue