Put save and close together
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user