You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.1 KiB

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.0
import QtQuick.Controls.Styles 1.1
import QtWebEngine 1.0
import QtWebEngine.experimental 1.0
10 years ago
import "js/ErrorLocationFormater.js" as ErrorLocationFormater
Item {
signal editorTextChanged
signal breakpointsChanged
property bool isClean: true
property string currentText: ""
property string currentMode: ""
property bool initialized: false
10 years ago
property var currentBreakpoints: [];
function setText(text, mode) {
currentText = text;
currentMode = mode;
10 years ago
if (initialized && editorBrowser) {
editorBrowser.runJavaScript("setTextBase64(\"" + Qt.btoa(text) + "\")");
editorBrowser.runJavaScript("setMode(\"" + mode + "\")");
}
setFocus();
}
function setFocus() {
10 years ago
if (editorBrowser)
editorBrowser.forceActiveFocus();
}
function getText() {
return currentText;
}
function syncClipboard() {
10 years ago
if (Qt.platform.os == "osx" && editorBrowser) {
var text = clipboard.text;
editorBrowser.runJavaScript("setClipboardBase64(\"" + Qt.btoa(text) + "\")");
}
}
function highlightExecution(location) {
10 years ago
if (initialized && editorBrowser)
editorBrowser.runJavaScript("highlightExecution(" + location.start + "," + location.end + ")");
}
function showWarning(content) {
10 years ago
if (initialized && editorBrowser)
editorBrowser.runJavaScript("showWarning('" + content + "')");
}
10 years ago
function getBreakpoints() {
return currentBreakpoints;
}
function toggleBreakpoint() {
10 years ago
if (initialized && editorBrowser)
editorBrowser.runJavaScript("toggleBreakpoint()");
10 years ago
}
function changeGeneration() {
10 years ago
if (initialized && editorBrowser)
editorBrowser.runJavaScript("changeGeneration()", function(result) {});
}
Connections {
target: clipboard
onClipboardChanged: syncClipboard()
}
anchors.top: parent.top
id: codeEditorView
anchors.fill: parent
WebEngineView {
id: editorBrowser
url: "qrc:///qml/html/codeeditor.html"
anchors.fill: parent
experimental.settings.javascriptCanAccessClipboard: true
onJavaScriptConsoleMessage: {
console.log("editor: " + sourceID + ":" + lineNumber + ":" + message);
}
10 years ago
Component.onDestruction:
{
codeModel.onCompilationComplete.disconnect(compilationComplete);
codeModel.onCompilationError.disconnect(compilationError);
}
onLoadingChanged:
{
10 years ago
if (!loading && editorBrowser) {
initialized = true;
setText(currentText, currentMode);
runJavaScript("getTextChanged()", function(result) { });
pollTimer.running = true;
syncClipboard();
10 years ago
if (currentMode === "solidity")
{
10 years ago
codeModel.onCompilationComplete.connect(compilationComplete);
codeModel.onCompilationError.connect(compilationError);
10 years ago
}
parent.changeGeneration();
}
}
10 years ago
function compilationComplete()
{
if (editorBrowser)
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
}
function compilationError(error)
{
if (!editorBrowser || !error)
return;
var errorInfo = ErrorLocationFormater.extractErrorInfo(error, false);
if (errorInfo.line && errorInfo.column)
editorBrowser.runJavaScript("compilationError('" + errorInfo.line + "', '" + errorInfo.column + "', '" + errorInfo.errorDetail + "')", function(result) { });
else
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
}
Timer
{
id: pollTimer
interval: 30
running: false
repeat: true
onTriggered: {
10 years ago
if (!editorBrowser)
return;
editorBrowser.runJavaScript("getTextChanged()", function(result) {
if (result === true) {
editorBrowser.runJavaScript("getText()" , function(textValue) {
currentText = textValue;
editorTextChanged();
});
}
});
10 years ago
editorBrowser.runJavaScript("getBreakpointsChanged()", function(result) {
if (result === true) {
editorBrowser.runJavaScript("getBreakpoints()" , function(bp) {
if (currentBreakpoints !== bp) {
currentBreakpoints = bp;
breakpointsChanged();
}
});
}
});
editorBrowser.runJavaScript("isClean()", function(result) {
isClean = result;
});
}
}
}
}