关闭所有

This commit is contained in:
Van 2014-11-01 21:28:18 +08:00
parent a6cecc0f5d
commit b496871322
4 changed files with 36 additions and 14 deletions

View File

@ -1,6 +1,14 @@
var editors = { var editors = {
data: [], data: [],
tabs: {}, tabs: {},
_removeAllMarker: function () {
var removeData = $("#dialogCloseEditor").data("removeData");
if (removeData && removeData.length > 0) {
removeData.splice(0, 1);
$("#dialogCloseEditor").data("removeData", removeData);
$(".edit-panel .tabs .ico-close:eq(0)").click();
}
},
init: function () { init: function () {
$("#dialogCloseEditor").dialog({ $("#dialogCloseEditor").dialog({
"modal": true, "modal": true,
@ -9,7 +17,7 @@ var editors = {
"title": config.label.tip, "title": config.label.tip,
"hideFooter": true, "hideFooter": true,
"afterOpen": function (fileName) { "afterOpen": function (fileName) {
$("#dialogCloseEditor > div:eq(0)").html(config.label.file $("#dialogCloseEditor > div:eq(0)").html(config.label.file
+ ' <b>' + fileName + '</b>. ' + config.label.confirm_save + '?'); + ' <b>' + fileName + '</b>. ' + config.label.confirm_save + '?');
$("#dialogCloseEditor button:eq(0)").focus(); $("#dialogCloseEditor button:eq(0)").focus();
}, },
@ -19,16 +27,22 @@ var editors = {
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.tabs.del(editors.data[i].id); editors.tabs.del(editors.data[i].id);
$("#dialogCloseEditor").dialog("close"); $("#dialogCloseEditor").dialog("close");
editors._removeAllMarker();
}); });
$("#dialogCloseEditor button.discard").click(function () { $("#dialogCloseEditor button.discard").click(function () {
$("#dialogCloseEditor").dialog("close"); $("#dialogCloseEditor").dialog("close");
editors._removeAllMarker();
}); });
$("#dialogCloseEditor button.cancel").click(function () { $("#dialogCloseEditor button.cancel").click(function () {
var i = $("#dialogCloseEditor").data("index"); var i = $("#dialogCloseEditor").data("index");
editors.tabs.del(editors.data[i].id); editors.tabs.del(editors.data[i].id);
$("#dialogCloseEditor").dialog("close"); $("#dialogCloseEditor").dialog("close");
editors._removeAllMarker();
}); });
} }
}); });
@ -56,7 +70,7 @@ var editors = {
}, },
removeBefore: function (id) { removeBefore: function (id) {
if (id === 'startPage') { // 当前关闭的 tab 是起始页 if (id === 'startPage') { // 当前关闭的 tab 是起始页
return false; return true;
} }
// 移除编辑器 // 移除编辑器
@ -76,6 +90,13 @@ var editors = {
} }
}, },
removeAfter: function (id, nextId) { removeAfter: function (id, nextId) {
editors._removeAllMarker();
if ($(".edit-panel .tabs > div").length === 0) {
// 全部 tab 都关闭时才 disables 菜单中“全部关闭”的按钮
menu.disabled(['close-all']);
}
if (id === 'startPage') { // 当前关闭的 tab 是起始页 if (id === 'startPage') { // 当前关闭的 tab 是起始页
return false; return false;
} }
@ -89,7 +110,7 @@ var editors = {
} }
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', 'build', 'run', 'go-test', 'go-get', 'go-install']);
$(".toolbars").hide(); $(".toolbars").hide();
} }
@ -98,7 +119,6 @@ var editors = {
// remove selected tree node // remove selected tree node
tree.fileTree.cancelSelectedNode(); tree.fileTree.cancelSelectedNode();
wide.curNode = undefined; wide.curNode = undefined;
wide.curEditor = undefined; wide.curEditor = undefined;
return false; return false;
} }

View File

@ -478,15 +478,17 @@ var wide = {
if ($(".menu li.close-all").hasClass("disabled")) { if ($(".menu li.close-all").hasClass("disabled")) {
return false; return false;
} }
this.saveAllFiles();
editors.data = [];
tree.fileTree.cancelSelectedNode();
wide.curNode = undefined;
wide.curEditor = undefined;
$(".toolbars").hide();
$(".edit-panel .tabs, .edit-panel .tabs-panel").html(''); // 设置全部关闭标识
menu.disabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']); var removeData = [];
$(".edit-panel .tabs > div").each(function (i) {
if (i !== 0) {
removeData.push($(this).data("index"));
}
});
$("#dialogCloseEditor").data("removeData", removeData);
// 开始关闭
$(".edit-panel .tabs .ico-close:eq(0)").click();
}, },
exit: function () { exit: function () {
var request = newWideRequest(); var request = newWideRequest();

View File

@ -8,5 +8,5 @@ button {
} }
.edit-exprinfo, .CodeMirror, .CodeMirror-hints { .edit-exprinfo, .CodeMirror, .CodeMirror-hints {
font-size: 9; font-size: ;
} }

View File

@ -33,7 +33,7 @@
<li class="save-all disabled" onclick="wide.saveAllFiles()"> <li class="save-all disabled" onclick="wide.saveAllFiles()">
<span>{{.i18n.save_all_files}}</span> <span>{{.i18n.save_all_files}}</span>
</li> </li>
<li class="close-all disabled" onclick="wide.closeAllFiles()"> <li class="close-all" onclick="wide.closeAllFiles()">
<span>{{.i18n.close_all_files}}</span> <span>{{.i18n.close_all_files}}</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>