diff --git a/src/filemanager.html b/src/filemanager.html index d76f9ee87..4b7ca087b 100644 --- a/src/filemanager.html +++ b/src/filemanager.html @@ -196,6 +196,25 @@ + + +
@@ -262,9 +281,9 @@
-
{{ textEditor.entry.fileName }}
- + +
diff --git a/src/js/filemanager.js b/src/js/filemanager.js index 963010734..bc25f7c3b 100644 --- a/src/js/filemanager.js +++ b/src/js/filemanager.js @@ -436,10 +436,12 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio busy: false, entry: null, editor: null, + unsaved: false, show: function (entry) { $scope.textEditor.entry = entry; $scope.textEditor.busy = false; + $scope.textEditor.unsaved = false; // clear model if any if ($scope.textEditor.editor && $scope.textEditor.editor.getModel()) $scope.textEditor.editor.setModel(null); @@ -460,14 +462,16 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio language: language, theme: 'vs-dark' }); + $scope.textEditor.editor.getModel().onDidChangeContent(function () { $scope.textEditor.unsaved = true; }); }, 200); } else { $scope.textEditor.editor.setModel(monaco.editor.createModel(result, 'javascript')); + $scope.textEditor.editor.getModel().onDidChangeContent(function () { $scope.textEditor.unsaved = true; }); // have to re-attach whenever model changes } }); }, - save: function () { + save: function (callback) { $scope.textEditor.busy = true; var newContent = $scope.textEditor.editor.getValue(); @@ -475,14 +479,31 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio var file = new File([newContent], 'file'); Client.filesUpload($scope.appId, filePath, file, function () {}, function (error) { - $scope.textEditor.busy = false; if (error) return Client.error(error); + + $timeout(function () { + $scope.textEditor.unsaved = false; + $scope.textEditor.busy = false; + if (callback) return callback(); + }, 1000); }); }, close: function () { $scope.view = 'fileTree'; - } + $('#textEditorCloseModal').modal('hide'); + }, + + saveAndClose: function () { + $scope.textEditor.save(function () { + $scope.textEditor.close(); + }); + }, + + maybeClose: function () { + if (!$scope.textEditor.unsaved) return $scope.textEditor.close(); + $('#textEditorCloseModal').modal('show'); + }, }; $scope.chownEntry = {