Disable support shortcuts when not support mode.

Fixes #5453.
This commit is contained in:
John Preston 2018-12-13 12:48:31 +04:00
parent 980d20473a
commit e876c9b6a6
4 changed files with 36 additions and 12 deletions

View File

@ -37,6 +37,12 @@ const auto MediaCommands = base::flat_set<Command>{
Command::MediaNext, Command::MediaNext,
}; };
const auto SupportCommands = base::flat_set<Command>{
Command::SupportReloadTemplates,
Command::SupportToggleMuted,
Command::SupportScrollToCurrent,
};
const auto CommandByName = base::flat_map<QString, Command>{ const auto CommandByName = base::flat_map<QString, Command>{
{ qsl("close_telegram") , Command::Close }, { qsl("close_telegram") , Command::Close },
{ qsl("lock_telegram") , Command::Lock }, { qsl("lock_telegram") , Command::Lock },
@ -86,6 +92,7 @@ public:
std::optional<Command> lookup(int shortcutId) const; std::optional<Command> lookup(int shortcutId) const;
void toggleMedia(bool toggled); void toggleMedia(bool toggled);
void toggleSupport(bool toggled);
const QStringList &errors() const; const QStringList &errors() const;
@ -104,6 +111,7 @@ private:
base::flat_map<int, Command> _commandByShortcutId; base::flat_map<int, Command> _commandByShortcutId;
base::flat_set<QShortcut*> _mediaShortcuts; base::flat_set<QShortcut*> _mediaShortcuts;
base::flat_set<QShortcut*> _supportShortcuts;
}; };
@ -168,6 +176,7 @@ void Manager::clear() {
_shortcuts.clear(); _shortcuts.clear();
_commandByShortcutId.clear(); _commandByShortcutId.clear();
_mediaShortcuts.clear(); _mediaShortcuts.clear();
_supportShortcuts.clear();
} }
const QStringList &Manager::errors() const { const QStringList &Manager::errors() const {
@ -187,6 +196,12 @@ void Manager::toggleMedia(bool toggled) {
} }
} }
void Manager::toggleSupport(bool toggled) {
for (const auto shortcut : _supportShortcuts) {
shortcut->setEnabled(toggled);
}
}
bool Manager::readCustomFile() { bool Manager::readCustomFile() {
// read custom shortcuts from file if it exists or write an empty custom shortcuts file // read custom shortcuts from file if it exists or write an empty custom shortcuts file
QFile file(CustomFilePath()); QFile file(CustomFilePath());
@ -352,7 +367,8 @@ void Manager::set(const QString &keys, Command command) {
shortcut->setAutoRepeat(false); shortcut->setAutoRepeat(false);
} }
const auto isMediaShortcut = MediaCommands.contains(command); const auto isMediaShortcut = MediaCommands.contains(command);
if (isMediaShortcut) { const auto isSupportShortcut = SupportCommands.contains(command);
if (isMediaShortcut || isSupportShortcut) {
shortcut->setEnabled(false); shortcut->setEnabled(false);
} }
const auto id = shortcut->id(); const auto id = shortcut->id();
@ -370,6 +386,9 @@ void Manager::set(const QString &keys, Command command) {
if (isMediaShortcut) { if (isMediaShortcut) {
_mediaShortcuts.emplace(i->second.get()); _mediaShortcuts.emplace(i->second.get());
} }
if (isSupportShortcut) {
_supportShortcuts.emplace(i->second.get());
}
} }
void Manager::remove(const QString &keys) { void Manager::remove(const QString &keys) {
@ -394,6 +413,7 @@ void Manager::unregister(base::unique_qptr<QShortcut> shortcut) {
if (shortcut) { if (shortcut) {
_commandByShortcutId.erase(shortcut->id()); _commandByShortcutId.erase(shortcut->id());
_mediaShortcuts.erase(shortcut.get()); _mediaShortcuts.erase(shortcut.get());
_supportShortcuts.erase(shortcut.get());
} }
} }
@ -451,14 +471,13 @@ bool HandleEvent(not_null<QShortcutEvent*> event) {
return false; return false;
} }
void EnableMediaShortcuts() { void ToggleMediaShortcuts(bool toggled) {
Data.toggleMedia(true); Data.toggleMedia(toggled);
Platform::SetWatchingMediaKeys(true); Platform::SetWatchingMediaKeys(toggled);
} }
void DisableMediaShortcuts() { void ToggleSupportShortcuts(bool toggled) {
Data.toggleMedia(false); Data.toggleSupport(toggled);
Platform::SetWatchingMediaKeys(false);
} }
void Finish() { void Finish() {

View File

@ -65,7 +65,10 @@ const QStringList &Errors();
// Media shortcuts are not enabled by default, because other // Media shortcuts are not enabled by default, because other
// applications also use them. They are enabled only when // applications also use them. They are enabled only when
// the in-app player is active and disabled back after. // the in-app player is active and disabled back after.
void EnableMediaShortcuts(); void ToggleMediaShortcuts(bool toggled);
void DisableMediaShortcuts();
// Support shortcuts are not enabled by default, because they
// have some conflicts with default input shortcuts, like Ctrl+Delete.
void ToggleSupportShortcuts(bool toggled);
} // namespace Shortcuts } // namespace Shortcuts

View File

@ -1210,7 +1210,7 @@ void MainWidget::closeBothPlayers() {
Media::Player::instance()->stop(AudioMsgId::Type::Voice); Media::Player::instance()->stop(AudioMsgId::Type::Voice);
Media::Player::instance()->stop(AudioMsgId::Type::Song); Media::Player::instance()->stop(AudioMsgId::Type::Song);
Shortcuts::DisableMediaShortcuts(); Shortcuts::ToggleMediaShortcuts(false);
} }
void MainWidget::createPlayer() { void MainWidget::createPlayer() {
@ -1232,7 +1232,7 @@ void MainWidget::createPlayer() {
if (_a_show.animating()) { if (_a_show.animating()) {
_player->show(anim::type::instant); _player->show(anim::type::instant);
_player->setVisible(false); _player->setVisible(false);
Shortcuts::EnableMediaShortcuts(); Shortcuts::ToggleMediaShortcuts(true);
} else { } else {
_player->hide(anim::type::instant); _player->hide(anim::type::instant);
} }
@ -1242,7 +1242,7 @@ void MainWidget::createPlayer() {
_player->show(anim::type::normal); _player->show(anim::type::normal);
_playerHeight = _contentScrollAddToY = _player->contentHeight(); _playerHeight = _contentScrollAddToY = _player->contentHeight();
updateControlsGeometry(); updateControlsGeometry();
Shortcuts::EnableMediaShortcuts(); Shortcuts::ToggleMediaShortcuts(true);
} }
} }
} }

View File

@ -593,6 +593,8 @@ void Messenger::startLocalStorage() {
_mtproto->requestConfig(); _mtproto->requestConfig();
} }
Platform::SetApplicationIcon(Window::CreateIcon()); Platform::SetApplicationIcon(Window::CreateIcon());
Shortcuts::ToggleSupportShortcuts(
_authSession && _authSession->supportMode());
}); });
}); });
} }