diff --git a/static/js/editors.js b/static/js/editors.js index e86cb4c..a9cbdad 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -641,7 +641,7 @@ var editors = { wide.saveFile(); }, "Shift-Ctrl-S": function () { - wide.saveAllFiles(); + menu.saveAllFiles(); }, "Shift-Alt-F": function () { var currentPath = editors.getCurrentPath(); diff --git a/static/js/hotkeys.js b/static/js/hotkeys.js index 642a960..cad007a 100644 --- a/static/js/hotkeys.js +++ b/static/js/hotkeys.js @@ -417,7 +417,7 @@ var hotkeys = { } if (event.which === hotKeys.buildRun.which) { // F6 构建并运行 - wide.run(); + menu.run(); event.preventDefault(); return; diff --git a/static/js/menu.js b/static/js/menu.js index 376e017..b9a34f6 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -12,11 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ var menu = { init: function () { this.subMenu(); + this._initPreference(); + this._initAbout(); // 点击子菜单后消失 $(".frame li").click(function () { @@ -24,6 +26,34 @@ var menu = { $(".menu > ul > li > a, .menu > ul> li > span").removeClass("selected"); }); }, + _initAbout: function () { + $("#dialogAbout").load('/about', function () { + $("#dialogAbout").dialog({ + "modal": true, + "height": 460, + "width": 800, + "title": config.label.about, + "hideFooter": true, + "afterOpen": function () { + $.ajax({ + url: "http://rhythm.b3log.org/version/wide/latest", + type: "GET", + dataType: "jsonp", + jsonp: "callback", + success: function (data, textStatus) { + if ($("#dialogAbout .version").text() === data.wideVersion) { + $(".upgrade").text(config.label.uptodate); + } else { + $(".upgrade").html(config.label.new_version_available + config.label.colon + + "" + data.wideVersion + ""); + } + } + }); + } + }); + }); + }, disabled: function (list) { for (var i = 0, max = list.length; i < max; i++) { $(".menu li." + list[i]).addClass("disabled"); @@ -51,5 +81,292 @@ var menu = { $(this).addClass("selected"); }); }); - } + }, + openPreference: function () { + $("#dialogPreference").dialog("open"); + }, + saveAllFiles: function () { + if ($(".menu li.save-all").hasClass("disabled")) { + return false; + } + for (var i = 0, ii = editors.data.length; i < ii; i++) { + var path = tree.fileTree.getNodeByTId(editors.data[i].id).path; + var editor = editors.data[i].editor; + + if ("text/x-go" === editor.getOption("mode")) { + wide.fmt(path, editor); + } else { + wide._save(path, editor); + } + } + }, + closeAllFiles: function () { + if ($(".menu li.close-all").hasClass("disabled")) { + return false; + } + + // 设置全部关闭标识 + var removeData = []; + $(".edit-panel .tabs > div").each(function (i) { + if (i !== 0) { + removeData.push($(this).data("index")); + } + }); + $("#dialogCloseEditor").data("removeData", removeData); + // 开始关闭 + $(".edit-panel .tabs .ico-close:eq(0)").click(); + }, + exit: function () { + var request = newWideRequest(); + + $.ajax({ + type: 'POST', + url: '/logout', + data: JSON.stringify(request), + dataType: "json", + success: function (data) { + if (data.succ) { + window.location.href = "/login"; + } + } + }); + }, + openAbout: function () { + $("#dialogAbout").dialog("open"); + }, + goget: function () { + menu.saveAllFiles(); + + var currentPath = editors.getCurrentPath(); + if (!currentPath) { + return false; + } + + if ($(".menu li.go-get").hasClass("disabled")) { + return false; + } + + var request = newWideRequest(); + request.file = currentPath; + + $.ajax({ + type: 'POST', + url: '/go/get', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + bottomGroup.resetOutput(); + }, + success: function (data) { + } + }); + }, + goinstall: function () { + menu.saveAllFiles(); + + var currentPath = editors.getCurrentPath(); + if (!currentPath) { + return false; + } + + if ($(".menu li.go-install").hasClass("disabled")) { + return false; + } + + var request = newWideRequest(); + request.file = currentPath; + + $.ajax({ + type: 'POST', + url: '/go/install', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + bottomGroup.resetOutput(); + }, + success: function (data) { + } + }); + }, + // 测试. + test: function () { + menu.saveAllFiles(); + + var currentPath = editors.getCurrentPath(); + if (!currentPath) { + return false; + } + + if ($(".menu li.test").hasClass("disabled")) { + return false; + } + + var request = newWideRequest(); + request.file = currentPath; + + $.ajax({ + type: 'POST', + url: '/go/test', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + bottomGroup.resetOutput(); + }, + success: function (data) { + } + }); + }, + // 构建并运行. + run: function () { + menu.saveAllFiles(); + + var currentPath = editors.getCurrentPath(); + if (!currentPath) { + return false; + } + + if ($(".menu li.run").hasClass("disabled")) { + return false; + } + + if ($(".toolbars .ico-stop").length === 1) { + wide.stop(); + return false; + } + + var request = newWideRequest(); + request.file = currentPath; + request.code = wide.curEditor.getValue(); + request.nextCmd = "run"; + + $.ajax({ + type: 'POST', + url: '/build', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + bottomGroup.resetOutput(); + }, + success: function (data) { + $(".toolbars .ico-buildrun").addClass("ico-stop") + .removeClass("ico-buildrun").attr("title", config.label.stop); + } + }); + }, + // 构建 + build: function () { + menu.saveAllFiles(); + + var currentPath = editors.getCurrentPath(); + if (!currentPath) { + return false; + } + + if ($(".menu li.build").hasClass("disabled")) { + return false; + } + + var request = newWideRequest(); + request.file = currentPath; + request.code = wide.curEditor.getValue(); + request.nextCmd = ""; // 只构建,无下一步操作 + + $.ajax({ + type: 'POST', + url: '/build', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + bottomGroup.resetOutput(); + }, + success: function (data) { + } + }); + }, + _initPreference: function () { + $("#dialogPreference").load('/preference', function () { + + $("#dialogPreference input").keyup(function () { + var isChange = false; + $("#dialogPreference input").each(function () { + if ($(this).val() !== $(this).data("value")) { + isChange = true; + } + }); + + var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + if (isChange) { + $okBtn.prop("disabled", false); + } else { + $okBtn.prop("disabled", true); + } + }); + + $("#dialogPreference").dialog({ + "modal": true, + "height": 460, + "width": 800, + "title": config.label.perference, + "okText": config.label.apply, + "cancelText": config.label.cancel, + "afterOpen": function () { + var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + $okBtn.prop("disabled", true); + }, + "ok": function () { + var request = newWideRequest(), + $dialogPreference = $("#dialogPreference"), + $fontFamily = $dialogPreference.find("input[name=fontFamily]"), + $fontSize = $dialogPreference.find("input[name=fontSize]"), + $editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"), + $editorFontSize = $dialogPreference.find("input[name=editorFontSize]"), + $editorLineHeight = $dialogPreference.find("input[name=editorLineHeight]"), + $goFmt = $dialogPreference.find("input[name=goFmt]"), + $workspace = $dialogPreference.find("input[name=workspace]"), + $password = $dialogPreference.find("input[name=password]"), + $locale = $dialogPreference.find("input[name=locale]"); + + $.extend(request, { + "fontFamily": $fontFamily.val(), + "fontSize": $fontSize.val(), + "editorFontFamily": $editorFontFamily.val(), + "editorFontSize": $editorFontSize.val(), + "editorLineHeight": $editorLineHeight.val(), + "goFmt": $goFmt.val(), + "workspace": $workspace.val(), + "password": $password.val(), + "locale": $locale.val() + }); + + $.ajax({ + type: 'POST', + url: '/preference', + data: JSON.stringify(request), + success: function (data, textStatus, jqXHR) { + if (!data.succ) { + return false; + } + + $fontFamily.data("value", $fontFamily.val()); + $fontSize.data("value", $fontSize.val()); + $editorFontFamily.data("value", $editorFontFamily.val()); + $editorFontSize.data("value", $editorFontSize.val()); + $editorLineHeight.data("value", $editorLineHeight.val()); + $goFmt.data("value", $goFmt.val()); + $workspace.data("value", $workspace.val()); + $password.data("value", $password.val()); + $locale.data("value", $locale.val()); + + var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + $okBtn.prop("disabled", true); + } + }); + } + }); + + new Tabs({ + id: ".preference" + }); + }); + }, }; \ No newline at end of file diff --git a/static/js/tree.js b/static/js/tree.js index 96697df..9eadac6 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -239,6 +239,8 @@ var tree = { } } }); + + this._initSearch(); }, openFile: function (treeNode) { wide.curNode = treeNode; @@ -284,5 +286,61 @@ var tree = { } }); } + }, + _initSearch: function () { + $("#dialogSearchForm > input:eq(0)").keyup(function (event) { + var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + if (event.which === 13 && !$okBtn.prop("disabled")) { + $okBtn.click(); + } + + if ($.trim($(this).val()) === "") { + $okBtn.prop("disabled", true); + } else { + $okBtn.prop("disabled", false); + } + }); + + $("#dialogSearchForm > input:eq(1)").keyup(function (event) { + var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + if (event.which === 13 && !$okBtn.prop("disabled")) { + $okBtn.click(); + } + }); + + $("#dialogSearchForm").dialog({ + "modal": true, + "height": 62, + "width": 260, + "title": config.label.search, + "okText": config.label.search, + "cancelText": config.label.cancel, + "afterOpen": function () { + $("#dialogSearchForm > input:eq(0)").val('').focus(); + $("#dialogSearchForm > input:eq(1)").val(''); + $("#dialogSearchForm").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true); + }, + "ok": function () { + var request = newWideRequest(); + request.dir = wide.curNode.path; + request.text = $("#dialogSearchForm > input:eq(0)").val(); + request.extension = $("#dialogSearchForm > input:eq(1)").val(); + + $.ajax({ + type: 'POST', + url: '/file/search/text', + data: JSON.stringify(request), + dataType: "json", + success: function (data) { + if (!data.succ) { + return; + } + + $("#dialogSearchForm").dialog("close"); + editors.appendSearch(data.founds, 'founds', request.text); + } + }); + } + }); } }; \ No newline at end of file diff --git a/static/js/wide.js b/static/js/wide.js index a3cee74..aface28 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -361,177 +361,6 @@ var wide = { editor.focus(); } }); - - $("#dialogSearchForm > input:eq(0)").keyup(function (event) { - var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)"); - if (event.which === 13 && !$okBtn.prop("disabled")) { - $okBtn.click(); - } - - if ($.trim($(this).val()) === "") { - $okBtn.prop("disabled", true); - } else { - $okBtn.prop("disabled", false); - } - }); - - $("#dialogSearchForm > input:eq(1)").keyup(function (event) { - var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)"); - if (event.which === 13 && !$okBtn.prop("disabled")) { - $okBtn.click(); - } - }); - - $("#dialogSearchForm").dialog({ - "modal": true, - "height": 62, - "width": 260, - "title": config.label.search, - "okText": config.label.search, - "cancelText": config.label.cancel, - "afterOpen": function () { - $("#dialogSearchForm > input:eq(0)").val('').focus(); - $("#dialogSearchForm > input:eq(1)").val(''); - $("#dialogSearchForm").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true); - }, - "ok": function () { - var request = newWideRequest(); - request.dir = wide.curNode.path; - request.text = $("#dialogSearchForm > input:eq(0)").val(); - request.extension = $("#dialogSearchForm > input:eq(1)").val(); - - $.ajax({ - type: 'POST', - url: '/file/search/text', - data: JSON.stringify(request), - dataType: "json", - success: function (data) { - if (!data.succ) { - return; - } - - $("#dialogSearchForm").dialog("close"); - editors.appendSearch(data.founds, 'founds', request.text); - } - }); - } - }); - - $("#dialogAbout").load('/about', function () { - $("#dialogAbout").dialog({ - "modal": true, - "height": 460, - "width": 800, - "title": config.label.about, - "hideFooter": true, - "afterOpen": function () { - $.ajax({ - url: "http://rhythm.b3log.org/version/wide/latest", - type: "GET", - dataType: "jsonp", - jsonp: "callback", - success: function (data, textStatus) { - if ($("#dialogAbout .version").text() === data.wideVersion) { - $(".upgrade").text(config.label.uptodate); - } else { - $(".upgrade").html(config.label.new_version_available + config.label.colon - + "" + data.wideVersion + ""); - } - } - }); - } - }); - }); - }, - openPreference: function () { - $("#dialogPreference").dialog("open"); - }, - _initPreference: function () { - $("#dialogPreference").load('/preference', function () { - - $("#dialogPreference input").keyup(function () { - var isChange = false; - $("#dialogPreference input").each(function () { - if ($(this).val() !== $(this).data("value")) { - isChange = true; - } - }); - - var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); - if (isChange) { - $okBtn.prop("disabled", false); - } else { - $okBtn.prop("disabled", true); - } - }); - - $("#dialogPreference").dialog({ - "modal": true, - "height": 460, - "width": 800, - "title": config.label.perference, - "okText": config.label.apply, - "cancelText": config.label.cancel, - "afterOpen": function () { - var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); - $okBtn.prop("disabled", true); - }, - "ok": function () { - var request = newWideRequest(), - $dialogPreference = $("#dialogPreference"), - $fontFamily = $dialogPreference.find("input[name=fontFamily]"), - $fontSize = $dialogPreference.find("input[name=fontSize]"), - $editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"), - $editorFontSize = $dialogPreference.find("input[name=editorFontSize]"), - $editorLineHeight = $dialogPreference.find("input[name=editorLineHeight]"), - $goFmt = $dialogPreference.find("input[name=goFmt]"), - $workspace = $dialogPreference.find("input[name=workspace]"), - $password = $dialogPreference.find("input[name=password]"), - $locale = $dialogPreference.find("input[name=locale]"); - - $.extend(request, { - "fontFamily": $fontFamily.val(), - "fontSize": $fontSize.val(), - "editorFontFamily": $editorFontFamily.val(), - "editorFontSize": $editorFontSize.val(), - "editorLineHeight": $editorLineHeight.val(), - "goFmt": $goFmt.val(), - "workspace": $workspace.val(), - "password": $password.val(), - "locale": $locale.val() - }); - - $.ajax({ - type: 'POST', - url: '/preference', - data: JSON.stringify(request), - success: function (data, textStatus, jqXHR) { - if (!data.succ) { - return false; - } - - $fontFamily.data("value", $fontFamily.val()); - $fontSize.data("value", $fontSize.val()); - $editorFontFamily.data("value", $editorFontFamily.val()); - $editorFontSize.data("value", $editorFontSize.val()); - $editorLineHeight.data("value", $editorLineHeight.val()); - $goFmt.data("value", $goFmt.val()); - $workspace.data("value", $workspace.val()); - $password.data("value", $password.val()); - $locale.data("value", $locale.val()); - - var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); - $okBtn.prop("disabled", true); - } - }); - } - }); - - new Tabs({ - id: ".preference" - }); - }); }, _initLayout: function () { var mainH = $(window).height() - $(".menu").height() - $(".footer").height(), @@ -666,8 +495,6 @@ var wide = { this._initLayout(); - this._initPreference(); - $(window).resize(function () { wide._initLayout(); var editorDatas = editors.data, @@ -724,55 +551,9 @@ var wide = { wide._save(path, wide.curEditor); }, - saveAllFiles: function () { - if ($(".menu li.save-all").hasClass("disabled")) { - return false; - } - for (var i = 0, ii = editors.data.length; i < ii; i++) { - var path = tree.fileTree.getNodeByTId(editors.data[i].id).path; - var editor = editors.data[i].editor; - - if ("text/x-go" === editor.getOption("mode")) { - wide.fmt(path, editor); - } else { - wide._save(path, editor); - } - } - }, - closeAllFiles: function () { - if ($(".menu li.close-all").hasClass("disabled")) { - return false; - } - - // 设置全部关闭标识 - var removeData = []; - $(".edit-panel .tabs > div").each(function (i) { - if (i !== 0) { - removeData.push($(this).data("index")); - } - }); - $("#dialogCloseEditor").data("removeData", removeData); - // 开始关闭 - $(".edit-panel .tabs .ico-close:eq(0)").click(); - }, - exit: function () { - var request = newWideRequest(); - - $.ajax({ - type: 'POST', - url: '/logout', - data: JSON.stringify(request), - dataType: "json", - success: function (data) { - if (data.succ) { - window.location.href = "/login"; - } - } - }); - }, stop: function () { if ($(".toolbars .ico-buildrun").length === 1) { - wide.run(); + menu.run(); return false; } @@ -794,155 +575,6 @@ var wide = { } }); }, - // 构建. - build: function () { - wide.saveAllFiles(); - - var currentPath = editors.getCurrentPath(); - if (!currentPath) { - return false; - } - - if ($(".menu li.build").hasClass("disabled")) { - return false; - } - - var request = newWideRequest(); - request.file = currentPath; - request.code = wide.curEditor.getValue(); - request.nextCmd = ""; // 只构建,无下一步操作 - - $.ajax({ - type: 'POST', - url: '/build', - data: JSON.stringify(request), - dataType: "json", - beforeSend: function (data) { - bottomGroup.resetOutput(); - }, - success: function (data) { - } - }); - }, - // 构建并运行. - run: function () { - wide.saveAllFiles(); - - var currentPath = editors.getCurrentPath(); - if (!currentPath) { - return false; - } - - if ($(".menu li.run").hasClass("disabled")) { - return false; - } - - if ($(".toolbars .ico-stop").length === 1) { - wide.stop(); - return false; - } - - var request = newWideRequest(); - request.file = currentPath; - request.code = wide.curEditor.getValue(); - request.nextCmd = "run"; - - $.ajax({ - type: 'POST', - url: '/build', - data: JSON.stringify(request), - dataType: "json", - beforeSend: function (data) { - bottomGroup.resetOutput(); - }, - success: function (data) { - $(".toolbars .ico-buildrun").addClass("ico-stop") - .removeClass("ico-buildrun").attr("title", config.label.stop); - } - }); - }, - // 测试. - test: function () { - wide.saveAllFiles(); - - var currentPath = editors.getCurrentPath(); - if (!currentPath) { - return false; - } - - if ($(".menu li.test").hasClass("disabled")) { - return false; - } - - var request = newWideRequest(); - request.file = currentPath; - - $.ajax({ - type: 'POST', - url: '/go/test', - data: JSON.stringify(request), - dataType: "json", - beforeSend: function (data) { - bottomGroup.resetOutput(); - }, - success: function (data) { - } - }); - }, - goget: function () { - wide.saveAllFiles(); - - var currentPath = editors.getCurrentPath(); - if (!currentPath) { - return false; - } - - if ($(".menu li.go-get").hasClass("disabled")) { - return false; - } - - var request = newWideRequest(); - request.file = currentPath; - - $.ajax({ - type: 'POST', - url: '/go/get', - data: JSON.stringify(request), - dataType: "json", - beforeSend: function (data) { - bottomGroup.resetOutput(); - }, - success: function (data) { - } - }); - }, - goinstall: function () { - wide.saveAllFiles(); - - var currentPath = editors.getCurrentPath(); - if (!currentPath) { - return false; - } - - if ($(".menu li.go-install").hasClass("disabled")) { - return false; - } - - var request = newWideRequest(); - request.file = currentPath; - - $.ajax({ - type: 'POST', - url: '/go/install', - data: JSON.stringify(request), - dataType: "json", - beforeSend: function (data) { - bottomGroup.resetOutput(); - }, - success: function (data) { - } - }); - }, gofmt: function (path, editor) { var cursor = editor.getCursor(); var scrollInfo = editor.getScrollInfo(); @@ -1022,9 +654,6 @@ var wide = { wide._save(path, editor); } }, - openAbout: function () { - $("#dialogAbout").dialog("open"); - }, getClassBySuffix: function (suffix) { var iconSkin = "ico-ztree-other "; switch (suffix) { diff --git a/views/index.html b/views/index.html index 6713c77..b27ed61 100644 --- a/views/index.html +++ b/views/index.html @@ -31,14 +31,14 @@ {{.i18n.file}}
@@ -48,21 +48,21 @@ {{.i18n.run}}
@@ -90,7 +90,7 @@
-
  • +
  • {{.i18n.perference}}
  • @@ -111,7 +111,7 @@
  • {{.i18n.start_page}}
  • -
  • +
  • {{.i18n.about}}
  • @@ -154,7 +154,7 @@
    - + @@ -164,7 +164,7 @@
  • {{.i18n.close}}
  • -
  • +
  • {{.i18n.close_all_files}}