[Improvement] Shortcuts to switch accounts
This commit is contained in:
parent
71af76e438
commit
35ab23dbe8
3 changed files with 64 additions and 0 deletions
|
|
@ -119,6 +119,17 @@ const auto CommandByName = base::flat_map<QString, Command>{
|
|||
{ qsl("pinned_3") , Command::ChatPinned3 },
|
||||
{ qsl("pinned_4") , Command::ChatPinned4 },
|
||||
{ qsl("pinned_5") , Command::ChatPinned5 },
|
||||
|
||||
{ qsl("account1") , Command::ShowAccount1 },
|
||||
{ qsl("account2") , Command::ShowAccount2 },
|
||||
{ qsl("account3") , Command::ShowAccount3 },
|
||||
{ qsl("account4") , Command::ShowAccount4 },
|
||||
{ qsl("account5") , Command::ShowAccount5 },
|
||||
{ qsl("account6") , Command::ShowAccount6 },
|
||||
{ qsl("account7") , Command::ShowAccount7 },
|
||||
{ qsl("account8") , Command::ShowAccount8 },
|
||||
{ qsl("account9") , Command::ShowAccount9 },
|
||||
{ qsl("last_account") , Command::ShowAccountLast },
|
||||
};
|
||||
|
||||
const auto CommandNames = base::flat_map<Command, QString>{
|
||||
|
|
@ -170,6 +181,17 @@ const auto CommandNames = base::flat_map<Command, QString>{
|
|||
{ Command::ChatPinned3 , u"pinned_3"_q },
|
||||
{ Command::ChatPinned4 , u"pinned_4"_q },
|
||||
{ Command::ChatPinned5 , u"pinned_5"_q },
|
||||
|
||||
{ Command::ShowAccount1 , u"account1"_q },
|
||||
{ Command::ShowAccount2 , u"account2"_q },
|
||||
{ Command::ShowAccount3 , u"account3"_q },
|
||||
{ Command::ShowAccount4 , u"account4"_q },
|
||||
{ Command::ShowAccount5 , u"account5"_q },
|
||||
{ Command::ShowAccount6 , u"account6"_q },
|
||||
{ Command::ShowAccount7 , u"account7"_q },
|
||||
{ Command::ShowAccount8 , u"account8"_q },
|
||||
{ Command::ShowAccount9 , u"account9"_q },
|
||||
{ Command::ShowAccountLast, u"last_account"_q },
|
||||
};
|
||||
|
||||
[[maybe_unused]] constexpr auto kNoValue = {
|
||||
|
|
@ -449,6 +471,16 @@ void Manager::fillDefaults() {
|
|||
set(u"%1+%2"_q.arg(ctrl).arg(index), command);
|
||||
}
|
||||
|
||||
auto &&accounts = ranges::views::zip(
|
||||
kShowAccount,
|
||||
ranges::views::ints(1, ranges::unreachable));
|
||||
|
||||
for (const auto [command, index] : accounts) {
|
||||
set(u"alt+%1"_q.arg(index), command);
|
||||
}
|
||||
|
||||
set(u"alt+0"_q, Command::ShowAccountLast);
|
||||
|
||||
set(u"%1+shift+down"_q.arg(ctrl), Command::FolderNext);
|
||||
set(u"%1+shift+up"_q.arg(ctrl), Command::FolderPrevious);
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ enum class Command {
|
|||
ShowAccount4,
|
||||
ShowAccount5,
|
||||
ShowAccount6,
|
||||
ShowAccount7,
|
||||
ShowAccount8,
|
||||
ShowAccount9,
|
||||
ShowAccountLast,
|
||||
|
||||
ShowAllChats,
|
||||
ShowFolder1,
|
||||
|
|
@ -101,6 +105,10 @@ enum class Command {
|
|||
Command::ShowAccount4,
|
||||
Command::ShowAccount5,
|
||||
Command::ShowAccount6,
|
||||
Command::ShowAccount7,
|
||||
Command::ShowAccount8,
|
||||
Command::ShowAccount9,
|
||||
Command::ShowAccountLast,
|
||||
};
|
||||
|
||||
[[nodiscard]] FnMut<bool()> RequestHandler(Command command);
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "apiwrap.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "window/window_session_controller.h"
|
||||
|
|
@ -4085,6 +4087,28 @@ void InnerWidget::setupShortcuts() {
|
|||
}
|
||||
}
|
||||
|
||||
const auto accounts = &Core::App().domain().accounts();
|
||||
if (const auto accountsCount = int(accounts->size())) {
|
||||
auto &&accountShortcuts = ranges::views::zip(
|
||||
Shortcuts::kShowAccount,
|
||||
ranges::views::ints(0, ranges::unreachable));
|
||||
|
||||
for (const auto [command, index] : accountShortcuts) {
|
||||
const auto select = (command == Command::ShowAccountLast)
|
||||
? accountsCount - 1
|
||||
: std::clamp(index, 0, accountsCount - 1);
|
||||
request->check(command) && request->handle([=] {
|
||||
if (select <= accountsCount) {
|
||||
const auto account = (*accounts)[select].account.get();
|
||||
if (account != &Core::App().domain().active()) {
|
||||
Core::App().domain().maybeActivate(account);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static const auto kPinned = {
|
||||
Command::ChatPinned1,
|
||||
Command::ChatPinned2,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue