diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js b/packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js index 5496ee1f4..4886deabb 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js @@ -160,33 +160,19 @@ RED.actionList = (function() { createDialog(); } dialog.slideDown(300); - searchInput.searchBox('value',v) + searchInput.searchBox('value',v); searchResults.editableList('empty'); results = []; var actions = RED.actions.list(); - actions.forEach(function (sc) { - var id = sc.id.replace(/^.*:/,""); - var key = "action-list."+id; - var translation = RED._(key); - if (translation !== key) { - sc.translation = translation; - } - }); actions.sort(function(A,B) { - var Aid = A.translation ? A.translation : A.id; - var Bid = B.translation ? B.translation : B.id; - return Aid.localeCompare(Bid); + var Akey = A.label; + var Bkey = B.label; + return Akey.localeCompare(Bkey); }); actions.forEach(function(action) { - if (action.translation) { - action.label = action.translation; - } - else { - action.label = action.id.replace(/:/,": ").replace(/-/g," ").replace(/(^| )./g,function() { return arguments[0].toUpperCase()}); - } action._label = action.label.toLowerCase(); - searchResults.editableList('addItem',action) - }) + searchResults.editableList('addItem',action); + }); RED.events.emit("actionList:open"); visible = true; } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js b/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js index c7c5dd950..4f0379adf 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/actions.js @@ -1,33 +1,39 @@ RED.actions = (function() { var actions = { - } + }; - function addAction(name,handler) { + function addAction(name,handler,options) { if (typeof handler !== 'function') { throw new Error("Action handler not a function"); } if (actions[name]) { throw new Error("Cannot override existing action"); } - actions[name] = handler; + actions[name] = { + handler: handler, + options: options, + }; } function removeAction(name) { - delete actions[name]; + delete actions[name].handler; } function getAction(name) { - return actions[name]; + return actions[name].handler; } function invokeAction() { var args = Array.prototype.slice.call(arguments); var name = args.shift(); if (actions.hasOwnProperty(name)) { - actions[name].apply(null, args); + var handler = actions[name].handler; + handler.apply(null, args); } } function listActions() { var result = []; + var missing = []; Object.keys(actions).forEach(function(action) { + var def = actions[action]; var shortcut = RED.keyboard.getShortcut(action); var isUser = false; if (shortcut) { @@ -35,13 +41,38 @@ RED.actions = (function() { } else { isUser = !!RED.keyboard.getUserShortcut(action); } + if (!def.label) { + var name = action; + var options = def.options; + var key = options ? options.label : undefined; + if (!key) { + key = "action-list." +name.replace(/^.*:/,""); + } + var label = RED._(key); + if (label === key) { + // no translation. convert `name` to description + label = name.replace(/(^.+:([a-z]))|(-([a-z]))/g, function() { + if (arguments[5] === 0) { + return arguments[2].toUpperCase(); + } else { + return " "+arguments[4].toUpperCase(); + } + }); + missing.push(key); + } + def.label = label; + } + //console.log("; missing:", missing); + result.push({ id:action, scope:shortcut?shortcut.scope:undefined, key:shortcut?shortcut.key:undefined, - user:isUser - }) - }) + user:isUser, + label: def.label, + options: def.options, + }); + }); return result; } return { diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js b/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js index c722d0411..cecb408bd 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js @@ -49,15 +49,15 @@ RED.keyboard = (function() { "]": 221, "{": 219,// <- QWERTY specific "}": 221 // <- QWERTY specific - } + }; var metaKeyCodes = { 16: true, 17: true, 18: true, 91: true, 93: true - } - var actionToKeyMap = {} + }; + var actionToKeyMap = {}; var defaultKeyMap = {}; // FF generates some different keycodes because reasons. @@ -65,7 +65,7 @@ RED.keyboard = (function() { 59:186, 61:187, 173:189 - } + }; function migrateOldKeymap() { // pre-0.18 @@ -80,7 +80,7 @@ RED.keyboard = (function() { } function getUserKey(action) { - return RED.settings.get('editor.keymap',{})[action] + return RED.settings.get('editor.keymap',{})[action]; } function mergeKeymaps(defaultKeymap, themeKeymap) { @@ -105,7 +105,7 @@ RED.keyboard = (function() { scope:scope, key:key, user:false - }) + }); } } } @@ -115,13 +115,13 @@ RED.keyboard = (function() { if (themeKeymap.hasOwnProperty(action)) { if (!themeKeymap[action].key) { // No key for this action - default is no keybinding - delete mergedKeymap[action] + delete mergedKeymap[action]; } else { mergedKeymap[action] = [{ scope: themeKeymap[action].scope || "*", key: themeKeymap[action].key, user: false - }] + }]; if (mergedKeymap[action][0].scope === "workspace") { mergedKeymap[action][0].scope = "red-ui-workspace"; } @@ -179,7 +179,7 @@ RED.keyboard = (function() { close: function() { RED.menu.refreshShortcuts(); } - }) + }); } function revertToDefault(action) { @@ -327,7 +327,7 @@ RED.keyboard = (function() { scope:scope, key:key, user:false - } + }; } if (!ondown) { var userAction = getUserKey(cbdown); @@ -350,7 +350,7 @@ RED.keyboard = (function() { } } } else { - keys.push([key,mod]) + keys.push([key,mod]); } var slot = handlers; for (i=0;i').appendTo(scope); scopeSelect.i18n(); @@ -495,7 +494,7 @@ RED.keyboard = (function() { scopeSelect.val(object.scope||'*'); scopeSelect.on("change", function() { keyInput.trigger("change"); - }) + }); var div = $('
').appendTo(scope); var okButton = $('').appendTo(div); @@ -521,10 +520,13 @@ RED.keyboard = (function() { id:object.id, scope:shortcut?shortcut.scope:undefined, key:shortcut?shortcut.key:undefined, - user:shortcut?shortcut.user:undefined - } + user:shortcut?shortcut.user:undefined, + + label: object.label, + options: object.options, + }; buildShortcutRow(container,obj); - }) + }); keyInput.trigger("focus"); } @@ -559,7 +561,7 @@ RED.keyboard = (function() { delete object.scope; } else { keyDiv.parent().removeClass("keyboard-shortcut-entry-unassigned"); - keyDiv.append(RED.keyboard.formatKey(key)) + keyDiv.append(RED.keyboard.formatKey(key)); $("").text(scope).appendTo(scopeDiv); object.key = key; object.scope = scope; @@ -572,7 +574,7 @@ RED.keyboard = (function() { userKeymap[object.id] = { scope:shortcut.scope, key:shortcut.key - } + }; RED.settings.set('editor.keymap',userKeymap); } } @@ -588,16 +590,7 @@ RED.keyboard = (function() { var item = $('
').appendTo(container); container.data('data',object); - var text = object.translation; - if (!object.translation) { - text = object.id.replace(/(^.+:([a-z]))|(-([a-z]))/g,function() { - if (arguments[5] === 0) { - return arguments[2].toUpperCase(); - } else { - return " "+arguments[4].toUpperCase(); - } - }); - } + var text = object.label; var label = $('
').addClass("keyboard-shortcut-entry-text").text(text).appendTo(item); var user = $('').prependTo(label); @@ -638,15 +631,9 @@ RED.keyboard = (function() { } else { filterValue = filterValue.replace(/\s/g,""); shortcutList.editableList('filter', function(data) { - var label; - if (data.translation) { - label = data.translation.toLowerCase(); - } - else { - label = data.id.toLowerCase().replace(/^.*:/,"").replace("-",""); - } + var label = data.label.toLowerCase(); return label.indexOf(filterValue) > -1; - }) + }); } } }); @@ -666,25 +653,10 @@ RED.keyboard = (function() { }); var shortcuts = RED.actions.list(); - var missing = []; - shortcuts.forEach(function (sc) { - var id = sc.id.replace(/^.*:/,""); - var key = "action-list."+id; - var translation = RED._(key); - - if (translation !== key) { - sc.translation = translation; - } - else { - missing.push(id); - } - }); - // console.log("; missing:", missing); - shortcuts.sort(function(A,B) { - var Aid = A.translation ? A.translation : A.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase(); - var Bid = B.translation ? B.translation : B.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase(); - return Aid.localeCompare(Bid); + var Akey = A.label; + var Bkey = B.label; + return Akey.localeCompare(Bkey); }); knownShortcuts = new Set(); shortcuts.forEach(function(s) {