Added Search Shortcut in Shared Media.

- Works for Documents, Audio files and Shared links.
This commit is contained in:
23rd 2019-03-09 21:44:46 +03:00 committed by John Preston
parent 178c0078c1
commit 9dc9e019f6
7 changed files with 27 additions and 7 deletions

View File

@ -328,7 +328,7 @@ void Widget::setupShortcuts() {
return isActiveWindow() && !Ui::isLayerShown() && inFocusChain();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
request->check(Command::Search, 1) && request->handle([=] {
request->check(Command::Search, 2) && request->handle([=] {
_fixedBar->showSearch();
return true;
});

View File

@ -303,7 +303,7 @@ void Widget::setupShortcuts() {
return isActiveWindow() && !Ui::isLayerShown() && inFocusChain();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
request->check(Command::Search, 1) && request->handle([=] {
request->check(Command::Search, 2) && request->handle([=] {
App::main()->searchInChat(_feed);
return true;
});

View File

@ -1321,7 +1321,7 @@ void HistoryWidget::setupShortcuts() {
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
if (_history) {
request->check(Command::Search) && request->handle([=] {
request->check(Command::Search, 1) && request->handle([=] {
App::main()->searchInChat(_history);
return true;
});

View File

@ -213,10 +213,7 @@ void TopBar::createSearchView(
auto button = base::make_unique_q<Ui::IconButton>(this, _st.search);
auto search = button.get();
search->addClickHandler([=] {
_searchModeEnabled = true;
updateControlsVisibility(anim::type::normal);
});
search->addClickHandler([=] { showSearch(); });
auto searchWrap = pushButton(std::move(button));
registerToggleControlCallback(searchWrap, [=] {
return !selectionMode()
@ -286,6 +283,11 @@ void TopBar::createSearchView(
}, wrap->lifetime());
}
void TopBar::showSearch() {
_searchModeEnabled = true;
updateControlsVisibility(anim::type::normal);
}
void TopBar::removeButton(not_null<Ui::RpWidget*> button) {
_buttons.erase(
std::remove(_buttons.begin(), _buttons.end(), button),

View File

@ -82,6 +82,8 @@ public:
updateControlsVisibility(anim::type::instant);
}
void showSearch();
protected:
int resizeGetHeight(int newWidth) override;
void paintEvent(QPaintEvent *e) override;

View File

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/fade_wrap.h"
#include "ui/search_field_controller.h"
#include "calls/calls_instance.h"
#include "core/shortcuts.h"
#include "window/window_controller.h"
#include "window/window_slide_animation.h"
#include "window/window_peer_menu.h"
@ -78,6 +79,19 @@ WrapWidget::WrapWidget(
restoreHistoryStack(memento->takeStack());
}
void WrapWidget::setupShortcuts() {
Shortcuts::Requests(
) | rpl::filter([=] {
return requireTopBarSearch();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
request->check(Command::Search) && request->handle([=] {
_topBar->showSearch();
return true;
});
}, lifetime());
}
void WrapWidget::restoreHistoryStack(
std::vector<std::unique_ptr<ContentMemento>> stack) {
Expects(!stack.empty());
@ -377,6 +391,7 @@ void WrapWidget::createTopBar() {
} else if (requireTopBarSearch()) {
auto search = _controller->searchFieldController();
Assert(search != nullptr);
setupShortcuts();
_topBar->createSearchView(
search,
_controller->searchEnabledByContent(),

View File

@ -171,6 +171,7 @@ private:
//void createTabs();
void createTopBar();
void highlightTopBar();
void setupShortcuts();
not_null<RpWidget*> topWidget() const;