shortcuts.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. namespace Shortcuts {
  9. enum class Command {
  10. Close,
  11. Lock,
  12. Minimize,
  13. Quit,
  14. MediaPlay,
  15. MediaPause,
  16. MediaPlayPause,
  17. MediaStop,
  18. MediaPrevious,
  19. MediaNext,
  20. Search,
  21. ChatPrevious,
  22. ChatNext,
  23. ChatFirst,
  24. ChatLast,
  25. ChatSelf,
  26. ChatPinned1,
  27. ChatPinned2,
  28. ChatPinned3,
  29. ChatPinned4,
  30. ChatPinned5,
  31. ChatPinned6,
  32. ChatPinned7,
  33. ChatPinned8,
  34. ShowAccount1,
  35. ShowAccount2,
  36. ShowAccount3,
  37. ShowAccount4,
  38. ShowAccount5,
  39. ShowAccount6,
  40. ShowAllChats,
  41. ShowFolder1,
  42. ShowFolder2,
  43. ShowFolder3,
  44. ShowFolder4,
  45. ShowFolder5,
  46. ShowFolder6,
  47. ShowFolderLast,
  48. FolderNext,
  49. FolderPrevious,
  50. ShowScheduled,
  51. ShowArchive,
  52. ShowContacts,
  53. JustSendMessage,
  54. SendSilentMessage,
  55. ScheduleMessage,
  56. ReadChat,
  57. ArchiveChat,
  58. MediaViewerFullscreen,
  59. ShowChatMenu,
  60. ShowChatPreview,
  61. SupportReloadTemplates,
  62. SupportToggleMuted,
  63. SupportScrollToCurrent,
  64. SupportHistoryBack,
  65. SupportHistoryForward,
  66. };
  67. [[maybe_unused]] constexpr auto kShowFolder = {
  68. Command::ShowAllChats,
  69. Command::ShowFolder1,
  70. Command::ShowFolder2,
  71. Command::ShowFolder3,
  72. Command::ShowFolder4,
  73. Command::ShowFolder5,
  74. Command::ShowFolder6,
  75. Command::ShowFolderLast,
  76. };
  77. [[maybe_unused]] constexpr auto kShowAccount = {
  78. Command::ShowAccount1,
  79. Command::ShowAccount2,
  80. Command::ShowAccount3,
  81. Command::ShowAccount4,
  82. Command::ShowAccount5,
  83. Command::ShowAccount6,
  84. };
  85. [[nodiscard]] FnMut<bool()> RequestHandler(Command command);
  86. class Request {
  87. public:
  88. bool check(Command command, int priority = 0);
  89. bool handle(FnMut<bool()> handler);
  90. private:
  91. explicit Request(std::vector<Command> commands);
  92. std::vector<Command> _commands;
  93. int _handlerPriority = -1;
  94. FnMut<bool()> _handler;
  95. friend FnMut<bool()> RequestHandler(std::vector<Command> commands);
  96. };
  97. rpl::producer<not_null<Request*>> Requests();
  98. void Start();
  99. void Finish();
  100. void Listen(not_null<QWidget*> widget);
  101. bool Launch(Command command);
  102. bool HandleEvent(not_null<QObject*> object, not_null<QShortcutEvent*> event);
  103. const QStringList &Errors();
  104. // Media shortcuts are not enabled by default, because other
  105. // applications also use them. They are enabled only when
  106. // the in-app player is active and disabled back after.
  107. void ToggleMediaShortcuts(bool toggled);
  108. // Support shortcuts are not enabled by default, because they
  109. // have some conflicts with default input shortcuts, like Ctrl+Delete.
  110. void ToggleSupportShortcuts(bool toggled);
  111. void Pause();
  112. void Unpause();
  113. [[nodiscard]] auto KeysDefaults()
  114. -> base::flat_map<QKeySequence, base::flat_set<Command>>;
  115. [[nodiscard]] auto KeysCurrents()
  116. -> base::flat_map<QKeySequence, base::flat_set<Command>>;
  117. void Change(
  118. QKeySequence was,
  119. QKeySequence now,
  120. Command command,
  121. std::optional<Command> restore = {});
  122. void ResetToDefaults();
  123. [[nodiscard]] bool AllowWithoutModifiers(int key);
  124. } // namespace Shortcuts