added command tab to settings but they don't save

This commit is contained in:
fourtf 2018-01-04 04:03:51 +01:00
parent 871195265a
commit 8693203c6d
5 changed files with 46 additions and 8 deletions

View file

@ -38,9 +38,9 @@ void CommandManager::setCommands(const QStringList &_commands)
continue;
}
if (command.at(0) != '/') {
command = QString("/") + command;
}
// if (command.at(0) != '/') {
// command = QString("/") + command;
// }
QString commandName = command.mid(0, command.indexOf(' '));
@ -58,7 +58,7 @@ QStringList CommandManager::getCommands()
return this->commandsStringList;
}
QString CommandManager::execCommand(QString text)
QString CommandManager::execCommand(QString text, bool dryRun)
{
Command command;
QStringList words = text.split(' ', QString::SkipEmptyParts);

View file

@ -18,7 +18,7 @@ class CommandManager
public:
static CommandManager &getInstance();
QString execCommand(QString text);
QString execCommand(QString text, bool dryRun);
void loadCommands();
void saveCommands();

View file

@ -1,4 +1,5 @@
#include "widgets/helper/splitinput.hpp"
#include "singletons/commandmanager.hpp"
#include "singletons/completionmanager.hpp"
#include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp"
@ -82,7 +83,11 @@ SplitInput::SplitInput(Split *_chatWidget)
}
QString message = textInput.toPlainText();
c->sendMessage(message.replace('\n', ' '));
QString sendMessage =
singletons::CommandManager::getInstance().execCommand(message, false);
sendMessage = sendMessage.replace('\n', ' ');
c->sendMessage(sendMessage);
prevMsg.append(message);
event->accept();
@ -229,6 +234,8 @@ void SplitInput::editTextChanged()
static QRegularExpression spaceRegex("\\s\\s+");
text = text.replace(spaceRegex, " ");
text = singletons::CommandManager::getInstance().execCommand(text, true);
QString labelText;
if (text.length() == 0) {

View file

@ -2,6 +2,7 @@
#include "const.hpp"
#include "debug/log.hpp"
#include "singletons/accountmanager.hpp"
#include "singletons/commandmanager.hpp"
#include "singletons/windowmanager.hpp"
#include "twitch/twitchmessagebuilder.hpp"
#include "twitch/twitchuser.hpp"
@ -87,8 +88,7 @@ void SettingsDialog::addTabs()
this->addTab(this->createBehaviourTab(), "Behaviour", ":/images/behave.svg");
// this->addTab(this->createCommandsTab(), "Commands",
// ":/images/CustomActionEditor_16x.png");
this->addTab(this->createCommandsTab(), "Commands", ":/images/CustomActionEditor_16x.png");
this->addTab(this->createEmotesTab(), "Emotes", ":/images/emote.svg");
@ -361,8 +361,37 @@ QVBoxLayout *SettingsDialog::createBehaviourTab()
QVBoxLayout *SettingsDialog::createCommandsTab()
{
singletons::CommandManager &commandManager = singletons::CommandManager::getInstance();
this->commandsTextChangedDelay.setSingleShot(true);
auto layout = this->createTabLayout();
layout->addWidget(new QLabel("One command per line. Commands don't save right now"));
layout->addWidget(new QLabel("\"/cmd example command\" will print "
"\"example command\" when you type /cmd in chat."));
layout->addWidget(new QLabel("{1} will be replaced with the first word you type after the "
"command, {2} with the second and so on."));
layout->addWidget(new QLabel("{1+} will be replaced with first word and everything after, {2+} "
"with everything after the second word and so on"));
layout->addWidget(new QLabel("Duplicate commands will be ignored."));
QTextEdit *textEdit = new QTextEdit();
textEdit->setPlainText(QString(commandManager.getCommands().join('\n')));
layout->addWidget(textEdit);
QObject::connect(textEdit, &QTextEdit::textChanged,
[this] { this->commandsTextChangedDelay.start(200); });
QObject::connect(&this->commandsTextChangedDelay, &QTimer::timeout,
[textEdit, &commandManager] {
QString text = textEdit->toPlainText();
QStringList lines = text.split(QRegularExpression("(\r?\n|\r\n?)"));
commandManager.setCommands(lines);
});
return layout;
}

View file

@ -14,6 +14,7 @@
#include <QMainWindow>
#include <QPushButton>
#include <QStackedLayout>
#include <QTimer>
#include <QVBoxLayout>
#include <QWidget>
#include <pajlada/settings/setting.hpp>
@ -52,6 +53,7 @@ private:
std::vector<SettingsDialogTab *> tabs;
pajlada::Settings::Setting<int> usernameDisplayMode;
QTimer commandsTextChangedDelay;
struct {
QVBoxLayout tabs;