Make menus and placeholders display appropriate custom key combos. (#4045)
* Add initial support for finding hotkey display key sequences * Make neededArguments work * Implement displaying key combos in SplitHeader main menu * Make Settings search text dynamic * Make tab hide notice use a custom hotkeys key sequence * Make Notebook menus use custom hotkeys key combo lookup for hiding tabs * shut up changelog ci * Make NotebookTab menus show custom hotkeys. SCUFFED: this does not update dynamically! * Scuffed: Make the show prefs button setting show the key bind * Scuffed: Make the R9K description refer to hotkeys * @pajlada, is something like this ok? Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
||||
#include "controllers/hotkeys/HotkeyModel.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
@@ -547,4 +548,40 @@ void HotkeyController::showHotkeyError(const std::shared_ptr<Hotkey> &hotkey,
|
||||
msgBox->exec();
|
||||
}
|
||||
|
||||
QKeySequence HotkeyController::getDisplaySequence(
|
||||
HotkeyCategory category, const QString &action,
|
||||
const std::optional<std::vector<QString>> &arguments) const
|
||||
{
|
||||
const auto &found = this->findLike(category, action, arguments);
|
||||
if (found != nullptr)
|
||||
{
|
||||
return found->keySequence();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<Hotkey> HotkeyController::findLike(
|
||||
HotkeyCategory category, const QString &action,
|
||||
const std::optional<std::vector<QString>> &arguments) const
|
||||
{
|
||||
for (auto other : this->hotkeys_)
|
||||
{
|
||||
if (other->category() == category && other->action() == action)
|
||||
{
|
||||
if (arguments)
|
||||
{
|
||||
if (other->arguments() == *arguments)
|
||||
{
|
||||
return other;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return other;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
||||
class QShortcut;
|
||||
@@ -33,6 +34,17 @@ public:
|
||||
|
||||
void save() override;
|
||||
std::shared_ptr<Hotkey> getHotkeyByName(QString name);
|
||||
/**
|
||||
* @brief returns a QKeySequence that perfoms the actions requested.
|
||||
* Accepted if and only if the category matches, the action matches and arguments match.
|
||||
* When arguments is present, contents of arguments must match the checked hotkey, otherwise arguments are ignored.
|
||||
* For example:
|
||||
* - std::nullopt (or {}) will match any hotkey satisfying category, action values,
|
||||
* - {{"foo", "bar"}} will only match a hotkey that has these arguments and these arguments only
|
||||
*/
|
||||
QKeySequence getDisplaySequence(
|
||||
HotkeyCategory category, const QString &action,
|
||||
const std::optional<std::vector<QString>> &arguments = {}) const;
|
||||
|
||||
/**
|
||||
* @brief removes the hotkey with the oldName and inserts newHotkey at the end
|
||||
@@ -114,6 +126,17 @@ private:
|
||||
**/
|
||||
static void showHotkeyError(const std::shared_ptr<Hotkey> &hotkey,
|
||||
QString warning);
|
||||
/**
|
||||
* @brief finds a Hotkey matching category, action and arguments.
|
||||
* Accepted if and only if the category matches, the action matches and arguments match.
|
||||
* When arguments is present, contents of arguments must match the checked hotkey, otherwise arguments are ignored.
|
||||
* For example:
|
||||
* - std::nullopt (or {}) will match any hotkey satisfying category, action values,
|
||||
* - {{"foo", "bar"}} will only match a hotkey that has these arguments and these arguments only
|
||||
*/
|
||||
std::shared_ptr<Hotkey> findLike(
|
||||
HotkeyCategory category, const QString &action,
|
||||
const std::optional<std::vector<QString>> &arguments = {}) const;
|
||||
|
||||
friend class KeyboardSettingsPage;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user