diff --git a/mix/qml/CodeEditorView.qml b/mix/qml/CodeEditorView.qml index 390670c8b..431f6c046 100644 --- a/mix/qml/CodeEditorView.qml +++ b/mix/qml/CodeEditorView.qml @@ -53,15 +53,17 @@ Item { breakpointsChanged(document.documentId); }); editor.setText(data, document.syntaxMode); - editor.onIsCleanChanged.connect(function(){ + 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; } @@ -96,10 +98,10 @@ Item { editor.toggleBreakpoint(); } - function resetEditStatus() { - var editor = getEditor(currentDocumentId); + function resetEditStatus(docId) { + var editor = getEditor(docId); if (editor) - editor.changeGenerator(); + editor.changeGeneration(); } Component.onCompleted: projectModel.codeEditor = codeEditorView; @@ -109,18 +111,19 @@ Item { onDocumentOpened: { openDocument(document); } + onProjectSaving: { for (var i = 0; i < editorListModel.count; i++) { - fileIo.writeFile(editorListModel.get(i).path, editors.itemAt(i).item.getText()); - resetEditStatus(); + var doc = editorListModel.get(i); + fileIo.writeFile(doc.path, editors.itemAt(i).item.getText()); + 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 = ""; } @@ -128,10 +131,11 @@ Item { onDocumentSaving: { for (var i = 0; i < editorListModel.count; i++) { - if (editorListModel.get(i).path === document) + var doc = editorListModel.get(i); + if (doc.path === document) { fileIo.writeFile(document, editors.itemAt(i).item.getText()); - resetEditStatus(); + resetEditStatus(doc.documentId); break; } } @@ -165,13 +169,15 @@ Item { onVisibleChanged: { loadIfNotLoaded() if (visible && item) - loader.item.setFocus(); - if (visible && changed) { - changed = false; - messageDialog.item = loader.item; - messageDialog.doc = editorListModel.get(index); - messageDialog.open(); + loader.item.setFocus(); + if (changed) + { + changed = false; + messageDialog.item = loader.item; + messageDialog.doc = editorListModel.get(index); + messageDialog.open(); + } } } Component.onCompleted: { @@ -185,6 +191,8 @@ Item { { target: projectModel onDocumentChanged: { + if (!item) + return; if (currentDocumentId == documentId) { messageDialog.item = loader.item; @@ -197,7 +205,7 @@ Item { } function loadIfNotLoaded () { - if(visible && !active) { + if (visible && !active) { active = true; } } diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index 37c1365c6..73c5901fe 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -32,7 +32,6 @@ Item { property bool isEmpty: (projectPath === "") readonly property string projectFileName: ".mix" - property bool haveUnsavedChanges: false property string projectPath: "" property string projectTitle: "" property string currentDocumentId: "" @@ -41,6 +40,7 @@ Item { property var listModel: projectListModel property var stateListModel: projectStateListModel.model property CodeEditorView codeEditor: null + property var unsavedFiles: [] //interface function saveAll() { ProjectModelCode.saveAll(); } @@ -76,7 +76,15 @@ Item { Connections { target: codeEditor onIsCleanChanged: { + for (var i in unsavedFiles) + { + if (unsavedFiles[i] === documentId && isClean) + unsavedFiles.splice(i, 1); + } + if (!isClean) + unsavedFiles.push(documentId); isCleanChanged(isClean, documentId); + console.log(JSON.stringify(unsavedFiles)); } } @@ -105,14 +113,15 @@ Item { MessageDialog { id: saveMessageDialog title: qsTr("Project") - text: qsTr("Do you want to save changes?") - standardButtons: StandardButton.Ok | StandardButton.Cancel + text: qsTr("Some files require to be saved. Do you want to save changes?"); + standardButtons: StandardButton.Yes | StandardButton.No | StandardButton.Cancel icon: StandardIcon.Question - onAccepted: { + onYes: { projectModel.saveAll(); ProjectModelCode.doCloseProject(); } - onRejected: { + onRejected: {} + onNo: { ProjectModelCode.doCloseProject(); } } @@ -158,6 +167,7 @@ Item { target: projectModel onProjectClosed: { projectSettings.lastProjectPath = ""; + projectPath = ""; } } diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index 20b30ce3b..6d4b5e7e1 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -77,11 +77,15 @@ Rectangle { function format(_message) { var formatted = _message.match(/(?:)/); + if (formatted === null) + formatted = _message.match(/(?:)/); if (formatted.length > 1) - formatted = formatted[1] + ": "; + formatted = formatted[1]; else return _message; var exceptionInfos = _message.match(/(?:tag_)(.+)/g); + if (exceptionInfos !== null && exceptionInfos.length > 0) + formatted += ": " for (var k in exceptionInfos) formatted += " " + exceptionInfos[k].replace("*]", "").replace("tag_", "").replace("=", ""); return formatted; diff --git a/mix/qml/WebCodeEditor.qml b/mix/qml/WebCodeEditor.qml index f6081d9cf..97cbcd30c 100644 --- a/mix/qml/WebCodeEditor.qml +++ b/mix/qml/WebCodeEditor.qml @@ -51,7 +51,7 @@ Item { editorBrowser.runJavaScript("toggleBreakpoint()"); } - function changeGenerator() { + function changeGeneration() { editorBrowser.runJavaScript("changeGeneration()", function(result) {}); } @@ -80,7 +80,7 @@ Item { runJavaScript("getTextChanged()", function(result) { }); pollTimer.running = true; syncClipboard(); - parent.changeGenerator(); + parent.changeGeneration(); } } diff --git a/mix/qml/html/codeeditor.js b/mix/qml/html/codeeditor.js index 30c70867b..ff16ae34b 100644 --- a/mix/qml/html/codeeditor.js +++ b/mix/qml/html/codeeditor.js @@ -113,6 +113,7 @@ highlightExecution = function(start, end) { var changeId; changeGeneration = function() { + console.log(""); changeId = editor.changeGeneration(true); } diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js index e2bb4b0c3..75b6a6f75 100644 --- a/mix/qml/js/ProjectModel.js +++ b/mix/qml/js/ProjectModel.js @@ -44,7 +44,7 @@ function createProject() { function closeProject() { if (!isEmpty) { - if (haveUnsavedChanges) + if (unsavedFiles.length > 0) saveMessageDialog.open(); else doCloseProject(); @@ -193,7 +193,6 @@ function doCloseProject() { projectListModel.clear(); projectPath = ""; currentDocumentId = ""; - fileIo.stopFilesWatcher(); projectClosed(); } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index e4db8c437..db173bf85 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -24,6 +24,7 @@ ApplicationWindow { MenuItem { action: openProjectAction } MenuSeparator {} MenuItem { action: saveAllFilesAction } + MenuItem { action: saveCurrentDocument } MenuSeparator {} MenuItem { action: addExistingFileAction } MenuItem { action: addNewJsFileAction } @@ -92,7 +93,12 @@ ApplicationWindow { id: exitAppAction text: qsTr("Exit") shortcut: "Ctrl+Q" - onTriggered: Qt.quit(); + onTriggered: + { + if (projectModel.projectPath !== "") + projectModel.closeProject() + Qt.quit(); + } } Action { @@ -279,6 +285,14 @@ ApplicationWindow { Action { id: saveAllFilesAction text: qsTr("Save All") + shortcut: "Ctrl+A" + enabled: !projectModel.isEmpty + onTriggered: projectModel.saveAll(); + } + + Action { + id: saveCurrentDocument + text: qsTr("Save Current Document") shortcut: "Ctrl+S" enabled: !projectModel.isEmpty onTriggered: projectModel.saveCurrentDocument();