mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
refactor: make Application::commands private
This commit is contained in:
parent
807ba5e44e
commit
fc942ab102
|
@ -361,6 +361,13 @@ CrashHandler *Application::getCrashHandler()
|
|||
return this->crashHandler;
|
||||
}
|
||||
|
||||
CommandController *Application::getCommands()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
return this->commands;
|
||||
}
|
||||
|
||||
FfzBadges *Application::getFfzBadges()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
|
|
@ -137,9 +137,9 @@ private:
|
|||
ImageUploader *const imageUploader{};
|
||||
SeventvAPI *const seventvAPI{};
|
||||
CrashHandler *const crashHandler{};
|
||||
CommandController *const commands{};
|
||||
|
||||
public:
|
||||
CommandController *const commands{};
|
||||
NotificationController *const notifications{};
|
||||
HighlightController *const highlights{};
|
||||
TwitchIrcServer *const twitch{};
|
||||
|
@ -176,12 +176,7 @@ public:
|
|||
WindowManager *getWindows() override;
|
||||
Toasts *getToasts() override;
|
||||
CrashHandler *getCrashHandler() override;
|
||||
CommandController *getCommands() override
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
return this->commands;
|
||||
}
|
||||
CommandController *getCommands() override;
|
||||
NotificationController *getNotifications() override
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
|
|
@ -71,7 +71,7 @@ void CommandSource::initializeItems()
|
|||
std::vector<CommandItem> commands;
|
||||
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
for (const auto &command : getApp()->commands->pluginCommands())
|
||||
for (const auto &command : getIApp()->getCommands()->pluginCommands())
|
||||
{
|
||||
addCommand(command, commands);
|
||||
}
|
||||
|
|
|
@ -166,7 +166,8 @@ int c2_send_msg(lua_State *L)
|
|||
}
|
||||
QString message = text;
|
||||
message = message.replace('\n', ' ');
|
||||
QString outText = getApp()->commands->execCommand(message, chn, false);
|
||||
QString outText =
|
||||
getIApp()->getCommands()->execCommand(message, chn, false);
|
||||
chn->sendMessage(outText);
|
||||
lua::push(L, true);
|
||||
return 1;
|
||||
|
|
|
@ -146,7 +146,7 @@ bool Plugin::registerCommand(const QString &name, const QString &functionName)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto ok = getApp()->commands->registerPluginCommand(name);
|
||||
auto ok = getIApp()->getCommands()->registerPluginCommand(name);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -281,7 +281,7 @@ bool PluginController::reload(const QString &id)
|
|||
}
|
||||
for (const auto &[cmd, _] : it->second->ownedCommands)
|
||||
{
|
||||
getApp()->commands->unregisterPluginCommand(cmd);
|
||||
getIApp()->getCommands()->unregisterPluginCommand(cmd);
|
||||
}
|
||||
it->second->ownedCommands.clear();
|
||||
QDir loadDir = it->second->loadDirectory_;
|
||||
|
|
|
@ -432,7 +432,7 @@ void SettingsDialog::onOkClicked()
|
|||
{
|
||||
if (!getApp()->getArgs().dontSaveSettings)
|
||||
{
|
||||
getApp()->commands->save();
|
||||
getIApp()->getCommands()->save();
|
||||
pajlada::Settings::SettingManager::gSave();
|
||||
}
|
||||
this->close();
|
||||
|
|
|
@ -226,7 +226,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
|
|||
.arg(calculateTimeoutDuration(button));
|
||||
}
|
||||
|
||||
msg = getApp()->commands->execCommand(
|
||||
msg = getIApp()->getCommands()->execCommand(
|
||||
msg, this->underlyingChannel_, false);
|
||||
|
||||
this->underlyingChannel_->sendMessage(msg);
|
||||
|
@ -415,25 +415,25 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
|
|||
|
||||
QObject::connect(mod.getElement(), &Button::leftClicked, [this] {
|
||||
QString value = "/mod " + this->userName_;
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
});
|
||||
QObject::connect(unmod.getElement(), &Button::leftClicked, [this] {
|
||||
QString value = "/unmod " + this->userName_;
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
});
|
||||
QObject::connect(vip.getElement(), &Button::leftClicked, [this] {
|
||||
QString value = "/vip " + this->userName_;
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
});
|
||||
QObject::connect(unvip.getElement(), &Button::leftClicked, [this] {
|
||||
QString value = "/unvip " + this->userName_;
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
});
|
||||
|
@ -500,7 +500,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
|
|||
if (this->underlyingChannel_)
|
||||
{
|
||||
QString value = "/ban " + this->userName_;
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
|
@ -511,7 +511,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
|
|||
if (this->underlyingChannel_)
|
||||
{
|
||||
QString value = "/unban " + this->userName_;
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
|
@ -524,7 +524,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
|
|||
QString value = "/timeout " + this->userName_ + " " +
|
||||
QString::number(arg);
|
||||
|
||||
value = getApp()->commands->execCommand(
|
||||
value = getIApp()->getCommands()->execCommand(
|
||||
value, this->underlyingChannel_, false);
|
||||
|
||||
this->underlyingChannel_->sendMessage(value);
|
||||
|
|
|
@ -2539,7 +2539,7 @@ void ChannelView::addCommandExecutionContextMenuItems(
|
|||
/* Get commands to be displayed in context menu;
|
||||
* only those that had the showInMsgContextMenu check box marked in the Commands page */
|
||||
std::vector<Command> cmds;
|
||||
for (const auto &cmd : getApp()->commands->items)
|
||||
for (const auto &cmd : getIApp()->getCommands()->items)
|
||||
{
|
||||
if (cmd.showInMsgContextMenu)
|
||||
{
|
||||
|
@ -2586,13 +2586,14 @@ void ChannelView::addCommandExecutionContextMenuItems(
|
|||
}
|
||||
|
||||
// Execute command through right-clicking a message -> Execute command
|
||||
QString value = getApp()->commands->execCustomCommand(
|
||||
QString value = getIApp()->getCommands()->execCustomCommand(
|
||||
inputText.split(' '), cmd, true, channel, layout->getMessage(),
|
||||
{
|
||||
{"input.text", userText},
|
||||
});
|
||||
|
||||
value = getApp()->commands->execCommand(value, channel, false);
|
||||
value =
|
||||
getIApp()->getCommands()->execCommand(value, channel, false);
|
||||
|
||||
channel->sendMessage(value);
|
||||
});
|
||||
|
@ -2757,11 +2758,12 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
|
|||
}
|
||||
|
||||
// Execute command clicking a moderator button
|
||||
value = getApp()->commands->execCustomCommand(
|
||||
value = getIApp()->getCommands()->execCustomCommand(
|
||||
QStringList(), Command{"(modaction)", value}, true, channel,
|
||||
layout->getMessage());
|
||||
|
||||
value = getApp()->commands->execCommand(value, channel, false);
|
||||
value =
|
||||
getIApp()->getCommands()->execCommand(value, channel, false);
|
||||
|
||||
channel->sendMessage(value);
|
||||
}
|
||||
|
|
|
@ -38,16 +38,17 @@ CommandPage::CommandPage()
|
|||
LayoutCreator<CommandPage> layoutCreator(this);
|
||||
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
|
||||
|
||||
EditableModelView *view =
|
||||
layout.emplace<EditableModelView>(app->commands->createModel(nullptr))
|
||||
.getElement();
|
||||
EditableModelView *view = layout
|
||||
.emplace<EditableModelView>(
|
||||
app->getCommands()->createModel(nullptr))
|
||||
.getElement();
|
||||
|
||||
view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"});
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
1, QHeaderView::Stretch);
|
||||
// We can safely ignore this signal connection since we own the view
|
||||
std::ignore = view->addButtonPressed.connect([] {
|
||||
getApp()->commands->items.append(
|
||||
getIApp()->getCommands()->items.append(
|
||||
Command{"/command", "I made a new command HeyGuys"});
|
||||
});
|
||||
|
||||
|
@ -66,7 +67,7 @@ CommandPage::CommandPage()
|
|||
{
|
||||
if (int index = line.indexOf(' '); index != -1)
|
||||
{
|
||||
getApp()->commands->items.insert(
|
||||
getIApp()->getCommands()->items.insert(
|
||||
Command(line.mid(0, index), line.mid(index + 1)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -690,7 +690,7 @@ void Split::addShortcuts()
|
|||
<< "runCommand hotkey called without arguments!";
|
||||
return "runCommand hotkey called without arguments!";
|
||||
}
|
||||
QString command = getApp()->commands->execCommand(
|
||||
QString command = getIApp()->getCommands()->execCommand(
|
||||
arguments.at(0).replace('\n', ' '), this->getChannel(), false);
|
||||
this->getChannel()->sendMessage(command);
|
||||
return "";
|
||||
|
|
|
@ -332,7 +332,7 @@ QString SplitInput::handleSendMessage(const std::vector<QString> &arguments)
|
|||
|
||||
message = message.replace('\n', ' ');
|
||||
QString sendMessage =
|
||||
getApp()->commands->execCommand(message, c, false);
|
||||
getIApp()->getCommands()->execCommand(message, c, false);
|
||||
|
||||
c->sendMessage(sendMessage);
|
||||
|
||||
|
@ -363,7 +363,8 @@ QString SplitInput::handleSendMessage(const std::vector<QString> &arguments)
|
|||
}
|
||||
|
||||
message = message.replace('\n', ' ');
|
||||
QString sendMessage = getApp()->commands->execCommand(message, c, false);
|
||||
QString sendMessage =
|
||||
getIApp()->getCommands()->execCommand(message, c, false);
|
||||
|
||||
// Reply within TwitchChannel
|
||||
tc->sendReply(sendMessage, this->replyThread_->id);
|
||||
|
@ -947,8 +948,8 @@ void SplitInput::editTextChanged()
|
|||
this->textChanged.invoke(text);
|
||||
|
||||
text = text.trimmed();
|
||||
text =
|
||||
app->commands->execCommand(text, this->split_->getChannel(), true);
|
||||
text = app->getCommands()->execCommand(text, this->split_->getChannel(),
|
||||
true);
|
||||
}
|
||||
|
||||
if (text.length() > 0 &&
|
||||
|
|
Loading…
Reference in a new issue