From 09bc3eefdb2a311dfb5e7ec7e77393bf98900597 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 27 Mar 2020 20:51:09 +0300 Subject: [PATCH] Added ability to open folders with shortcuts. --- Telegram/SourceFiles/core/shortcuts.cpp | 24 ++++++++++++------- Telegram/SourceFiles/core/shortcuts.h | 24 +++++++++++++++++++ .../dialogs/dialogs_inner_widget.cpp | 19 +++++++++++++++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index 8437e0aa0..2a97f61ce 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -295,6 +295,8 @@ bool Manager::readCustomFile() { } void Manager::fillDefaults() { + const auto ctrl = Platform::IsMac() ? qsl("meta") : qsl("ctrl"); + set(qsl("ctrl+w"), Command::Close); set(qsl("ctrl+f4"), Command::Close); set(qsl("ctrl+l"), Command::Lock); @@ -316,15 +318,11 @@ void Manager::fillDefaults() { set(qsl("alt+down"), Command::ChatNext); set(qsl("ctrl+pgup"), Command::ChatPrevious); set(qsl("alt+up"), Command::ChatPrevious); - if (Platform::IsMac()) { - set(qsl("meta+tab"), Command::ChatNext); - set(qsl("meta+shift+tab"), Command::ChatPrevious); - set(qsl("meta+backtab"), Command::ChatPrevious); - } else { - set(qsl("ctrl+tab"), Command::ChatNext); - set(qsl("ctrl+shift+tab"), Command::ChatPrevious); - set(qsl("ctrl+backtab"), Command::ChatPrevious); - } + + set(qsl("%1+tab").arg(ctrl), Command::ChatNext); + set(qsl("%1+shift+tab").arg(ctrl), Command::ChatPrevious); + set(qsl("%1+backtab").arg(ctrl), Command::ChatPrevious); + set(qsl("ctrl+alt+home"), Command::ChatFirst); set(qsl("ctrl+alt+end"), Command::ChatLast); @@ -340,6 +338,14 @@ void Manager::fillDefaults() { set(qsl("ctrl+4"), Command::ChatPinned4); set(qsl("ctrl+5"), Command::ChatPinned5); + auto &&folders = ranges::view::zip( + kShowFolder, + ranges::view::ints(1, ranges::unreachable)); + + for (const auto [command, index] : folders) { + set(qsl("%1+shift+%2").arg(ctrl).arg(index > 9 ? 0 : index), command); + } + set(qsl("ctrl+0"), Command::ChatSelf); set(qsl("ctrl+9"), Command::ShowArchive); diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index 49e8c0d28..178433665 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -35,6 +35,17 @@ enum class Command { ChatPinned4, ChatPinned5, + ShowFolder1, + ShowFolder2, + ShowFolder3, + ShowFolder4, + ShowFolder5, + ShowFolder6, + ShowFolder7, + ShowFolder8, + ShowFolder9, + ShowFolder10, + ShowArchive, JustSendMessage, @@ -48,6 +59,19 @@ enum class Command { SupportHistoryForward, }; +constexpr auto kShowFolder = { + Command::ShowFolder1, + Command::ShowFolder2, + Command::ShowFolder3, + Command::ShowFolder4, + Command::ShowFolder5, + Command::ShowFolder6, + Command::ShowFolder7, + Command::ShowFolder8, + Command::ShowFolder9, + Command::ShowFolder10, +}; + [[nodiscard]] FnMut RequestHandler(Command command); class Request { diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 4c3587e52..53d1a7ec0 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -3034,6 +3034,25 @@ void InnerWidget::setupShortcuts() { return jumpToDialogRow({ row->key(), FullMsgId() }); }); } + + auto &&folders = ranges::view::zip( + Shortcuts::kShowFolder, + ranges::view::ints(0, ranges::unreachable)); + + for (const auto [command, index] : folders) { + request->check(command) && request->handle([=, index = index] { + const auto list = &session().data().chatsFilters().list(); + if (index >= list->size()) { + return false; + } + const auto filterId = list->at(index).id(); + _controller->setActiveChatsFilter((filterId == _filterId) + ? 0 + : filterId); + return true; + }); + } + if (session().supportMode() && row.key.history()) { request->check( Command::SupportScrollToCurrent