1
0
Fork 0

DBG+GUI: added error script command

This commit is contained in:
mrexodia 2017-03-12 05:40:07 +01:00
parent 8340cd5aab
commit 1ae30cef53
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
3 changed files with 42 additions and 8 deletions

View File

@ -322,6 +322,11 @@ static CMDRESULT scriptinternalcmdexec(const char* cmd)
scriptstack.pop_back(); //remove last stack entry
return STATUS_CONTINUE;
}
else if(scriptisinternalcommand(cmd, "error")) //show an error and end the script
{
GuiScriptError(0, StringUtils::Trim(cmd + strlen("error"), " \"'").c_str());
return STATUS_EXIT;
}
else if(scriptisinternalcommand(cmd, "invalid")) //invalid command for testing
return STATUS_ERROR;
else if(scriptisinternalcommand(cmd, "pause")) //pause the script

View File

@ -131,28 +131,53 @@ QString ScriptView::paintContent(QPainter* painter, dsint rowBase, int rowOffset
command.truncate(comment_idx);
}
QString mnemonic, argument;
//setup the richText list
switch(linetype)
{
case linecommand:
{
if(isScriptCommand(command, "ret"))
if(isScriptCommand(command, "ret", mnemonic, argument))
{
newRichText.flags = RichTextPainter::FlagAll;
newRichText.textColor = ConfigColor("InstructionRetColor");
newRichText.textBackground = ConfigColor("InstructionRetBackgroundColor");
newRichText.text = "ret";
newRichText.text = mnemonic;
richText.push_back(newRichText);
QString remainder = command.right(command.length() - 3);
if(remainder.length())
if(argument.length())
{
newRichText.flags = RichTextPainter::FlagAll;
newRichText.textColor = ConfigColor("InstructionUncategorizedColor");
newRichText.textBackground = ConfigColor("InstructionUncategorizedBackgroundColor");
newRichText.text = remainder;
newRichText.text = argument;
richText.push_back(newRichText);
}
}
else if(isScriptCommand(command, "invalid", mnemonic, argument) || isScriptCommand(command, "error", mnemonic, argument))
{
newRichText.flags = RichTextPainter::FlagAll;
newRichText.textColor = ConfigColor("InstructionUnusualColor");
newRichText.textBackground = ConfigColor("InstructionUnusualBackgroundColor");
newRichText.text = mnemonic;
richText.push_back(newRichText);
if(argument.length())
{
newRichText.flags = RichTextPainter::FlagAll;
newRichText.textColor = ConfigColor("InstructionUncategorizedColor");
newRichText.textBackground = ConfigColor("InstructionUncategorizedBackgroundColor");
newRichText.text = argument;
richText.push_back(newRichText);
}
}
else if(isScriptCommand(command, "nop", mnemonic, argument))
{
newRichText.flags = RichTextPainter::FlagAll;
newRichText.textColor = ConfigColor("InstructionNopColor");
newRichText.textBackground = ConfigColor("InstructionNopBackgroundColor");
newRichText.text = mnemonic;
richText.push_back(newRichText);
}
else
{
newRichText.flags = RichTextPainter::FlagAll;
@ -363,8 +388,10 @@ void ScriptView::setupContextMenu()
mMenu->addAction(makeShortcutAction(DIcon("terminal-command.png"), tr("&Execute Command..."), SLOT(cmdExec()), "ActionExecuteCommandScript"));
}
bool ScriptView::isScriptCommand(QString text, QString cmd)
bool ScriptView::isScriptCommand(QString text, QString cmd, QString & mnemonic, QString & argument)
{
mnemonic = cmd;
argument.clear();
int len = text.length();
int cmdlen = cmd.length();
if(cmdlen > len)
@ -372,7 +399,10 @@ bool ScriptView::isScriptCommand(QString text, QString cmd)
else if(cmdlen == len)
return (text.compare(cmd, Qt::CaseInsensitive) == 0);
else if(text.at(cmdlen) == ' ')
{
argument = text.mid(cmdlen);
return (text.left(cmdlen).compare(cmd, Qt::CaseInsensitive) == 0);
}
return false;
}
@ -417,7 +447,6 @@ void ScriptView::error(int line, QString message)
msg->setWindowTitle(title);
msg->setText(message);
msg->setWindowIcon(DIcon("script-error.png"));
msg->setParent(this, Qt::Dialog);
msg->show();
}

View File

@ -48,7 +48,7 @@ private:
//private functions
void setupContextMenu();
void setSelection(int line);
bool isScriptCommand(QString text, QString cmd);
bool isScriptCommand(QString text, QString cmd, QString & mnemonic, QString & argument);
//private variables
int mIpLine;