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)
if !createFile(path, fileType) {
if "f" == fileType {
extension := filepath.Ext(path)
data["mode"] = getEditorMode(extension)
}
data["succ"] = false
}
}

View File

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

View File

@ -77,9 +77,6 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
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))
// 添加用户事件处理器
@ -100,14 +97,5 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
glog.Error("Notification WS ERROR: " + err.Error())
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 */
/* start output */
/* start bottom-window-group */
.bottom-window-group .tabs {
background-color: #CAD3E3;
border-top: 1px solid #8E97A7;
@ -245,13 +245,39 @@ ul {
cursor: pointer;
}
.bottom-window-group .tabs-panel {
height: 133px;
}
.bottom-window-group textarea {
border-width: 0;
color: #555555;
height: 130px;
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 */
.notification-count {

View File

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

View File

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

View File

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

View File

@ -153,7 +153,7 @@
<div class="search" tabindex="-1"></div>
</div>
<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>
@ -163,7 +163,7 @@
<div class="footer">
<span>|</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>
<script type="text/javascript">