Feature: execute commands on chat messages using the context menu (#3738)
This commit is contained in:
@@ -15,11 +15,14 @@ Command::Command(const QString &_text)
|
||||
|
||||
this->name = _text.mid(0, index).trimmed();
|
||||
this->func = _text.mid(index + 1).trimmed();
|
||||
this->showInMsgContextMenu = false;
|
||||
}
|
||||
|
||||
Command::Command(const QString &_name, const QString &_func)
|
||||
Command::Command(const QString &_name, const QString &_func,
|
||||
bool _showInMsgContextMenu)
|
||||
: name(_name.trimmed())
|
||||
, func(_func.trimmed())
|
||||
, showInMsgContextMenu(_showInMsgContextMenu)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,12 @@ namespace chatterino {
|
||||
struct Command {
|
||||
QString name;
|
||||
QString func;
|
||||
bool showInMsgContextMenu;
|
||||
|
||||
Command() = default;
|
||||
explicit Command(const QString &text);
|
||||
Command(const QString &name, const QString &func);
|
||||
Command(const QString &name, const QString &func,
|
||||
bool showInMsgContextMenu = false);
|
||||
|
||||
QString toString() const;
|
||||
};
|
||||
@@ -31,6 +33,8 @@ struct Serialize<chatterino::Command> {
|
||||
|
||||
chatterino::rj::set(ret, "name", value.name, a);
|
||||
chatterino::rj::set(ret, "func", value.func, a);
|
||||
chatterino::rj::set(ret, "showInMsgContextMenu",
|
||||
value.showInMsgContextMenu, a);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -59,6 +63,15 @@ struct Deserialize<chatterino::Command> {
|
||||
PAJLADA_REPORT_ERROR(error);
|
||||
return command;
|
||||
}
|
||||
if (!chatterino::rj::getSafe(value, "showInMsgContextMenu",
|
||||
command.showInMsgContextMenu))
|
||||
{
|
||||
command.showInMsgContextMenu = false;
|
||||
|
||||
PAJLADA_REPORT_ERROR(error);
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace chatterino {
|
||||
|
||||
// commandmodel
|
||||
CommandModel::CommandModel(QObject *parent)
|
||||
: SignalVectorModel<Command>(2, parent)
|
||||
: SignalVectorModel<Command>(Column::COUNT, parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,16 +14,21 @@ CommandModel::CommandModel(QObject *parent)
|
||||
Command CommandModel::getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
const Command &original)
|
||||
{
|
||||
return Command(row[0]->data(Qt::EditRole).toString(),
|
||||
row[1]->data(Qt::EditRole).toString());
|
||||
return Command(row[Column::Trigger]->data(Qt::EditRole).toString(),
|
||||
row[Column::CommandFunc]->data(Qt::EditRole).toString(),
|
||||
row[Column::ShowInMessageContextMenu]
|
||||
->data(Qt::CheckStateRole)
|
||||
.toBool());
|
||||
}
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
void CommandModel::getRowFromItem(const Command &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item.name);
|
||||
setStringItem(row[1], item.func);
|
||||
setStringItem(row[Column::Trigger], item.name);
|
||||
setStringItem(row[Column::CommandFunc], item.func);
|
||||
setBoolItem(row[Column::ShowInMessageContextMenu],
|
||||
item.showInMsgContextMenu);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -13,6 +13,13 @@ class CommandModel : public SignalVectorModel<Command>
|
||||
{
|
||||
explicit CommandModel(QObject *parent);
|
||||
|
||||
enum Column {
|
||||
Trigger = 0,
|
||||
CommandFunc = 1,
|
||||
ShowInMessageContextMenu = 2,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
protected:
|
||||
// turn a vector item into a model row
|
||||
virtual Command getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
|
||||
Reference in New Issue
Block a user