2019-09-06 05:05:57 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Window 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "Base"
|
|
|
|
|
|
|
|
Window {
|
2019-09-06 06:28:06 +10:00
|
|
|
id: debugConsole
|
2019-09-06 05:05:57 +10:00
|
|
|
title: qsTr("Debug console")
|
|
|
|
width: 640
|
|
|
|
height: 480
|
|
|
|
visible: false
|
|
|
|
flags: Qt.WA_TranslucentBackground
|
|
|
|
color: "transparent"
|
|
|
|
|
|
|
|
|
2019-09-06 06:09:04 +10:00
|
|
|
property var target: null
|
|
|
|
property alias t: debugConsole.target
|
|
|
|
|
2019-09-20 08:26:52 +10:00
|
|
|
property var history: []
|
|
|
|
property alias his: debugConsole.history
|
|
|
|
property int historyEntry: -1
|
|
|
|
|
2019-09-06 06:09:04 +10:00
|
|
|
|
2019-09-20 06:47:35 +10:00
|
|
|
Component.onCompleted: {
|
|
|
|
mainUI.shortcuts.debugConsole = debugConsole
|
2019-09-06 06:09:04 +10:00
|
|
|
commandsView.model.insert(0, {
|
2019-11-04 04:47:33 +11:00
|
|
|
input: "t = " + String(target),
|
2019-09-06 06:09:04 +10:00
|
|
|
output: "",
|
|
|
|
error: false,
|
|
|
|
})
|
|
|
|
visible = true
|
|
|
|
}
|
|
|
|
|
2019-09-20 08:26:52 +10:00
|
|
|
onHistoryEntryChanged:
|
|
|
|
inputField.text =
|
|
|
|
historyEntry === -1 ? "" : history.slice(-historyEntry - 1)[0]
|
|
|
|
|
2019-09-06 06:09:04 +10:00
|
|
|
|
2019-09-06 05:05:57 +10:00
|
|
|
function runJS(input) {
|
2019-09-20 08:26:52 +10:00
|
|
|
if (history.slice(-1)[0] !== input) history.push(input)
|
|
|
|
|
2019-09-06 05:05:57 +10:00
|
|
|
let error = false
|
|
|
|
|
|
|
|
try {
|
2019-09-20 08:26:52 +10:00
|
|
|
if (input.startsWith("j ")) {
|
|
|
|
var output = JSON.stringify(eval(input.substring(2)), null, 4)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
let result = eval(input)
|
|
|
|
var output = result instanceof Array ?
|
|
|
|
"[" + String(result) + "]" : String(result)
|
|
|
|
}
|
|
|
|
|
2019-09-06 05:05:57 +10:00
|
|
|
} catch (err) {
|
|
|
|
error = true
|
|
|
|
var output = err.toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
commandsView.model.insert(0, { input, output, error })
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
2019-09-06 06:28:06 +10:00
|
|
|
Keys.onEscapePressed: debugConsole.visible = false
|
|
|
|
|
2019-09-06 05:05:57 +10:00
|
|
|
HListView {
|
|
|
|
id: commandsView
|
|
|
|
spacing: theme.spacing
|
|
|
|
topMargin: theme.spacing
|
|
|
|
bottomMargin: topMargin
|
|
|
|
leftMargin: theme.spacing
|
2019-09-06 06:09:04 +10:00
|
|
|
rightMargin: leftMargin
|
2019-09-06 05:05:57 +10:00
|
|
|
clip: true
|
|
|
|
verticalLayoutDirection: ListView.BottomToTop
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
model: ListModel {}
|
|
|
|
|
|
|
|
delegate: HColumnLayout {
|
2019-09-06 06:09:04 +10:00
|
|
|
width: commandsView.width -
|
|
|
|
commandsView.leftMargin - commandsView.rightMargin
|
2019-09-06 05:05:57 +10:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: "> " + model.input
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: theme.chat.message.quote
|
2019-09-06 06:09:04 +10:00
|
|
|
font.family: theme.fontFamily.mono
|
2019-09-06 06:24:49 +10:00
|
|
|
visible: Boolean(model.input)
|
2019-09-06 05:05:57 +10:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: "" + model.output
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: model.error ?
|
|
|
|
theme.colors.errorText : theme.colors.text
|
2019-09-06 06:09:04 +10:00
|
|
|
font.family: theme.fontFamily.mono
|
2019-09-06 06:24:49 +10:00
|
|
|
visible: Boolean(model.output)
|
2019-09-06 05:05:57 +10:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
z: -10
|
|
|
|
anchors.fill: parent
|
|
|
|
color: theme.colors.weakBackground
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HTextField {
|
2019-09-20 08:26:52 +10:00
|
|
|
id: inputField
|
2019-09-06 05:05:57 +10:00
|
|
|
focus: true
|
2019-09-20 08:43:25 +10:00
|
|
|
onAccepted: if (text) { runJS(text); text = ""; historyEntry = -1 }
|
2019-09-06 05:05:57 +10:00
|
|
|
backgroundColor: Qt.hsla(0, 0, 0, 0.85)
|
|
|
|
bordered: false
|
|
|
|
placeholderText: qsTr("Type some JavaScript...")
|
2019-09-06 06:09:04 +10:00
|
|
|
font.family: theme.fontFamily.mono
|
2019-09-06 05:05:57 +10:00
|
|
|
|
2019-09-20 08:26:52 +10:00
|
|
|
Keys.onUpPressed:
|
|
|
|
if (historyEntry + 1 < history.length ) historyEntry += 1
|
|
|
|
Keys.onDownPressed:
|
|
|
|
if (historyEntry - 1 >= -1) historyEntry -= 1
|
|
|
|
|
2019-09-06 05:05:57 +10:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|