Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.contextMenu.tree.onClick = async (id) => {
// Custom callback?
const customItem = items.find(i => i.callback && i.id === id);
if (customItem) {
customItem.callback(asset);
return this.contextMenu.hide();
}
switch (id) {
// Rename the asset
case 'rename':
if (!component.onRenameAsset)
return;
const oldName = asset.name;
const newName = await Dialog.CreateWithTextInput('New asset name');
asset.name = newName;
component.onRenameAsset(asset, newName);
UndoRedo.Push({
fn: (type) => {
if (type === 'from')
component.onRenameAsset(asset, oldName);
else
component.onRenameAsset(asset, newName);
this.refresh();
this.showTab(component.id);
}
});
break;
protected async add (): Promise {
// Configure
GraphExtension.ClearNodes();
GraphExtension.RegisterNodes(this.node);
// Create data
const name = await Dialog.CreateWithTextInput('Graph Name');
const data: BehaviorGraph = {
name: name,
active: true,
graph: new LGraph().serialize()
};
this.datas.metadatas.push(data);
// Add to grid
this.grid.addRow({
recid: this.datas.metadatas.length - 1,
name: data.name,
active: true
});
// Select latest script
this.grid.select([this.datas.metadatas.length - 1]);
public async addAsset (component?: IAssetComponent): Promise> {
if (!component)
component = this.currentComponent;
if (component && component.onCreateAsset) {
const name = await Dialog.CreateWithTextInput('New asset name');
const asset = await component.onCreateAsset(name);
this.showTab(component.id);
this.refresh(component.id);
return asset;
}
return null;
}