This commit is contained in:
Liang Ding 2014-09-20 11:54:33 +08:00
parent 4b7fee14f4
commit 7d24c3adfa
9 changed files with 99 additions and 64 deletions

View File

@ -168,6 +168,11 @@ func NewFile(w http.ResponseWriter, r *http.Request) {
fileType := args["fileType"].(string) fileType := args["fileType"].(string)
if !createFile(path, fileType) { if !createFile(path, fileType) {
if "f" == fileType {
extension := filepath.Ext(path)
data["mode"] = getEditorMode(extension)
}
data["succ"] = false data["succ"] = false
} }
} }

View File

@ -22,6 +22,7 @@
"goinstall": "go install", "goinstall": "go install",
"build_n_run": "构建 & 运行", "build_n_run": "构建 & 运行",
"full_screen": "全屏", "full_screen": "全屏",
"unread_notification": "未读通知",
"notification_2": "没有检查到 gocode这将会导致 [自动完成] 失效", "notification_2": "没有检查到 gocode这将会导致 [自动完成] 失效",
"notification_3": "没有检查到 ide_stub这将会导致 [跳转到声明]、[查找使用] 失效" "notification_3": "没有检查到 ide_stub这将会导致 [跳转到声明]、[查找使用] 失效"
} }

View File

@ -77,9 +77,6 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
session.NotificationWS[sid] = &wsChan session.NotificationWS[sid] = &wsChan
ret := map[string]interface{}{"output": "Notification initialized", "cmd": "init-notification"}
wsChan.Conn.WriteJSON(&ret)
glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(session.NotificationWS)) glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(session.NotificationWS))
// 添加用户事件处理器 // 添加用户事件处理器
@ -100,14 +97,5 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
glog.Error("Notification WS ERROR: " + err.Error()) glog.Error("Notification WS ERROR: " + err.Error())
return return
} }
ret = map[string]interface{}{"output": "", "cmd": "notification-output"}
if err := wsChan.Conn.WriteJSON(&ret); err != nil {
glog.Error("Notification WS ERROR: " + err.Error())
return
}
wsChan.Time = time.Now()
} }
} }

View File

@ -234,7 +234,7 @@ ul {
} }
/* end editor */ /* end editor */
/* start output */ /* start bottom-window-group */
.bottom-window-group .tabs { .bottom-window-group .tabs {
background-color: #CAD3E3; background-color: #CAD3E3;
border-top: 1px solid #8E97A7; border-top: 1px solid #8E97A7;
@ -245,13 +245,39 @@ ul {
cursor: pointer; cursor: pointer;
} }
.bottom-window-group .tabs-panel {
height: 133px;
}
.bottom-window-group textarea { .bottom-window-group textarea {
border-width: 0; border-width: 0;
color: #555555; color: #555555;
height: 130px; height: 130px;
width: 100%; width: 100%;
} }
/* end output */
.bottom-window-group .notification,
.bottom-window-group .search,
.bottom-window-group .output {
height: 133px;
overflow: auto;
}
.bottom-window-group .notification > table {
width: 100%;
}
.bottom-window-group .notification td {
border-bottom: 1px solid #DDD;
line-height: 20px;
}
.bottom-window-group .notification .type,
.bottom-window-group .notification .severity {
width: 50px;
padding: 0 5px;
}
/* end bottom-window-group */
/* start footer */ /* start footer */
.notification-count { .notification-count {

View File

@ -267,6 +267,9 @@ var editors = {
"Ctrl-S": function () { "Ctrl-S": function () {
wide.saveFile(); wide.saveFile();
}, },
"Shift-Ctrl-S": function () {
wide.saveAllFiles();
},
"Shift-Alt-F": function () { "Shift-Alt-F": function () {
wide.fmt(); wide.fmt();
}, },

View File

@ -1,6 +1,6 @@
var notification = { var notification = {
init: function() { init: function () {
$(".notification-count").click(function() { $(".notification-count").click(function () {
wide.bottomWindowTab.setCurrent("notification"); wide.bottomWindowTab.setCurrent("notification");
$(".bottom-window-group .notification").focus(); $(".bottom-window-group .notification").focus();
$(this).hide(); $(this).hide();
@ -8,28 +8,32 @@ var notification = {
this._initWS(); this._initWS();
}, },
_initWS: function() { _initWS: function () {
var notificationWS = new WebSocket(config.channel.shell + '/notification/ws?sid=' + config.wideSessionId); var notificationWS = new WebSocket(config.channel.shell + '/notification/ws?sid=' + config.wideSessionId);
notificationWS.onopen = function() { notificationWS.onopen = function () {
console.log('[notification onopen] connected'); console.log('[notification onopen] connected');
}; };
notificationWS.onmessage = function(e) { notificationWS.onmessage = function (e) {
var data = JSON.parse(e.data); var data = JSON.parse(e.data),
if ('init-notification' !== data.cmd) { $notification = $('.bottom-window-group .notification > table'),
$(".notification-count").show(); notificationHTML = '';
$('.bottom-window-group .notification').text(
$('.bottom-window-group .notification').text() + data.output); notificationHTML += '<tr><td class="severity">' + data.severity
} + '</td><td class="message">' + data.message
+ '</td><td class="type">' + data.type + '</td></tr>';
$notification.append(notificationHTML);
$(".notification-count").show();
}; };
notificationWS.onclose = function(e) { notificationWS.onclose = function (e) {
console.log('[notification onclose] disconnected (' + e.code + ')'); console.log('[notification onclose] disconnected (' + e.code + ')');
delete notificationWS; delete notificationWS;
}; };
notificationWS.onerror = function(e) { notificationWS.onerror = function (e) {
console.log('[notification onerror] ' + e); console.log('[notification onerror] ' + e);
}; };
} }

View File

@ -121,7 +121,8 @@ var tree = {
tree.fileTree.addNodes(wide.curNode, [{ tree.fileTree.addNodes(wide.curNode, [{
"name": name, "name": name,
"iconSkin": iconSkin, "iconSkin": iconSkin,
"path": request.path "path": request.path,
"mode": data.mode
}]); }]);
} }
}); });

View File

@ -1,9 +1,9 @@
var outputWS = new WebSocket(config.channel.output + '/output/ws?sid=' + config.wideSessionId); var outputWS = new WebSocket(config.channel.output + '/output/ws?sid=' + config.wideSessionId);
outputWS.onopen = function() { outputWS.onopen = function () {
console.log('[output onopen] connected'); console.log('[output onopen] connected');
}; };
outputWS.onmessage = function(e) { outputWS.onmessage = function (e) {
console.log('[output onmessage]' + e.data); console.log('[output onmessage]' + e.data);
var data = JSON.parse(e.data); var data = JSON.parse(e.data);
@ -20,10 +20,10 @@ outputWS.onmessage = function(e) {
url: '/run', url: '/run',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
beforeSend: function(data) { beforeSend: function (data) {
$('.bottom-window-group .output').text(''); $('.bottom-window-group .output').text('');
}, },
success: function(data) { success: function (data) {
} }
}); });
@ -54,11 +54,11 @@ outputWS.onmessage = function(e) {
$('.bottom-window-group .output').text($('.bottom-window-group .output').text() + data.output); $('.bottom-window-group .output').text($('.bottom-window-group .output').text() + data.output);
} }
}; };
outputWS.onclose = function(e) { outputWS.onclose = function (e) {
console.log('[output onclose] disconnected (' + e.code + ')'); console.log('[output onclose] disconnected (' + e.code + ')');
delete outputWS; delete outputWS;
}; };
outputWS.onerror = function(e) { outputWS.onerror = function (e) {
console.log('[output onerror] ' + e); console.log('[output onerror] ' + e);
}; };
@ -66,26 +66,26 @@ var wide = {
curNode: undefined, curNode: undefined,
curEditor: undefined, curEditor: undefined,
bottomWindowTab: undefined, bottomWindowTab: undefined,
_initLayout: function() { _initLayout: function () {
var mainH = $(window).height() - $(".menu").height() - $(".footer").height() - 2; var mainH = $(window).height() - $(".menu").height() - $(".footer").height() - 2;
$(".content, .ztree").height(mainH); $(".content, .ztree").height(mainH);
$(".edit-panel").height(mainH - $(".bottom-window-group").height()); $(".edit-panel").height(mainH - $(".bottom-window-group").height());
}, },
_initBottomWindowGroup: function() { _initBottomWindowGroup: function () {
this.bottomWindowTab = new Tabs({ this.bottomWindowTab = new Tabs({
id: ".bottom-window-group", id: ".bottom-window-group",
clickAfter: function(id) { clickAfter: function (id) {
this._$tabsPanel.find("." + id).focus(); this._$tabsPanel.find("." + id).focus();
} }
}); });
}, },
init: function() { init: function () {
this._initLayout(); this._initLayout();
this._initBottomWindowGroup(); this._initBottomWindowGroup();
$("body").bind("mousedown", function(event) { $("body").bind("mousedown", function (event) {
if (!(event.target.id === "dirRMenu" || $(event.target).closest("#dirRMenu").length > 0)) { if (!(event.target.id === "dirRMenu" || $(event.target).closest("#dirRMenu").length > 0)) {
$("#dirRMenu").hide(); $("#dirRMenu").hide();
} }
@ -102,7 +102,7 @@ var wide = {
}); });
}, },
saveFile: function() { _save: function () {
var request = newWideRequest(); var request = newWideRequest();
request.file = $(".edit-header .current span:eq(0)").attr("title"); request.file = $(".edit-header .current span:eq(0)").attr("title");
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();
@ -112,24 +112,29 @@ var wide = {
url: '/file/save', url: '/file/save',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function(data) { success: function (data) {
} }
}); });
}, },
saveAllFiles: function() { saveFile: function () {
// TODO: save all files // 格式化后会对文件进行保存
this.fmt();
}, },
closeFile: function() { saveAllFiles: function () {
// TODO: save all files
console.log("TODO: ssave all files");
},
closeFile: function () {
// TODO: close file // TODO: close file
}, },
closeAllFiles: function() { closeAllFiles: function () {
// TODO: close all files // TODO: close all files
}, },
exit: function() { exit: function () {
// TODO: exit // TODO: exit
}, },
// 构建 & 运行. // 构建 & 运行.
run: function() { run: function () {
var request = newWideRequest(); var request = newWideRequest();
request.file = $(".edit-header .current span:eq(0)").attr("title"); request.file = $(".edit-header .current span:eq(0)").attr("title");
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();
@ -141,14 +146,14 @@ var wide = {
url: '/build', url: '/build',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
beforeSend: function(data) { beforeSend: function (data) {
$('.bottom-window-group .output').text(''); $('.bottom-window-group .output').text('');
}, },
success: function(data) { success: function (data) {
} }
}); });
}, },
goget: function() { goget: function () {
var request = newWideRequest(); var request = newWideRequest();
request.file = $(".edit-header .current span:eq(0)").attr("title"); request.file = $(".edit-header .current span:eq(0)").attr("title");
@ -157,14 +162,14 @@ var wide = {
url: '/go/get', url: '/go/get',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
beforeSend: function(data) { beforeSend: function (data) {
$('.bottom-window-group .output').text(''); $('.bottom-window-group .output').text('');
}, },
success: function(data) { success: function (data) {
} }
}); });
}, },
goinstall: function() { goinstall: function () {
var request = newWideRequest(); var request = newWideRequest();
request.file = $(".edit-header .current span:eq(0)").attr("title"); request.file = $(".edit-header .current span:eq(0)").attr("title");
request.code = wide.curEditor.getValue(); request.code = wide.curEditor.getValue();
@ -174,14 +179,14 @@ var wide = {
url: '/go/install', url: '/go/install',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
beforeSend: function(data) { beforeSend: function (data) {
$('.bottom-window-group .output').text(''); $('.bottom-window-group .output').text('');
}, },
success: function(data) { success: function (data) {
} }
}); });
}, },
fmt: function() { fmt: function () {
var path = $(".edit-header .current span:eq(0)").attr("title"); var path = $(".edit-header .current span:eq(0)").attr("title");
var mode = wide.curNode.mode; var mode = wide.curNode.mode;
@ -192,13 +197,13 @@ var wide = {
request.cursorCh = wide.curEditor.getCursor().ch; request.cursorCh = wide.curEditor.getCursor().ch;
switch (mode) { switch (mode) {
case "text/x-go": case "text/x-go": // 会保存文件
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/go/fmt', url: '/go/fmt',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function(data) { success: function (data) {
if (data.succ) { if (data.succ) {
wide.curEditor.setValue(data.code); wide.curEditor.setValue(data.code);
} }
@ -206,13 +211,13 @@ var wide = {
}); });
break; break;
case "text/html": case "text/html": // 会保存文件
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/html/fmt', url: '/html/fmt',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function(data) { success: function (data) {
if (data.succ) { if (data.succ) {
wide.curEditor.setValue(data.code); wide.curEditor.setValue(data.code);
} }
@ -226,7 +231,7 @@ var wide = {
var json = JSON.parse(wide.curEditor.getValue()); var json = JSON.parse(wide.curEditor.getValue());
wide.curEditor.setValue(JSON.stringify(json, "", " ")); wide.curEditor.setValue(JSON.stringify(json, "", " "));
this.save(); wide._save();
} catch (e) { } catch (e) {
delete e; delete e;
} }
@ -234,12 +239,14 @@ var wide = {
break; break;
default : default :
// TODO: XML 格式化处理 // TODO: XML 格式化处理
// 所有文件格式化后都需要进行保存
wide._save();
break; break;
} }
} }
}; };
$(document).ready(function() { $(document).ready(function () {
wide.init(); wide.init();
tree.init(); tree.init();
menu.init(); menu.init();

View File

@ -153,7 +153,7 @@
<div class="search" tabindex="-1"></div> <div class="search" tabindex="-1"></div>
</div> </div>
<div class="fn-none" data-index="notification"> <div class="fn-none" data-index="notification">
<textarea class="notification"></textarea> <div tabindex="-1" class="notification"><table cellpadding="0" cellspacing="0"></table></div>
</div> </div>
</div> </div>
</div> </div>
@ -163,7 +163,7 @@
<div class="footer"> <div class="footer">
<span>|</span> <span>|</span>
<span id="footer-cursor" style="float: right;"></span> <span id="footer-cursor" style="float: right;"></span>
<span class="notification-count" title="you have unread notification">N</span> <span class="notification-count" title="{{.i18n.unread_notification}}">Noty</span>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">