Browse Source

- Warn user to save on exit.

- Save all in file Menu.
cl-refactor
yann300 10 years ago
parent
commit
d03968cb6a
  1. 42
      mix/qml/CodeEditorView.qml
  2. 20
      mix/qml/ProjectModel.qml
  3. 6
      mix/qml/StatusPane.qml
  4. 4
      mix/qml/WebCodeEditor.qml
  5. 1
      mix/qml/html/codeeditor.js
  6. 3
      mix/qml/js/ProjectModel.js
  7. 16
      mix/qml/main.qml

42
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;
}
}

20
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 = "";
}
}

6
mix/qml/StatusPane.qml

@ -77,11 +77,15 @@ Rectangle {
function format(_message)
{
var formatted = _message.match(/(?:<dev::eth::)(.+)(?:>)/);
if (formatted === null)
formatted = _message.match(/(?:<dev::)(.+)(?:>)/);
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;

4
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();
}
}

1
mix/qml/html/codeeditor.js

@ -113,6 +113,7 @@ highlightExecution = function(start, end) {
var changeId;
changeGeneration = function()
{
console.log("");
changeId = editor.changeGeneration(true);
}

3
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();
}

16
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();

Loading…
Cancel
Save