This commit is contained in:
Liang Ding 2015-05-11 15:46:17 +08:00
parent e3b5fbbfa8
commit e8c27e762f
12 changed files with 55 additions and 14 deletions

View File

@ -58,6 +58,7 @@ type User struct {
FontFamily string
FontSize string
Theme string
Keymap string // wide/vim
Created int64 // user create time in unix nano
Updated int64 // preference update time in unix nano
Lived int64 // the latest session activity in unix nano
@ -87,6 +88,7 @@ func NewUser(username, password, email, workspace string) *User {
return &User{Name: username, Password: password, Salt: salt, Email: email, Gravatar: gravatar, Workspace: workspace,
Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default",
Keymap: "wide",
Created: now, Updated: now, Lived: now,
Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px",
Theme: "wide", TabSize: "4"}}

View File

@ -10,6 +10,7 @@
"FontFamily": "Helvetica",
"FontSize": "13px",
"Theme": "default",
"Keymap": "wide",
"Created": 1414080000000000000,
"Updated": 1414080000000000000,
"Lived": 1414080000000000000,

View File

@ -126,6 +126,11 @@ func initUsers() {
os.Exit(-1)
}
// Compatibility upgrade (1.3.0): https://github.com/b3log/wide/issues/83
if "" == user.Keymap {
user.Keymap = "wide"
}
Users = append(Users, user)
}

View File

@ -177,5 +177,6 @@
"git_clone": "Git Clone",
"terms": "Terms",
"download": "Download",
"decompress": "Decompress"
"decompress": "Decompress",
"keymap": "Keymap"
}

View File

@ -177,5 +177,6 @@
"git_clone": "Git クローン",
"terms": "利用規約",
"download": "ダウンロード",
"decompress": "解凍する"
"decompress": "解凍する",
"keymap": "キーマップ"
}

View File

@ -177,5 +177,6 @@
"git_clone": "Git 克隆",
"terms": "使用条款",
"download": "下载",
"decompress": "解压缩"
"decompress": "解压缩",
"keymap": "快捷键"
}

View File

@ -177,5 +177,6 @@
"git_clone": "Git 克隆",
"terms": "使用條款",
"download": "下載",
"decompress": "解壓縮"
"decompress": "解壓縮",
"keymap": "快捷鍵"
}

View File

@ -96,6 +96,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
FontFamily string
FontSize string
GoFmt string
Keymap string
Workspace string
Username string
Password string
@ -119,6 +120,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
user.FontFamily = args.FontFamily
user.FontSize = args.FontSize
user.GoFormat = args.GoFmt
user.Keymap = args.Keymap
// XXX: disallow change workspace at present
// user.Workspace = args.Workspace
if user.Password != args.Password {

View File

@ -835,8 +835,7 @@ var editors = {
});
editor.on('changes', function (cm) {
if (cm.doc.isClean()) {
// 没有修改过
if (cm.doc.isClean()) { // no modification
$(".edit-panel .tabs > div").each(function () {
var $span = $(this).find("span:eq(0)");
if ($span.attr("title") === cm.options.path) {
@ -844,7 +843,6 @@ var editors = {
}
});
} else {
// 修改过
$(".edit-panel .tabs > div").each(function () {
var $span = $(this).find("span:eq(0)");
if ($span.attr("title") === cm.options.path) {
@ -858,6 +856,10 @@ var editors = {
editor.setOption("mode", data.mode);
editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]);
if ("wide" !== config.keymap) {
editor.setOption("keyMap", config.keymap);
}
if ("text/x-go" === data.mode || "application/json" === data.mode) {
editor.setOption("lint", true);
}

View File

@ -426,7 +426,8 @@ var menu = {
$editorFontSize = $dialogPreference.find("input[name=editorFontSize]"),
$editorLineHeight = $dialogPreference.find("input[name=editorLineHeight]"),
$editorTheme = $dialogPreference.find("select[name=editorTheme]"),
$editorTabSize = $dialogPreference.find("input[name=editorTabSize]");
$editorTabSize = $dialogPreference.find("input[name=editorTabSize]"),
$keymap = $dialogPreference.find("select[name=keymap]");
$.extend(request, {
"fontFamily": $fontFamily.val(),
@ -441,9 +442,14 @@ var menu = {
"editorFontSize": $editorFontSize.val(),
"editorLineHeight": $editorLineHeight.val(),
"editorTheme": $editorTheme.val(),
"editorTabSize": $editorTabSize.val()
"editorTabSize": $editorTabSize.val(),
"keymap": $keymap.val()
});
if (config.keymap !== $keymap.val()) {
window.location.reload();
}
$.ajax({
type: 'POST',
url: config.context + '/preference',
@ -466,6 +472,10 @@ var menu = {
$editorLineHeight.data("value", $editorLineHeight.val());
$editorTheme.data("value", $editorTheme.val());
$editorTabSize.data("value", $editorTabSize.val());
$keymap.data("value", $keymap.val());
// update the config
config.keymap = $keymap.val();
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
$okBtn.prop("disabled", true);

View File

@ -608,7 +608,8 @@
"wideSessionId": '{{.session.ID}}',
"editorTheme": '{{.user.Editor.Theme}}',
"latestSessionContent": {{.latestSessionContent}},
"editorTabSize": '{{.user.Editor.TabSize}}'
"editorTabSize": '{{.user.Editor.TabSize}}',
"keymap": '{{.user.Keymap}}'
};
// 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数.
function newWideRequest() {
@ -657,6 +658,8 @@
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/css/css.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/shell/shell.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/sql/sql.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/keymap/vim.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/lint/json-lint.js?{{.conf.StaticResourceVersion}}"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/lint/go-lint.js?{{.conf.StaticResourceVersion}}"></script>

View File

@ -9,6 +9,9 @@
<div data-index="gotool">
<span title="{{.i18n.gotool}}">{{.i18n.gotool}}</span>
</div>
<div data-index="keymap">
<span title="{{.i18n.keymap}}">{{.i18n.keymap}}</span>
</div>
<div data-index="user">
<span title="{{.i18n.user}}">{{.i18n.user}}</span>
</div>
@ -68,6 +71,15 @@
</select>
</label>
</div>
<div class="fn-none" data-index="keymap">
<label>
{{.i18n.keymap}}{{.i18n.colon}}
<select class="select" data-value="{{.user.Keymap}}" name="keymap">
<option name="wide" value="wide" {{if eq $.user.Keymap "wide"}}selected="selected"{{end}}>wide</option>
<option name="vim" value="vim" {{if eq $.user.Keymap "vim"}}selected="selected"{{end}}>vim</option>
</select>
</label>
</div>
<div class="fn-none" data-index="user">
<label>
{{.i18n.locale}}{{.i18n.colon}}