Skip to content

Commit 288050e

Browse files
committed
Rev4537, Add warning on invalid file save in UiFileManager
1 parent 785d235 commit 288050e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

plugins/UiFileManager/media/js/FileEditor.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ class FileEditor extends Class
127127
return false
128128

129129
handleSaveClick: =>
130+
num_errors = (mark for mark in Page.file_editor.cm.getAllMarks() when mark.className == "CodeMirror-lint-mark-error").length
131+
if num_errors > 0
132+
Page.cmd "wrapperConfirm", ["<b>Warning:</b> The file looks invalid.", "Save anyway"], @save
133+
else
134+
@save()
135+
return false
136+
137+
save: =>
138+
Page.projector.scheduleRender()
130139
@is_saving = true
131140
Page.cmd "fileWrite", [@inner_path, Text.fileEncode(@cm.getValue())], (res) =>
132141
@is_saving = false
@@ -144,7 +153,6 @@ class FileEditor extends Class
144153
@mode = "Edit"
145154
Page.file_list.need_update = true
146155
Page.projector.scheduleRender()
147-
return false
148156

149157
render: ->
150158
if @need_update

plugins/UiFileManager/media/js/all.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@
19321932

19331933
function FileEditor(inner_path1) {
19341934
this.inner_path = inner_path1;
1935+
this.save = bind(this.save, this);
19351936
this.handleSaveClick = bind(this.handleSaveClick, this);
19361937
this.handleSidebarButtonClick = bind(this.handleSidebarButtonClick, this);
19371938
this.foldJson = bind(this.foldJson, this);
@@ -2095,8 +2096,31 @@
20952096
};
20962097

20972098
FileEditor.prototype.handleSaveClick = function() {
2099+
var mark, num_errors;
2100+
num_errors = ((function() {
2101+
var i, len, ref, results;
2102+
ref = Page.file_editor.cm.getAllMarks();
2103+
results = [];
2104+
for (i = 0, len = ref.length; i < len; i++) {
2105+
mark = ref[i];
2106+
if (mark.className === "CodeMirror-lint-mark-error") {
2107+
results.push(mark);
2108+
}
2109+
}
2110+
return results;
2111+
})()).length;
2112+
if (num_errors > 0) {
2113+
Page.cmd("wrapperConfirm", ["<b>Warning:</b> The file looks invalid.", "Save anyway"], this.save);
2114+
} else {
2115+
this.save();
2116+
}
2117+
return false;
2118+
};
2119+
2120+
FileEditor.prototype.save = function() {
2121+
Page.projector.scheduleRender();
20982122
this.is_saving = true;
2099-
Page.cmd("fileWrite", [this.inner_path, Text.fileEncode(this.cm.getValue())], (function(_this) {
2123+
return Page.cmd("fileWrite", [this.inner_path, Text.fileEncode(this.cm.getValue())], (function(_this) {
21002124
return function(res) {
21012125
_this.is_saving = false;
21022126
if (res.error) {
@@ -2117,7 +2141,6 @@
21172141
return Page.projector.scheduleRender();
21182142
};
21192143
})(this));
2120-
return false;
21212144
};
21222145

21232146
FileEditor.prototype.render = function() {

src/Config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Config(object):
1414

1515
def __init__(self, argv):
1616
self.version = "0.7.2"
17-
self.rev = 4536
17+
self.rev = 4537
1818
self.argv = argv
1919
self.action = None
2020
self.test_parser = None

0 commit comments

Comments
 (0)