Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customizing the behavior of Right Clicking of usernames. #4622

Merged
merged 11 commits into from
Jul 1, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Minor: Added a Send button in the input box so you can click to send a message. This is disabled by default and can be enabled with the "Show send message button" setting. (#4607)
- Minor: Improved error messages when the updater fails a download. (#4594)
- Minor: Added `/shield` and `/shieldoff` commands to toggle shield mode. (#4580)
- Minor: Allow for customizing the behavior of `Right Click`ing of usernames. (#4622)
- Bugfix: Fixed the menu warping on macOS on Qt6. (#4595)
- Bugfix: Fixed link tooltips not showing unless the thumbnail setting was enabled. (#4597)
- Bugfix: Domains starting with `http` are now parsed as links again. (#4598)
Expand Down
20 changes: 20 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ enum ThumbnailPreviewMode : int {
ShowOnShift = 2,
};

enum UsernameRightClickBehavior : int {
Reply = 0,
Mention = 1,
Ignore = 2,
};

/// Settings which are availlable for reading and writing on the gui thread.
// These settings are still accessed concurrently in the code but it is bad practice.
class Settings : public ABSettings, public ConcurrentSettings
Expand Down Expand Up @@ -194,6 +200,20 @@ class Settings : public ABSettings, public ConcurrentSettings
BoolSetting autoCloseUserPopup = {"/behaviour/autoCloseUserPopup", true};
BoolSetting autoCloseThreadPopup = {"/behaviour/autoCloseThreadPopup",
false};

EnumSetting<UsernameRightClickBehavior> usernameRightClickBehavior = {
"/behaviour/usernameRightClickBehavior",
UsernameRightClickBehavior::Mention,
};
EnumSetting<UsernameRightClickBehavior> usernameRightClickModifierBehavior =
{
"/behaviour/usernameRightClickBehaviorWithModifier",
UsernameRightClickBehavior::Reply,
};
EnumSetting<Qt::KeyboardModifier> usernameRightClickModifier = {
"/behaviour/usernameRightClickModifier",
Qt::KeyboardModifier::ShiftModifier};

BoolSetting autoSubToParticipatedThreads = {
"/behaviour/autoSubToParticipatedThreads",
true,
Expand Down
81 changes: 66 additions & 15 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2084,22 +2084,73 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
if (link.type == Link::UserInfo)
{
if (hoveredElement->getFlags().has(
MessageElementFlag::Username) &&
event->modifiers() == Qt::ShiftModifier)
MessageElementFlag::Username))
{
// Start a new reply if Shift+Right-clicking the message username
this->setInputReply(layout->getMessagePtr());
}
else
{
// Insert @username into split input
const bool commaMention =
getSettings()->mentionUsersWithComma;
const bool isFirstWord =
split && split->getInput().isEditFirstWord();
auto userMention = formatUserMention(
link.value, isFirstWord, commaMention);
insertText("@" + userMention + " ");
Qt::KeyboardModifier userSpecifiedModifier =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'userSpecifiedModifier' of type 'Qt::KeyboardModifier' can be declared 'const' [misc-const-correctness]

Suggested change
Qt::KeyboardModifier userSpecifiedModifier =
Qt::KeyboardModifier const userSpecifiedModifier =

getSettings()->usernameRightClickModifier;

if (userSpecifiedModifier ==
Qt::KeyboardModifier::NoModifier)
{
qCWarning(chatterinoCommon)
<< "sanity check failed: "
"invalid settings detected "
"Settings::usernameRightClickModifier is "
"NoModifier, which should never happen";
return;
}

Qt::KeyboardModifiers modifiers{userSpecifiedModifier};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'modifiers' of type 'Qt::KeyboardModifiers' (aka 'QFlagsQt::KeyboardModifier') can be declared 'const' [misc-const-correctness]

Suggested change
Qt::KeyboardModifiers modifiers{userSpecifiedModifier};
Qt::KeyboardModifiers const modifiers{userSpecifiedModifier};

auto isModifierHeld = event->modifiers() == modifiers;

UsernameRightClickBehavior action{};
if (isModifierHeld)
{
action = getSettings()
->usernameRightClickModifierBehavior;
}
else
{
action = getSettings()->usernameRightClickBehavior;
}

switch (action)
{
case UsernameRightClickBehavior::Mention: {
if (split == nullptr)
{
return;
}

// Insert @username into split input
const bool commaMention =
getSettings()->mentionUsersWithComma;
const bool isFirstWord =
split->getInput().isEditFirstWord();
auto userMention = formatUserMention(
link.value, isFirstWord, commaMention);
insertText("@" + userMention + " ");
}
break;

case UsernameRightClickBehavior::Reply: {
// Start a new reply if matching user's settings
this->setInputReply(layout->getMessagePtr());
}
break;

case UsernameRightClickBehavior::Ignore:
break;

default: {
qCWarning(chatterinoCommon)
<< "unhandled or corrupted "
"UsernameRightClickBehavior value in "
"ChannelView::handleMouseClick:"
<< action;
}
break; // unreachable
}
}

return;
Expand Down
68 changes: 68 additions & 0 deletions src/widgets/settingspages/GeneralPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,74 @@ void GeneralPage::initLayout(GeneralPageView &layout)
false,
"Specify how Chatterino will handle messages that exceed Twitch "
"message limits");
layout.addDropdown<std::underlying_type<UsernameRightClickBehavior>::type>(
Mm2PL marked this conversation as resolved.
Show resolved Hide resolved
"Username right-click behavior",
{
"Reply",
"Mention",
"Ignore",
},
s.usernameRightClickBehavior,
[](auto index) {
return index;
},
[](auto args) {
return static_cast<UsernameRightClickBehavior>(args.index);
},
false,
"Specify how Chatterino will handle right-clicking a username in "
"chat when not holding the modifier.");
layout.addDropdown<std::underlying_type<UsernameRightClickBehavior>::type>(
"Username right-click with modifier behavior",
{
"Reply",
"Mention",
"Ignore",
},
s.usernameRightClickModifierBehavior,
[](auto index) {
return index;
},
[](auto args) {
return static_cast<UsernameRightClickBehavior>(args.index);
},
false,
"Specify how Chatterino will handle right-clicking a username in "
"chat when holding down the modifier.");
layout.addDropdown<std::underlying_type<Qt::KeyboardModifier>::type>(
"Modifier for alternate right-click action",
{"Shift", "Control", "Alt", META_KEY}, s.usernameRightClickModifier,
[](int index) {
switch (index)
{
case Qt::ShiftModifier:
return 0;
case Qt::ControlModifier:
return 1;
case Qt::AltModifier:
return 2;
case Qt::MetaModifier:
return 3;
default:
return 0;
}
},
[](DropdownArgs args) {
Mm2PL marked this conversation as resolved.
Show resolved Hide resolved
switch (args.index)
{
case 0:
return Qt::ShiftModifier;
case 1:
return Qt::ControlModifier;
case 2:
return Qt::AltModifier;
case 3:
return Qt::MetaModifier;
default:
return Qt::NoModifier;
}
},
false);

layout.addTitle("Messages");
layout.addCheckbox(
Expand Down
Loading