diff --git a/editor/js/ui/utils.js b/editor/js/ui/utils.js index 260db2b61..98159a9a6 100644 --- a/editor/js/ui/utils.js +++ b/editor/js/ui/utils.js @@ -50,7 +50,7 @@ RED.utils = (function() { } return result; } - function makeExpandable(el,onexpand) { + function makeExpandable(el,onexpand,expand) { el.addClass("debug-message-expandable"); el.click(function(e) { var parent = $(this).parent(); @@ -65,34 +65,111 @@ RED.utils = (function() { } e.preventDefault(); }); + if (expand) { + el.click(); + } } - function addMessageControls(obj,key,msg) { - var tools = $('').appendTo(obj); - var copyPath = $('').appendTo(tools).click(function(e) { + + var pinnedPaths = {}; + + + function addMessageControls(obj,sourceId,key,msg,rootPath,strippedKey) { + if (!pinnedPaths.hasOwnProperty(sourceId)) { + pinnedPaths[sourceId] = {} + } + var tools = $('').appendTo(obj); + var copyTools = $('').appendTo(tools); + var copyPath = $('').appendTo(copyTools).click(function(e) { e.preventDefault(); e.stopPropagation(); RED.clipboard.copyText(key,copyPath,"clipboard.copyMessagePath"); }) - var copyPayload = $('').appendTo(tools).click(function(e) { + var copyPayload = $('').appendTo(copyTools).click(function(e) { e.preventDefault(); e.stopPropagation(); RED.clipboard.copyText(msg,copyPayload,"clipboard.copyMessageValue"); }) + if (strippedKey !== '') { + var isPinned = pinnedPaths[sourceId].hasOwnProperty(strippedKey); + var pinPath = $('').appendTo(tools).click(function(e) { + e.preventDefault(); + e.stopPropagation(); + if (pinnedPaths[sourceId].hasOwnProperty(strippedKey)) { + delete pinnedPaths[sourceId][strippedKey]; + $(this).removeClass("selected"); + obj.removeClass("debug-message-row-pinned"); + } else { + var rootedPath = "$"+(strippedKey[0] === '['?"":".")+strippedKey; + pinnedPaths[sourceId][strippedKey] = normalisePropertyExpression(rootedPath); + $(this).addClass("selected"); + obj.addClass("debug-message-row-pinned"); + } + }).toggleClass("selected",isPinned); + obj.toggleClass("debug-message-row-pinned",isPinned); + } + } + function checkExpanded(strippedKey,expandPaths,minRange,maxRange) { + if (expandPaths && expandPaths.length > 0) { + if (strippedKey === '' && minRange === undefined) { + return true; + } + for (var i=0;i'); header = $('').appendTo(element); - addMessageControls(header,path,obj); + if (sourceId) { + addMessageControls(header,sourceId,path,obj,rootPath,strippedKey); + } if (!key) { element.addClass("debug-message-top-level"); + if (sourceId) { + var pinned = pinnedPaths[sourceId]; + expandPaths = []; + if (pinned) { + for (var pinnedPath in pinned) { + if (pinned.hasOwnProperty(pinnedPath)) { + try { + var res = getMessageProperty({$:obj},pinned[pinnedPath]); + if (res !== undefined) { + expandPaths.push(pinnedPath); + } + } catch(err) { + } + } + } + expandPaths.sort(); + } + } } else { if (!hideKey) { $('').text(key).appendTo(header); @@ -118,7 +195,7 @@ RED.utils = (function() { $('').html(typeHint||'string').appendTo(header); var row = $('').appendTo(element); $('
').text(obj).appendTo(row);
-                });
+                },checkExpanded(strippedKey,expandPaths));
             }
             e = $('').html('"'+formatString(sanitize(obj))+'"').appendTo(entryObj);
             if (/^#[0-9a-f]{6}$/i.test(obj)) {
@@ -205,7 +282,7 @@ RED.utils = (function() {
                     if (fullLength <= 10) {
                         for (i=0;i