Fix the script editor breaking when trying to add a new script with errors
Fixes #1006
This commit is contained in:
parent
7539e8c348
commit
709fb25ff6
@ -961,6 +961,11 @@ void CodeCompletion::moveCursor(CodeCompletion::MoveOperation moveOperation, int
|
|||||||
emit cursorPositionChanged();
|
emit cursorPositionChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case MoveOperationAbsoluteLine:
|
||||||
|
m_cursor.movePosition(QTextCursor::Start);
|
||||||
|
m_cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, count - 1);
|
||||||
|
emit cursorPositionChanged();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,7 @@ public:
|
|||||||
MoveOperationNextLine,
|
MoveOperationNextLine,
|
||||||
MoveOperationPreviousWord,
|
MoveOperationPreviousWord,
|
||||||
MoveOperationNextWord,
|
MoveOperationNextWord,
|
||||||
|
MoveOperationAbsoluteLine,
|
||||||
};
|
};
|
||||||
Q_ENUM(MoveOperation)
|
Q_ENUM(MoveOperation)
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,8 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
NYMEA_LOGGING_CATEGORY(dcScriptManager, "Scripts")
|
NYMEA_LOGGING_CATEGORY(dcScriptManager, "Scripts")
|
||||||
|
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
ScriptManager::ScriptManager(JsonRpcClient *jsonClient, QObject *parent):
|
ScriptManager::ScriptManager(JsonRpcClient *jsonClient, QObject *parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_client(jsonClient)
|
m_client(jsonClient)
|
||||||
@ -116,15 +118,19 @@ void ScriptManager::onScriptsFetched(int /*commandId*/, const QVariantMap ¶m
|
|||||||
|
|
||||||
void ScriptManager::onScriptFetched(int commandId, const QVariantMap ¶ms)
|
void ScriptManager::onScriptFetched(int commandId, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
QMetaEnum metaEnum = QMetaEnum::fromType<ScriptError>();
|
||||||
|
ScriptError status = static_cast<ScriptError>(metaEnum.keyToValue(params.value("scriptError").toByteArray()));
|
||||||
emit fetchScriptReply(commandId,
|
emit fetchScriptReply(commandId,
|
||||||
params.value("scriptError").toString(),
|
status,
|
||||||
params.value("content").toString());
|
params.value("content").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptManager::onScriptAdded(int commandId, const QVariantMap ¶ms)
|
void ScriptManager::onScriptAdded(int commandId, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
QMetaEnum metaEnum = QMetaEnum::fromType<ScriptError>();
|
||||||
|
ScriptError status = static_cast<ScriptError>(metaEnum.keyToValue(params.value("scriptError").toByteArray()));
|
||||||
emit addScriptReply(commandId,
|
emit addScriptReply(commandId,
|
||||||
params.value("scriptError").toString(),
|
status,
|
||||||
params.value("script").toMap().value("id").toUuid(),
|
params.value("script").toMap().value("id").toUuid(),
|
||||||
params.value("errors").toStringList());
|
params.value("errors").toStringList());
|
||||||
|
|
||||||
@ -132,20 +138,26 @@ void ScriptManager::onScriptAdded(int commandId, const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void ScriptManager::onScriptEdited(int commandId, const QVariantMap ¶ms)
|
void ScriptManager::onScriptEdited(int commandId, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
QMetaEnum metaEnum = QMetaEnum::fromType<ScriptError>();
|
||||||
|
ScriptError status = static_cast<ScriptError>(metaEnum.keyToValue(params.value("scriptError").toByteArray()));
|
||||||
emit editScriptReply(commandId,
|
emit editScriptReply(commandId,
|
||||||
params.value("scriptError").toString(),
|
status,
|
||||||
params.value("errors").toStringList());
|
params.value("errors").toStringList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptManager::onScriptRenamed(int commandId, const QVariantMap ¶ms)
|
void ScriptManager::onScriptRenamed(int commandId, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
emit renameScriptReply(commandId, params.value("scriptError").toString());
|
QMetaEnum metaEnum = QMetaEnum::fromType<ScriptError>();
|
||||||
|
ScriptError status = static_cast<ScriptError>(metaEnum.keyToValue(params.value("scriptError").toByteArray()));
|
||||||
|
emit renameScriptReply(commandId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptManager::onScriptRemoved(int commandId, const QVariantMap ¶ms)
|
void ScriptManager::onScriptRemoved(int commandId, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
emit removeScriptReply(commandId, params.value("scriptError").toString());
|
QMetaEnum metaEnum = QMetaEnum::fromType<ScriptError>();
|
||||||
|
ScriptError status = static_cast<ScriptError>(metaEnum.keyToValue(params.value("scriptError").toByteArray()));
|
||||||
|
emit removeScriptReply(commandId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptManager::onNotificationReceived(const QVariantMap ¶ms)
|
void ScriptManager::onNotificationReceived(const QVariantMap ¶ms)
|
||||||
|
|||||||
@ -44,6 +44,14 @@ class ScriptManager : public QObject
|
|||||||
Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged)
|
Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum ScriptError {
|
||||||
|
ScriptErrorNoError,
|
||||||
|
ScriptErrorScriptNotFound,
|
||||||
|
ScriptErrorInvalidScript,
|
||||||
|
ScriptErrorHardwareFailure
|
||||||
|
};
|
||||||
|
Q_ENUM(ScriptError)
|
||||||
|
|
||||||
explicit ScriptManager(JsonRpcClient* jsonClient, QObject *parent = nullptr);
|
explicit ScriptManager(JsonRpcClient* jsonClient, QObject *parent = nullptr);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
@ -59,11 +67,11 @@ public slots:
|
|||||||
int fetchScript(const QUuid &id);
|
int fetchScript(const QUuid &id);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void addScriptReply(int id, const QString &scriptError, const QUuid &scriptId, const QStringList &errors);
|
void addScriptReply(int id, ScriptError status, const QUuid &scriptId, const QStringList &errors);
|
||||||
void editScriptReply(int id, const QString &scriptError, const QStringList &errors);
|
void editScriptReply(int id, ScriptError status, const QStringList &errors);
|
||||||
void renameScriptReply(int id, const QString &scriptError);
|
void renameScriptReply(int id, ScriptError status);
|
||||||
void removeScriptReply(int id, const QString &scriptError);
|
void removeScriptReply(int id, ScriptError status);
|
||||||
void fetchScriptReply(int id, const QString &scriptError, const QString &content);
|
void fetchScriptReply(int id, ScriptError status, const QString &content);
|
||||||
|
|
||||||
void scriptMessage(const QUuid &scriptId, const QString &type, const QString &message);
|
void scriptMessage(const QUuid &scriptId, const QString &type, const QString &message);
|
||||||
void fetchingDataChanged();
|
void fetchingDataChanged();
|
||||||
|
|||||||
@ -149,18 +149,24 @@ Page {
|
|||||||
Connections {
|
Connections {
|
||||||
target: engine.scriptManager
|
target: engine.scriptManager
|
||||||
onAddScriptReply: {
|
onAddScriptReply: {
|
||||||
deployReply(id, scriptError, errors)
|
print("Add reply", status)
|
||||||
d.scriptId = scriptId;
|
deployReply(id, status, errors)
|
||||||
|
if (status == ScriptManager.ScriptErrorNoError) {
|
||||||
|
d.scriptId = scriptId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onEditScriptReply: deployReply(id, scriptError, errors)
|
onEditScriptReply: {
|
||||||
function deployReply(id, scriptError, errors) {
|
print("Edit reply", status)
|
||||||
|
deployReply(id, status, errors)
|
||||||
|
}
|
||||||
|
function deployReply(id, status, errors) {
|
||||||
if (id === d.callId) {
|
if (id === d.callId) {
|
||||||
d.callId = -1;
|
d.callId = -1;
|
||||||
if (scriptError === "ScriptErrorNoError") {
|
if (status === ScriptManager.ScriptErrorNoError) {
|
||||||
d.oldContent = scriptEdit.text;
|
d.oldContent = scriptEdit.text;
|
||||||
infoPane.hide();
|
infoPane.hide();
|
||||||
errorPane.hide();
|
errorPane.hide();
|
||||||
} else if (scriptError === "ScriptErrorInvalidScript") {
|
} else if (status === ScriptManager.ScriptErrorInvalidScript) {
|
||||||
errorPane.show();
|
errorPane.show();
|
||||||
}
|
}
|
||||||
errorModel.update(errors)
|
errorModel.update(errors)
|
||||||
@ -168,7 +174,7 @@ Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onFetchScriptReply: {
|
onFetchScriptReply: {
|
||||||
if (id == d.callId && scriptError == "ScriptErrorNoError") {
|
if (id == d.callId && status == ScriptManager.ScriptErrorNoError) {
|
||||||
d.callId = -1;
|
d.callId = -1;
|
||||||
d.oldContent = content;
|
d.oldContent = content;
|
||||||
|
|
||||||
@ -433,9 +439,35 @@ Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delegate: Label {
|
delegate: Label {
|
||||||
|
id: errorDelegate
|
||||||
width: parent.width
|
width: parent.width
|
||||||
text: model.line + ":" + model.column + ": " + model.message
|
text: model.line + ":" + model.column + ": " + model.message
|
||||||
font: scriptEdit.font
|
font: scriptEdit.font
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
onClicked: {
|
||||||
|
if (mouse.button == Qt.LeftButton) {
|
||||||
|
scriptEdit.forceActiveFocus()
|
||||||
|
completion.moveCursor(CodeCompletion.MoveOperationAbsoluteLine, model.line)
|
||||||
|
} else {
|
||||||
|
print("rmb")
|
||||||
|
var popup = rmbMenuComponent.createObject(errorDelegate, {x: mouseX})
|
||||||
|
popup.copy.connect(function() {
|
||||||
|
PlatformHelper.toClipBoard(errorDelegate.text)
|
||||||
|
})
|
||||||
|
popup.copyAll.connect(function() {
|
||||||
|
var text = [];
|
||||||
|
for (var i = 0; i < errorModel.count; i++) {
|
||||||
|
var line = errorModel.get(i)
|
||||||
|
text.push(line.line + ":" + line.column + ": " + line.message)
|
||||||
|
}
|
||||||
|
PlatformHelper.toClipBoard(text.join("\n"))
|
||||||
|
})
|
||||||
|
popup.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -506,4 +538,21 @@ Page {
|
|||||||
BusyOverlay {
|
BusyOverlay {
|
||||||
shown: d.callId != -1
|
shown: d.callId != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: rmbMenuComponent
|
||||||
|
Menu {
|
||||||
|
signal copy()
|
||||||
|
signal copyAll()
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: qsTr("Copy")
|
||||||
|
onClicked: copy()
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: qsTr("Copy all")
|
||||||
|
onClicked: copyAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user