Keyboard shortcut settings

This commit is contained in:
Benoit Schweblin 2013-09-30 18:37:58 -04:00
parent 1229f9f06d
commit d861987d9b
7 changed files with 83 additions and 66 deletions

View File

@ -130,6 +130,9 @@ define([
utils.setInputValue("#textarea-settings-publish-pdf-template", settings.pdfTemplate); utils.setInputValue("#textarea-settings-publish-pdf-template", settings.pdfTemplate);
// SSH proxy // SSH proxy
utils.setInputValue("#input-settings-ssh-proxy", settings.sshProxy); utils.setInputValue("#input-settings-ssh-proxy", settings.sshProxy);
// Load shortcuts settings
shortcutMgr.loadSettings();
// Load extension settings // Load extension settings
eventMgr.onLoadSettings(); eventMgr.onLoadSettings();
@ -584,6 +587,9 @@ define([
else { else {
document.body.innerHTML = bodyIndexHTML; document.body.innerHTML = bodyIndexHTML;
} }
// Populate shortcuts in settings
shortcutMgr.addSettingEntries();
// listen to online/offline events // listen to online/offline events
$(window).on('offline', core.setOffline); $(window).on('offline', core.setOffline);

View File

@ -34,7 +34,6 @@ define([
"extensions/buttonHtmlCode", "extensions/buttonHtmlCode",
"extensions/buttonViewer", "extensions/buttonViewer",
"extensions/welcomeTour", "extensions/welcomeTour",
"extensions/shortcutRecorder",
"extensions/userCustom", "extensions/userCustom",
"bootstrap", "bootstrap",
"jquery-waitforimages" "jquery-waitforimages"

View File

@ -1,24 +0,0 @@
define([
"jquery",
"underscore",
"classes/Extension",
"mousetrap",
"mousetrap-record",
], function($, _, Extension, mousetrap) {
var shortcutRecorder = new Extension("shortcutRecorder", "Shortcut recorder");
shortcutRecorder.onReady = function() {
$('.button-record-shortcut').click(function() {
var $button = $(this);
Mousetrap.record(function(sequence) {
$button.before(['<div class="alert alert-dismissable">',
'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>',
sequence.join(' '),
'</div>'].join());
});
});
};
return shortcutRecorder;
});

View File

@ -886,11 +886,11 @@
<li class="active"><a class="action-load-settings" <li class="active"><a class="action-load-settings"
href="#tabpane-settings-editor" data-toggle="tab">Editor</a></li> href="#tabpane-settings-editor" data-toggle="tab">Editor</a></li>
<li><a class="action-load-settings" <li><a class="action-load-settings"
href="#tabpane-settings-shortcuts" data-toggle="tab">Shortcuts</a></li> href="#tabpane-settings-services" data-toggle="tab">Services</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-publish" data-toggle="tab">Publish</a></li>
<li><a class="action-load-settings" <li><a class="action-load-settings"
href="#tabpane-settings-extensions" data-toggle="tab">Extensions</a></li> href="#tabpane-settings-extensions" data-toggle="tab">Extensions</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-shortcuts" data-toggle="tab">Shortcuts</a></li>
<li><a class="action-load-settings" <li><a class="action-load-settings"
href="#tabpane-settings-utils" data-toggle="tab">Utils</a></li> href="#tabpane-settings-utils" data-toggle="tab">Utils</a></li>
</ul> </ul>
@ -969,18 +969,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="tab-pane" id="tabpane-settings-shortcuts"> <div class="tab-pane" id="tabpane-settings-services">
<div class="form-horizontal">
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-settings-shortcut">Shortcut</label>
<div class="col-lg-7">
<button class="btn btn-default button-record-shortcut">Click to record</button>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="tabpane-settings-publish">
<div class="form-horizontal"> <div class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label class="col-lg-4 control-label" <label class="col-lg-4 control-label"
@ -1026,6 +1015,10 @@
href="https://github.com/benweet/stackedit/blob/master/doc/developer-guide.md#architecture">Create href="https://github.com/benweet/stackedit/blob/master/doc/developer-guide.md#architecture">Create
your own extension...</a></span> your own extension...</a></span>
</div> </div>
<div class="tab-pane" id="tabpane-settings-shortcuts">
<div class="form-horizontal">
</div>
</div>
<div class="tab-pane" id="tabpane-settings-utils"> <div class="tab-pane" id="tabpane-settings-utils">
<div class="tab-pane-button-container"> <div class="tab-pane-button-container">
<a href="#" <a href="#"

View File

@ -0,0 +1,13 @@
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-settings-shortcut-<%= shortcut.name %>"><%= shortcut.title %></label>
<div class="col-lg-8 form-inline">
<input type="text" id="input-settings-shortcut-<%= shortcut.name %>"
class="form-control col-lg-4">
<label class="col-lg-2 control-label"
for="input-settings-shortcut-<%= shortcut.name %>-mac">Mac</label>
<input type="text"
id="input-settings-shortcut-<%= shortcut.name %>-mac"
class="form-control col-lg-4">
</div>
</div>

View File

@ -2,7 +2,9 @@ define([
"underscore", "underscore",
"eventMgr", "eventMgr",
"settings", "settings",
], function(_, eventMgr, settings) { "utils",
"text!html/settingsShortcutEntry.html",
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
var shortcutMgr = {}; var shortcutMgr = {};
@ -16,7 +18,7 @@ define([
isPageDown: true isPageDown: true
}, },
'italic': { 'italic': {
name: 'Emphasis', title: 'Emphasis',
defaultKey: { defaultKey: {
win: 'Ctrl-I', win: 'Ctrl-I',
mac: 'Command-I|Ctrl-I', mac: 'Command-I|Ctrl-I',
@ -24,7 +26,7 @@ define([
isPageDown: true isPageDown: true
}, },
'link': { 'link': {
name: 'Hyperlink', title: 'Hyperlink',
defaultKey: { defaultKey: {
win: 'Ctrl-L', win: 'Ctrl-L',
mac: 'Command-L|Ctrl-L', mac: 'Command-L|Ctrl-L',
@ -32,7 +34,7 @@ define([
isPageDown: true isPageDown: true
}, },
'quote': { 'quote': {
name: 'Blockquote', title: 'Blockquote',
defaultKey: { defaultKey: {
win: 'Ctrl-Q', win: 'Ctrl-Q',
mac: 'Command-Q|Ctrl-Q', mac: 'Command-Q|Ctrl-Q',
@ -40,7 +42,7 @@ define([
isPageDown: true isPageDown: true
}, },
'code': { 'code': {
name: 'Code Sample', title: 'Code Sample',
defaultKey: { defaultKey: {
win: 'Ctrl-K', win: 'Ctrl-K',
mac: 'Command-K|Ctrl-K', mac: 'Command-K|Ctrl-K',
@ -48,7 +50,7 @@ define([
isPageDown: true isPageDown: true
}, },
'image': { 'image': {
name: 'Image', title: 'Image',
defaultKey: { defaultKey: {
win: 'Ctrl-G', win: 'Ctrl-G',
mac: 'Command-G|Ctrl-G', mac: 'Command-G|Ctrl-G',
@ -56,7 +58,7 @@ define([
isPageDown: true isPageDown: true
}, },
'olist': { 'olist': {
name: 'Numbered List', title: 'Numbered List',
defaultKey: { defaultKey: {
win: 'Ctrl-O', win: 'Ctrl-O',
mac: 'Command-O|Ctrl-O', mac: 'Command-O|Ctrl-O',
@ -64,7 +66,7 @@ define([
isPageDown: true isPageDown: true
}, },
'ulist': { 'ulist': {
name: 'Bulleted List', title: 'Bulleted List',
defaultKey: { defaultKey: {
win: 'Ctrl-U', win: 'Ctrl-U',
mac: 'Command-U|Ctrl-U', mac: 'Command-U|Ctrl-U',
@ -72,7 +74,7 @@ define([
isPageDown: true isPageDown: true
}, },
'heading': { 'heading': {
name: 'Heading', title: 'Heading',
defaultKey: { defaultKey: {
win: 'Ctrl-H', win: 'Ctrl-H',
mac: 'Command-H|Ctrl-H', mac: 'Command-H|Ctrl-H',
@ -80,7 +82,7 @@ define([
isPageDown: true isPageDown: true
}, },
'hr': { 'hr': {
name: 'Horizontal Rule', title: 'Horizontal Rule',
defaultKey: { defaultKey: {
win: 'Ctrl-R', win: 'Ctrl-R',
mac: 'Command-R|Ctrl-R', mac: 'Command-R|Ctrl-R',
@ -88,7 +90,7 @@ define([
isPageDown: true isPageDown: true
}, },
'undo': { 'undo': {
name: 'Undo', title: 'Undo',
defaultKey: { defaultKey: {
win: 'Ctrl-Z', win: 'Ctrl-Z',
mac: 'Command-Z', mac: 'Command-Z',
@ -101,8 +103,8 @@ define([
'redo': { 'redo': {
title: 'Redo', title: 'Redo',
defaultKey: { defaultKey: {
win: 'Ctrl-Shift-Z|Ctrl-Y', win: 'Ctrl-Y|Ctrl-Shift-Z',
mac: 'Command-Shift-Z|Command-Y', mac: 'Command-Y|Command-Shift-Z',
}, },
exec: function(editor) { exec: function(editor) {
editor.redo(); editor.redo();
@ -153,17 +155,6 @@ define([
}, },
multiSelectAction: "forEachLine" multiSelectAction: "forEachLine"
}, },
'indent': {
title: 'Sort Lines',
defaultKey: {
win: 'Ctrl-Alt-S',
mac: 'Command-Alt-S',
},
exec: function(editor) {
editor.sortLines();
},
multiSelectAction: "forEachLine"
},
'modifyNumberUp': { 'modifyNumberUp': {
title: 'Number Up', title: 'Number Up',
defaultKey: { defaultKey: {
@ -214,6 +205,28 @@ define([
}, },
readOnly: true readOnly: true
}, },
'findnext': {
title: 'Find Next',
defaultKey: {
win: 'Ctrl-P',
mac: 'Command-P',
},
exec: function(editor) {
editor.findNext();
},
readOnly: true
},
'findprevious': {
title: 'Find Previous',
defaultKey: {
win: 'Ctrl-Shift-P',
mac: 'Command-Shift-P',
},
exec: function(editor) {
editor.findPrevious();
},
readOnly: true
},
'togglerecording': { 'togglerecording': {
title: 'Toggle Recording', title: 'Toggle Recording',
defaultKey: { defaultKey: {
@ -249,5 +262,22 @@ define([
}); });
}; };
shortcutMgr.addSettingEntries = function() {
var shortcutEntries = _.reduce(shortcuts, function(result, shortcut) {
return result + _.template(settingsShortcutEntryHTML, {
shortcut: shortcut
});
}, '');
var settingsFormElement = document.querySelector('#tabpane-settings-shortcuts .form-horizontal');
settingsFormElement && (settingsFormElement.innerHTML = shortcutEntries);
};
shortcutMgr.loadSettings = function() {
_.each(shortcuts, function(shortcut) {
utils.setInputValue("#input-settings-shortcut-" + shortcut.name, shortcut.bindKey.win);
utils.setInputValue("#input-settings-shortcut-" + shortcut.name + '-mac', shortcut.bindKey.mac);
});
};
return shortcutMgr; return shortcutMgr;
}); });

View File

@ -455,9 +455,9 @@ body {
.close { .close {
position: absolute; position: absolute;
float: none; float: none;
line-height: 10px; line-height: 34px;
margin: 2px 0 2px -30px; margin: 2px 0 2px -30px;
padding: 0 8px 4px; padding: 0 8px;
font-weight: normal; font-weight: normal;
height: 34px; height: 34px;
} }