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,9 +58,10 @@ type User struct {
FontFamily string FontFamily string
FontSize string FontSize string
Theme string Theme string
Created int64 // user create time in unix nano Keymap string // wide/vim
Updated int64 // preference update time in unix nano Created int64 // user create time in unix nano
Lived int64 // the latest session activity in unix nano Updated int64 // preference update time in unix nano
Lived int64 // the latest session activity in unix nano
Editor *editor Editor *editor
LatestSessionContent *LatestSessionContent LatestSessionContent *LatestSessionContent
} }
@ -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, 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", Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default",
Keymap: "wide",
Created: now, Updated: now, Lived: now, Created: now, Updated: now, Lived: now,
Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px", Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px",
Theme: "wide", TabSize: "4"}} Theme: "wide", TabSize: "4"}}

View File

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

View File

@ -126,6 +126,11 @@ func initUsers() {
os.Exit(-1) 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) Users = append(Users, user)
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -133,7 +133,7 @@ var editors = {
} }
// set tree node selected // set tree node selected
var tId = tree.getTIdByPath(id); var tId = tree.getTIdByPath(id);
var node = tree.fileTree.getNodeByTId(tId); var node = tree.fileTree.getNodeByTId(tId);
tree.fileTree.selectNode(node); tree.fileTree.selectNode(node);
wide.curNode = node; wide.curNode = node;
@ -835,8 +835,7 @@ var editors = {
}); });
editor.on('changes', function (cm) { editor.on('changes', function (cm) {
if (cm.doc.isClean()) { if (cm.doc.isClean()) { // no modification
// 没有修改过
$(".edit-panel .tabs > div").each(function () { $(".edit-panel .tabs > div").each(function () {
var $span = $(this).find("span:eq(0)"); var $span = $(this).find("span:eq(0)");
if ($span.attr("title") === cm.options.path) { if ($span.attr("title") === cm.options.path) {
@ -844,7 +843,6 @@ var editors = {
} }
}); });
} else { } else {
// 修改过
$(".edit-panel .tabs > div").each(function () { $(".edit-panel .tabs > div").each(function () {
var $span = $(this).find("span:eq(0)"); var $span = $(this).find("span:eq(0)");
if ($span.attr("title") === cm.options.path) { if ($span.attr("title") === cm.options.path) {
@ -858,6 +856,10 @@ var editors = {
editor.setOption("mode", data.mode); editor.setOption("mode", data.mode);
editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]); 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) { if ("text/x-go" === data.mode || "application/json" === data.mode) {
editor.setOption("lint", true); editor.setOption("lint", true);
} }

View File

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

View File

@ -608,7 +608,8 @@
"wideSessionId": '{{.session.ID}}', "wideSessionId": '{{.session.ID}}',
"editorTheme": '{{.user.Editor.Theme}}', "editorTheme": '{{.user.Editor.Theme}}',
"latestSessionContent": {{.latestSessionContent}}, "latestSessionContent": {{.latestSessionContent}},
"editorTabSize": '{{.user.Editor.TabSize}}' "editorTabSize": '{{.user.Editor.TabSize}}',
"keymap": '{{.user.Keymap}}'
}; };
// 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数. // 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数.
function newWideRequest() { 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/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/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}}/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/json-lint.js?{{.conf.StaticResourceVersion}}"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/lint/go-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"> <div data-index="gotool">
<span title="{{.i18n.gotool}}">{{.i18n.gotool}}</span> <span title="{{.i18n.gotool}}">{{.i18n.gotool}}</span>
</div> </div>
<div data-index="keymap">
<span title="{{.i18n.keymap}}">{{.i18n.keymap}}</span>
</div>
<div data-index="user"> <div data-index="user">
<span title="{{.i18n.user}}">{{.i18n.user}}</span> <span title="{{.i18n.user}}">{{.i18n.user}}</span>
</div> </div>
@ -68,6 +71,15 @@
</select> </select>
</label> </label>
</div> </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"> <div class="fn-none" data-index="user">
<label> <label>
{{.i18n.locale}}{{.i18n.colon}} {{.i18n.locale}}{{.i18n.colon}}