Fix #138
This commit is contained in:
parent
861d79fc93
commit
8036401a3c
|
@ -21,7 +21,6 @@ import (
|
||||||
// File node, used to construct the file tree.
|
// File node, used to construct the file tree.
|
||||||
type FileNode struct {
|
type FileNode struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Title string `json:"title"`
|
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
IconSkin string `json:"iconSkin"` // Value should be end with a space
|
IconSkin string `json:"iconSkin"` // Value should be end with a space
|
||||||
Type string `json:"type"` // "f": file, "d": directory
|
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"
|
workspacePath := workspace + conf.PathSeparator + "src"
|
||||||
|
|
||||||
workspaceNode := FileNode{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
|
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{}}
|
Creatable: true, Removable: false, FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
walk(workspacePath, &workspaceNode, true, true)
|
walk(workspacePath, &workspaceNode, true, true)
|
||||||
|
@ -71,7 +70,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// construct Go API node
|
// construct Go API node
|
||||||
apiPath := runtime.GOROOT() + conf.PathSeparator + "src" + conf.PathSeparator + "pkg"
|
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{}}
|
Creatable: false, Removable: false, FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
goapiBuildOKSignal := make(chan bool)
|
goapiBuildOKSignal := make(chan bool)
|
||||||
|
@ -262,7 +261,7 @@ func RenameFile(w http.ResponseWriter, r *http.Request) {
|
||||||
data["succ"] = false
|
data["succ"] = false
|
||||||
|
|
||||||
wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
|
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)
|
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)
|
node.FileNodes = append(node.FileNodes, &child)
|
||||||
|
|
||||||
if nil == fio {
|
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.
|
// renameFile renames (moves) a file from the specified old path to the specified new path.
|
||||||
func renameFile(oldPath, newPath string) bool {
|
func renameFile(oldPath, newPath string) bool {
|
||||||
if err := os.Rename(oldPath, newPath); nil != err {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"create": "Create",
|
"create": "Create",
|
||||||
"create_dir": "Create Dir",
|
"create_dir": "Create Dir",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
|
"rename": "Rename",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"exit": "Exit",
|
"exit": "Exit",
|
||||||
"close_all_files": "Close All",
|
"close_all_files": "Close All",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"create": "作成",
|
"create": "作成",
|
||||||
"create_dir": "新規ディレクトリ",
|
"create_dir": "新規ディレクトリ",
|
||||||
"delete": "削除",
|
"delete": "削除",
|
||||||
|
"rename": "名前の変更",
|
||||||
"save": "保存",
|
"save": "保存",
|
||||||
"exit": "終了",
|
"exit": "終了",
|
||||||
"close_all_files": "全てのファイルを閉じる",
|
"close_all_files": "全てのファイルを閉じる",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"create": "创建",
|
"create": "创建",
|
||||||
"create_dir": "创建目录",
|
"create_dir": "创建目录",
|
||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
|
"rename": "重命名",
|
||||||
"save": "保存",
|
"save": "保存",
|
||||||
"exit": "退出",
|
"exit": "退出",
|
||||||
"close_all_files": "关闭所有文件",
|
"close_all_files": "关闭所有文件",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"create": "建立",
|
"create": "建立",
|
||||||
"create_dir": "建立目錄",
|
"create_dir": "建立目錄",
|
||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
|
"rename": "重命名",
|
||||||
"save": "儲存",
|
"save": "儲存",
|
||||||
"exit": "退出",
|
"exit": "退出",
|
||||||
"close_all_files": "關閉所有文件",
|
"close_all_files": "關閉所有文件",
|
||||||
|
|
|
@ -111,6 +111,17 @@ var tree = {
|
||||||
$("#fileRMenu").hide();
|
$("#fileRMenu").hide();
|
||||||
$("#dialogRemoveConfirm").dialog("open");
|
$("#dialogRemoveConfirm").dialog("open");
|
||||||
},
|
},
|
||||||
|
rename: function (it) {
|
||||||
|
if (it) {
|
||||||
|
if ($(it).hasClass("disabled")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#dirRMenu").hide();
|
||||||
|
$("#fileRMenu").hide();
|
||||||
|
$("#dialogRenamePrompt").dialog("open");
|
||||||
|
},
|
||||||
init: function () {
|
init: function () {
|
||||||
$("#file").click(function () {
|
$("#file").click(function () {
|
||||||
$(this).focus();
|
$(this).focus();
|
||||||
|
@ -130,7 +141,7 @@ var tree = {
|
||||||
var setting = {
|
var setting = {
|
||||||
data: {
|
data: {
|
||||||
key: {
|
key: {
|
||||||
title: "title"
|
title: "path"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
view: {
|
view: {
|
||||||
|
@ -154,7 +165,7 @@ var tree = {
|
||||||
} else {
|
} else {
|
||||||
$("#fileRMenu .remove").addClass("disabled");
|
$("#fileRMenu .remove").addClass("disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#fileRMenu").show();
|
$("#fileRMenu").show();
|
||||||
|
|
||||||
fileRMenu.css({
|
fileRMenu.css({
|
||||||
|
@ -164,9 +175,9 @@ var tree = {
|
||||||
});
|
});
|
||||||
} else { // 右击了目录
|
} else { // 右击了目录
|
||||||
if (wide.curNode.removable) {
|
if (wide.curNode.removable) {
|
||||||
$("#dirRMenu .remove").removeClass("disabled");
|
$("#dirRMenu .remove, #dirRMenu .rename").removeClass("disabled");
|
||||||
} else {
|
} else {
|
||||||
$("#dirRMenu .remove").addClass("disabled");
|
$("#dirRMenu .remove, #dirRMenu .rename").addClass("disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wide.curNode.creatable) {
|
if (wide.curNode.creatable) {
|
||||||
|
|
|
@ -50,6 +50,10 @@ var wide = {
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (!data.succ) {
|
if (!data.succ) {
|
||||||
|
$("#dialogRemoveConfirm").dialog("close");
|
||||||
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
|
windows.flowBottom();
|
||||||
|
$(".bottom-window-group .notification").focus();
|
||||||
return false;
|
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({
|
$("#dialogNewFilePrompt").dialog({
|
||||||
"modal": true,
|
"modal": true,
|
||||||
"height": 52,
|
"height": 52,
|
||||||
|
@ -103,8 +162,13 @@ var wide = {
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (!data.succ) {
|
if (!data.succ) {
|
||||||
|
$("#dialogNewFilePrompt").dialog("close");
|
||||||
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
|
windows.flowBottom();
|
||||||
|
$(".bottom-window-group .notification").focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#dialogNewFilePrompt").dialog("close");
|
$("#dialogNewFilePrompt").dialog("close");
|
||||||
var suffix = name.split(".")[1],
|
var suffix = name.split(".")[1],
|
||||||
iconSkin = "ico-ztree-other ";
|
iconSkin = "ico-ztree-other ";
|
||||||
|
@ -179,6 +243,10 @@ var wide = {
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (!data.succ) {
|
if (!data.succ) {
|
||||||
|
$("#dialogNewDirPrompt").dialog("close");
|
||||||
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
|
windows.flowBottom();
|
||||||
|
$(".bottom-window-group .notification").focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +278,7 @@ var wide = {
|
||||||
"ok": function () {
|
"ok": function () {
|
||||||
var line = parseInt($("#dialogGoLinePrompt > input").val()) - 1;
|
var line = parseInt($("#dialogGoLinePrompt > input").val()) - 1;
|
||||||
$("#dialogGoLinePrompt").dialog("close");
|
$("#dialogGoLinePrompt").dialog("close");
|
||||||
|
|
||||||
var editor = wide.curEditor;
|
var editor = wide.curEditor;
|
||||||
var cursor = editor.getCursor();
|
var cursor = editor.getCursor();
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,7 @@
|
||||||
<li class="create" onclick="tree.newFile(this);">{{.i18n.create_file}}</li>
|
<li class="create" onclick="tree.newFile(this);">{{.i18n.create_file}}</li>
|
||||||
<li class="create" onclick="tree.newDir(this);">{{.i18n.create_dir}}</li>
|
<li class="create" onclick="tree.newDir(this);">{{.i18n.create_dir}}</li>
|
||||||
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
|
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
|
||||||
|
<li class="rename" onclick="tree.rename(this);">{{.i18n.rename}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -141,6 +142,7 @@
|
||||||
<div id="fileRMenu" class="frame">
|
<div id="fileRMenu" class="frame">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
|
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
|
||||||
|
<li class="rename" onclick="tree.rename(this);">{{.i18n.rename}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -233,6 +235,9 @@
|
||||||
<div id="dialogNewFilePrompt" class="dialog-prompt fn-none">
|
<div id="dialogNewFilePrompt" class="dialog-prompt fn-none">
|
||||||
<input/>
|
<input/>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="dialogRenamePrompt" class="dialog-prompt fn-none">
|
||||||
|
<input/>
|
||||||
|
</div>
|
||||||
<div id="dialogNewDirPrompt" class="dialog-prompt fn-none">
|
<div id="dialogNewDirPrompt" class="dialog-prompt fn-none">
|
||||||
<input/>
|
<input/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -259,6 +264,7 @@
|
||||||
"restore_editor": "{{.i18n.restore_editor}}",
|
"restore_editor": "{{.i18n.restore_editor}}",
|
||||||
"max_editor": "{{.i18n.max_editor}}",
|
"max_editor": "{{.i18n.max_editor}}",
|
||||||
"delete": "{{.i18n.delete}}",
|
"delete": "{{.i18n.delete}}",
|
||||||
|
"rename": "{{.i18n.rename}}",
|
||||||
"cancel": "{{.i18n.cancel}}",
|
"cancel": "{{.i18n.cancel}}",
|
||||||
"goto_line": "{{.i18n.goto_line}}",
|
"goto_line": "{{.i18n.goto_line}}",
|
||||||
"go": "{{.i18n.go}}",
|
"go": "{{.i18n.go}}",
|
||||||
|
|
Loading…
Reference in New Issue