This commit is contained in:
Van 2014-11-18 10:03:08 +08:00
parent f74ee1cac4
commit 97a6b1b69f
6 changed files with 392 additions and 388 deletions

View File

@ -641,7 +641,7 @@ var editors = {
wide.saveFile();
},
"Shift-Ctrl-S": function () {
wide.saveAllFiles();
menu.saveAllFiles();
},
"Shift-Alt-F": function () {
var currentPath = editors.getCurrentPath();

View File

@ -417,7 +417,7 @@ var hotkeys = {
}
if (event.which === hotKeys.buildRun.which) { // F6 构建并运行
wide.run();
menu.run();
event.preventDefault();
return;

View File

@ -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
+ "<a href='" + data.wideDownload
+ "' target='_blank'>" + data.wideVersion + "</a>");
}
}
});
}
});
});
},
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"
});
});
},
};

View File

@ -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);
}
});
}
});
}
};

View File

@ -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
+ "<a href='" + data.wideDownload
+ "' target='_blank'>" + data.wideVersion + "</a>");
}
}
});
}
});
});
},
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) {

View File

@ -31,14 +31,14 @@
<span>{{.i18n.file}}</span>
<div class="frame">
<ul>
<li class="save-all disabled" onclick="wide.saveAllFiles()">
<li class="save-all disabled" onclick="menu.saveAllFiles()">
<span>{{.i18n.save_all_files}}</span>
</li>
<li class="close-all" onclick="wide.closeAllFiles()">
<li class="close-all" onclick="menu.closeAllFiles()">
<span>{{.i18n.close_all_files}}</span>
</li>
<li class="hr"></li>
<li onclick="wide.exit()">
<li onclick="menu.exit()">
<span>{{.i18n.exit}}</span>
</li>
</ul>
@ -48,21 +48,21 @@
<span>{{.i18n.run}}</span>
<div class="frame">
<ul>
<li class="build disabled" onclick="wide.build()">
<li class="build disabled" onclick="menu.build()">
<span>{{.i18n.build}}</span>
</li>
<li class="run disabled" onclick="wide.run()">
<li class="run disabled" onclick="menu.run()">
<span>{{.i18n.build_n_run}}</span>
</li>
<li class="hr"></li>
<li class="go-test disabled" onclick="wide.test()">
<li class="go-test disabled" onclick="menu.test()">
<span>{{.i18n.test}}</span>
</li>
<li class="hr"></li>
<li class="go-get disabled" onclick="wide.goget()">
<li class="go-get disabled" onclick="menu.goget()">
<span>{{.i18n.goget}}</span>
</li>
<li class="go-install disabled" onclick="wide.goinstall()">
<li class="go-install disabled" onclick="menu.goinstall()">
<span>{{.i18n.goinstall}}</span>
</li>
</ul>
@ -90,7 +90,7 @@
</ul>
</div>
</li>
<li onclick="wide.openPreference()">
<li onclick="meun.openPreference()">
<span>{{.i18n.perference}}</span>
</li>
<li>
@ -111,7 +111,7 @@
<li onclick="editors.openStartPage()">
<span>{{.i18n.start_page}}</span>
</li>
<li onclick="wide.openAbout()">
<li onclick="menu.openAbout()">
<span>{{.i18n.about}}</span>
</li>
</ul>
@ -154,7 +154,7 @@
<div class="edit-panel">
<div class="toolbars fn-none">
<span onclick="wide.run()" class="font-ico ico-buildrun" title="{{.i18n.build_n_run}}"></span>
<span onclick="menu.run()" class="font-ico ico-buildrun" title="{{.i18n.build_n_run}}"></span>
<span onclick="wide.saveFile()" title="{{.i18n.save}}" class="font-ico ico-save"></span>
<span onclick="wide.fmt(editors.getCurrentPath(), wide.curEditor)" class="ico-format font-ico" title="{{.i18n.format}}"></span>
<span class="font-ico ico-max" onclick="windows.maxEditor()" title="{{.i18n.max_editor}}"></span>
@ -164,7 +164,7 @@
<li onclick="editors.close()" title="{{.i18n.close}}">
<span>{{.i18n.close}}</span>
</li>
<li onclick="wide.closeAllFiles()" title="{{.i18n.close_all_files}}">
<li onclick="menu.closeAllFiles()" title="{{.i18n.close_all_files}}">
<span>{{.i18n.close_all_files}}</span>
</li>
<li onclick="editors.closeOther()" title="{{.i18n.close_other}}">