右键菜单修改。bug修改

This commit is contained in:
Van 2014-09-12 17:50:46 +08:00
parent 4cb56230b0
commit a5725f5c71
5 changed files with 95 additions and 21 deletions

View File

@ -130,7 +130,7 @@ var editors = {
var cur = wide.curEditor.getCursor(); var cur = wide.curEditor.getCursor();
var request = { var request = {
file: wide.curNode.path, file: $tabs.children(".current").data("index"),
code: wide.curEditor.getValue(), code: wide.curEditor.getValue(),
cursorLine: cur.line, cursorLine: cur.line,
cursorCh: cur.ch cursorCh: cur.ch

View File

@ -53,10 +53,10 @@ $.extend(Tabs.prototype, {
prevId = currentId; prevId = currentId;
} else { } else {
prevId = this.obj._prevId; prevId = this.obj._prevId;
this.setCurrent(prevId);
} }
this.obj.removeAfter(id, prevId); this.obj.removeAfter(id, prevId);
this.setCurrent(prevId);
}, },
getCurrentId: function() { getCurrentId: function() {
var $tabs = this.obj._$tabs; var $tabs = this.obj._$tabs;

View File

@ -1,14 +1,26 @@
var tree = { var tree = {
fileTree: undefined, fileTree: undefined,
_isParents: function(tId, parentTId) {
var node = tree.fileTree.getNodeByTId(tId);
if (!node || !node.parentTId) {
return false;
} else {
if (node.parentTId === parentTId) {
return true;
} else {
return tree._isParents(node.parentTId, parentTId);
}
}
},
newFile: function() { newFile: function() {
$("#dirRMenu ul").hide(); $("#dirRMenu").hide();
var name = prompt("Name", ""); var name = prompt("Name", "");
if (!name) { if (!name) {
return false; return false;
} }
var request = { var request = {
path: wide.curNode.path + '/' + name, path: wide.curNode.path + '\\' + name,
fileType: "f" fileType: "f"
}; };
$.ajax({ $.ajax({
@ -20,21 +32,62 @@ var tree = {
if (!data.succ) { if (!data.succ) {
return false; return false;
} }
var suffix = name.split(".")[1],
iconSkin = "ico-ztree-other ";
switch (suffix) {
case "html", "htm":
iconSkin = "ico-ztree-html ";
break;
case "go":
iconSkin = "ico-ztree-go ";
break;
case "css":
iconSkin = "ico-ztree-css ";
break;
case "txt":
iconSkin = "ico-ztree-text ";
break;
case "sql":
iconSkin = "ico-ztree-sql ";
break;
case "properties":
iconSkin = "ico-ztree-pro ";
break;
case "md":
iconSkin = "ico-ztree-md ";
break;
case "md":
iconSkin = "ico-ztree-md ";
break;
case "js", "json":
iconSkin = "ico-ztree-js ";
break;
case "xml":
iconSkin = "ico-ztree-xml ";
break;
case "jpg", "jpeg", "bmp", "gif", "png", "svg", "ico":
iconSkin = "ico-ztree-img ";
break;
}
tree.fileTree.addNodes(wide.curNode, [{ tree.fileTree.addNodes(wide.curNode, [{
"name": name "name": name,
"iconSkin": iconSkin,
"path": request.path
}]); }]);
} }
}); });
}, },
newDir: function() { newDir: function() {
$("#dirRMenu ul").hide(); $("#dirRMenu").hide();
var name = prompt("Name", ""); var name = prompt("Name", "");
if (!name) { if (!name) {
return false; return false;
} }
var request = { var request = {
path: wide.curNode.path + '/' + name, path: wide.curNode.path + '\\' + name,
fileType: "d" fileType: "d"
}; };
$.ajax({ $.ajax({
@ -47,14 +100,16 @@ var tree = {
return false; return false;
} }
tree.fileTree.addNodes(wide.curNode, [{ tree.fileTree.addNodes(wide.curNode, [{
"name": name "name": name,
"iconSkin": "ico-ztree-dir ",
"path": request.path
}]); }]);
} }
}); });
}, },
removeIt: function() { removeIt: function() {
$("#dirRMenu ul").hide(); $("#dirRMenu").hide();
$("#fileRMenu ul").hide(); $("#fileRMenu").hide();
if (!confirm("Remove it?")) { if (!confirm("Remove it?")) {
return; return;
@ -71,6 +126,25 @@ var tree = {
if (!data.succ) { if (!data.succ) {
return false; return false;
} }
if ("ico-ztree-dir " !== wide.curNode.iconSkin) {
// 是文件的话,查看 editor 中是否被打开,如打开则移除
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === wide.curNode.tId) {
$(".edit-header .tabs > div[data-index=" + wide.curNode.tId + "]").find(".ico-close").click();
break;
}
}
} else {
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (tree._isParents(editors.data[i].id, wide.curNode.tId)) {
$(".edit-header .tabs > div[data-index=" + editors.data[i].id + "]").find(".ico-close").click();
i--;
ii--;
}
}
}
tree.fileTree.removeNode(wide.curNode); tree.fileTree.removeNode(wide.curNode);
} }
}); });
@ -92,7 +166,7 @@ var tree = {
onRightClick: function(event, treeId, treeNode) { onRightClick: function(event, treeId, treeNode) {
if (treeNode) { if (treeNode) {
wide.curNode = treeNode; wide.curNode = treeNode;
if ("f" === treeNode.type) { // 如果右击了文件 if ("ico-ztree-dir " !== treeNode.iconSkin) { // 如果右击了文件
$("#fileRMenu ul").show(); $("#fileRMenu ul").show();
fileRMenu.css({ fileRMenu.css({
"top": event.clientY - 10 + "px", "top": event.clientY - 10 + "px",
@ -141,7 +215,7 @@ var tree = {
wide.curNode = treeNode; wide.curNode = treeNode;
if ("f" === treeNode.type) { // 如果单击了文件 if ("ico-ztree-dir " !== treeNode.iconSkin) { // 如果单击了文件
var request = { var request = {
path: treeNode.path path: treeNode.path
}; };

View File

@ -91,7 +91,7 @@ var wide = {
}, },
saveFile: function() { saveFile: function() {
var request = { var request = {
file: wide.curNode.path, file: $(".edit-header .current span:eq(0)").attr("title"),
code: wide.curEditor.getValue() code: wide.curEditor.getValue()
}; };
$.ajax({ $.ajax({
@ -117,7 +117,7 @@ var wide = {
}, },
run: function() { run: function() {
var request = { var request = {
file: wide.curNode.path, file: $(".edit-header .current span:eq(0)").attr("title"),
code: wide.curEditor.getValue() code: wide.curEditor.getValue()
}; };
@ -135,7 +135,7 @@ var wide = {
}, },
goget: function() { goget: function() {
var request = { var request = {
file: wide.curNode.path file: $(".edit-header .current span:eq(0)").attr("title")
}; };
$.ajax({ $.ajax({
@ -152,7 +152,7 @@ var wide = {
}, },
goinstall: function() { goinstall: function() {
var request = { var request = {
file: wide.curNode.path, file: $(".edit-header .current span:eq(0)").attr("title"),
code: wide.curEditor.getValue() code: wide.curEditor.getValue()
}; };
@ -169,7 +169,7 @@ var wide = {
}); });
}, },
fmt: function() { fmt: function() {
var path = wide.curNode.path; var path = $(".edit-header .current span:eq(0)").attr("title");
var mode = wide.curNode.mode; var mode = wide.curNode.mode;
var request = { var request = {

View File

@ -94,7 +94,7 @@
<div class="toolbars fn-right"> <div class="toolbars fn-right">
<span onclick="wide.run()" class="font-ico icon-buildrun" title="{{.i18n.build_n_run}}"></span> <span onclick="wide.run()" class="font-ico icon-buildrun" title="{{.i18n.build_n_run}}"></span>
<span onclick="wide.save()" title="{{.i18n.save}}" class="font-ico ico-save"></span> <span onclick="wide.saveFile()" title="{{.i18n.save}}" class="font-ico ico-save"></span>
<span onclick="wide.fmt()" class="ico-format font-ico" title="{{.i18n.format}}"></span> <span onclick="wide.fmt()" class="ico-format font-ico" title="{{.i18n.format}}"></span>
<span class="fn-none font-ico ico-fullscreen" onclick="editors.fullscreen()" title="{{.i18n.full_screen}}"></span> <span class="fn-none font-ico ico-fullscreen" onclick="editors.fullscreen()" title="{{.i18n.full_screen}}"></span>
</div> </div>