Fix #138
This commit is contained in:
parent
861d79fc93
commit
8036401a3c
|
@ -21,7 +21,6 @@ import (
|
|||
// File node, used to construct the file tree.
|
||||
type FileNode struct {
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
Path string `json:"path"`
|
||||
IconSkin string `json:"iconSkin"` // Value should be end with a space
|
||||
Type string `json:"type"` // "f": file, "d": directory
|
||||
|
@ -60,7 +59,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
|||
workspacePath := workspace + conf.PathSeparator + "src"
|
||||
|
||||
workspaceNode := FileNode{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
|
||||
Title: workspace, Path: workspacePath, IconSkin: "ico-ztree-dir-workspace ", Type: "d",
|
||||
Path: workspacePath, IconSkin: "ico-ztree-dir-workspace ", Type: "d",
|
||||
Creatable: true, Removable: false, FileNodes: []*FileNode{}}
|
||||
|
||||
walk(workspacePath, &workspaceNode, true, true)
|
||||
|
@ -71,7 +70,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// construct Go API node
|
||||
apiPath := runtime.GOROOT() + conf.PathSeparator + "src" + conf.PathSeparator + "pkg"
|
||||
apiNode := FileNode{Name: "Go API", Title: apiPath, Path: apiPath, IconSkin: "ico-ztree-dir-api ", Type: "d",
|
||||
apiNode := FileNode{Name: "Go API", Path: apiPath, IconSkin: "ico-ztree-dir-api ", Type: "d",
|
||||
Creatable: false, Removable: false, FileNodes: []*FileNode{}}
|
||||
|
||||
goapiBuildOKSignal := make(chan bool)
|
||||
|
@ -262,7 +261,7 @@ func RenameFile(w http.ResponseWriter, r *http.Request) {
|
|||
data["succ"] = false
|
||||
|
||||
wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
|
||||
Data: "can't rename file " + path}
|
||||
Data: "can't rename file " + oldPath}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +297,7 @@ func walk(path string, node *FileNode, creatable, removable bool) {
|
|||
|
||||
fio, _ := os.Lstat(fpath)
|
||||
|
||||
child := FileNode{Name: filename, Title: fpath, Path: fpath, Removable: removable, FileNodes: []*FileNode{}}
|
||||
child := FileNode{Name: filename, Path: fpath, Removable: removable, FileNodes: []*FileNode{}}
|
||||
node.FileNodes = append(node.FileNodes, &child)
|
||||
|
||||
if nil == fio {
|
||||
|
@ -473,7 +472,7 @@ func removeFile(path string) bool {
|
|||
// renameFile renames (moves) a file from the specified old path to the specified new path.
|
||||
func renameFile(oldPath, newPath string) bool {
|
||||
if err := os.Rename(oldPath, newPath); nil != err {
|
||||
glog.Errorf("Renames [%s] failed: [%s]", path, err.Error())
|
||||
glog.Errorf("Renames [%s] failed: [%s]", oldPath, err.Error())
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"create": "Create",
|
||||
"create_dir": "Create Dir",
|
||||
"delete": "Delete",
|
||||
"rename": "Rename",
|
||||
"save": "Save",
|
||||
"exit": "Exit",
|
||||
"close_all_files": "Close All",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"create": "作成",
|
||||
"create_dir": "新規ディレクトリ",
|
||||
"delete": "削除",
|
||||
"rename": "名前の変更",
|
||||
"save": "保存",
|
||||
"exit": "終了",
|
||||
"close_all_files": "全てのファイルを閉じる",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"create": "创建",
|
||||
"create_dir": "创建目录",
|
||||
"delete": "删除",
|
||||
"rename": "重命名",
|
||||
"save": "保存",
|
||||
"exit": "退出",
|
||||
"close_all_files": "关闭所有文件",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"create": "建立",
|
||||
"create_dir": "建立目錄",
|
||||
"delete": "删除",
|
||||
"rename": "重命名",
|
||||
"save": "儲存",
|
||||
"exit": "退出",
|
||||
"close_all_files": "關閉所有文件",
|
||||
|
|
|
@ -111,6 +111,17 @@ var tree = {
|
|||
$("#fileRMenu").hide();
|
||||
$("#dialogRemoveConfirm").dialog("open");
|
||||
},
|
||||
rename: function (it) {
|
||||
if (it) {
|
||||
if ($(it).hasClass("disabled")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$("#dirRMenu").hide();
|
||||
$("#fileRMenu").hide();
|
||||
$("#dialogRenamePrompt").dialog("open");
|
||||
},
|
||||
init: function () {
|
||||
$("#file").click(function () {
|
||||
$(this).focus();
|
||||
|
@ -130,7 +141,7 @@ var tree = {
|
|||
var setting = {
|
||||
data: {
|
||||
key: {
|
||||
title: "title"
|
||||
title: "path"
|
||||
}
|
||||
},
|
||||
view: {
|
||||
|
@ -164,9 +175,9 @@ var tree = {
|
|||
});
|
||||
} else { // 右击了目录
|
||||
if (wide.curNode.removable) {
|
||||
$("#dirRMenu .remove").removeClass("disabled");
|
||||
$("#dirRMenu .remove, #dirRMenu .rename").removeClass("disabled");
|
||||
} else {
|
||||
$("#dirRMenu .remove").addClass("disabled");
|
||||
$("#dirRMenu .remove, #dirRMenu .rename").addClass("disabled");
|
||||
}
|
||||
|
||||
if (wide.curNode.creatable) {
|
||||
|
|
|
@ -50,6 +50,10 @@ var wide = {
|
|||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
$("#dialogRemoveConfirm").dialog("close");
|
||||
bottomGroup.tabs.setCurrent("notification");
|
||||
windows.flowBottom();
|
||||
$(".bottom-window-group .notification").focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -78,6 +82,61 @@ var wide = {
|
|||
}
|
||||
});
|
||||
|
||||
$("#dialogRenamePrompt").dialog({
|
||||
"modal": true,
|
||||
"height": 52,
|
||||
"width": 260,
|
||||
"title": config.label.rename,
|
||||
"okText": config.label.rename,
|
||||
"cancelText": config.label.cancel,
|
||||
"afterOpen": function () {
|
||||
var index = wide.curNode.name.lastIndexOf(".");
|
||||
$("#dialogRenamePrompt > input").val(wide.curNode.name.substring(0, index)).focus();
|
||||
$("#dialogRenamePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
|
||||
},
|
||||
"ok": function () {
|
||||
var name = $("#dialogRenamePrompt > input").val(),
|
||||
request = newWideRequest();
|
||||
|
||||
request.oldPath = wide.curNode.path;
|
||||
|
||||
var pathIndex = wide.curNode.path.lastIndexOf(config.pathSeparator),
|
||||
nameIndex = wide.curNode.name.lastIndexOf("."),
|
||||
ext = wide.curNode.name.substring(nameIndex, wide.curNode.name.length);
|
||||
request.newPath = wide.curNode.path.substring(0, pathIndex) + config.pathSeparator
|
||||
+ name + ext;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/file/rename',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
$("#dialogRenamePrompt").dialog("close");
|
||||
bottomGroup.tabs.setCurrent("notification");
|
||||
windows.flowBottom();
|
||||
$(".bottom-window-group .notification").focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#dialogRenamePrompt").dialog("close");
|
||||
|
||||
// update tree node
|
||||
wide.curNode.name = name + ext;
|
||||
wide.curNode.title = request.newPath;
|
||||
wide.curNode.path = request.newPath;
|
||||
tree.fileTree.updateNode(wide.curNode);
|
||||
|
||||
// update open editor tab name
|
||||
var $currentSpan = $(".edit-panel .tabs > div[data-index=" + wide.curNode.tId + "] > span:eq(0)");
|
||||
$currentSpan.attr("title", request.newPath);
|
||||
$currentSpan.html($currentSpan.find("span").html() + wide.curNode.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#dialogNewFilePrompt").dialog({
|
||||
"modal": true,
|
||||
"height": 52,
|
||||
|
@ -103,8 +162,13 @@ var wide = {
|
|||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
$("#dialogNewFilePrompt").dialog("close");
|
||||
bottomGroup.tabs.setCurrent("notification");
|
||||
windows.flowBottom();
|
||||
$(".bottom-window-group .notification").focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#dialogNewFilePrompt").dialog("close");
|
||||
var suffix = name.split(".")[1],
|
||||
iconSkin = "ico-ztree-other ";
|
||||
|
@ -179,6 +243,10 @@ var wide = {
|
|||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
$("#dialogNewDirPrompt").dialog("close");
|
||||
bottomGroup.tabs.setCurrent("notification");
|
||||
windows.flowBottom();
|
||||
$(".bottom-window-group .notification").focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
<li class="create" onclick="tree.newFile(this);">{{.i18n.create_file}}</li>
|
||||
<li class="create" onclick="tree.newDir(this);">{{.i18n.create_dir}}</li>
|
||||
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
|
||||
<li class="rename" onclick="tree.rename(this);">{{.i18n.rename}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
@ -141,6 +142,7 @@
|
|||
<div id="fileRMenu" class="frame">
|
||||
<ul>
|
||||
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
|
||||
<li class="rename" onclick="tree.rename(this);">{{.i18n.rename}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -233,6 +235,9 @@
|
|||
<div id="dialogNewFilePrompt" class="dialog-prompt fn-none">
|
||||
<input/>
|
||||
</div>
|
||||
<div id="dialogRenamePrompt" class="dialog-prompt fn-none">
|
||||
<input/>
|
||||
</div>
|
||||
<div id="dialogNewDirPrompt" class="dialog-prompt fn-none">
|
||||
<input/>
|
||||
</div>
|
||||
|
@ -259,6 +264,7 @@
|
|||
"restore_editor": "{{.i18n.restore_editor}}",
|
||||
"max_editor": "{{.i18n.max_editor}}",
|
||||
"delete": "{{.i18n.delete}}",
|
||||
"rename": "{{.i18n.rename}}",
|
||||
"cancel": "{{.i18n.cancel}}",
|
||||
"goto_line": "{{.i18n.goto_line}}",
|
||||
"go": "{{.i18n.go}}",
|
||||
|
|
Loading…
Reference in New Issue