|
@ -2,12 +2,14 @@ import QtQuick 2.0 |
|
|
import QtQuick.Window 2.0 |
|
|
import QtQuick.Window 2.0 |
|
|
import QtQuick.Layouts 1.0 |
|
|
import QtQuick.Layouts 1.0 |
|
|
import QtQuick.Controls 1.0 |
|
|
import QtQuick.Controls 1.0 |
|
|
|
|
|
import QtQuick.Dialogs 1.1 |
|
|
|
|
|
|
|
|
Item { |
|
|
Item { |
|
|
id: codeEditorView |
|
|
id: codeEditorView |
|
|
property string currentDocumentId: "" |
|
|
property string currentDocumentId: "" |
|
|
signal documentEdit(string documentId) |
|
|
signal documentEdit(string documentId) |
|
|
signal breakpointsChanged(string documentId) |
|
|
signal breakpointsChanged(string documentId) |
|
|
|
|
|
signal isCleanChanged(var isClean, string documentId) |
|
|
|
|
|
|
|
|
function getDocumentText(documentId) { |
|
|
function getDocumentText(documentId) { |
|
|
for (var i = 0; i < editorListModel.count; i++) { |
|
|
for (var i = 0; i < editorListModel.count; i++) { |
|
@ -51,12 +53,17 @@ Item { |
|
|
breakpointsChanged(document.documentId); |
|
|
breakpointsChanged(document.documentId); |
|
|
}); |
|
|
}); |
|
|
editor.setText(data, document.syntaxMode); |
|
|
editor.setText(data, document.syntaxMode); |
|
|
|
|
|
editor.onIsCleanChanged.connect(function() { |
|
|
|
|
|
isCleanChanged(editor.isClean, document.documentId); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function getEditor(documentId) { |
|
|
function getEditor(documentId) { |
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
|
|
|
{ |
|
|
if (editorListModel.get(i).documentId === documentId) |
|
|
if (editorListModel.get(i).documentId === documentId) |
|
|
return editors.itemAt(i).item; |
|
|
return editors.itemAt(i).item; |
|
|
|
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -91,6 +98,12 @@ Item { |
|
|
editor.toggleBreakpoint(); |
|
|
editor.toggleBreakpoint(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function resetEditStatus(docId) { |
|
|
|
|
|
var editor = getEditor(docId); |
|
|
|
|
|
if (editor) |
|
|
|
|
|
editor.changeGeneration(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Component.onCompleted: projectModel.codeEditor = codeEditorView; |
|
|
Component.onCompleted: projectModel.codeEditor = codeEditorView; |
|
|
|
|
|
|
|
|
Connections { |
|
|
Connections { |
|
@ -98,17 +111,65 @@ Item { |
|
|
onDocumentOpened: { |
|
|
onDocumentOpened: { |
|
|
openDocument(document); |
|
|
openDocument(document); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onProjectSaving: { |
|
|
onProjectSaving: { |
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
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: { |
|
|
onProjectClosed: { |
|
|
for (var i = 0; i < editorListModel.count; i++) { |
|
|
for (var i = 0; i < editorListModel.count; i++) |
|
|
editors.itemAt(i).visible = false; |
|
|
editors.itemAt(i).visible = false; |
|
|
} |
|
|
|
|
|
editorListModel.clear(); |
|
|
editorListModel.clear(); |
|
|
currentDocumentId = ""; |
|
|
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 { |
|
|
Repeater { |
|
@ -121,10 +182,20 @@ Item { |
|
|
anchors.fill: parent |
|
|
anchors.fill: parent |
|
|
source: "CodeEditor.qml" |
|
|
source: "CodeEditor.qml" |
|
|
visible: (index >= 0 && index < editorListModel.count && currentDocumentId === editorListModel.get(index).documentId) |
|
|
visible: (index >= 0 && index < editorListModel.count && currentDocumentId === editorListModel.get(index).documentId) |
|
|
|
|
|
property bool changed: false |
|
|
onVisibleChanged: { |
|
|
onVisibleChanged: { |
|
|
loadIfNotLoaded() |
|
|
loadIfNotLoaded() |
|
|
if (visible && item) |
|
|
if (visible && item) |
|
|
|
|
|
{ |
|
|
loader.item.setFocus(); |
|
|
loader.item.setFocus(); |
|
|
|
|
|
if (changed) |
|
|
|
|
|
{ |
|
|
|
|
|
changed = false; |
|
|
|
|
|
messageDialog.item = loader.item; |
|
|
|
|
|
messageDialog.doc = editorListModel.get(index); |
|
|
|
|
|
messageDialog.open(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
Component.onCompleted: { |
|
|
Component.onCompleted: { |
|
|
loadIfNotLoaded() |
|
|
loadIfNotLoaded() |
|
@ -133,8 +204,39 @@ Item { |
|
|
doLoadDocument(loader.item, editorListModel.get(index)) |
|
|
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 () { |
|
|
function loadIfNotLoaded () { |
|
|
if(visible && !active) { |
|
|
if (visible && !active) { |
|
|
active = true; |
|
|
active = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|