Skip to content

Commit

Permalink
Add custom hotkeys. (Chatterino#2340)
Browse files Browse the repository at this point in the history
Co-authored-by: LosFarmosCTL <80157503+LosFarmosCTL@users.noreply.github.com>
Co-authored-by: Paweł <zneix@zneix.eu>
Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
  • Loading branch information
5 people committed Nov 21, 2021
1 parent b94e21a commit 703f371
Show file tree
Hide file tree
Showing 54 changed files with 3,627 additions and 631 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore submodule files
lib/*/
conan-pkgs/*/
cmake/sanitizers-cmake/

.github/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unversioned

- Major: Added customizable shortcuts. (#2340)
- Minor: Added middle click split to open in browser (#3356)
- Minor: Added new search predicate to filter for messages matching a regex (#3282)
- Minor: Add `{channel.name}`, `{channel.id}`, `{stream.game}`, `{stream.title}`, `{my.id}`, `{my.name}` placeholders for commands (#3155)
Expand Down
16 changes: 14 additions & 2 deletions chatterino.pro
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ SOURCES += \
src/controllers/highlights/HighlightModel.cpp \
src/controllers/highlights/HighlightPhrase.cpp \
src/controllers/highlights/UserHighlightModel.cpp \
src/controllers/hotkeys/Hotkey.cpp \
src/controllers/hotkeys/HotkeyController.cpp \
src/controllers/hotkeys/HotkeyHelpers.cpp \
src/controllers/hotkeys/HotkeyModel.cpp \
src/controllers/ignores/IgnoreController.cpp \
src/controllers/ignores/IgnoreModel.cpp \
src/controllers/moderationactions/ModerationAction.cpp \
Expand Down Expand Up @@ -266,6 +270,7 @@ SOURCES += \
src/widgets/dialogs/BadgePickerDialog.cpp \
src/widgets/dialogs/ChannelFilterEditorDialog.cpp \
src/widgets/dialogs/ColorPickerDialog.cpp \
src/widgets/dialogs/EditHotkeyDialog.cpp \
src/widgets/dialogs/EmotePopup.cpp \
src/widgets/dialogs/IrcConnectionEditor.cpp \
src/widgets/dialogs/LastRunCrashDialog.cpp \
Expand Down Expand Up @@ -389,6 +394,12 @@ HEADERS += \
src/controllers/highlights/HighlightModel.hpp \
src/controllers/highlights/HighlightPhrase.hpp \
src/controllers/highlights/UserHighlightModel.hpp \
src/controllers/hotkeys/ActionNames.hpp \
src/controllers/hotkeys/Hotkey.hpp \
src/controllers/hotkeys/HotkeyCategory.hpp \
src/controllers/hotkeys/HotkeyController.hpp \
src/controllers/hotkeys/HotkeyHelpers.hpp \
src/controllers/hotkeys/HotkeyModel.hpp \
src/controllers/ignores/IgnoreController.hpp \
src/controllers/ignores/IgnoreModel.hpp \
src/controllers/ignores/IgnorePhrase.hpp \
Expand Down Expand Up @@ -512,7 +523,6 @@ HEADERS += \
src/util/SampleCheerMessages.hpp \
src/util/SampleLinks.hpp \
src/util/SharedPtrElementLess.hpp \
src/util/Shortcut.hpp \
src/util/SplitCommand.hpp \
src/util/StandardItemHelper.hpp \
src/util/StreamerMode.hpp \
Expand All @@ -528,6 +538,7 @@ HEADERS += \
src/widgets/dialogs/BadgePickerDialog.hpp \
src/widgets/dialogs/ChannelFilterEditorDialog.hpp \
src/widgets/dialogs/ColorPickerDialog.hpp \
src/widgets/dialogs/EditHotkeyDialog.hpp \
src/widgets/dialogs/EmotePopup.hpp \
src/widgets/dialogs/IrcConnectionEditor.hpp \
src/widgets/dialogs/LastRunCrashDialog.hpp \
Expand Down Expand Up @@ -604,7 +615,8 @@ RESOURCES += \
DISTFILES +=

FORMS += \
src/widgets/dialogs/IrcConnectionEditor.ui
src/widgets/dialogs/IrcConnectionEditor.ui \
src/widgets/dialogs/EditHotkeyDialog.ui

# do not use windows min/max macros
#win32 {
Expand Down
2 changes: 2 additions & 0 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common/Version.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandController.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "debug/AssertInGuiThread.hpp"
Expand Down Expand Up @@ -54,6 +55,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, fonts(&this->emplace<Fonts>())
, emotes(&this->emplace<Emotes>())
, accounts(&this->emplace<AccountController>())
, hotkeys(&this->emplace<HotkeyController>())
, windows(&this->emplace<WindowManager>())
, toasts(&this->emplace<Toasts>())

Expand Down
2 changes: 2 additions & 0 deletions src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PubSub;
class CommandController;
class AccountController;
class NotificationController;
class HotkeyController;

class Theme;
class WindowManager;
Expand Down Expand Up @@ -51,6 +52,7 @@ class Application
Fonts *const fonts{};
Emotes *const emotes{};
AccountController *const accounts{};
HotkeyController *const hotkeys{};
WindowManager *const windows{};
Toasts *const toasts{};

Expand Down
13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ set(SOURCE_FILES
controllers/highlights/UserHighlightModel.cpp
controllers/highlights/UserHighlightModel.hpp

controllers/hotkeys/ActionNames.hpp
controllers/hotkeys/Hotkey.cpp
controllers/hotkeys/Hotkey.hpp
controllers/hotkeys/HotkeyCategory.hpp
controllers/hotkeys/HotkeyController.cpp
controllers/hotkeys/HotkeyController.hpp
controllers/hotkeys/HotkeyHelpers.cpp
controllers/hotkeys/HotkeyHelpers.hpp
controllers/hotkeys/HotkeyModel.cpp
controllers/hotkeys/HotkeyModel.hpp

controllers/ignores/IgnoreController.cpp
controllers/ignores/IgnoreController.hpp
controllers/ignores/IgnoreModel.cpp
Expand Down Expand Up @@ -335,6 +346,8 @@ set(SOURCE_FILES
widgets/dialogs/ChannelFilterEditorDialog.hpp
widgets/dialogs/ColorPickerDialog.cpp
widgets/dialogs/ColorPickerDialog.hpp
widgets/dialogs/EditHotkeyDialog.cpp
widgets/dialogs/EditHotkeyDialog.hpp
widgets/dialogs/EmotePopup.cpp
widgets/dialogs/EmotePopup.hpp
widgets/dialogs/IrcConnectionEditor.cpp
Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Q_LOGGING_CATEGORY(chatterinoCommon, "chatterino.common", logThreshold);
Q_LOGGING_CATEGORY(chatterinoEmoji, "chatterino.emoji", logThreshold);
Q_LOGGING_CATEGORY(chatterinoFfzemotes, "chatterino.ffzemotes", logThreshold);
Q_LOGGING_CATEGORY(chatterinoHelper, "chatterino.helper", logThreshold);
Q_LOGGING_CATEGORY(chatterinoHotkeys, "chatterino.hotkeys", logThreshold);
Q_LOGGING_CATEGORY(chatterinoHTTP, "chatterino.http", logThreshold);
Q_LOGGING_CATEGORY(chatterinoImage, "chatterino.image", logThreshold);
Q_LOGGING_CATEGORY(chatterinoIrc, "chatterino.irc", logThreshold);
Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoCommon);
Q_DECLARE_LOGGING_CATEGORY(chatterinoEmoji);
Q_DECLARE_LOGGING_CATEGORY(chatterinoFfzemotes);
Q_DECLARE_LOGGING_CATEGORY(chatterinoHelper);
Q_DECLARE_LOGGING_CATEGORY(chatterinoHotkeys);
Q_DECLARE_LOGGING_CATEGORY(chatterinoHTTP);
Q_DECLARE_LOGGING_CATEGORY(chatterinoImage);
Q_DECLARE_LOGGING_CATEGORY(chatterinoIrc);
Expand Down
203 changes: 203 additions & 0 deletions src/controllers/hotkeys/ActionNames.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#pragma once

#include "HotkeyCategory.hpp"

#include <QString>

#include <map>

namespace chatterino {

// ActionDefinition is an action that can be performed with a hotkey
struct ActionDefinition {
// displayName is the value that would be shown to a user when they edit or create a hotkey for an action
QString displayName;

QString argumentDescription = "";

// minCountArguments is the minimum amount of arguments the action accepts
// Example action: "Select Tab" in a popup window accepts 1 argument for which tab to select
uint8_t minCountArguments = 0;

// maxCountArguments is the maximum amount of arguments the action accepts
uint8_t maxCountArguments = minCountArguments;
};

using ActionDefinitionMap = std::map<QString, ActionDefinition>;

inline const std::map<HotkeyCategory, ActionDefinitionMap> actionNames{
{HotkeyCategory::PopupWindow,
{
{"reject", ActionDefinition{"Confirmable popups: Cancel"}},
{"accept", ActionDefinition{"Confirmable popups: Confirm"}},
{"delete", ActionDefinition{"Close"}},
{"openTab",
ActionDefinition{
"Select Tab",
"<next, previous, or index of tab to select>",
1,
}},
{"scrollPage",
ActionDefinition{
"Scroll",
"<up or down>",
1,
}},
{"search", ActionDefinition{"Focus search box"}},
}},
{HotkeyCategory::Split,
{
{"changeChannel", ActionDefinition{"Change channel"}},
{"clearMessages", ActionDefinition{"Clear messages"}},
{"createClip", ActionDefinition{"Create a clip"}},
{"delete", ActionDefinition{"Close"}},
{"focus",
ActionDefinition{
"Focus neighbouring split",
"<up, down, left, or right>",
1,
}},
{"openInBrowser", ActionDefinition{"Open channel in browser"}},
{"openInCustomPlayer",
ActionDefinition{"Open stream in custom player"}},
{"openInStreamlink", ActionDefinition{"Open stream in streamlink"}},
{"openModView", ActionDefinition{"Open mod view in browser"}},
{"openViewerList", ActionDefinition{"Open viewer list"}},
{"pickFilters", ActionDefinition{"Pick filters"}},
{"reconnect", ActionDefinition{"Reconnect to chat"}},
{"reloadEmotes",
ActionDefinition{
"Reload emotes",
"[channel or subscriber]",
0,
1,
}},
{"runCommand",
ActionDefinition{
"Run a command",
"<name of command>",
1,
}},
{"scrollPage",
ActionDefinition{
"Scroll",
"<up or down>",
1,
}},
{"scrollToBottom", ActionDefinition{"Scroll to the bottom"}},
{"setChannelNotification",
ActionDefinition{
"Set channel live notification",
"[on or off. default: toggle]",
0,
1,
}},
{"setModerationMode",
ActionDefinition{
"Set moderation mode",
"[on or off. default: toggle]",
0,
1,
}},
{"showSearch", ActionDefinition{"Search"}},
{"startWatching", ActionDefinition{"Start watching"}},
{"debug", ActionDefinition{"Show debug popup"}},
}},
{HotkeyCategory::SplitInput,
{
{"clear", ActionDefinition{"Clear message"}},
{"copy",
ActionDefinition{
"Copy",
"<source of text: split, splitInput or auto>",
1,
}},
{"cursorToStart",
ActionDefinition{
"To start of message",
"<withSelection or withoutSelection>",
1,
}},
{"cursorToEnd",
ActionDefinition{
"To end of message",
"<withSelection or withoutSelection>",
1,
}},
{"nextMessage", ActionDefinition{"Choose next sent message"}},
{"openEmotesPopup", ActionDefinition{"Open emotes list"}},
{"paste", ActionDefinition{"Paste"}},
{"previousMessage",
ActionDefinition{"Choose previously sent message"}},
{"redo", ActionDefinition{"Redo"}},
{"selectAll", ActionDefinition{"Select all"}},
{"sendMessage",
ActionDefinition{
"Send message",
"[keepInput to not clear the text after sending]",
0,
1,
}},
{"undo", ActionDefinition{"Undo"}},

}},
{HotkeyCategory::Window,
{
#ifdef C_DEBUG
{"addCheerMessage", ActionDefinition{"Debug: Add cheer test message"}},
{"addEmoteMessage", ActionDefinition{"Debug: Add emote test message"}},
{"addLinkMessage",
ActionDefinition{"Debug: Add test message with a link"}},
{"addMiscMessage", ActionDefinition{"Debug: Add misc test message"}},
{"addRewardMessage",
ActionDefinition{"Debug: Add reward test message"}},
#endif
{"moveTab",
ActionDefinition{
"Move tab",
"<next, previous, or new index of tab>",
1,
}},
{"newSplit", ActionDefinition{"Create a new split"}},
{"newTab", ActionDefinition{"Create a new tab"}},
{"openSettings", ActionDefinition{"Open settings"}},
{"openTab",
ActionDefinition{
"Select tab",
"<last, next, previous, or index of tab to select>",
1,
}},
{"openQuickSwitcher", ActionDefinition{"Open the quick switcher"}},
{"popup",
ActionDefinition{
"New popup",
"<split or window>",
1,
}},
{"quit", ActionDefinition{"Quit Chatterino"}},
{"removeTab", ActionDefinition{"Remove current tab"}},
{"reopenSplit", ActionDefinition{"Reopen closed split"}},
{"setStreamerMode",
ActionDefinition{
"Set streamer mode",
"[on, off, toggle, or auto. default: toggle]",
0,
1,
}},
{"toggleLocalR9K", ActionDefinition{"Toggle local R9K"}},
{"zoom",
ActionDefinition{
"Zoom in/out",
"<in, out, or reset>",
1,
}},
{"setTabVisibility",
ActionDefinition{
"Set tab visibility",
"[on, off, or toggle. default: toggle]",
0,
1,
}}}},
};

} // namespace chatterino
Loading

0 comments on commit 703f371

Please sign in to comment.