Fix hashtags in separate windows.

This commit is contained in:
John Preston 2023-01-18 13:35:52 +04:00
parent e4c16ccba4
commit ba520aadcb
9 changed files with 130 additions and 51 deletions

View File

@ -1304,6 +1304,7 @@ void Application::closeWindow(not_null<Window::Controller*> window) {
_lastActiveWindow = next;
if (_lastActiveWindow) {
_lastActiveWindow->activate();
_lastActiveWindow->widget()->updateGlobalMenu();
}
}
_closingAsyncWindows.remove(window);
@ -1362,6 +1363,7 @@ void Application::windowActivated(not_null<Window::Controller*> window) {
if (window->isPrimary()) {
_lastActivePrimaryWindow = window;
}
window->widget()->updateGlobalMenu();
const auto wasSession = was ? was->maybeSession() : nullptr;
const auto nowSession = now->maybeSession();

View File

@ -124,8 +124,7 @@ QString UiIntegration::angleBackendFilePath() {
}
void UiIntegration::textActionsUpdated() {
// #TODO windows global menu
if (const auto window = Core::App().activePrimaryWindow()) {
if (const auto window = Core::App().activeWindow()) {
window->widget()->updateGlobalMenu();
}
}

View File

@ -4549,35 +4549,52 @@ void HistoryWidget::searchInChat() {
return;
} else if (controller()->isPrimary()) {
controller()->content()->searchInChat(_history);
} else if (!_composeSearch) {
const auto search = [=] {
const auto update = [=] {
updateControlsVisibility();
updateBotKeyboard();
updateFieldPlaceholder();
} else {
searchInChatEmbedded();
}
}
updateControlsGeometry();
};
_composeSearch = std::make_unique<HistoryView::ComposeSearch>(
this,
controller(),
_history);
update();
setInnerFocus();
_composeSearch->destroyRequests(
) | rpl::take(
1
) | rpl::start_with_next([=] {
_composeSearch = nullptr;
update();
setInnerFocus();
}, _composeSearch->lifetime());
};
if (!preventsClose(search)) {
search();
void HistoryWidget::searchInChatEmbedded(std::optional<QString> query) {
if (!_history) {
return;
} else if (_composeSearch) {
if (query) {
_composeSearch->setQuery(*query);
}
_composeSearch->setInnerFocus();
return;
}
const auto search = crl::guard(_list, [=] {
if (!_history) {
return;
}
const auto update = [=] {
updateControlsVisibility();
updateBotKeyboard();
updateFieldPlaceholder();
updateControlsGeometry();
};
_composeSearch = std::make_unique<HistoryView::ComposeSearch>(
this,
controller(),
_history,
query.value_or(QString()));
update();
setInnerFocus();
_composeSearch->destroyRequests(
) | rpl::take(
1
) | rpl::start_with_next([=] {
_composeSearch = nullptr;
update();
setInnerFocus();
}, _composeSearch->lifetime());
});
if (!preventsClose(search)) {
search();
}
}

View File

@ -235,6 +235,7 @@ public:
[[nodiscard]] rpl::producer<> cancelRequests() const {
return _cancelRequests.events();
}
void searchInChatEmbedded(std::optional<QString> query = {});
void updateNotifyControls();

View File

@ -254,9 +254,10 @@ List CreateList(
class TopBar final : public Ui::RpWidget {
public:
TopBar(not_null<Ui::RpWidget*> parent);
TopBar(not_null<Ui::RpWidget*> parent, const QString &query);
void setInnerFocus();
void setQuery(const QString &query);
[[nodiscard]] rpl::producer<SearchRequest> searchRequests() const;
[[nodiscard]] rpl::producer<PeerData*> fromValue() const;
@ -291,13 +292,14 @@ private:
rpl::event_stream<not_null<QKeyEvent*>> _keyEvents;
};
TopBar::TopBar(not_null<Ui::RpWidget*> parent)
TopBar::TopBar(not_null<Ui::RpWidget*> parent, const QString &query)
: Ui::RpWidget(parent)
, _cancel(base::make_unique_q<Ui::IconButton>(this, st::historyTopBarBack))
, _select(base::make_unique_q<Ui::MultiSelect>(
this,
st::searchInChatMultiSelect,
tr::lng_dlg_filter()))
tr::lng_dlg_filter(),
query))
, _searchTimer([=] { requestSearch(); }) {
parent->geometryValue(
@ -352,6 +354,10 @@ void TopBar::setInnerFocus() {
_select->setInnerFocus();
}
void TopBar::setQuery(const QString &query) {
_select->setQuery(query);
}
void TopBar::clearItems() {
_select->setItemRemovedCallback(nullptr);
@ -647,11 +653,13 @@ public:
Inner(
not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> window,
not_null<History*> history);
not_null<History*> history,
const QString &query);
~Inner();
void hideAnimated();
void setInnerFocus();
void setQuery(const QString &query);
[[nodiscard]] rpl::producer<> destroyRequests() const;
[[nodiscard]] rpl::lifetime &lifetime();
@ -683,10 +691,11 @@ private:
ComposeSearch::Inner::Inner(
not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> window,
not_null<History*> history)
not_null<History*> history,
const QString &query)
: _window(window)
, _history(history)
, _topBar(base::make_unique_q<TopBar>(parent))
, _topBar(base::make_unique_q<TopBar>(parent, query))
, _bottomBar(base::make_unique_q<BottomBar>(parent, HasChooseFrom(history)))
, _list(CreateList(parent, history))
, _apiSearch(history) {
@ -835,12 +844,20 @@ ComposeSearch::Inner::Inner(
) | rpl::map([=](PeerData *from) {
return HasChooseFrom(_history) && !from;
}));
if (!query.isEmpty()) {
_apiSearch.search({ query });
}
}
void ComposeSearch::Inner::setInnerFocus() {
_topBar->setInnerFocus();
}
void ComposeSearch::Inner::setQuery(const QString &query) {
_topBar->setQuery(query);
}
void ComposeSearch::Inner::showAnimated() {
// Don't animate bottom bar.
_bottomBar->show();
@ -874,8 +891,9 @@ ComposeSearch::Inner::~Inner() {
ComposeSearch::ComposeSearch(
not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> window,
not_null<History*> history)
: _inner(std::make_unique<Inner>(parent, window, history)) {
not_null<History*> history,
const QString &query)
: _inner(std::make_unique<Inner>(parent, window, history, query)) {
}
ComposeSearch::~ComposeSearch() {
@ -889,6 +907,10 @@ void ComposeSearch::setInnerFocus() {
_inner->setInnerFocus();
}
void ComposeSearch::setQuery(const QString &query) {
_inner->setQuery(query);
}
rpl::producer<> ComposeSearch::destroyRequests() const {
return _inner->destroyRequests();
}

View File

@ -24,11 +24,13 @@ public:
ComposeSearch(
not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> window,
not_null<History*> history);
not_null<History*> history,
const QString &query = QString());
~ComposeSearch();
void hideAnimated();
void setInnerFocus();
void setQuery(const QString &query);
[[nodiscard]] rpl::producer<> destroyRequests() const;

View File

@ -731,15 +731,33 @@ void MainWidget::hideSingleUseKeyboard(PeerData *peer, MsgId replyTo) {
}
void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) {
// #TODO windows
if (!_dialogs) {
return;
}
_dialogs->searchMessages(query, inChat);
if (isOneColumn()) {
_controller->clearSectionStack();
if (controller()->isPrimary()) {
_dialogs->searchMessages(query, inChat);
if (isOneColumn()) {
_controller->clearSectionStack();
} else {
_dialogs->setInnerFocus();
}
} else {
_dialogs->setInnerFocus();
const auto searchIn = [&](not_null<Window::Controller*> window) {
if (const auto controller = window->sessionController()) {
controller->content()->searchMessages(query, inChat);
controller->widget()->activate();
}
};
const auto account = &session().account();
if (const auto peer = inChat.peer()) {
if (peer == controller()->singlePeer()) {
if (_history->peer() != peer) {
controller()->showPeerHistory(peer);
}
_history->searchInChatEmbedded(query);
} else if (const auto window = Core::App().windowFor(peer)) {
searchIn(window);
}
} else if (const auto window = Core::App().windowFor(account)) {
searchIn(window);
}
}
}

View File

@ -416,9 +416,11 @@ public:
QWidget *parent,
const style::MultiSelect &st,
rpl::producer<QString> placeholder,
const QString &query,
ScrollCallback callback);
QString getQuery() const;
[[nodiscard]] QString getQuery() const;
void setQuery(const QString &query);
bool setInnerFocus();
void clearQuery();
@ -511,7 +513,8 @@ private:
MultiSelect::MultiSelect(
QWidget *parent,
const style::MultiSelect &st,
rpl::producer<QString> placeholder)
rpl::producer<QString> placeholder,
const QString &query)
: RpWidget(parent)
, _st(st)
, _scroll(this, _st.scroll) {
@ -522,6 +525,7 @@ MultiSelect::MultiSelect(
this,
st,
std::move(placeholder),
query,
scrollCallback));
_scroll->installEventFilter(this);
_inner->setResizedCallback([this](int innerHeightDelta) {
@ -597,6 +601,10 @@ QString MultiSelect::getQuery() const {
return _inner->getQuery();
}
void MultiSelect::setQuery(const QString &query) {
_inner->setQuery(query);
}
void MultiSelect::addItem(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage, AddItemWay way) {
addItemInBunch(itemId, text, color, std::move(paintRoundImage));
_inner->finishItemsBunch(way);
@ -643,11 +651,12 @@ MultiSelect::Inner::Inner(
QWidget *parent,
const style::MultiSelect &st,
rpl::producer<QString> placeholder,
const QString &query,
ScrollCallback callback)
: TWidget(parent)
, _st(st)
, _scrollCallback(std::move(callback))
, _field(this, _st.field, std::move(placeholder))
, _field(this, _st.field, std::move(placeholder), query)
, _cancel(this, _st.fieldCancel) {
_field->customUpDown(true);
connect(_field, &Ui::InputField::focused, [=] { fieldFocused(); });
@ -674,6 +683,13 @@ QString MultiSelect::Inner::getQuery() const {
return _field->getLastText().trimmed();
}
void MultiSelect::Inner::setQuery(const QString &query) {
_field->setText(query);
if (const auto last = _field->getLastText(); !last.isEmpty()) {
_field->setCursorPosition(last.size());
}
}
bool MultiSelect::Inner::setInnerFocus() {
if (_active >= 0) {
setFocus();

View File

@ -23,9 +23,11 @@ public:
MultiSelect(
QWidget *parent,
const style::MultiSelect &st,
rpl::producer<QString> placeholder = nullptr);
rpl::producer<QString> placeholder = nullptr,
const QString &query = QString());
QString getQuery() const;
[[nodiscard]] QString getQuery() const;
void setQuery(const QString &query);
void setInnerFocus();
void clearQuery();