初始化页面添加

This commit is contained in:
Van 2014-10-17 14:47:29 +08:00
parent 0d7205defb
commit 3a295ff7c5
7 changed files with 97 additions and 34 deletions

View File

@ -16,9 +16,15 @@
"Password": "admin",
"Workspace": "{pwd}/data/user_workspaces/admin",
"LatestSessionContent": {
"FileTree": [],
"Files": [],
"CurrentFile": ""
"FileTree": [
"E:\\Work\\go\\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\\hello",
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time"
],
"Files": [
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go"
],
"CurrentFile": "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go"
}
}
]

View File

@ -46,5 +46,6 @@
"search_text": "查找文本",
"restore_bottom": "底部窗口还原",
"file_format": "文件后缀",
"keyword": "关键字"
"keyword": "关键字",
"initialise": "初始化"
}

View File

@ -2,10 +2,13 @@ var editors = {
data: [],
tabs: {},
init: function () {
editors._initAutocomplete();
editors.tabs = new Tabs({
id: ".edit-panel",
clickAfter: function (id) {
if (id === 'startPage') {
return false;
}
// set tree node selected
var node = tree.fileTree.getNodeByTId(id);
tree.fileTree.selectNode(node);
@ -21,6 +24,10 @@ var editors = {
wide.curEditor.focus();
},
removeAfter: function (id, nextId) {
if (id === 'startPage') {
return false;
}
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) {
wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
@ -36,7 +43,7 @@ var editors = {
wide.curNode = undefined;
wide.curEditor = undefined;
menu.disabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
$(".toolbars").hide();
return false;
@ -60,7 +67,6 @@ var editors = {
}
});
$(".edit-panel .tabs").on("dblclick", function () {
if ($(".toolbars .ico-max").length === 1) {
windows.maxEditor();
@ -68,14 +74,32 @@ var editors = {
windows.restoreEditor();
}
});
this._initCodeMirrorHotKeys();
this._initStartPage()
},
_initStartPage: function () {
editors.tabs.add({
id: "startPage",
title: '<span title="' + config.label.initialise + '">' + config.label.initialise + '</span>',
content: '<textarea id="editor"></textarea>'
});
},
getCurrentId: function () {
return $(".edit-panel .tabs .current").data("index");
var currentId = editors.tabs.getCurrentId();
if (currentId === 'startPage') {
currentId = null;
}
return currentId;
},
getCurrentPath: function () {
return $(".edit-panel .tabs .current span:eq(0)").attr("title");
var currentPath = $(".edit-panel .tabs .current span:eq(0)").attr("title");
if (currentPath === config.label.initialise) {
currentPath = null;
}
return currentPath;
},
_initAutocomplete: function () {
_initCodeMirrorHotKeys: function () {
CodeMirror.registerHelper("hint", "go", function (editor) {
var word = /[\w$]+/;
@ -360,7 +384,7 @@ var editors = {
+ wide.curNode.iconSkin + 'ico"></span>' + wide.curNode.name + '</span>',
content: '<textarea id="editor' + id + '"></textarea>'
});
menu.undisabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
var rulers = [];
@ -392,7 +416,11 @@ var editors = {
wide.saveAllFiles();
},
"Shift-Alt-F": function () {
wide.fmt(editors.getCurrentPath(), wide.curEditor);
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
wide.fmt(currentPath, wide.curEditor);
},
"Alt-F7": "findUsages"
}

View File

@ -256,8 +256,9 @@ var hotkeys = {
if (event.ctrlKey === hotKeys.closeCurEditor.ctrlKey
&& event.which === hotKeys.closeCurEditor.which) { // Ctrl+Q 关闭当前编辑器
if (editors.tabs.getCurrentId()) {
editors.tabs.del(editors.tabs.getCurrentId());
var currentId = editors.getCurrentId();
if (currentId) {
editors.tabs.del(currentId);
}
event.preventDefault();
@ -293,15 +294,18 @@ var hotkeys = {
if (editors.data.length > 1) {
var nextId = "";
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.tabs.getCurrentId() === editors.data[i].id) {
if (i < ii - 1) {
nextId = editors.data[i + 1].id;
wide.curEditor = editors.data[i + 1].editor;
} else {
nextId = editors.data[0].id;
wide.curEditor = editors.data[0].editor;
var currentId = editors.getCurrentId();
if (currentId) {
if (currentId === editors.data[i].id) {
if (i < ii - 1) {
nextId = editors.data[i + 1].id;
wide.curEditor = editors.data[i + 1].editor;
} else {
nextId = editors.data[0].id;
wide.curEditor = editors.data[0].editor;
}
break;
}
break;
}
}

View File

@ -7,15 +7,14 @@ var session = {
var request = newWideRequest(),
filse = [],
fileTree = [],
currentFile = "";
currentId = editors.getCurrentId(),
currentFile = currentId ? editors.getCurrentPath() : "";
editors.tabs.obj._$tabs.find("div").each(function () {
var $it = $(this);
if ($it.hasClass("current")) {
currentFile = $it.find("span:eq(0)").attr("title");
if ($it.find("span:eq(0)").attr("title") !== config.label.initialise) {
filse.push($it.find("span:eq(0)").attr("title"));
}
filse.push($it.find("span:eq(0)").attr("title"));
});
fileTree = tree.getOpenPaths();

View File

@ -320,7 +320,7 @@ var wide = {
$(".toolbars .ico-stop").removeClass("ico-stop")
.addClass("ico-buildrun").attr("title", config.label.build_n_run);
} else if ('build' === data.cmd || 'go install' === data.cmd) {
wide.fillOutput(data.output);
wide.fillOutput(data.output);
if (0 !== data.output.length) { // 说明编译有错误输出
for (var i = 0; i < data.lints.length; i++) {
@ -382,8 +382,13 @@ var wide = {
this._initLayout();
},
_save: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
var request = newWideRequest();
request.file = editors.getCurrentPath();
request.file = currentPath;
request.code = wide.curEditor.getValue();
$.ajax({
@ -396,8 +401,12 @@ var wide = {
});
},
saveFile: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
// 格式化后会对文件进行保存
this.fmt(editors.getCurrentPath(), wide.curEditor);
this.fmt(currentPath, wide.curEditor);
},
saveAllFiles: function () {
if ($(".menu li.save-all").hasClass("disabled")) {
@ -467,6 +476,11 @@ var wide = {
},
// 构建 & 运行.
run: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
if ($(".menu li.run").hasClass("disabled")) {
return false;
}
@ -477,7 +491,7 @@ var wide = {
}
var request = newWideRequest();
request.file = editors.getCurrentPath();
request.file = currentPath;
request.code = wide.curEditor.getValue();
$.ajax({
@ -495,12 +509,17 @@ var wide = {
});
},
goget: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
if ($(".menu li.go-get").hasClass("disabled")) {
return false;
}
var request = newWideRequest();
request.file = editors.getCurrentPath();
request.file = currentPath;
$.ajax({
type: 'POST',
@ -515,12 +534,17 @@ var wide = {
});
},
goinstall: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
if ($(".menu li.go-install").hasClass("disabled")) {
return false;
}
var request = newWideRequest();
request.file = editors.getCurrentPath();
request.file = currentPath;
request.code = wide.curEditor.getValue();
$.ajax({

View File

@ -214,7 +214,8 @@
"stop": "{{.i18n.stop}}",
"usages": "{{.i18n.usages}}",
"search_text": "{{.i18n.search_text}}",
"search": "{{.i18n.search}}"
"search": "{{.i18n.search}}",
"initialise": "{{.i18n.initialise}}"
},
"channel": {
"editor": '{{.conf.EditorChannel}}',