|
|
@ -2,12 +2,14 @@ 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: codeEditorView |
|
|
|
property string currentDocumentId: "" |
|
|
|
signal documentEdit(string documentId) |
|
|
|
signal breakpointsChanged(string documentId) |
|
|
|
signal isCleanChanged(var isClean, string documentId) |
|
|
|
|
|
|
|
function getDocumentText(documentId) { |
|
|
|
for (var i = 0; i < editorListModel.count; i++) { |
|
|
@ -51,12 +53,17 @@ Item { |
|
|
|
breakpointsChanged(document.documentId); |
|
|
|
}); |
|
|
|
editor.setText(data, document.syntaxMode); |
|
|
|
editor.onIsCleanChanged.connect(function() { |
|
|
|
isCleanChanged(editor.isClean, document.documentId); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function getEditor(documentId) { |
|
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
{ |
|
|
|
if (editorListModel.get(i).documentId === documentId) |
|
|
|
return editors.itemAt(i).item; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
@ -91,6 +98,12 @@ Item { |
|
|
|
editor.toggleBreakpoint(); |
|
|
|
} |
|
|
|
|
|
|
|
function resetEditStatus(docId) { |
|
|
|
var editor = getEditor(docId); |
|
|
|
if (editor) |
|
|
|
editor.changeGeneration(); |
|
|
|
} |
|
|
|
|
|
|
|
Component.onCompleted: projectModel.codeEditor = codeEditorView; |
|
|
|
|
|
|
|
Connections { |
|
|
@ -98,17 +111,65 @@ Item { |
|
|
|
onDocumentOpened: { |
|
|
|
openDocument(document); |
|
|
|
} |
|
|
|
|
|
|
|
onProjectSaving: { |
|
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
fileIo.writeFile(editorListModel.get(i).path, editors.itemAt(i).item.getText()); |
|
|
|
{ |
|
|
|
var doc = editorListModel.get(i); |
|
|
|
fileIo.writeFile(doc.path, editors.itemAt(i).item.getText()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onProjectSaved: { |
|
|
|
if (projectModel.appIsClosing) |
|
|
|
return; |
|
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
{ |
|
|
|
var doc = editorListModel.get(i); |
|
|
|
resetEditStatus(doc.documentId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onProjectClosed: { |
|
|
|
for (var i = 0; i < editorListModel.count; i++) { |
|
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
editors.itemAt(i).visible = false; |
|
|
|
} |
|
|
|
editorListModel.clear(); |
|
|
|
currentDocumentId = ""; |
|
|
|
} |
|
|
|
|
|
|
|
onDocumentSaved: { |
|
|
|
resetEditStatus(documentId); |
|
|
|
} |
|
|
|
|
|
|
|
onContractSaved: { |
|
|
|
resetEditStatus(documentId); |
|
|
|
} |
|
|
|
|
|
|
|
onDocumentSaving: { |
|
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
{ |
|
|
|
var doc = editorListModel.get(i); |
|
|
|
if (doc.path === document.path) |
|
|
|
{ |
|
|
|
fileIo.writeFile(document.path, editors.itemAt(i).item.getText()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
MessageDialog |
|
|
|
{ |
|
|
|
id: messageDialog |
|
|
|
title: qsTr("File Changed") |
|
|
|
text: qsTr("This file has been changed outside of the editor. Do you want to reload it?") |
|
|
|
standardButtons: StandardButton.Yes | StandardButton.No |
|
|
|
property variant item |
|
|
|
property variant doc |
|
|
|
onYes: { |
|
|
|
doLoadDocument(item, doc); |
|
|
|
resetEditStatus(doc.documentId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Repeater { |
|
|
@ -121,10 +182,20 @@ Item { |
|
|
|
anchors.fill: parent |
|
|
|
source: "CodeEditor.qml" |
|
|
|
visible: (index >= 0 && index < editorListModel.count && currentDocumentId === editorListModel.get(index).documentId) |
|
|
|
property bool changed: false |
|
|
|
onVisibleChanged: { |
|
|
|
loadIfNotLoaded() |
|
|
|
if (visible && item) |
|
|
|
{ |
|
|
|
loader.item.setFocus(); |
|
|
|
if (changed) |
|
|
|
{ |
|
|
|
changed = false; |
|
|
|
messageDialog.item = loader.item; |
|
|
|
messageDialog.doc = editorListModel.get(index); |
|
|
|
messageDialog.open(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Component.onCompleted: { |
|
|
|
loadIfNotLoaded() |
|
|
@ -133,6 +204,37 @@ Item { |
|
|
|
doLoadDocument(loader.item, editorListModel.get(index)) |
|
|
|
} |
|
|
|
|
|
|
|
Connections |
|
|
|
{ |
|
|
|
target: projectModel |
|
|
|
onDocumentChanged: { |
|
|
|
if (!item) |
|
|
|
return; |
|
|
|
var current = editorListModel.get(index); |
|
|
|
if (documentId === current.documentId) |
|
|
|
{ |
|
|
|
if (currentDocumentId === current.documentId) |
|
|
|
{ |
|
|
|
messageDialog.item = loader.item; |
|
|
|
messageDialog.doc = editorListModel.get(index); |
|
|
|
messageDialog.open(); |
|
|
|
} |
|
|
|
else |
|
|
|
changed = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onDocumentUpdated: { |
|
|
|
var document = projectModel.getDocument(documentId); |
|
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
if (editorListModel.get(i).documentId === documentId) |
|
|
|
{ |
|
|
|
editorListModel.set(i, document); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function loadIfNotLoaded () { |
|
|
|
if (visible && !active) { |
|
|
|
active = true; |
|
|
|