mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-13 01:24:46 -07:00
support shortcuts for tab menu actions (#5564)
* support shortcuts for tab menu actions * refactor * add migration
This commit is contained in:
parent
12ae7a9eeb
commit
b509eed3e0
3 changed files with 49 additions and 7 deletions
|
|
@ -222,7 +222,14 @@ void TabSupervisor::retranslateUi()
|
||||||
void TabSupervisor::refreshShortcuts()
|
void TabSupervisor::refreshShortcuts()
|
||||||
{
|
{
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
aTabDeckEditor->setShortcuts(shortcuts.getShortcut("MainWindow/aDeckEditor"));
|
aTabDeckEditor->setShortcuts(shortcuts.getShortcut("Tabs/aTabDeckEditor"));
|
||||||
|
aTabVisualDeckStorage->setShortcuts(shortcuts.getShortcut("Tabs/aTabVisualDeckStorage"));
|
||||||
|
aTabServer->setShortcuts(shortcuts.getShortcut("Tabs/aTabServer"));
|
||||||
|
aTabAccount->setShortcuts(shortcuts.getShortcut("Tabs/aTabAccount"));
|
||||||
|
aTabDeckStorage->setShortcuts(shortcuts.getShortcut("Tabs/aTabDeckStorage"));
|
||||||
|
aTabReplays->setShortcuts(shortcuts.getShortcut("Tabs/aTabReplays"));
|
||||||
|
aTabAdmin->setShortcuts(shortcuts.getShortcut("Tabs/aTabAdmin"));
|
||||||
|
aTabLog->setShortcuts(shortcuts.getShortcut("Tabs/aTabLog"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabSupervisor::closeRequest()
|
bool TabSupervisor::closeRequest()
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,14 @@ void ShortcutsSettings::migrateShortcuts()
|
||||||
shortCutsFile.remove("tab_game/aFocusChat");
|
shortCutsFile.remove("tab_game/aFocusChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR #5564 changes "MainWindow/aDeckEditor" to "Tabs/aTabDeckEditor"
|
||||||
|
if (shortCutsFile.contains("MainWindow/aDeckEditor")) {
|
||||||
|
qCDebug(ShortcutsSettingsLog) << "MainWindow/aDeckEditor shortcut found. Migrating to Tabs/aTabDeckEditor.";
|
||||||
|
QString keySequence = shortCutsFile.value("MainWindow/aDeckEditor", "").toString();
|
||||||
|
this->setShortcuts("Tabs/aTabDeckEditor", keySequence);
|
||||||
|
shortCutsFile.remove("MainWindow/aDeckEditor");
|
||||||
|
}
|
||||||
|
|
||||||
shortCutsFile.endGroup();
|
shortCutsFile.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -221,6 +229,14 @@ bool ShortcutsSettings::isValid(const QString &name, const QString &sequences) c
|
||||||
return findOverlaps(name, sequences).isEmpty();
|
return findOverlaps(name, sequences).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the shortcut is a shortcut that is active in all windows
|
||||||
|
*/
|
||||||
|
static bool isAlwaysActiveShortcut(const QString &shortcutName)
|
||||||
|
{
|
||||||
|
return shortcutName.startsWith("MainWindow") || shortcutName.startsWith("Tabs");
|
||||||
|
}
|
||||||
|
|
||||||
QStringList ShortcutsSettings::findOverlaps(const QString &name, const QString &sequences) const
|
QStringList ShortcutsSettings::findOverlaps(const QString &name, const QString &sequences) const
|
||||||
{
|
{
|
||||||
QString checkSequence = sequences.split(sep).last();
|
QString checkSequence = sequences.split(sep).last();
|
||||||
|
|
@ -228,7 +244,7 @@ QStringList ShortcutsSettings::findOverlaps(const QString &name, const QString &
|
||||||
|
|
||||||
QStringList overlaps;
|
QStringList overlaps;
|
||||||
for (const auto &key : shortCuts.keys()) {
|
for (const auto &key : shortCuts.keys()) {
|
||||||
if (key.startsWith(checkKey) || key.startsWith("MainWindow") || checkKey.startsWith("MainWindow")) {
|
if (key.startsWith(checkKey) || isAlwaysActiveShortcut(key) || isAlwaysActiveShortcut(checkKey)) {
|
||||||
QString storedSequence = stringifySequence(shortCuts.value(key));
|
QString storedSequence = stringifySequence(shortCuts.value(key));
|
||||||
if (storedSequence.split(sep).contains(checkSequence)) {
|
if (storedSequence.split(sep).contains(checkSequence)) {
|
||||||
overlaps.append(getShortcutFriendlyName(key));
|
overlaps.append(getShortcutFriendlyName(key));
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ public:
|
||||||
Chat_room,
|
Chat_room,
|
||||||
Game_window,
|
Game_window,
|
||||||
Load_deck,
|
Load_deck,
|
||||||
Replays
|
Replays,
|
||||||
|
Tabs
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString getGroupName(ShortcutGroup::Groups group)
|
static QString getGroupName(ShortcutGroup::Groups group)
|
||||||
|
|
@ -72,6 +73,8 @@ public:
|
||||||
return QApplication::translate("shortcutsTab", "Load Deck from Clipboard");
|
return QApplication::translate("shortcutsTab", "Load Deck from Clipboard");
|
||||||
case Replays:
|
case Replays:
|
||||||
return QApplication::translate("shortcutsTab", "Replays");
|
return QApplication::translate("shortcutsTab", "Replays");
|
||||||
|
case Tabs:
|
||||||
|
return QApplication::translate("shortcutsTab", "Tabs");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -150,9 +153,6 @@ private:
|
||||||
{"MainWindow/aConnect", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Connect..."),
|
{"MainWindow/aConnect", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Connect..."),
|
||||||
parseSequenceString("Ctrl+L"),
|
parseSequenceString("Ctrl+L"),
|
||||||
ShortcutGroup::Main_Window)},
|
ShortcutGroup::Main_Window)},
|
||||||
{"MainWindow/aDeckEditor", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Deck Editor"),
|
|
||||||
parseSequenceString(""),
|
|
||||||
ShortcutGroup::Main_Window)},
|
|
||||||
{"MainWindow/aDisconnect", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Disconnect"),
|
{"MainWindow/aDisconnect", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Disconnect"),
|
||||||
parseSequenceString(""),
|
parseSequenceString(""),
|
||||||
ShortcutGroup::Main_Window)},
|
ShortcutGroup::Main_Window)},
|
||||||
|
|
@ -626,7 +626,26 @@ private:
|
||||||
ShortcutGroup::Replays)},
|
ShortcutGroup::Replays)},
|
||||||
{"Replays/fastForwardButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Toggle Fast Forward"),
|
{"Replays/fastForwardButton", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Toggle Fast Forward"),
|
||||||
parseSequenceString("Ctrl+P"),
|
parseSequenceString("Ctrl+P"),
|
||||||
ShortcutGroup::Replays)}};
|
ShortcutGroup::Replays)},
|
||||||
|
{"Tabs/aTabDeckEditor",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Deck Editor"), parseSequenceString(""), ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabVisualDeckStorage", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Visual Deck Storage"),
|
||||||
|
parseSequenceString(""),
|
||||||
|
ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabDeckStorage",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Deck Storage"), parseSequenceString(""), ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabReplays",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Replays"), parseSequenceString(""), ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabServer",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Server"), parseSequenceString(""), ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabAccount",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Account"), parseSequenceString(""), ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabAdmin", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Administration"),
|
||||||
|
parseSequenceString(""),
|
||||||
|
ShortcutGroup::Tabs)},
|
||||||
|
{"Tabs/aTabLogs",
|
||||||
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Logs"), parseSequenceString(""), ShortcutGroup::Tabs)},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHORTCUTSSETTINGS_H
|
#endif // SHORTCUTSSETTINGS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue