保存所有文件,关闭所有文件

This commit is contained in:
Van 2014-10-13 16:18:45 +08:00
parent bf505af3a8
commit 3e720d8179
7 changed files with 31 additions and 36 deletions

View File

@ -5,7 +5,6 @@
"OutputChannel": "ws://{IP}:7070", "OutputChannel": "ws://{IP}:7070",
"ShellChannel": "ws://{IP}:7070", "ShellChannel": "ws://{IP}:7070",
"SessionChannel": "ws://{IP}:7070", "SessionChannel": "ws://{IP}:7070",
"HTTPSessionMaxAge": 86400,
"StaticResourceVersion": "201409032040", "StaticResourceVersion": "201409032040",
"MaxProcs": 4, "MaxProcs": 4,
"RuntimeMode": "dev", "RuntimeMode": "dev",
@ -17,13 +16,12 @@
"Workspace": "{pwd}/data/user_workspaces/admin", "Workspace": "{pwd}/data/user_workspaces/admin",
"LatestSessionContent": { "LatestSessionContent": {
"FileTree": [ "FileTree": [
"/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest", "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest",
"/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest/time" "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time",
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\pkg"
], ],
"Files": [ "Files": [],
"/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest/time/main.go" "CurrentFile": ""
],
"CurrentFile": "/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest/time/main.go"
} }
} }
] ]

View File

@ -13,5 +13,5 @@ func Now1() time.Time {
} }
func Now2() { func Now2() {
} }

View File

@ -21,7 +21,6 @@
"delete": "删除", "delete": "删除",
"save": "保存", "save": "保存",
"exit": "退出", "exit": "退出",
"close_file": "关闭文件",
"close_all_files": "关闭所有文件", "close_all_files": "关闭所有文件",
"save_all_files": "保存所有文件", "save_all_files": "保存所有文件",
"format": "格式化", "format": "格式化",

View File

@ -146,13 +146,13 @@
float: left; float: left;
} }
.menu > ul > li > a,
.menu > ul > li > span { .menu > ul > li > span {
color: #000; color: #000;
font-size: 12px; font-size: 12px;
line-height: 24px; line-height: 24px;
padding: 5px; padding: 5px;
text-decoration: none; text-decoration: none;
cursor: pointer;
} }
/* end menu */ /* end menu */

View File

@ -24,6 +24,7 @@ var editors = {
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); editors.data.splice(i, 1);
wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
break; break;
} }
} }
@ -388,7 +389,7 @@ var editors = {
wide.saveAllFiles(); wide.saveAllFiles();
}, },
"Shift-Alt-F": function () { "Shift-Alt-F": function () {
wide.fmt(); wide.fmt(editors.getCurrentPath(), wide.curEditor);
}, },
"Alt-F7": "findUsages" "Alt-F7": "findUsages"
} }

View File

@ -398,20 +398,26 @@ var wide = {
}, },
saveFile: function () { saveFile: function () {
// 格式化后会对文件进行保存 // 格式化后会对文件进行保存
this.fmt(); this.fmt(editors.getCurrentPath(), wide.curEditor);
}, },
saveAllFiles: function () { saveAllFiles: function () {
// TODO: save all open files // TODO: 需要全部保存的接口
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);
} }
console.log("TODO: save all files");
}, },
closeFile: function () { closeFile: function () {
// TODO: close file // TODO: close file
}, },
closeAllFiles: function () { closeAllFiles: function () {
// TODO: close all files this.saveAllFiles();
editors.data = [];
tree.fileTree.cancelSelectedNode();
wide.curNode = undefined;
wide.curEditor = undefined;
$(".toolbars").hide();
$(".edit-panel .tabs, .edit-panel .tabs-panel").html('');
}, },
exit: function () { exit: function () {
// TODO: exit // TODO: exit
@ -497,15 +503,14 @@ var wide = {
} }
}); });
}, },
fmt: function () { fmt: function (path, curEditor) {
var path = editors.getCurrentPath(); var mode = curEditor.getOption("mode");
var mode = wide.curEditor.getOption("mode");
var request = newWideRequest(); var request = newWideRequest();
request.file = path; request.file = path;
request.code = wide.curEditor.getValue(); request.code = curEditor.getValue();
request.cursorLine = wide.curEditor.getCursor().line; request.cursorLine = curEditor.getCursor().line;
request.cursorCh = wide.curEditor.getCursor().ch; request.cursorCh = curEditor.getCursor().ch;
switch (mode) { switch (mode) {
case "text/x-go": // 会保存文件 case "text/x-go": // 会保存文件
@ -516,7 +521,7 @@ var wide = {
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (data.succ) { if (data.succ) {
wide.curEditor.setValue(data.code); curEditor.setValue(data.code);
} }
} }
}); });
@ -530,7 +535,7 @@ var wide = {
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (data.succ) { if (data.succ) {
wide.curEditor.setValue(data.code); curEditor.setValue(data.code);
} }
} }
}); });
@ -539,14 +544,13 @@ var wide = {
case "application/json": case "application/json":
try { try {
// 在客户端浏览器中进行 JSON 格式化 // 在客户端浏览器中进行 JSON 格式化
var json = JSON.parse(wide.curEditor.getValue()); var json = JSON.parse(curEditor.getValue());
wide.curEditor.setValue(JSON.stringify(json, "", " ")); curEditor.setValue(JSON.stringify(json, "", " "));
wide._save(); wide._save();
} catch (e) { } catch (e) {
delete e; delete e;
} }
break; break;
default : default :
// TODO: XML 格式化处理 // TODO: XML 格式化处理

View File

@ -25,17 +25,10 @@
<li> <li>
<span>{{.i18n.file}}</span> <span>{{.i18n.file}}</span>
<div class="frame"> <div class="frame">
<ul> <ul>
<li onclick="wide.saveFile()">
<span>{{.i18n.save}}</span>
</li>
<li onclick="wide.saveAllFiles()"> <li onclick="wide.saveAllFiles()">
<span>{{.i18n.save_all_files}}</span> <span>{{.i18n.save_all_files}}</span>
</li> </li>
<li class="hr"></li>
<li onclick="wide.closeFile()">
<span>{{.i18n.close_file}}</span>
</li>
<li onclick="wide.closeAllFiles()"> <li onclick="wide.closeAllFiles()">
<span>{{.i18n.close_all_files}}</span> <span>{{.i18n.close_all_files}}</span>
</li> </li>
@ -132,7 +125,7 @@
<div class="toolbars fn-none"> <div class="toolbars fn-none">
<span onclick="wide.run()" class="font-ico ico-buildrun" title="{{.i18n.build_n_run}}"></span> <span onclick="wide.run()" class="font-ico ico-buildrun" title="{{.i18n.build_n_run}}"></span>
<span onclick="wide.saveFile()" 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(editors.getCurrentPath(), wide.curEditor)" class="ico-format font-ico" title="{{.i18n.format}}"></span>
<span class="font-ico ico-max" onclick="windows.maxEditor()" title="{{.i18n.max_editor}}"></span> <span class="font-ico ico-max" onclick="windows.maxEditor()" title="{{.i18n.max_editor}}"></span>
</div> </div>
<div class="tabs"></div> <div class="tabs"></div>