初始化页面添加

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", "Password": "admin",
"Workspace": "{pwd}/data/user_workspaces/admin", "Workspace": "{pwd}/data/user_workspaces/admin",
"LatestSessionContent": { "LatestSessionContent": {
"FileTree": [], "FileTree": [
"Files": [], "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest",
"CurrentFile": "" "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": "查找文本", "search_text": "查找文本",
"restore_bottom": "底部窗口还原", "restore_bottom": "底部窗口还原",
"file_format": "文件后缀", "file_format": "文件后缀",
"keyword": "关键字" "keyword": "关键字",
"initialise": "初始化"
} }

View File

@ -2,10 +2,13 @@ var editors = {
data: [], data: [],
tabs: {}, tabs: {},
init: function () { init: function () {
editors._initAutocomplete();
editors.tabs = new Tabs({ editors.tabs = new Tabs({
id: ".edit-panel", id: ".edit-panel",
clickAfter: function (id) { clickAfter: function (id) {
if (id === 'startPage') {
return false;
}
// set tree node selected // set tree node selected
var node = tree.fileTree.getNodeByTId(id); var node = tree.fileTree.getNodeByTId(id);
tree.fileTree.selectNode(node); tree.fileTree.selectNode(node);
@ -21,6 +24,10 @@ var editors = {
wide.curEditor.focus(); wide.curEditor.focus();
}, },
removeAfter: function (id, nextId) { removeAfter: function (id, nextId) {
if (id === 'startPage') {
return false;
}
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) {
wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor); wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
@ -60,7 +67,6 @@ var editors = {
} }
}); });
$(".edit-panel .tabs").on("dblclick", function () { $(".edit-panel .tabs").on("dblclick", function () {
if ($(".toolbars .ico-max").length === 1) { if ($(".toolbars .ico-max").length === 1) {
windows.maxEditor(); windows.maxEditor();
@ -68,14 +74,32 @@ var editors = {
windows.restoreEditor(); 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 () { getCurrentId: function () {
return $(".edit-panel .tabs .current").data("index"); var currentId = editors.tabs.getCurrentId();
if (currentId === 'startPage') {
currentId = null;
}
return currentId;
}, },
getCurrentPath: function () { 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) { CodeMirror.registerHelper("hint", "go", function (editor) {
var word = /[\w$]+/; var word = /[\w$]+/;
@ -392,7 +416,11 @@ var editors = {
wide.saveAllFiles(); wide.saveAllFiles();
}, },
"Shift-Alt-F": function () { "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" "Alt-F7": "findUsages"
} }

View File

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

View File

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

View File

@ -382,8 +382,13 @@ var wide = {
this._initLayout(); this._initLayout();
}, },
_save: function () { _save: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
var request = newWideRequest(); var request = newWideRequest();
request.file = editors.getCurrentPath(); request.file = currentPath;
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();
$.ajax({ $.ajax({
@ -396,8 +401,12 @@ var wide = {
}); });
}, },
saveFile: function () { saveFile: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
// 格式化后会对文件进行保存 // 格式化后会对文件进行保存
this.fmt(editors.getCurrentPath(), wide.curEditor); this.fmt(currentPath, wide.curEditor);
}, },
saveAllFiles: function () { saveAllFiles: function () {
if ($(".menu li.save-all").hasClass("disabled")) { if ($(".menu li.save-all").hasClass("disabled")) {
@ -467,6 +476,11 @@ var wide = {
}, },
// 构建 & 运行. // 构建 & 运行.
run: function () { run: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
if ($(".menu li.run").hasClass("disabled")) { if ($(".menu li.run").hasClass("disabled")) {
return false; return false;
} }
@ -477,7 +491,7 @@ var wide = {
} }
var request = newWideRequest(); var request = newWideRequest();
request.file = editors.getCurrentPath(); request.file = currentPath;
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();
$.ajax({ $.ajax({
@ -495,12 +509,17 @@ var wide = {
}); });
}, },
goget: function () { goget: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
if ($(".menu li.go-get").hasClass("disabled")) { if ($(".menu li.go-get").hasClass("disabled")) {
return false; return false;
} }
var request = newWideRequest(); var request = newWideRequest();
request.file = editors.getCurrentPath(); request.file = currentPath;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
@ -515,12 +534,17 @@ var wide = {
}); });
}, },
goinstall: function () { goinstall: function () {
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
if ($(".menu li.go-install").hasClass("disabled")) { if ($(".menu li.go-install").hasClass("disabled")) {
return false; return false;
} }
var request = newWideRequest(); var request = newWideRequest();
request.file = editors.getCurrentPath(); request.file = currentPath;
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();
$.ajax({ $.ajax({

View File

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