arkpar
10 years ago
15 changed files with 384 additions and 170 deletions
@ -0,0 +1,81 @@ |
|||
import QtQuick 2.0 |
|||
import QtQuick.Window 2.0 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls 1.0 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
|
|||
Component { |
|||
Item { |
|||
signal editorTextChanged |
|||
|
|||
function setText(text) { |
|||
codeEditor.text = text; |
|||
} |
|||
|
|||
function getText() { |
|||
return codeEditor.text; |
|||
} |
|||
|
|||
anchors.fill: parent |
|||
id: contentView |
|||
width: parent.width |
|||
height: parent.height * 0.7 |
|||
Rectangle { |
|||
id: lineColumn |
|||
property int rowHeight: codeEditor.font.pixelSize + 3 |
|||
color: "#202020" |
|||
width: 50 |
|||
height: parent.height |
|||
Column { |
|||
y: -codeEditor.flickableItem.contentY + 4 |
|||
width: parent.width |
|||
Repeater { |
|||
model: Math.max(codeEditor.lineCount + 2, (lineColumn.height/lineColumn.rowHeight)) |
|||
delegate: Text { |
|||
id: text |
|||
color: codeEditor.textColor |
|||
font: codeEditor.font |
|||
width: lineColumn.width - 4 |
|||
horizontalAlignment: Text.AlignRight |
|||
verticalAlignment: Text.AlignVCenter |
|||
height: lineColumn.rowHeight |
|||
renderType: Text.NativeRendering |
|||
text: index + 1 |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
TextArea { |
|||
id: codeEditor |
|||
textColor: "#EEE8D5" |
|||
style: TextAreaStyle { |
|||
backgroundColor: "#002B36" |
|||
} |
|||
|
|||
anchors.left: lineColumn.right |
|||
anchors.right: parent.right |
|||
anchors.top: parent.top |
|||
anchors.bottom: parent.bottom |
|||
wrapMode: TextEdit.NoWrap |
|||
frameVisible: false |
|||
|
|||
height: parent.height |
|||
font.family: "Monospace" |
|||
font.pointSize: 12 |
|||
width: parent.width |
|||
|
|||
tabChangesFocus: false |
|||
Keys.onPressed: { |
|||
if (event.key === Qt.Key_Tab) { |
|||
codeEditor.insert(codeEditor.cursorPosition, "\t"); |
|||
event.accepted = true; |
|||
} |
|||
} |
|||
onTextChanged: { |
|||
editorTextChanged(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
pragma Singleton |
|||
|
|||
import QtQuick 2.0 |
|||
import QtQuick.Window 2.0 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls 1.0 |
|||
import QtQuick.Dialogs 1.1 |
|||
|
|||
Item { |
|||
id: codeEditorModel |
|||
|
|||
property var codeDocuments: [] |
|||
} |
@ -0,0 +1,80 @@ |
|||
import QtQuick 2.0 |
|||
import QtQuick.Window 2.0 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls 1.0 |
|||
import org.ethereum.qml.ProjectModel 1.0 |
|||
|
|||
Item { |
|||
|
|||
property string currentDocumentId: "" |
|||
|
|||
function getDocumentText(documentId) { |
|||
for (i = 0; i < editorListModel.count; i++) { |
|||
if (editorListModel.get(i).documentId === documentId) { |
|||
return editors.itemAt(i).getDocumentText(); |
|||
} |
|||
} |
|||
return ""; |
|||
} |
|||
|
|||
function openDocument(document) { |
|||
loadDocument(document); |
|||
currentDocumentId = document.documentId; |
|||
} |
|||
|
|||
function loadDocument(document) { |
|||
for (var i = 0; i < editorListModel.count; i++) |
|||
if (editorListModel.get(i).documentId === document.documentId) |
|||
return; //already open |
|||
|
|||
editorListModel.append(document); |
|||
} |
|||
|
|||
function doLoadDocument(editor, document) { |
|||
var data = fileIo.readFile(document.path); |
|||
if (document.isContract) |
|||
editor.onEditorTextChanged.connect(function() { |
|||
codeModel.registerCodeChange(editor.getText()); |
|||
}); |
|||
editor.setText(data); |
|||
} |
|||
|
|||
Connections { |
|||
target: ProjectModel |
|||
onDocumentOpen: { |
|||
openDocument(document); |
|||
} |
|||
} |
|||
|
|||
CodeEditor { |
|||
id: codeEditor |
|||
} |
|||
|
|||
Repeater { |
|||
id: editors |
|||
model: editorListModel |
|||
delegate: Loader { |
|||
active: false; |
|||
asynchronous: true |
|||
anchors.fill: parent |
|||
sourceComponent: codeEditor |
|||
visible: (currentDocumentId === editorListModel.get(index).documentId) |
|||
onVisibleChanged: { |
|||
loadIfNotLoaded() |
|||
} |
|||
Component.onCompleted: { |
|||
loadIfNotLoaded() |
|||
} |
|||
onLoaded: { doLoadDocument(item, editorListModel.get(index)) } |
|||
|
|||
function loadIfNotLoaded () { |
|||
if(visible && !active) { |
|||
active = true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
ListModel { |
|||
id: editorListModel |
|||
} |
|||
} |
Loading…
Reference in new issue