diff --git a/conf/wide.json b/conf/wide.json index 51afa6f..4b19b1e 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -21,17 +21,16 @@ "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", "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\pkg", + "D:\\go\\src\\pkg", "D:\\go\\src\\pkg\\archive", "D:\\go\\src\\pkg\\archive\\tar", "D:\\go\\src\\pkg\\archive\\tar\\testdata" ], "files": [ - "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\1123", - "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\123\\q.exe", - "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello\\2.json", - "D:\\go\\src\\pkg\\archive\\tar\\testdata\\small.txt" + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\pkg\\time.go", + "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go" ], - "currentFile": "D:\\go\\src\\pkg\\archive\\tar\\testdata\\small.txt" + "currentFile": "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go" } } ] diff --git a/static/css/base.css b/static/css/base.css index bdfd0ee..c1c9a3f 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -71,10 +71,14 @@ ul { content: "\e60b"; } -.icon-buildrun:before { +.ico-buildrun:before { content: "\e607"; } +.ico-stop:before { + content: "\e608"; +} + .ico-close { color: #666; } diff --git a/static/css/fonts/icomoon.eot b/static/css/fonts/icomoon.eot index 5f57e8c..8d8a97e 100644 Binary files a/static/css/fonts/icomoon.eot and b/static/css/fonts/icomoon.eot differ diff --git a/static/css/fonts/icomoon.svg b/static/css/fonts/icomoon.svg index 63163d8..5086ee8 100644 --- a/static/css/fonts/icomoon.svg +++ b/static/css/fonts/icomoon.svg @@ -15,6 +15,7 @@ + diff --git a/static/css/fonts/icomoon.ttf b/static/css/fonts/icomoon.ttf index 487a84c..aceb5d0 100644 Binary files a/static/css/fonts/icomoon.ttf and b/static/css/fonts/icomoon.ttf differ diff --git a/static/css/fonts/icomoon.woff b/static/css/fonts/icomoon.woff index 9207ffd..983654b 100644 Binary files a/static/css/fonts/icomoon.woff and b/static/css/fonts/icomoon.woff differ diff --git a/static/js/editor.js b/static/js/editor.js index cc43e1b..ea410a5 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -35,7 +35,7 @@ var editors = { wide.curNode = undefined; wide.curEditor = undefined; - $(".ico-fullscreen").hide(); + $(".toolbars").hide(); return false; } @@ -207,7 +207,7 @@ var editors = { }, // 新建一个编辑器 Tab,如果已经存在 Tab 则切换到该 Tab. newEditor: function (data) { - $(".ico-fullscreen").show(); + $(".toolbars").show(); var id = wide.curNode.tId; // 光标位置 diff --git a/static/js/wide.js b/static/js/wide.js index 3dc71f7..fd6791e 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -1,93 +1,29 @@ -var outputWS = new WebSocket(config.channel.output + '/output/ws?sid=' + config.wideSessionId); -outputWS.onopen = function() { - console.log('[output onopen] connected'); -}; - -outputWS.onmessage = function(e) { - console.log('[output onmessage]' + e.data); - var data = JSON.parse(e.data); - - if (goLintFound) { - goLintFound = []; - } - - if ('run' === data.nextCmd) { - var request = newWideRequest(); - request.executable = data.executable; - - $.ajax({ - type: 'POST', - url: '/run', - data: JSON.stringify(request), - dataType: "json", - beforeSend: function(data) { - $('.bottom-window-group .output').text(''); - }, - success: function(data) { - - } - }); - } - - if ('run' === data.cmd) { // 正在运行 - $('.bottom-window-group .output').text($('.bottom-window-group .output').text() + data.output); - } else if ('run-done' === data.cmd) { // 运行结束 - // TODO: 运行结束后修改 [构建&运行] 图标状态为可用状态 - } else if ('build' === data.cmd || 'go install' === data.cmd) { - $('.bottom-window-group .output').text(data.output); - - if (0 !== data.output.length) { // 说明编译有错误输出 - for (var i = 0; i < data.lints.length; i++) { - var lint = data.lints[i]; - - goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0), - to: CodeMirror.Pos(lint.lineNo, 0), - message: lint.msg, severity: lint.severity}); - } - - // TODO: 修改 [构建&运行] 图标状态为可用状态 - } - - // 触发一次 gutter lint - CodeMirror.signal(wide.curEditor, "change", wide.curEditor); - } else if ('go get' === data.cmd || 'go install' === data.cmd) { - $('.bottom-window-group .output').text($('.bottom-window-group .output').text() + data.output); - } -}; -outputWS.onclose = function(e) { - console.log('[output onclose] disconnected (' + e.code + ')'); - delete outputWS; -}; -outputWS.onerror = function(e) { - console.log('[output onerror] ' + e); -}; - var wide = { curNode: undefined, curEditor: undefined, bottomWindowTab: undefined, - _initDialog: function() { + _initDialog: function () { $("#dialogAlert").dialog({ "height": 26, "width": 260, "title": config.label.tip, "hiddenOk": true, "cancelText": config.label.confirm, - "afterOpen": function(msg) { + "afterOpen": function (msg) { $("#dialogAlert").html(msg); } }); - + $("#dialogRemoveConfirm").dialog({ "height": 26, "width": 260, "title": config.label.delete, "okText": config.label.delete, "cancelText": config.label.cancel, - "afterOpen": function() { + "afterOpen": function () { $("#dialogRemoveConfirm > b").html('"' + wide.curNode.name + '"'); }, - "ok": function() { + "ok": function () { var request = newWideRequest(); request.path = wide.curNode.path; @@ -96,7 +32,7 @@ var wide = { url: '/file/remove', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (!data.succ) { return false; } @@ -126,9 +62,9 @@ var wide = { } }); - $(".dialog-prompt > input").keydown(function(event) { + $(".dialog-prompt > input").keydown(function (event) { $(".dialog-prompt > .tip").text(''); - + if (event.which === 13) { $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)").click(); } @@ -140,10 +76,10 @@ var wide = { "title": config.label.create_file, "okText": config.label.create, "cancelText": config.label.cancel, - "afterOpen": function() { + "afterOpen": function () { $("#dialogNewFilePrompt > input").val('').focus(); }, - "ok": function() { + "ok": function () { var request = newWideRequest(), name = $("#dialogNewFilePrompt > input").val(); if ($.trim(name) === "") { @@ -159,7 +95,7 @@ var wide = { url: '/file/new', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (!data.succ) { return false; } @@ -216,10 +152,10 @@ var wide = { "title": config.label.create_dir, "okText": config.label.create, "cancelText": config.label.cancel, - "afterOpen": function() { + "afterOpen": function () { $("#dialogNewDirPrompt > input").val('').focus(); }, - "ok": function() { + "ok": function () { var name = $("#dialogNewDirPrompt > input").val(), request = newWideRequest(); if ($.trim(name) === "") { @@ -234,7 +170,7 @@ var wide = { url: '/file/new', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (!data.succ) { return false; } @@ -257,10 +193,10 @@ var wide = { "title": config.label.goto_line, "okText": config.label.goto, "cancelText": config.label.cancel, - "afterOpen": function() { + "afterOpen": function () { $("#dialogGoLinePrompt > input").val('').focus(); }, - "ok": function() { + "ok": function () { var line = parseInt($("#dialogGoLinePrompt > input").val()); if ($.trim(line) === "") { $("#dialogGoLinePrompt > .tip").text(config.label.input_no_empty); @@ -272,26 +208,93 @@ var wide = { } }); }, - _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() { + _initWS: function () { + var outputWS = new WebSocket(config.channel.output + '/output/ws?sid=' + config.wideSessionId); + outputWS.onopen = function () { + console.log('[output onopen] connected'); + }; + + outputWS.onmessage = function (e) { + console.log('[output onmessage]' + e.data); + var data = JSON.parse(e.data); + + if (goLintFound) { + goLintFound = []; + } + + if ('run' === data.nextCmd) { + var request = newWideRequest(); + request.executable = data.executable; + + $.ajax({ + type: 'POST', + url: '/run', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + $('.bottom-window-group .output').text(''); + }, + success: function (data) { + + } + }); + } + + if ('run' === data.cmd) { // 正在运行 + $('.bottom-window-group .output').text($('.bottom-window-group .output').text() + data.output); + } else if ('run-done' === data.cmd) { // 运行结束 + // TODO: 运行结束后修改 [构建&运行] 图标状态为可用状态 + } else if ('build' === data.cmd || 'go install' === data.cmd) { + $('.bottom-window-group .output').text(data.output); + + if (0 !== data.output.length) { // 说明编译有错误输出 + for (var i = 0; i < data.lints.length; i++) { + var lint = data.lints[i]; + + goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0), + to: CodeMirror.Pos(lint.lineNo, 0), + message: lint.msg, severity: lint.severity}); + } + + // TODO: 修改 [构建&运行] 图标状态为可用状态 + } + + // 触发一次 gutter lint + CodeMirror.signal(wide.curEditor, "change", wide.curEditor); + } else if ('go get' === data.cmd || 'go install' === data.cmd) { + $('.bottom-window-group .output').text($('.bottom-window-group .output').text() + data.output); + } + }; + outputWS.onclose = function (e) { + console.log('[output onclose] disconnected (' + e.code + ')'); + delete outputWS; + }; + outputWS.onerror = function (e) { + console.log('[output onerror] ' + e); + }; + }, + init: function () { + this._initWS(); + 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(); } @@ -309,7 +312,7 @@ var wide = { this._initDialog(); }, - _save: function() { + _save: function () { var request = newWideRequest(); request.file = $(".edit-header .current span:eq(0)").attr("title"); request.code = wide.curEditor.getValue(); @@ -319,51 +322,77 @@ var wide = { url: '/file/save', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { } }); }, - saveFile: function() { + saveFile: function () { // 格式化后会对文件进行保存 this.fmt(); }, - saveAllFiles: function() { + saveAllFiles: function () { // TODO: save all open files for (var i = 0, ii = editors.data.length; i < ii; i++) { } console.log("TODO: save all files"); }, - closeFile: function() { + closeFile: function () { // TODO: close file }, - closeAllFiles: function() { + closeAllFiles: function () { // TODO: close all files }, - exit: function() { + exit: function () { // TODO: exit }, + stop: function () { + if ($(".toolbars .ico-buildrun").length === 1) { + wide.run(); + return false; + } + + var request = newWideRequest(); + request.pid = 0; + + $.ajax({ + type: 'POST', + url: '/stop', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + $('.bottom-window-group .output').text(''); + }, + success: function (data) { + $(".toolbars .ico-stop").removeClass("ico-stop").addClass("ico-buildrun"); + } + }); + }, // 构建 & 运行. - run: function() { + run: function () { + if ($(".toolbars .ico-stop").length === 1) { + wide.stop(); + return false; + } + var request = newWideRequest(); request.file = $(".edit-header .current span:eq(0)").attr("title"); request.code = wide.curEditor.getValue(); - // TODO: 修改 [构建&运行] 图标状态为不可用状态 - $.ajax({ type: 'POST', 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) { + $(".toolbars .ico-buildrun").addClass("ico-stop").removeClass("ico-buildrun"); } }); }, - goget: function() { + goget: function () { var request = newWideRequest(); request.file = $(".edit-header .current span:eq(0)").attr("title"); @@ -372,14 +401,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(); @@ -389,14 +418,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.curEditor.getOption("mode"); @@ -413,7 +442,7 @@ var wide = { url: '/go/fmt', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (data.succ) { wide.curEditor.setValue(data.code); } @@ -427,7 +456,7 @@ var wide = { url: '/html/fmt', data: JSON.stringify(request), dataType: "json", - success: function(data) { + success: function (data) { if (data.succ) { wide.curEditor.setValue(data.code); } @@ -456,7 +485,7 @@ var wide = { } }; -$(document).ready(function() { +$(document).ready(function () { wide.init(); tree.init(); menu.init(); diff --git a/view/index.html b/view/index.html index dd6e973..ce82a8b 100644 --- a/view/index.html +++ b/view/index.html @@ -95,11 +95,11 @@ -
- +
+ - +