diff --git a/doc/zh_CN/keyboard_shortcuts.html b/doc/zh_CN/keyboard_shortcuts.html
index 5c841c3..71a311f 100644
--- a/doc/zh_CN/keyboard_shortcuts.html
+++ b/doc/zh_CN/keyboard_shortcuts.html
@@ -27,8 +27,10 @@
- Ctrl+1:焦点切换到文件树
- Ctrl+4:焦点切换到输出窗口
+ - Ctrl+5:焦点切换到搜索窗口
+ - Ctrl+6:焦点切换到通知窗口
-
+
运行
- F6:构建 & 运行
diff --git a/main.go b/main.go
index 9efef3e..f5f73d4 100644
--- a/main.go
+++ b/main.go
@@ -40,7 +40,7 @@ func init() {
// Wide 首页.
func indexHandler(w http.ResponseWriter, r *http.Request) {
// 创建一个 Wide 会话
- wideSession := user.NewSession()
+ wideSession := user.WideSessions.New()
i18n.Load()
@@ -54,7 +54,8 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
name := conf.Wide.Users[0].Name
httpSession.Values["username"] = name
- httpSession.Values["id"] = strconv.Itoa(rand.Int())
+ httpSessionId := strconv.Itoa(rand.Int())
+ httpSession.Values["id"] = httpSessionId
// 一天过期
httpSession.Options.MaxAge = 60 * 60 * 24
@@ -63,6 +64,9 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
httpSession.Save(r, w)
+ // Wide 会话关联 HTTP 会话
+ wideSession.HTTPSessionId = httpSession.Values["id"].(string)
+
t, err := template.ParseFiles("view/index.html")
if nil != err {
diff --git a/static/js/editor.js b/static/js/editor.js
index 9f5c572..d58e3ac 100644
--- a/static/js/editor.js
+++ b/static/js/editor.js
@@ -1,10 +1,10 @@
var editors = {
data: [],
- init: function() {
+ init: function () {
editors._initAutocomplete();
editors.tabs = new Tabs({
id: ".edit-panel",
- clickAfter: function(id) {
+ clickAfter: function (id) {
// set tree node selected
var node = tree.fileTree.getNodeByTId(id);
tree.fileTree.selectNode(node);
@@ -19,7 +19,7 @@ var editors = {
wide.curEditor.focus();
},
- removeAfter: function(id, nextId) {
+ removeAfter: function (id, nextId) {
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) {
editors.data.splice(i, 1);
@@ -57,16 +57,16 @@ var editors = {
});
- $(".edit-header .tabs").on("dblclick", "div", function() {
+ $(".edit-header .tabs").on("dblclick", "div", function () {
editors.fullscreen();
});
},
- fullscreen: function() {
+ fullscreen: function () {
wide.curEditor.setOption("fullScreen", true);
wide.curEditor.focus();
},
- _initAutocomplete: function() {
- CodeMirror.registerHelper("hint", "go", function(editor) {
+ _initAutocomplete: function () {
+ CodeMirror.registerHelper("hint", "go", function (editor) {
var word = /[\w$]+/;
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
@@ -78,13 +78,12 @@ var editors = {
while (start && word.test(curLine.charAt(start - 1))) {
--start;
}
-
- var request = {
- path: $(".edit-header .current > span:eq(0)").attr("title"),
- code: editor.getValue(),
- cursorLine: cur.line,
- cursorCh: cur.ch
- };
+
+ var request = newWideRequest();
+ request.path = $(".edit-header .current > span:eq(0)").attr("title");
+ request.code = editor.getValue();
+ request.cursorLine = cur.line;
+ request.cursorCh = cur.ch;
var autocompleteHints = [];
@@ -94,7 +93,7 @@ var editors = {
url: '/autocomplete',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
var autocompleteArray = data[1];
if (autocompleteArray) {
@@ -108,8 +107,8 @@ var editors = {
return {list: autocompleteHints, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
- CodeMirror.commands.autocompleteAfterDot = function(cm) {
- setTimeout(function() {
+ CodeMirror.commands.autocompleteAfterDot = function (cm) {
+ setTimeout(function () {
if (!cm.state.completionActive) {
cm.showHint({hint: CodeMirror.hint.go, completeSingle: false});
}
@@ -118,35 +117,34 @@ var editors = {
return CodeMirror.Pass;
};
- CodeMirror.commands.autocompleteAnyWord = function(cm) {
+ CodeMirror.commands.autocompleteAnyWord = function (cm) {
cm.showHint({hint: CodeMirror.hint.auto});
};
- CodeMirror.commands.gotoLine = function(cm) {
+ CodeMirror.commands.gotoLine = function (cm) {
var line = prompt("Go To Line: ", "0");
cm.setCursor(CodeMirror.Pos(line - 1, 0));
};
- CodeMirror.commands.doNothing = function(cm) {
+ CodeMirror.commands.doNothing = function (cm) {
};
- CodeMirror.commands.jumpToDecl = function(cm) {
+ CodeMirror.commands.jumpToDecl = function (cm) {
var cur = wide.curEditor.getCursor();
- var request = {
- path: $(".edit-header .current > span:eq(0)").attr("title"),
- code: wide.curEditor.getValue(),
- cursorLine: cur.line,
- cursorCh: cur.ch
- };
+ var request = newWideRequest();
+ request.path = $(".edit-header .current > span:eq(0)").attr("title");
+ request.code = wide.curEditor.getValue();
+ request.cursorLine = cur.line;
+ request.cursorCh = cur.ch;
$.ajax({
type: 'POST',
url: '/find/decl',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (!data.succ) {
return;
}
@@ -154,16 +152,15 @@ var editors = {
var cursorLine = data.cursorLine;
var cursorCh = data.cursorCh;
- var request = {
- path: data.path
- };
+ var request = newWideRequest();
+ request.path = data.path;
$.ajax({
type: 'POST',
url: '/file',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (!data.succ) {
alert(data.msg);
@@ -183,22 +180,21 @@ var editors = {
});
};
- CodeMirror.commands.findUsages = function(cm) {
+ CodeMirror.commands.findUsages = function (cm) {
var cur = wide.curEditor.getCursor();
- var request = {
- file: wide.curNode.path,
- code: wide.curEditor.getValue(),
- cursorLine: cur.line,
- cursorCh: cur.ch
- };
+ var request = newWideRequest();
+ request.file = wide.curNode.path;
+ request.code = wide.curEditor.getValue();
+ request.cursorLine = cur.line;
+ request.cursorCh = cur.ch;
$.ajax({
type: 'POST',
url: '/find/usages',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
console.log(data);
if (!data.succ) {
@@ -211,7 +207,7 @@ var editors = {
};
},
// 新建一个编辑器 Tab,如果已经存在 Tab 则切换到该 Tab.
- newEditor: function(data) {
+ newEditor: function (data) {
$(".ico-fullscreen").show();
var id = wide.curNode.tId;
@@ -256,12 +252,12 @@ var editors = {
extraKeys: {
"Ctrl-\\": "autocompleteAnyWord",
".": "autocompleteAfterDot",
- "Esc": function(cm) {
+ "Esc": function (cm) {
if (cm.getOption("fullScreen")) {
cm.setOption("fullScreen", false);
}
},
- "F11": function(cm) {
+ "F11": function (cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Ctrl-G": "gotoLine",
@@ -269,16 +265,16 @@ var editors = {
"Ctrl-D": "doNothing", // 取消默认的 deleteLine
"Ctrl-B": "jumpToDecl",
"Ctrl-S": function () {
- wide.saveFile();
+ wide.saveFile();
},
"Shift-Alt-F": function () {
- wide.fmt();
+ wide.fmt();
},
"Alt-F7": "findUsages"
}
});
- editor.on('cursorActivity', function(cm) {
+ editor.on('cursorActivity', function (cm) {
var cursor = cm.getCursor();
$("#footer-cursor").text('| ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + ' |');
diff --git a/static/js/tree.js b/static/js/tree.js
index 2aa6ec3..9af1139 100644
--- a/static/js/tree.js
+++ b/static/js/tree.js
@@ -1,6 +1,6 @@
var tree = {
// 递归获取当前节点展开中的最后一个节点
- getCurrentNodeLastNode: function(node) {
+ getCurrentNodeLastNode: function (node) {
var returnNode = node.children[node.children.length - 1];
if (returnNode.open) {
return tree.getCurrentNodeLastNode(returnNode);
@@ -9,7 +9,7 @@ var tree = {
}
},
// 按照树展现获取下一个节点
- getNextShowNode: function(node) {
+ getNextShowNode: function (node) {
if (node.level !== 0) {
if (node.getParentNode().getNextNode()) {
return node.getParentNode().getNextNode();
@@ -20,7 +20,7 @@ var tree = {
return node.getNextNode();
}
},
- isBottomNode: function(node) {
+ isBottomNode: function (node) {
if (node.open) {
return false;
}
@@ -39,7 +39,7 @@ var tree = {
}
}
},
- getTIdByPath: function(path) {
+ getTIdByPath: function (path) {
var nodes = tree.fileTree.transformToArray(tree.fileTree.getNodes());
for (var i = 0, ii = nodes.length; i < ii; i++) {
if (nodes[i].path === path) {
@@ -50,7 +50,7 @@ var tree = {
return undefined;
},
fileTree: undefined,
- _isParents: function(tId, parentTId) {
+ _isParents: function (tId, parentTId) {
var node = tree.fileTree.getNodeByTId(tId);
if (!node || !node.parentTId) {
return false;
@@ -62,23 +62,23 @@ var tree = {
}
}
},
- newFile: function() {
+ newFile: function () {
$("#dirRMenu").hide();
var name = prompt("Name", "");
if (!name) {
return false;
}
- var request = {
- path: wide.curNode.path + '\\' + name,
- fileType: "f"
- };
+ var request = newWideRequest();
+ request.path = wide.curNode.path + '\\' + name;
+ request.fileType = "f";
+
$.ajax({
type: 'POST',
url: '/file/new',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (!data.succ) {
return false;
}
@@ -126,23 +126,23 @@ var tree = {
}
});
},
- newDir: function() {
+ newDir: function () {
$("#dirRMenu").hide();
var name = prompt("Name", "");
if (!name) {
return false;
}
- var request = {
- path: wide.curNode.path + '\\' + name,
- fileType: "d"
- };
+ var request = newWideRequest();
+ request.path = wide.curNode.path + '\\' + name;
+ request.fileType = "d";
+
$.ajax({
type: 'POST',
url: '/file/new',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (!data.succ) {
return false;
}
@@ -154,22 +154,23 @@ var tree = {
}
});
},
- removeIt: function() {
+ removeIt: function () {
$("#dirRMenu").hide();
$("#fileRMenu").hide();
if (!confirm("Remove it?")) {
return;
}
- var request = {
- path: wide.curNode.path
- };
+
+ var request = newWideRequest();
+ request.path = wide.curNode.path;
+
$.ajax({
type: 'POST',
url: '/file/remove',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (!data.succ) {
return false;
}
@@ -196,12 +197,15 @@ var tree = {
}
});
},
- init: function() {
+ init: function () {
+ var request = newWideRequest();
+
$.ajax({
- type: 'GET',
+ type: 'POST',
url: '/files',
+ data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (data.succ) {
var dirRMenu = $("#dirRMenu");
var fileRMenu = $("#fileRMenu");
@@ -210,7 +214,7 @@ var tree = {
selectedMulti: false
},
callback: {
- onRightClick: function(event, treeId, treeNode) {
+ onRightClick: function (event, treeId, treeNode) {
if (treeNode) {
wide.curNode = treeNode;
if ("ico-ztree-dir " !== treeNode.iconSkin) { // 如果右击了文件
@@ -230,7 +234,7 @@ var tree = {
}
}
},
- onClick: function(event, treeId, treeNode, clickFlag) {
+ onClick: function (event, treeId, treeNode, clickFlag) {
tree._onClick(treeNode);
}
}
@@ -240,7 +244,7 @@ var tree = {
}
});
},
- _onClick: function(treeNode) {
+ _onClick: function (treeNode) {
if (wide.curNode) {
for (var i = 0, ii = editors.data.length; i < ii; i++) {
// 该节点文件已经打开
@@ -256,15 +260,15 @@ var tree = {
wide.curNode = treeNode;
if ("ico-ztree-dir " !== treeNode.iconSkin) { // 如果单击了文件
- var request = {
- path: treeNode.path
- };
+ var request = newWideRequest();
+ request.path = treeNode.path;
+
$.ajax({
type: 'POST',
url: '/file',
data: JSON.stringify(request),
dataType: "json",
- success: function(data) {
+ success: function (data) {
if (!data.succ) {
alert(data.msg);
diff --git a/static/js/wide.js b/static/js/wide.js
index 194615c..7662874 100644
--- a/static/js/wide.js
+++ b/static/js/wide.js
@@ -12,9 +12,8 @@ outputWS.onmessage = function(e) {
}
if ('run' === data.nextCmd) {
- var request = {
- executable: data.executable
- };
+ var request = newWideRequest();
+ request.executable = data.executable;
$.ajax({
type: 'POST',
@@ -80,7 +79,7 @@ var wide = {
},
init: function() {
this._initLayout();
-
+
this._initBottomWindowGroup();
$("body").bind("mousedown", function(event) {
@@ -101,10 +100,10 @@ var wide = {
},
saveFile: function() {
- var request = {
- file: $(".edit-header .current span:eq(0)").attr("title"),
- code: wide.curEditor.getValue()
- };
+ var request = newWideRequest();
+ request.file = $(".edit-header .current span:eq(0)").attr("title");
+ request.code = wide.curEditor.getValue();
+
$.ajax({
type: 'POST',
url: '/file/save',
@@ -128,10 +127,9 @@ var wide = {
},
// 构建 & 运行.
run: function() {
- var request = {
- file: $(".edit-header .current span:eq(0)").attr("title"),
- code: wide.curEditor.getValue()
- };
+ var request = newWideRequest();
+ request.file = $(".edit-header .current span:eq(0)").attr("title");
+ request.code = wide.curEditor.getValue();
// TODO: 修改 [构建&运行] 图标状态为不可用状态
@@ -148,9 +146,8 @@ var wide = {
});
},
goget: function() {
- var request = {
- file: $(".edit-header .current span:eq(0)").attr("title")
- };
+ var request = newWideRequest();
+ request.file = $(".edit-header .current span:eq(0)").attr("title");
$.ajax({
type: 'POST',
@@ -165,10 +162,9 @@ var wide = {
});
},
goinstall: function() {
- var request = {
- file: $(".edit-header .current span:eq(0)").attr("title"),
- code: wide.curEditor.getValue()
- };
+ var request = newWideRequest();
+ request.file = $(".edit-header .current span:eq(0)").attr("title");
+ request.code = wide.curEditor.getValue();
$.ajax({
type: 'POST',
@@ -186,12 +182,11 @@ var wide = {
var path = $(".edit-header .current span:eq(0)").attr("title");
var mode = wide.curNode.mode;
- var request = {
- file: path,
- code: wide.curEditor.getValue(),
- cursorLine: wide.curEditor.getCursor().line,
- cursorCh: wide.curEditor.getCursor().ch
- };
+ var request = newWideRequest();
+ request.file = path;
+ request.code = wide.curEditor.getValue();
+ request.cursorLine = wide.curEditor.getCursor().line;
+ request.cursorCh = wide.curEditor.getCursor().ch;
switch (mode) {
case "text/x-go":
diff --git a/user/sessions.go b/user/sessions.go
index 162596e..559be74 100644
--- a/user/sessions.go
+++ b/user/sessions.go
@@ -5,6 +5,7 @@ import (
"strconv"
"time"
+ "github.com/golang/glog"
"github.com/gorilla/sessions"
)
@@ -17,23 +18,55 @@ var Session = sessions.NewCookieStore([]byte("BEYOND"))
// Wide 会话,对应一个浏览器 tab.
type WideSession struct {
- Id string // 唯一标识
- State int // 状态
- Created time.Time // 创建时间
- Updated time.Time // 最近一次使用时间
+ Id string // 唯一标识
+ HTTPSessionId string // HTTP 会话 id
+ State int // 状态
+ Created time.Time // 创建时间
+ Updated time.Time // 最近一次使用时间
}
+type Sessions []*WideSession
+
+// 所有 Wide 会话集.
+var WideSessions Sessions
+
// 创建一个 Wide 会话.
-func NewSession() *WideSession {
+func (sessions *Sessions) New() *WideSession {
rand.Seed(time.Now().UnixNano())
id := strconv.Itoa(rand.Int())
now := time.Now()
- return &WideSession{
+ ret := &WideSession{
Id: id,
State: SessionStateActive,
Created: now,
Updated: now,
}
+
+ *sessions = append(*sessions, ret)
+
+ return ret
+}
+
+// 移除 Wide 会话.
+func (sessions *Sessions) Remove(sid string) {
+ for i, s := range *sessions {
+ if s.Id == sid {
+ *sessions = append((*sessions)[:i], (*sessions)[i+1:]...)
+
+ glog.V(3).Infof("Has [%d] wide sessions currently", len(*sessions))
+ }
+ }
+}
+
+// 移除 HTTP 会话关联的所有 Wide 会话.
+func (sessions *Sessions) RemoveByHTTPSid(httpSessionId string) {
+ for i, s := range *sessions {
+ if s.HTTPSessionId == httpSessionId {
+ *sessions = append((*sessions)[:i], (*sessions)[i+1:]...)
+
+ glog.V(3).Infof("Has [%d] wide sessions currently", len(*sessions))
+ }
+ }
}
diff --git a/view/index.html b/view/index.html
index 88df788..d8e2bfb 100644
--- a/view/index.html
+++ b/view/index.html
@@ -2,7 +2,7 @@
- {{.i18n.wide}} - {{.session.Id}}
+ {{.i18n.wide}}
@@ -168,11 +168,22 @@
+
+