From 4e86fa1570760143bb55843ad0fb2a1cacf3a73b Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Tue, 1 Aug 2017 23:05:28 +0200 Subject: [PATCH] dev-environment: add ctrl+alt+R shortcut to reload styles --- src/js/app.js | 5 +++++ src/js/service/keyboard/Shortcuts.js | 4 ++++ src/js/utils/Environment.js | 4 ++++ src/piskel-boot.js | 11 ++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/js/app.js b/src/js/app.js index 3ef2718..8e63091 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -201,6 +201,11 @@ dialogId : 'unsupported-browser' }); } + + if (pskl.utils.Environment.isDebug()) { + pskl.app.shortcutService.registerShortcut(pskl.service.keyboard.Shortcuts.DEBUG.RELOAD_STYLES, + window.reloadStyles); + } }, loadPiskel_ : function (piskelData) { diff --git a/src/js/service/keyboard/Shortcuts.js b/src/js/service/keyboard/Shortcuts.js index 0a27bca..2c26f62 100644 --- a/src/js/service/keyboard/Shortcuts.js +++ b/src/js/service/keyboard/Shortcuts.js @@ -84,6 +84,10 @@ '123456789'.split(''), '1 to 9') }, + DEBUG : { + RELOAD_STYLES : createShortcut('move-left', 'Move viewport left', 'ctrl+alt+R'), + }, + CATEGORIES : ['TOOL', 'SELECTION', 'MISC', 'STORAGE', 'COLOR'] }; })(); diff --git a/src/js/utils/Environment.js b/src/js/utils/Environment.js index a2987ac..c3d635e 100644 --- a/src/js/utils/Environment.js +++ b/src/js/utils/Environment.js @@ -23,6 +23,10 @@ isIntegrationTest : function () { return window.location.href.indexOf('integration-test') !== -1; + }, + + isDebug : function () { + return window.location.href.indexOf('debug') !== -1; } }; diff --git a/src/piskel-boot.js b/src/piskel-boot.js index 644cf46..5ce1e66 100644 --- a/src/piskel-boot.js +++ b/src/piskel-boot.js @@ -68,12 +68,21 @@ }; loadScript('piskel-script-list.js', 'loadNextScript()'); + var styles; window.loadStyles = function () { - var styles = window.pskl_exports.styles; + styles = window.pskl_exports.styles; for (var i = 0 ; i < styles.length ; i++) { loadStyle(styles[i]); } }; + + window.reloadStyles = function () { + for (var i = 0 ; i < styles.length ; i++) { + document.querySelector('link[href="' + styles[i] + '"]').remove(); + loadStyle(styles[i]); + } + }; + loadScript('piskel-style-list.js', 'loadStyles()'); } else { var script;