菜单栏

This commit is contained in:
Van 2014-10-13 17:01:44 +08:00
parent 3e720d8179
commit 058f400dc5
5 changed files with 55 additions and 12 deletions

View File

@ -80,11 +80,20 @@
cursor: pointer; cursor: pointer;
} }
.frame li.disabled {
color: #999;
}
.frame li:hover { .frame li:hover {
background-color: #3875D7; background-color: #3875D7;
color: #FFF; color: #FFF;
} }
.frame li.disabled:hover {
background-color: #F8F8F8;
color: #999;
}
.frame a { .frame a {
color: #000; color: #000;
text-decoration: none; text-decoration: none;

View File

@ -23,8 +23,8 @@ var editors = {
removeAfter: function (id, nextId) { removeAfter: function (id, nextId) {
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) {
editors.data.splice(i, 1);
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);
break; break;
} }
} }
@ -36,6 +36,8 @@ var editors = {
wide.curNode = undefined; wide.curNode = undefined;
wide.curEditor = undefined; wide.curEditor = undefined;
menu.disabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
$(".toolbars").hide(); $(".toolbars").hide();
return false; return false;
} }
@ -359,6 +361,8 @@ var editors = {
+ wide.curNode.iconSkin + 'ico"></span>' + wide.curNode.name + '</span>', + wide.curNode.iconSkin + 'ico"></span>' + wide.curNode.name + '</span>',
content: '<textarea id="editor' + id + '"></textarea>' content: '<textarea id="editor' + id + '"></textarea>'
}); });
menu.undisabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
var rulers = []; var rulers = [];
rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"}); rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"});

View File

@ -1,21 +1,31 @@
var menu = { var menu = {
init: function() { init: function () {
this.subMenu(); this.subMenu();
// 点击子菜单后消失 // 点击子菜单后消失
$(".frame li").click(function() { $(".frame li").click(function () {
$(this).closest(".frame").hide(); $(this).closest(".frame").hide();
}); });
}, },
disabled: function (list) {
for (var i = 0, max = list.length; i < max; i++) {
$(".menu li." + list[i]).addClass("disabled");
}
},
undisabled: function (list) {
for (var i = 0, max = list.length; i < max; i++) {
$(".menu li." + list[i]).removeClass("disabled");
}
},
// 焦点不在菜单上时需点击展开子菜单,否则为鼠标移动展开 // 焦点不在菜单上时需点击展开子菜单,否则为鼠标移动展开
subMenu: function() { subMenu: function () {
$(".menu > ul > li > a, .menu > ul> li > span").click(function() { $(".menu > ul > li > a, .menu > ul> li > span").click(function () {
var $it = $(this); var $it = $(this);
$it.next().show(); $it.next().show();
$(".menu > ul > li > a, .menu > ul> li > span").unbind(); $(".menu > ul > li > a, .menu > ul> li > span").unbind();
$(".menu > ul > li > a, .menu > ul> li > span").mouseover(function() { $(".menu > ul > li > a, .menu > ul> li > span").mouseover(function () {
$(".frame").hide(); $(".frame").hide();
var $it = $(this); var $it = $(this);
$it.next().show(); $it.next().show();

View File

@ -402,6 +402,10 @@ var wide = {
}, },
saveAllFiles: function () { saveAllFiles: function () {
// TODO: 需要全部保存的接口 // TODO: 需要全部保存的接口
if ($(".menu li.save-all").hasClass("disabled")) {
return false;
}
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);
} }
@ -410,14 +414,18 @@ var wide = {
// TODO: close file // TODO: close file
}, },
closeAllFiles: function () { closeAllFiles: function () {
if ($(".menu li.close-all").hasClass("disabled")) {
return false;
}
this.saveAllFiles(); this.saveAllFiles();
editors.data = []; editors.data = [];
tree.fileTree.cancelSelectedNode(); tree.fileTree.cancelSelectedNode();
wide.curNode = undefined; wide.curNode = undefined;
wide.curEditor = undefined; wide.curEditor = undefined;
$(".toolbars").hide(); $(".toolbars").hide();
$(".edit-panel .tabs, .edit-panel .tabs-panel").html(''); $(".edit-panel .tabs, .edit-panel .tabs-panel").html('');
menu.disabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
}, },
exit: function () { exit: function () {
// TODO: exit // TODO: exit
@ -447,6 +455,10 @@ var wide = {
}, },
// 构建 & 运行. // 构建 & 运行.
run: function () { run: function () {
if ($(".menu li.run").hasClass("disabled")) {
return false;
}
if ($(".toolbars .ico-stop").length === 1) { if ($(".toolbars .ico-stop").length === 1) {
wide.stop(); wide.stop();
return false; return false;
@ -471,6 +483,10 @@ var wide = {
}); });
}, },
goget: function () { goget: function () {
if ($(".menu li.go-get").hasClass("disabled")) {
return false;
}
var request = newWideRequest(); var request = newWideRequest();
request.file = editors.getCurrentPath(); request.file = editors.getCurrentPath();
@ -487,6 +503,10 @@ var wide = {
}); });
}, },
goinstall: function () { goinstall: function () {
if ($(".menu li.go-install").hasClass("disabled")) {
return false;
}
var request = newWideRequest(); var request = newWideRequest();
request.file = editors.getCurrentPath(); request.file = editors.getCurrentPath();
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();

View File

@ -26,10 +26,10 @@
<span>{{.i18n.file}}</span> <span>{{.i18n.file}}</span>
<div class="frame"> <div class="frame">
<ul> <ul>
<li 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 onclick="wide.closeAllFiles()"> <li class="close-all disabled" 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>
@ -43,14 +43,14 @@
<span>{{.i18n.run}}</span> <span>{{.i18n.run}}</span>
<div class="frame"> <div class="frame">
<ul> <ul>
<li onclick="wide.run()"> <li class="run disabled" onclick="wide.run()">
<span>{{.i18n.build_n_run}}</span> <span>{{.i18n.build_n_run}}</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li onclick="wide.goget()"> <li class="go-get disabled" onclick="wide.goget()">
<span>{{.i18n.goget}}</span> <span>{{.i18n.goget}}</span>
</li> </li>
<li onclick="wide.goinstall()"> <li class="go-install disabled" onclick="wide.goinstall()">
<span>{{.i18n.goinstall}}</span> <span>{{.i18n.goinstall}}</span>
</li> </li>
</ul> </ul>