Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy & Paste support for Attached Literals #341

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/commands/NodeActionCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,33 @@ export function addNodeActionCommands(
label: trans.__('Add Comment')
});

function selectAllRelevantNodes(widget: XircuitsPanel){
widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities().forEach(entity => {
if(entity.getType() === 'custom-node'){
const node = (entity as CustomNodeModel);
// Find links to attached node and copy them too
Object.values(node.getPorts()).forEach(port => {
Object.values(port.getLinks()).forEach(link => {
const parentNode = link.getSourcePort().getParent();
if(parentNode.getOptions()?.extras?.attached){
parentNode.setSelected(true);
link.setSelected(true);
}
})
})
}
});

return widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities();
}

function cutNode(): void {
const widget = tracker.currentWidget?.content as XircuitsPanel;

if (!widget) return;

const engine = widget.xircuitsApp.getDiagramEngine();
const selected = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities()
const selected = selectAllRelevantNodes(widget);
const copies = selected.map(entity =>
entity.serialize()
);
Expand All @@ -536,9 +556,7 @@ export function addNodeActionCommands(

if (!widget) return;

const copies = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities().map(entity =>
entity.serialize(),
);
const copies = selectAllRelevantNodes(widget).map(entity => entity.serialize());

localStorage.setItem('clipboard', JSON.stringify(copies));
}
Expand Down Expand Up @@ -658,7 +676,7 @@ export function addNodeActionCommands(
clipboardLinks.forEach(serializedLink => {
const newSourceID = idMap[serializedLink.sourcePort];
const newTargetID = idMap[serializedLink.targetPort];

if (newSourceID && newTargetID) {
const { sourcePort, targetPort } = getSourceAndTargetPorts(model, newSourceID, newTargetID);
if(sourcePort && targetPort) recreateLink(engine, model, serializedLink, sourcePort, targetPort, mousePosition, centerX, centerY);
Expand Down
4 changes: 2 additions & 2 deletions src/dialog/FormDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const preventDefaultDialogHandler = (
event.stopPropagation();
event.preventDefault();
}
// When 'Enter' key is pressed while on input dialog and the input isn't Literal Chat, force focus to submit button
// When 'Enter' key is pressed while on input dialog and the input isn't Literal Chat or the attached checkbox, force focus to submit button
const dialogInput = dialog.node.getElementsByTagName('input')[0];
if (dialogInput && dialogInput.name !== 'messages') {
if (dialogInput && !['messages', 'attachNode'].includes(dialogInput.name)) {
await defaultButton.focus();
}
} else {
Expand Down
1 change: 0 additions & 1 deletion src/dialog/LiteralInputDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const LiteralInputDialog = ({ title, oldValue, type, inputType, attached,
const InputValueDialog = () => {
const [attach, setAttach] = useState(attached || false)
const InputComponent = inputComponents[inputType === 'textarea' ? inputType.toLowerCase() : type.toLowerCase()];
console.log("me seeks", InputComponent, showAttachOption);

// The `type` prop is now passed to all components
const extraProps = { type, inputType };
Expand Down
2 changes: 0 additions & 2 deletions src/tray_library/GeneralComponentLib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export async function handleLiteralInput(nodeName, nodeData, inputValue = "", ty
let attached = false;

do {
console.log("valuexxx", nodeConnections);

const isCreatingNewNode = nodeConnections === 0;
let dialogOptions = inputDialog({ title, oldValue: inputValue, type, attached: (nodeData.extras?.attached || false ), showAttachOption: !isCreatingNewNode});
let dialogResult = await showFormDialog(dialogOptions);
Expand Down