Added shortcut for synchronize button

This commit is contained in:
benweet 2013-10-12 20:13:29 +01:00
parent 1de9571cd3
commit 94a0f30856
7 changed files with 52 additions and 16 deletions

View File

@ -19,7 +19,7 @@
"requirejs-text": "~2.0.10",
"bootstrap-tour": "~0.6.0",
"ace": "#51b7cb67a63998c9c0b7d089a85c60e032a7cc17",
"pagedown-ace": "git@github.com:benweet/pagedown-ace.git#master",
"pagedown-ace": "git@github.com:benweet/pagedown-ace.git#7805f240f343b5b2a05a5b9c0d4a3f5091e7a49b",
"pagedown-extra": "git@github.com:jmcmanus/pagedown-extra.git#cca554948c362affb1cbab3bacc3861e2d90d426",
"crel": "git@github.com:KoryNunn/crel.git#8dbda04b129fc0aec01a2a080d1cab26816e11c1",
"waitForImages": "git@github.com:alexanderdickson/waitForImages.git#~1.4.2",

View File

@ -24,7 +24,7 @@ var WELCOME_DOCUMENT_TITLE = "Welcome document";
var DOWNLOAD_PROXY_URL = "https://stackedit-download-proxy.herokuapp.com/";
var PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/";
var SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
var HTMLTOPDF_URL = "http://benweet.insomnia247.nl/stackedit-htmltopdf/";
var HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
// Use by Google's client.js
var delayedFunction = undefined;

View File

@ -473,7 +473,9 @@ define([
}
if(!lightMode) {
editor = new Markdown.Editor(converter);
editor = new Markdown.Editor(converter, undefined, {
keyStrokes: shortcutMgr.getPagedownKeyStrokes()
});
// Custom insert link dialog
editor.hooks.set("insertLinkDialog", function(callback) {
core.insertLinkCallback = callback;

View File

@ -4,21 +4,25 @@ define([
"crel",
"utils",
"classes/Extension",
"mousetrap",
"text!html/buttonSyncSettingsBlock.html",
], function($, _, crel, utils, Extension, buttonSyncSettingsBlockHTML) {
], function($, _, crel, utils, Extension, mousetrap, buttonSyncSettingsBlockHTML) {
var buttonSync = new Extension("buttonSync", 'Button "Synchronize"');
var buttonSync = new Extension("buttonSync", 'Button "Synchronize"', false, true);
buttonSync.settingsBlock = buttonSyncSettingsBlockHTML;
buttonSync.defaultConfig = {
syncPeriod: 180000
syncPeriod: 180000,
syncShortcut: 'mod+s'
};
buttonSync.onLoadSettings = function() {
utils.setInputValue("#input-sync-period", buttonSync.config.syncPeriod);
utils.setInputValue("#input-sync-shortcut", buttonSync.config.syncShortcut);
};
buttonSync.onSaveSettings = function(newConfig, event) {
newConfig.syncPeriod = utils.getInputIntValue("#input-sync-period", event, 0);
newConfig.syncShortcut = utils.getInputTextValue("#input-sync-shortcut", event);
};
var synchronizer = undefined;
@ -45,12 +49,10 @@ define([
// Run sync periodically
var lastSync = 0;
buttonSync.onPeriodicRun = function() {
if(viewerMode === true || !buttonSync.config.syncPeriod || lastSync + buttonSync.config.syncPeriod > utils.currentTime) {
if(!buttonSync.config.syncPeriod || lastSync + buttonSync.config.syncPeriod > utils.currentTime) {
return;
}
if(synchronizer.sync() === true) {
lastSync = utils.currentTime;
}
synchronizer.sync() && (lastSync = utils.currentTime);
};
buttonSync.onCreateButton = function() {
@ -60,9 +62,10 @@ define([
}, crel('i', {
class: 'icon-refresh'
}));
$button = $(button).click(function() {
if(!$(this).hasClass("disabled")) {
synchronizer.sync();
$button = $(button);
$button.click(function() {
if(!$button.hasClass("disabled")) {
synchronizer.sync() && (lastSync = utils.currentTime);
}
});
return button;
@ -84,6 +87,13 @@ define([
isOffline = isOfflineParameter;
updateButtonState();
};
buttonSync.onReady = function() {
mousetrap.bind(buttonSync.config.syncShortcut, function(e) {
synchronizer.sync() && (lastSync = utils.currentTime);
e.preventDefault();
});
};
return buttonSync;

View File

@ -8,4 +8,13 @@
class="col-lg-5 form-control" placeholder="180000"> ms
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label"
for="input-sync-shortcut">Sync
shortcut <a href="http://craig.is/killing/mice#keys" target="_blank">(?)</a></label>
<div class="col-lg-6">
<input type="text" id="input-sync-shortcut"
class="form-control">
</div>
</div>
</div>

View File

@ -261,6 +261,14 @@ define([
shortcut.exec && aceEditor.commands.addCommand(_.pick(shortcut, 'name', 'bindKey', 'exec', 'readOnly', 'multiSelectAction'));
});
};
shortcutMgr.getPagedownKeyStrokes = function() {
return _.chain(shortcuts).where({
isPageDown: true
}).map(function(shortcut) {
return [shortcut.name, shortcut.bindKey];
}).object().value();
};
shortcutMgr.addSettingEntries = function() {
var shortcutEntries = _.reduce(shortcuts, function(result, shortcut) {

View File

@ -171,16 +171,23 @@ a {
.transition(~"background-color ease-in-out .15s, color ease-in-out .15s, z-index ease-in-out .15s");
}
.btn-default:hover {
.btn-default:hover,
.btn-default:focus,
.btn-default:active {
background-color: @btn-default-hover-bg;
}
.btn-primary:hover {
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
color: @btn-primary-color;
background-color: @btn-primary-hover-bg;
}
.btn-success:hover, .open .dropdown-toggle.btn-success {
.btn-success:hover,
.btn-success:focus,
.btn-success:active,
.open .dropdown-toggle.btn-success {
color: @btn-success-color;
background-color: @bg-navbar-hover !important; // important to override .nav > li > a:hover
}