mirror of https://github.com/procxx/kepka.git
Fix switch to prev/next in Support.
This commit is contained in:
parent
479a6d9ad2
commit
163ee73719
|
@ -417,10 +417,17 @@ bool Request::handle(FnMut<bool()> handler) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launch(Command command) {
|
FnMut<bool()> RequestHandler(Command command) {
|
||||||
auto request = Request(command);
|
auto request = Request(command);
|
||||||
RequestsStream.fire(&request);
|
RequestsStream.fire(&request);
|
||||||
return request._handler ? request._handler() : false;
|
return std::move(request._handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Launch(Command command) {
|
||||||
|
if (auto handler = RequestHandler(command)) {
|
||||||
|
return handler();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<not_null<Request*>> Requests() {
|
rpl::producer<not_null<Request*>> Requests() {
|
||||||
|
|
|
@ -34,7 +34,7 @@ enum class Command {
|
||||||
SupportScrollToCurrent,
|
SupportScrollToCurrent,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Launch(Command command);
|
[[nodiscard]] FnMut<bool()> RequestHandler(Command command);
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
public:
|
public:
|
||||||
|
@ -48,7 +48,7 @@ private:
|
||||||
int _handlerPriority = -1;
|
int _handlerPriority = -1;
|
||||||
FnMut<bool()> _handler;
|
FnMut<bool()> _handler;
|
||||||
|
|
||||||
friend bool Launch(Command command);
|
friend FnMut<bool()> RequestHandler(Command command);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ rpl::producer<not_null<Request*>> Requests();
|
||||||
void Start();
|
void Start();
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
|
bool Launch(Command command);
|
||||||
bool HandleEvent(not_null<QShortcutEvent*> event);
|
bool HandleEvent(not_null<QShortcutEvent*> event);
|
||||||
|
|
||||||
const QStringList &Errors();
|
const QStringList &Errors();
|
||||||
|
|
|
@ -2792,18 +2792,20 @@ void DialogsInner::setupShortcuts() {
|
||||||
}
|
}
|
||||||
const auto row = _controller->activeChatEntryCurrent();
|
const auto row = _controller->activeChatEntryCurrent();
|
||||||
if (row.key) {
|
if (row.key) {
|
||||||
|
const auto prev = computeJump(chatListEntryBefore(row), -1);
|
||||||
|
const auto next = computeJump(chatListEntryAfter(row), 1);
|
||||||
request->check(Command::ChatPrevious) && request->handle([=] {
|
request->check(Command::ChatPrevious) && request->handle([=] {
|
||||||
return showPreviousChat(row);
|
return jumpToDialogRow(prev);
|
||||||
});
|
});
|
||||||
request->check(Command::ChatNext) && request->handle([=] {
|
request->check(Command::ChatNext) && request->handle([=] {
|
||||||
return showNextChat(row);
|
return jumpToDialogRow(next);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
request->check(Command::ChatFirst) && request->handle([=] {
|
request->check(Command::ChatFirst) && request->handle([=] {
|
||||||
return showFirstChat();
|
return jumpToDialogRow(computeJump(chatListEntryFirst(), 1));
|
||||||
});
|
});
|
||||||
request->check(Command::ChatLast) && request->handle([=] {
|
request->check(Command::ChatLast) && request->handle([=] {
|
||||||
return showLastChat();
|
return jumpToDialogRow(computeJump(chatListEntryLast(), -1));
|
||||||
});
|
});
|
||||||
if (Auth().supportMode() && row.key.history()) {
|
if (Auth().supportMode() && row.key.history()) {
|
||||||
request->check(
|
request->check(
|
||||||
|
@ -2816,26 +2818,9 @@ void DialogsInner::setupShortcuts() {
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DialogsInner::showNextChat(const Dialogs::RowDescriptor ¤t) {
|
Dialogs::RowDescriptor DialogsInner::computeJump(
|
||||||
return jumpToDialogRow(chatListEntryAfter(current), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DialogsInner::showPreviousChat(const Dialogs::RowDescriptor ¤t) {
|
|
||||||
return jumpToDialogRow(chatListEntryBefore(current), -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DialogsInner::showFirstChat() {
|
|
||||||
return jumpToDialogRow(chatListEntryFirst(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DialogsInner::showLastChat() {
|
|
||||||
return jumpToDialogRow(chatListEntryLast(), -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DialogsInner::jumpToDialogRow(
|
|
||||||
const Dialogs::RowDescriptor &to,
|
const Dialogs::RowDescriptor &to,
|
||||||
int skipDirection) {
|
int skipDirection) {
|
||||||
const auto entry = [&] {
|
|
||||||
auto result = to;
|
auto result = to;
|
||||||
if (Auth().supportMode()) {
|
if (Auth().supportMode()) {
|
||||||
while (result.key
|
while (result.key
|
||||||
|
@ -2847,12 +2832,14 @@ bool DialogsInner::jumpToDialogRow(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}();
|
}
|
||||||
if (const auto history = entry.key.history()) {
|
|
||||||
Ui::showPeerHistory(history, entry.fullId.msg);
|
bool DialogsInner::jumpToDialogRow(const Dialogs::RowDescriptor &to) {
|
||||||
|
if (const auto history = to.key.history()) {
|
||||||
|
Ui::showPeerHistory(history, to.fullId.msg);
|
||||||
return true;
|
return true;
|
||||||
} else if (const auto feed = entry.key.feed()) {
|
} else if (const auto feed = to.key.feed()) {
|
||||||
if (const auto item = App::histItemById(entry.fullId)) {
|
if (const auto item = App::histItemById(to.fullId)) {
|
||||||
_controller->showSection(
|
_controller->showSection(
|
||||||
HistoryFeed::Memento(feed, item->position()));
|
HistoryFeed::Memento(feed, item->position()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -188,13 +188,10 @@ private:
|
||||||
bool hasHistoryInSearchResults(not_null<History*> history) const;
|
bool hasHistoryInSearchResults(not_null<History*> history) const;
|
||||||
|
|
||||||
void setupShortcuts();
|
void setupShortcuts();
|
||||||
bool showNextChat(const Dialogs::RowDescriptor ¤t);
|
Dialogs::RowDescriptor computeJump(
|
||||||
bool showPreviousChat(const Dialogs::RowDescriptor ¤t);
|
|
||||||
bool showFirstChat();
|
|
||||||
bool showLastChat();
|
|
||||||
bool jumpToDialogRow(
|
|
||||||
const Dialogs::RowDescriptor &to,
|
const Dialogs::RowDescriptor &to,
|
||||||
int skipDirection);
|
int skipDirection);
|
||||||
|
bool jumpToDialogRow(const Dialogs::RowDescriptor &to);
|
||||||
|
|
||||||
Dialogs::RowDescriptor chatListEntryBefore(
|
Dialogs::RowDescriptor chatListEntryBefore(
|
||||||
const Dialogs::RowDescriptor &which) const;
|
const Dialogs::RowDescriptor &which) const;
|
||||||
|
|
|
@ -3738,9 +3738,10 @@ void HistoryWidget::handleSupportSwitch(not_null<History*> updated) {
|
||||||
if (_history != updated || !Auth().supportMode()) {
|
if (_history != updated || !Auth().supportMode()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
crl::on_main(this, [to = Auth().settings().supportSwitch()] {
|
|
||||||
Support::PerformSwitch(to);
|
crl::on_main(
|
||||||
});
|
this,
|
||||||
|
Support::GetSwitchMethod(Auth().settings().supportSwitch()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::inlineBotResolveDone(
|
void HistoryWidget::inlineBotResolveDone(
|
||||||
|
|
|
@ -33,17 +33,14 @@ Qt::KeyboardModifiers SkipSwitchModifiers() {
|
||||||
return Qt::ControlModifier | Qt::ShiftModifier;
|
return Qt::ControlModifier | Qt::ShiftModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerformSwitch(SwitchSettings value) {
|
FnMut<bool()> GetSwitchMethod(SwitchSettings value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case SwitchSettings::Next:
|
case SwitchSettings::Next:
|
||||||
Shortcuts::Launch(Shortcuts::Command::ChatNext);
|
return Shortcuts::RequestHandler(Shortcuts::Command::ChatNext);
|
||||||
break;
|
|
||||||
case SwitchSettings::Previous:
|
case SwitchSettings::Previous:
|
||||||
Shortcuts::Launch(Shortcuts::Command::ChatPrevious);
|
return Shortcuts::RequestHandler(Shortcuts::Command::ChatPrevious);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Support
|
} // namespace Support
|
||||||
|
|
|
@ -19,6 +19,6 @@ enum class SwitchSettings {
|
||||||
|
|
||||||
Qt::KeyboardModifiers SkipSwitchModifiers();
|
Qt::KeyboardModifiers SkipSwitchModifiers();
|
||||||
bool HandleSwitch(Qt::KeyboardModifiers modifiers);
|
bool HandleSwitch(Qt::KeyboardModifiers modifiers);
|
||||||
void PerformSwitch(SwitchSettings value);
|
FnMut<bool()> GetSwitchMethod(SwitchSettings value);
|
||||||
|
|
||||||
} // namespace Support
|
} // namespace Support
|
||||||
|
|
Loading…
Reference in New Issue