mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Added button in menu to join to channel. (#724)
This commit is contained in:
parent
a3a7317e62
commit
9a6650b56c
5 changed files with 29 additions and 2 deletions
|
@ -1126,6 +1126,25 @@ void ChannelView::addContextMenuItems(
|
|||
QGuiApplication::clipboard()->setText(copyString);
|
||||
});
|
||||
|
||||
// Join to channel
|
||||
if (hoveredElement->getLink().type == Link::Url) {
|
||||
static QRegularExpression twitchChannelRegex(
|
||||
R"(^(?:https?:\/\/)?(?:www\.|go\.)?twitch\.tv\/(?<username>[a-z0-9_]+))",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
auto twitchMatch = twitchChannelRegex.match(
|
||||
hoveredElement->getLink().value);
|
||||
auto twitchUsername = twitchMatch.captured("username");
|
||||
if (!twitchUsername.isEmpty() &&
|
||||
twitchUsername != "settings" &&
|
||||
twitchUsername != "videos") {
|
||||
menu->addSeparator();
|
||||
menu->addAction("Join to channel", [twitchUsername, this] {
|
||||
this->joinToChannel.invoke(twitchUsername);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
menu->popup(QCursor::pos());
|
||||
menu->raise();
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
pajlada::Signals::NoArgSignal selectionChanged;
|
||||
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
|
||||
pajlada::Signals::Signal<const Link &> linkClicked;
|
||||
pajlada::Signals::Signal<QString> joinToChannel;
|
||||
|
||||
protected:
|
||||
void themeChangedEvent() override;
|
||||
|
|
|
@ -105,6 +105,11 @@ Split::Split(QWidget *parent)
|
|||
}
|
||||
});
|
||||
|
||||
this->view_->joinToChannel.connect([this](QString twitchChannel) {
|
||||
this->container_->appendNewSplit(false)->setChannel(
|
||||
getApp()->twitch.server->getOrAddChannel(twitchChannel));
|
||||
});
|
||||
|
||||
this->input_->textChanged.connect([=](const QString &newText) {
|
||||
if (getSettings()->showEmptyInput) {
|
||||
return;
|
||||
|
|
|
@ -101,7 +101,7 @@ void SplitContainer::resetMouseStatus()
|
|||
this->update();
|
||||
}
|
||||
|
||||
void SplitContainer::appendNewSplit(bool openChannelNameDialog)
|
||||
Split* SplitContainer::appendNewSplit(bool openChannelNameDialog)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
|
@ -115,6 +115,8 @@ void SplitContainer::appendNewSplit(bool openChannelNameDialog)
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
return split;
|
||||
}
|
||||
|
||||
void SplitContainer::appendSplit(Split *split)
|
||||
|
|
|
@ -171,7 +171,7 @@ private:
|
|||
public:
|
||||
SplitContainer(Notebook *parent);
|
||||
|
||||
void appendNewSplit(bool openChannelNameDialog);
|
||||
Split* appendNewSplit(bool openChannelNameDialog);
|
||||
void appendSplit(Split *split);
|
||||
void insertSplit(Split *split, const Position &position);
|
||||
void insertSplit(Split *split, Direction direction, Split *relativeTo);
|
||||
|
|
Loading…
Reference in a new issue