保存文件时,未修改的不需要再次保存

This commit is contained in:
Van 2014-10-31 17:01:23 +08:00
parent 2c20093661
commit 7cb70347bf
2 changed files with 16 additions and 4 deletions

View File

@ -28,13 +28,16 @@ var editors = {
return false; return false;
} }
// 移除编辑器
for (var i = 0, ii = editors.data.length; i < ii; i++) { for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) { if (editors.data[i].id === id) {
wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor); wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
editors.data.splice(i, 1); editors.data.splice(i, 1);
break; break;
} }
} }
if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断 if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断
menu.disabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install']); menu.disabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install']);
$(".toolbars").hide(); $(".toolbars").hide();
@ -51,6 +54,7 @@ var editors = {
} }
if (nextId === editors.tabs.getCurrentId()) { if (nextId === editors.tabs.getCurrentId()) {
// 关闭的不是当前编辑器
return false; return false;
} }
@ -219,6 +223,7 @@ var editors = {
} }
} }
// 清除未保存状态
editor.doc.markClean(); editor.doc.markClean();
$(".edit-panel .tabs > div.current > span").removeClass("changed"); $(".edit-panel .tabs > div.current > span").removeClass("changed");
} }

View File

@ -470,9 +470,6 @@ var wide = {
if ($(".menu li.save-all").hasClass("disabled")) { if ($(".menu li.save-all").hasClass("disabled")) {
return false; return false;
} }
// TODO: 只保存未保存过的文件
for (var i = 0, ii = editors.data.length; i < ii; i++) { for (var i = 0, ii = editors.data.length; i < ii; i++) {
this.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor); this.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
} }
@ -695,6 +692,10 @@ var wide = {
}); });
}, },
fmt: function (path, curEditor) { fmt: function (path, curEditor) {
if (curEditor.doc.isClean()) { // 没有修改过,不需要保存
return false;
}
var mode = curEditor.getOption("mode"); var mode = curEditor.getOption("mode");
var cursor = curEditor.getCursor(); var cursor = curEditor.getCursor();
@ -749,8 +750,14 @@ var wide = {
wide._save(); wide._save();
} }
// 清除未保存状态
curEditor.doc.markClean(); curEditor.doc.markClean();
$(".edit-panel .tabs > div.current > span").removeClass("changed"); $(".edit-panel .tabs > div").each(function () {
var $span = $(this).find("span:eq(0)");
if ($span.attr("title") === path) {
$span.removeClass("changed");
}
});
}, },
openAbout: function () { openAbout: function () {
$("#dialogAbout").dialog("open"); $("#dialogAbout").dialog("open");