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

View file

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

View file

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

View file

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

View file

@ -24,11 +24,13 @@ public:
ComposeSearch( ComposeSearch(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> window, not_null<Window::SessionController*> window,
not_null<History*> history); not_null<History*> history,
const QString &query = QString());
~ComposeSearch(); ~ComposeSearch();
void hideAnimated(); void hideAnimated();
void setInnerFocus(); void setInnerFocus();
void setQuery(const QString &query);
[[nodiscard]] rpl::producer<> destroyRequests() const; [[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) { void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) {
// #TODO windows if (controller()->isPrimary()) {
if (!_dialogs) { _dialogs->searchMessages(query, inChat);
return; if (isOneColumn()) {
} _controller->clearSectionStack();
_dialogs->searchMessages(query, inChat); } else {
if (isOneColumn()) { _dialogs->setInnerFocus();
_controller->clearSectionStack(); }
} else { } 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, QWidget *parent,
const style::MultiSelect &st, const style::MultiSelect &st,
rpl::producer<QString> placeholder, rpl::producer<QString> placeholder,
const QString &query,
ScrollCallback callback); ScrollCallback callback);
QString getQuery() const; [[nodiscard]] QString getQuery() const;
void setQuery(const QString &query);
bool setInnerFocus(); bool setInnerFocus();
void clearQuery(); void clearQuery();
@ -511,7 +513,8 @@ private:
MultiSelect::MultiSelect( MultiSelect::MultiSelect(
QWidget *parent, QWidget *parent,
const style::MultiSelect &st, const style::MultiSelect &st,
rpl::producer<QString> placeholder) rpl::producer<QString> placeholder,
const QString &query)
: RpWidget(parent) : RpWidget(parent)
, _st(st) , _st(st)
, _scroll(this, _st.scroll) { , _scroll(this, _st.scroll) {
@ -522,6 +525,7 @@ MultiSelect::MultiSelect(
this, this,
st, st,
std::move(placeholder), std::move(placeholder),
query,
scrollCallback)); scrollCallback));
_scroll->installEventFilter(this); _scroll->installEventFilter(this);
_inner->setResizedCallback([this](int innerHeightDelta) { _inner->setResizedCallback([this](int innerHeightDelta) {
@ -597,6 +601,10 @@ QString MultiSelect::getQuery() const {
return _inner->getQuery(); 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) { void MultiSelect::addItem(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage, AddItemWay way) {
addItemInBunch(itemId, text, color, std::move(paintRoundImage)); addItemInBunch(itemId, text, color, std::move(paintRoundImage));
_inner->finishItemsBunch(way); _inner->finishItemsBunch(way);
@ -643,11 +651,12 @@ MultiSelect::Inner::Inner(
QWidget *parent, QWidget *parent,
const style::MultiSelect &st, const style::MultiSelect &st,
rpl::producer<QString> placeholder, rpl::producer<QString> placeholder,
const QString &query,
ScrollCallback callback) ScrollCallback callback)
: TWidget(parent) : TWidget(parent)
, _st(st) , _st(st)
, _scrollCallback(std::move(callback)) , _scrollCallback(std::move(callback))
, _field(this, _st.field, std::move(placeholder)) , _field(this, _st.field, std::move(placeholder), query)
, _cancel(this, _st.fieldCancel) { , _cancel(this, _st.fieldCancel) {
_field->customUpDown(true); _field->customUpDown(true);
connect(_field, &Ui::InputField::focused, [=] { fieldFocused(); }); connect(_field, &Ui::InputField::focused, [=] { fieldFocused(); });
@ -674,6 +683,13 @@ QString MultiSelect::Inner::getQuery() const {
return _field->getLastText().trimmed(); 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() { bool MultiSelect::Inner::setInnerFocus() {
if (_active >= 0) { if (_active >= 0) {
setFocus(); setFocus();

View file

@ -23,9 +23,11 @@ public:
MultiSelect( MultiSelect(
QWidget *parent, QWidget *parent,
const style::MultiSelect &st, 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 setInnerFocus();
void clearQuery(); void clearQuery();