mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
ref: unify Split popup logic (#3848)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
53a625e26e
commit
e1b512a373
|
@ -887,7 +887,7 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
});
|
});
|
||||||
|
|
||||||
this->registerCommand("/popup", [](const QStringList &words,
|
this->registerCommand("/popup", [](const QStringList &words,
|
||||||
ChannelPtr channel) {
|
ChannelPtr sourceChannel) {
|
||||||
static const auto *usageMessage =
|
static const auto *usageMessage =
|
||||||
"Usage: /popup [channel]. Open specified Twitch channel in "
|
"Usage: /popup [channel]. Open specified Twitch channel in "
|
||||||
"a new window. If no channel argument is specified, open "
|
"a new window. If no channel argument is specified, open "
|
||||||
|
@ -896,6 +896,7 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
QString target(words.value(1));
|
QString target(words.value(1));
|
||||||
stripChannelName(target);
|
stripChannelName(target);
|
||||||
|
|
||||||
|
// Popup the current split
|
||||||
if (target.isEmpty())
|
if (target.isEmpty())
|
||||||
{
|
{
|
||||||
auto *currentPage =
|
auto *currentPage =
|
||||||
|
@ -914,19 +915,14 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channel->addMessage(makeSystemMessage(usageMessage));
|
sourceChannel->addMessage(makeSystemMessage(usageMessage));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open channel passed as argument in a popup
|
||||||
auto *app = getApp();
|
auto *app = getApp();
|
||||||
Window &window = app->windows->createWindow(WindowType::Popup, true);
|
auto targetChannel = app->twitch->getOrAddChannel(target);
|
||||||
|
app->windows->openInPopup(targetChannel);
|
||||||
auto *split = new Split(static_cast<SplitContainer *>(
|
|
||||||
window.getNotebook().getOrAddSelectedPage()));
|
|
||||||
|
|
||||||
split->setChannel(app->twitch->getOrAddChannel(target));
|
|
||||||
|
|
||||||
window.getNotebook().getOrAddSelectedPage()->appendSplit(split);
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
|
|
|
@ -295,6 +295,16 @@ Window &WindowManager::createWindow(WindowType type, bool show, QWidget *parent)
|
||||||
return *window;
|
return *window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Window &WindowManager::openInPopup(ChannelPtr channel)
|
||||||
|
{
|
||||||
|
auto &popup = this->createWindow(WindowType::Popup, true);
|
||||||
|
auto *split =
|
||||||
|
popup.getNotebook().getOrAddSelectedPage()->appendNewSplit(false);
|
||||||
|
split->setChannel(channel);
|
||||||
|
|
||||||
|
return popup;
|
||||||
|
}
|
||||||
|
|
||||||
void WindowManager::select(Split *split)
|
void WindowManager::select(Split *split)
|
||||||
{
|
{
|
||||||
this->selectSplit.invoke(split);
|
this->selectSplit.invoke(split);
|
||||||
|
|
|
@ -60,6 +60,10 @@ public:
|
||||||
Window &createWindow(WindowType type, bool show = true,
|
Window &createWindow(WindowType type, bool show = true,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
// Use this method if you want to open a "new" channel in a popup. If you want to popup an
|
||||||
|
// existing Split or SplitContainer, consider using Split::popup() or SplitContainer::popup().
|
||||||
|
Window &openInPopup(ChannelPtr channel);
|
||||||
|
|
||||||
void select(Split *split);
|
void select(Split *split);
|
||||||
void select(SplitContainer *container);
|
void select(SplitContainer *container);
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,8 @@ NewPopupItem::NewPopupItem(const QString &channelName)
|
||||||
void NewPopupItem::action()
|
void NewPopupItem::action()
|
||||||
{
|
{
|
||||||
auto *app = getApp();
|
auto *app = getApp();
|
||||||
auto &popup = app->windows->createWindow(WindowType::Popup, true);
|
auto channel = app->twitch->getOrAddChannel(this->channelName_);
|
||||||
auto *split =
|
app->windows->openInPopup(channel);
|
||||||
popup.getNotebook().getOrAddSelectedPage()->appendNewSplit(false);
|
|
||||||
split->setChannel(app->twitch->getOrAddChannel(this->channelName_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewPopupItem::paint(QPainter *painter, const QRect &rect) const
|
void NewPopupItem::paint(QPainter *painter, const QRect &rect) const
|
||||||
|
|
Loading…
Reference in a new issue