Skip to content

Commit

Permalink
Add changing name to node options
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminaaron committed Dec 24, 2024
1 parent 3ee826a commit 462ec98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const canvasCtxMenuItems = [

const nodeHeaderCtxMenuItems = [
// { label: "Toggle View Mode", action: "ToggleViewModeAction" },
{ label: "Change name", action: "ChangeNameAction" },
{ label: "Delete Node", action: "DeleteNodeAction" },
{ label: "Duplicate Node", action: "DuplicateNodeAction",
submenu: [
Expand Down
5 changes: 5 additions & 0 deletions src/graph/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export class Node {
</div>`
}

setName(name) {
this.name = name
this.nodeDiv.querySelector(".title-box").textContent = name
}

postConstructor() {
let modalOpenBtn = document.querySelector(`#node-${this.id} .modal-open-btn`)
modalOpenBtn.addEventListener("click", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ <h2>HowTo</h2>
if (hasIncomingEdges) disabledItems.push("DuplicateNodeWithIncomingEdgesAction")
setupNodeHeaderContextMenu(event, disabledItems, action => {
switch (action) {
case "ChangeNameAction":
let name = prompt("New name", node.name)
if (name) node.setName(name)
break
case "DeleteNodeAction":
editor.removeNodeId(nodeDivId)
break
Expand Down

0 comments on commit 462ec98

Please sign in to comment.