diff --git a/Projects/Foundations/Icons-SVG-Sources/menu/create-reference.svg b/Projects/Foundations/Icons-SVG-Sources/menu/create-reference.svg new file mode 100644 index 000000000..0ef162664 --- /dev/null +++ b/Projects/Foundations/Icons-SVG-Sources/menu/create-reference.svg @@ -0,0 +1,258 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/Projects/Foundations/Icons/create-reference.png b/Projects/Foundations/Icons/create-reference.png new file mode 100644 index 000000000..beed8f3e4 Binary files /dev/null and b/Projects/Foundations/Icons/create-reference.png differ diff --git a/Projects/Foundations/UI/Spaces/Floating-Space/ListSelector.js b/Projects/Foundations/UI/Spaces/Floating-Space/ListSelector.js index 2339da76f..9ffcc847b 100644 --- a/Projects/Foundations/UI/Spaces/Floating-Space/ListSelector.js +++ b/Projects/Foundations/UI/Spaces/Floating-Space/ListSelector.js @@ -47,8 +47,8 @@ function newListSelector() { const SIZE = 36 const FONT_SIZE = 24 - const VISIBLE_LABELS = 7 - let selected = Math.ceil(VISIBLE_LABELS / 2) - 1 + let VISIBLE_LABELS = 7 + let selected = 0 let wheelDeltaDirection let wheelDeltaCounter = 0 @@ -102,6 +102,15 @@ function newListSelector() { optionsList = listValues + if (optionsList.length < 1) { + thisObject.payload.uiObject.setErrorMessage("No Valid List Entries Found") + deactivate() + } + + if (optionsList.length < VISIBLE_LABELS) { + VISIBLE_LABELS = optionsList.length + } + EDITOR_ON_FOCUS = true } @@ -150,8 +159,8 @@ function newListSelector() { } selected = selected - event.delta - if (selected < Math.ceil(VISIBLE_LABELS / 2)) { selected = Math.ceil(VISIBLE_LABELS / 2) - 1 } - if (selected > optionsList.length - Math.ceil(VISIBLE_LABELS / 2)) { selected = optionsList.length - Math.ceil(VISIBLE_LABELS / 2) } + if (selected < 0) { selected = 0 } + if (selected > optionsList.length - VISIBLE_LABELS) { selected = optionsList.length - VISIBLE_LABELS } if (selected !== lastSelected) { lastSelected = selected @@ -180,7 +189,7 @@ function newListSelector() { if (pPoint.y >= upperBoundary && pPoint.y <= lowerBoundary) { - let clickedValue = (i - Math.floor(VISIBLE_LABELS / 2) + selected) + let clickedValue = (i + selected) let event = { point: pPoint, @@ -261,6 +270,7 @@ function newListSelector() { } } } + function drawForeground() { if (thisObject.visible === true) { @@ -271,10 +281,19 @@ function newListSelector() { for (let i = 0; i < VISIBLE_LABELS; i++) { - let index = i - Math.floor(VISIBLE_LABELS / 2) + selected + let index = i + selected let label = '' if (index >= 0 && index < optionsList.length) { - label = optionsList[index] + if (typeof(optionsList[index]) !== "string") { + label = optionsList[index].name + + if (optionsList[index].payload.uiObject.icon !== undefined) { + icon = optionsList[index].payload.uiObject.icon + } + + } else { + label = optionsList[index] + } } fontColor = UI_COLOR.BLACK fontSize = FONT_SIZE @@ -311,9 +330,14 @@ function newListSelector() { browserCanvasContext.fill(); let middleValue = Math.floor(VISIBLE_LABELS / 2) + let evenOffset = 0 - UI.projects.foundations.utilities.drawPrint.drawIcon(icon, 1 / 2, 1 / 2, - offset + SIZE, (i - middleValue) * rowHeight, SIZE, thisObject.container) - UI.projects.foundations.utilities.drawPrint.drawLabel(label, 1 / 2, 1 / 2, 0, (SIZE - fontSize) / 2 + (i - middleValue) * rowHeight, fontSize, thisObject.container, fontColor, undefined, undefined, opacity) + if (VISIBLE_LABELS % 2 === 0) { + evenOffset = rowHeight / 2 + } + + UI.projects.foundations.utilities.drawPrint.drawIcon(icon, 1 / 2, 1 / 2, - offset + SIZE, (i - middleValue) * rowHeight + evenOffset, SIZE, thisObject.container) + UI.projects.foundations.utilities.drawPrint.drawLabel(label, 1 / 2, 1 / 2, 0, (SIZE - fontSize) / 2 + (i - middleValue) * rowHeight + evenOffset, fontSize, thisObject.container, fontColor, undefined, undefined, opacity) } } } diff --git a/Projects/Foundations/UI/Spaces/Floating-Space/UiObjectConstructor.js b/Projects/Foundations/UI/Spaces/Floating-Space/UiObjectConstructor.js index 855aa10b7..9d0e92797 100644 --- a/Projects/Foundations/UI/Spaces/Floating-Space/UiObjectConstructor.js +++ b/Projects/Foundations/UI/Spaces/Floating-Space/UiObjectConstructor.js @@ -224,7 +224,7 @@ function newUiObjectConstructor() { return } - function addLeftIcons(menuItemsInitialValues, floatingObject, isPersonalData) { + function addLeftIcons(menuItemsInitialValues, floatingObject, schemaDocument) { menuItemsInitialValues.push( { action: 'Pin / Unpin', @@ -348,7 +348,7 @@ function newUiObjectConstructor() { ring: 2 } ) - if (isPersonalData !== true) { + if (schemaDocument.isPersonalData !== true) { menuItemsInitialValues.push( { action: 'Share', @@ -431,6 +431,23 @@ function newUiObjectConstructor() { ring: 3 } ) + if (schemaDocument.referencingRules !== undefined) { + menuItemsInitialValues.push( + { + action: 'Create Reference', + actionFunction: floatingObject.payload.executeAction, + actionProject: 'Visual-Scripting', + label: undefined, + visible: true, + iconPathOn: 'create-reference', + iconPathOff: 'create-reference', + rawRadius: 12, + targetRadius: 0, + currentRadius: 0, + ring: 3 + } + ) + } menuItemsInitialValues.push( { @@ -486,8 +503,14 @@ function newUiObjectConstructor() { uiObject.conditionEditor.initialize() } } + if (schemaDocument.referencingRules !== undefined) { + uiObject.listSelector = newListSelector() + uiObject.listSelector.isVisibleFunction = uiObject.isVisibleFunction + uiObject.listSelector.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.listSelector.initialize() + } if (schemaDocument.addLeftIcons === true) { - addLeftIcons(menuItemsInitialValues, floatingObject, schemaDocument.isPersonalData) + addLeftIcons(menuItemsInitialValues, floatingObject, schemaDocument) } if (schemaDocument.isPinned === true) { floatingObject.isPinned = true diff --git a/Projects/Governance/UI/Function-Libraries/PluginsFunctions.js b/Projects/Governance/UI/Function-Libraries/PluginsFunctions.js index 2eaf1b188..ccf09dd35 100644 --- a/Projects/Governance/UI/Function-Libraries/PluginsFunctions.js +++ b/Projects/Governance/UI/Function-Libraries/PluginsFunctions.js @@ -29,7 +29,7 @@ function newGovernanceFunctionLibraryPluginsFunctions() { } function addSpecifiedUserProfile(node, rootNodes) { - let action = { node: node} + let action = { node: node } let projectName = UI.projects.communityPlugins.utilities.plugins.getProjectName(node) if (projectName === "" || projectName === undefined) { diff --git a/Projects/Visual-Scripting/UI/Function-Libraries/ActionSwitch.js b/Projects/Visual-Scripting/UI/Function-Libraries/ActionSwitch.js index 785bb7a46..c6c900d8a 100644 --- a/Projects/Visual-Scripting/UI/Function-Libraries/ActionSwitch.js +++ b/Projects/Visual-Scripting/UI/Function-Libraries/ActionSwitch.js @@ -193,6 +193,11 @@ function newVisualScriptingActionSwitch() { UI.projects.visualScripting.functionLibraries.attachDetach.referenceDetachNode(action.node) } break + case 'Create Reference': + { + UI.projects.visualScripting.functionLibraries.attachDetach.createReference(action.node, action.rootNodes) + } + break default: { console.log("[WARN] Action sent to Visual-Scripting Action Switch does not belong here. Verify at the App Schema file of the node that triggered this action that the actionProject is pointing to the right project. -> Action = " + action.name + " -> Action Node Name = " + action.node.name) diff --git a/Projects/Visual-Scripting/UI/Function-Libraries/ReferenceAttachDetach.js b/Projects/Visual-Scripting/UI/Function-Libraries/ReferenceAttachDetach.js index 0a685a711..477f051f4 100644 --- a/Projects/Visual-Scripting/UI/Function-Libraries/ReferenceAttachDetach.js +++ b/Projects/Visual-Scripting/UI/Function-Libraries/ReferenceAttachDetach.js @@ -2,7 +2,8 @@ function newVisualScriptingFunctionLibraryReferenceAttachDetach() { let thisObject = { referenceDetachNode: referenceDetachNode, - referenceAttachNode: referenceAttachNode + referenceAttachNode: referenceAttachNode, + createReference: createReference } return thisObject @@ -18,6 +19,35 @@ function newVisualScriptingFunctionLibraryReferenceAttachDetach() { completeAttachment(node, attachToNode) } + function createReference(node, rootNodes) { + + let action = { node: node } + let allNodesFound = [] + + let schemaDocument = getSchemaDocument(node) + let workspaceRootNodes = UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes + + let compatibleTypes = schemaDocument.referencingRules.compatibleTypes.split('->').filter(i => i) + + for (let i = 0; i < compatibleTypes.length; i++) { + for (let j = 0; j < workspaceRootNodes.length; j++) { + let rootNode = workspaceRootNodes[j] + if (rootNode !== null) { + let nodeArray = UI.projects.visualScripting.utilities.branches.nodeBranchToArray(rootNode, compatibleTypes[i]) + allNodesFound = allNodesFound.concat(nodeArray) + } + } + } + + let eventSubscriptionId = node.payload.uiObject.container.eventHandler.listenToEvent('listSelectorClicked', onListSelect) + node.payload.uiObject.listSelector.activate(action, allNodesFound, eventSubscriptionId) + + function onListSelect(event) { + referenceAttachNode(node, event.selectedNode) + node.payload.uiObject.container.eventHandler.stopListening('listSelectorClicked') + } + } + // Store the path to the reference parent to make restoring it possible if the reference parent is updated and given a new id function storeAttachNodePath(node, attachToNode) { if (node === undefined) { return }