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

✨Add context menu option to open node's script #127

Merged
merged 1 commit into from
Mar 28, 2022
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
15 changes: 15 additions & 0 deletions src/commands/NodeActionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ export function addNodeActionCommands(
);
}

//Add command to open canvas's node its script
commands.addCommand(commandIDs.openScript, {
execute: () =>{
const widget = tracker.currentWidget?.content as XPipePanel;
const selectedEntities = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities();
_.forEach(selectedEntities, (model) => {
const filePath = model.extras.path
app.commands.execute(commandIDs.openDocManager, {
path: filePath
});
});
widget.xircuitsApp.getDiagramEngine().repaintCanvas();
}
});

//Add command to undo
commands.addCommand(commandIDs.undo, {
execute: () =>{
Expand Down
3 changes: 2 additions & 1 deletion src/components/xircuitBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const commandIDs = {
runXircuit: 'Xircuit-editor:run-node',
debugXircuit: 'Xircuit-editor:debug-node',
lockXircuit: 'Xircuit-editor:lock-node',
openScript: 'Xircuit-editor:open-node-script',
undo: 'Xircuit-editor:undo',
redo: 'Xircuit-editor:redo',
cutNode: 'Xircuit-editor:cut-node',
Expand Down Expand Up @@ -1693,7 +1694,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
if (current_node.header == "GENERAL") {
node = GeneralComponentLibrary({ name: data.name, color: current_node["color"], type: data.type });
} else if (current_node.header == "ADVANCED") {
node = new CustomNodeModel({ name: data.name, color: current_node["color"], extras: { "type": data.type } });
node = new CustomNodeModel({ name: data.name, color: data.color, extras: { "type": data.type, "path": data.path } });
node.addInPortEnhance('▶', 'in-0');
node.addOutPortEnhance('▶', 'out-0');

Expand Down
6 changes: 6 additions & 0 deletions src/context-menu/NodeActionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export class NodeActionsPanel extends React.Component<NodeActionsPanelProps> {
}}>
Edit
</div>
<div className="option"
onClick={() => {
this.props.app.commands.execute(commandIDs.openScript)
}}>
Open Script
</div>
<div className="option"
onClick={() => {
this.props.app.commands.execute(commandIDs.deleteNode)
Expand Down
2 changes: 1 addition & 1 deletion src/context-menu/TrayItemPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TrayItemPanel extends React.Component<TrayItemWidgetProps> {
if (current_node.header == "GENERAL") {
node = GeneralComponentLibrary({ name: current_node["task"], color: current_node["color"], type: current_node["type"] });
} else {
node = new CustomNodeModel({ name: current_node["task"], color: current_node["color"], extras: { "type": current_node["type"] } });
node = new CustomNodeModel({ name: current_node["task"], color: current_node["color"], extras: { "type": current_node["type"], "path": current_node["file_path"] } });
node.addInPortEnhance('▶', 'in-0');
node.addOutPortEnhance('▶', 'out-0');

Expand Down
11 changes: 9 additions & 2 deletions src/tray_library/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ export default function Sidebar(props: SidebarProps) {
<TrayItemWidget
model={{
type: componentVal.type,
name: componentVal.task
name: componentVal.task,
color: componentVal.color,
path: componentVal.file_path
}}
name={componentVal.task}
color={componentVal.color}
Expand All @@ -245,7 +247,12 @@ export default function Sidebar(props: SidebarProps) {
return (
<div key={`index-3-${i}`}>
<TrayItemWidget
model={{ type: val.type, name: val.task }}
model={{
type: val.type,
name: val.task,
color: val.color,
path: val.file_path
}}
name={val.task}
color={val.color}
app={props.lab}
Expand Down
2 changes: 1 addition & 1 deletion style/NodeActionPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

.option {
cursor: pointer;
width: 50px;
width: 70px;
height: 13px;
font-size:small;
padding: 5px 7px;
Expand Down