diff --git a/src/components/projecteditor/compiler.js b/src/components/projecteditor/compiler.js index 00df3a17..fbb0e63b 100644 --- a/src/components/projecteditor/compiler.js +++ b/src/components/projecteditor/compiler.js @@ -26,7 +26,6 @@ export default class Compiler extends Component { this.id=props.id+"_compiler"; this.props.parent.childComponent=this; this.consoleRows=[]; - const projectname=this.props.project.props.state.dir; this.dappfile = this.props.project.props.state.data.dappfile; this.run(); } diff --git a/src/components/projecteditor/contractinteraction.js b/src/components/projecteditor/contractinteraction.js index a5ada17a..ecb21e67 100644 --- a/src/components/projecteditor/contractinteraction.js +++ b/src/components/projecteditor/contractinteraction.js @@ -94,6 +94,7 @@ export default class ContractInteraction extends Component { render2 = () => { const env=this.state.network; const contract = this.dappfile.getItem("contracts", [{name: this.props.contract}]); + if (!contract) return; // This gets called twice, with the previous contract name, after renaming a contract. const src=contract.get('source'); const network=this.state.network; const endpoint=(this.props.functions.networks.endpoints[network] || {}).endpoint; diff --git a/src/components/projecteditor/control/control.js b/src/components/projecteditor/control/control.js index d514a83d..6281ed45 100644 --- a/src/components/projecteditor/control/control.js +++ b/src/components/projecteditor/control/control.js @@ -505,28 +505,51 @@ export default class Control extends Component { if(this.props.router.panes) this.props.router.panes.openItem(item); }; - _anyContractItemsOpen = (contractName) => { + _closeAnyContractItemsOpen = (contractName, includeConfigure, cb) => { const project = this.getActiveProject(); if(project) { // TODO: this lookup is bad since it depends on the order of the menu items. // TODO: look through project object for the contract named contractName, then get the item for the Editor, Compiler, Deployer and Interact window. const items = []; - const item = project.props.state.children[1].getChildren()[0].props.state._children[0]; + const item = project.props.state.children[1].getChildren()[0].props.state._children.filter( (item) => { + return item.props._contract && item.props._contract.name == contractName; + })[0]; + if (!item) { + if (cb) cb(2); + return; + } items.push(item); - items.push(item.props.state.children[0]); // Configure item + if (includeConfigure) { + items.push(item.props.state.children[0]); // Configure item + } items.push(item.props.state.children[1]); items.push(item.props.state.children[2]); items.push(item.props.state.children[3]); - console.log(items); - for(let index=0;index { + if (items.length == 0) { + if (cb) cb(0); + return; } - } + const item = items.pop(); + const {pane, winId} = this.props.router.panes.getWindowByItem(item); + if (pane && winId) { + this.props.router.panes.closeWindow(pane.id, winId, (status) => { + if (status != 0) { + if (cb) cb(status); + return; + } + close(items, cb); + }); + } + else { + close(items, cb); + } + }; + close(items, cb); + return; } - return false; + if (cb) cb(1); }; redraw = () => { @@ -917,18 +940,20 @@ export default class Control extends Component { e.stopPropagation(); if(!confirm("Really delete contract?")) return; const contract=projectItem.props.state.data.dappfile.contracts()[contractIndex]; - if (this._anyContractItemsOpen(contract.name)) { - alert("Could not delete contract, close editor/compiler/deployer/interaction windows and try again."); - return; - } - projectItem.deleteFile(contract.source, (status)=>{ - if(status>0) { - alert("Could not delete contract, close editor and try again."); + this._closeAnyContractItemsOpen(contract.name, true, (status) => { + if (status != 0) { + alert("Could not delete contract, close editor/compiler/deployer/interaction windows and try again."); return; } - projectItem.props.state.data.dappfile.contracts().splice(contractIndex,1); - projectItem.save(); - this.props.router.main.redraw(true); + projectItem.deleteFile(contract.source, (status)=>{ + if(status>0) { + alert("Could not delete contract, close editor and try again."); + return; + } + projectItem.props.state.data.dappfile.contracts().splice(contractIndex,1); + projectItem.save(); + this.props.router.main.redraw(true); + }); }); }; diff --git a/src/components/projecteditor/deployer.js b/src/components/projecteditor/deployer.js index 7d0d9810..0646e737 100644 --- a/src/components/projecteditor/deployer.js +++ b/src/components/projecteditor/deployer.js @@ -29,7 +29,6 @@ export default class Deployer extends Component { this.id=props.id+"_deployer"; this.props.parent.childComponent=this; this.consoleRows=[]; - const projectname=this.props.project.props.state.dir; this.dappfile = this.props.project.props.state.data.dappfile; this.recompile=this.props.recompile || false; this.redeploy=this.props.redeploy || false; diff --git a/src/components/projecteditor/editor-account.js b/src/components/projecteditor/editor-account.js index bd4cb0d5..b695052d 100644 --- a/src/components/projecteditor/editor-account.js +++ b/src/components/projecteditor/editor-account.js @@ -30,6 +30,10 @@ export default class AccountEditor extends Component { this.setEnv("browser"); } + componentWillReceiveProps(props) { + this.dappfile = props.project.props.state.data.dappfile; + } + componentDidMount() { this.redraw(); } diff --git a/src/components/projecteditor/editor-app.js b/src/components/projecteditor/editor-app.js index 7f9762d0..c9b15183 100644 --- a/src/components/projecteditor/editor-app.js +++ b/src/components/projecteditor/editor-app.js @@ -33,6 +33,10 @@ export default class AppEditor extends Component { this.setState({form:{title:this.project.info.title}}); } + componentWillReceiveProps(props) { + this.dappfile = props.project.props.state.data.dappfile; + } + componentDidMount() { this.redraw(); } diff --git a/src/components/projecteditor/editor-constant.js b/src/components/projecteditor/editor-constant.js index 87c43b31..b59797da 100644 --- a/src/components/projecteditor/editor-constant.js +++ b/src/components/projecteditor/editor-constant.js @@ -27,6 +27,10 @@ export default class AccountConstant extends Component { this.form={env:""}; } + componentWillReceiveProps(props) { + this.dappfile = props.project.props.state.data.dappfile; + } + componentDidMount() { this.redraw(); } diff --git a/src/components/projecteditor/editor-contract.js b/src/components/projecteditor/editor-contract.js index 30cec8cb..feee9ecf 100644 --- a/src/components/projecteditor/editor-contract.js +++ b/src/components/projecteditor/editor-contract.js @@ -119,6 +119,10 @@ export default class ContractEditor extends Component { this._originalsourcepath=this.contract.get("source"); } + componentWillReceiveProps(props) { + this.dappfile = props.project.props.state.data.dappfile; + } + componentDidMount() { this.redraw(); } @@ -145,8 +149,8 @@ export default class ContractEditor extends Component { alert('Error: Missing fields.'); return; } - if(!this.contract.obj.name.match(/^([a-zA-Z0-9-_]+)$/)) { - alert('Illegal contract name. Only A-Za-z0-9, dash (-) and underscore (_) allowed.'); + if(!this.contract.obj.name.match(/^([a-zA-Z0-9-_]+)$/) || this.contract.obj.name.length > 16) { + alert('Illegal contract name. Only A-Za-z0-9, dash (-) and underscore (_) allowed. Max 16 characters.'); return; } for(var index=0;index { - if (status == 4) { - // File doesn't exist (yet). - // Fall through - } - else if (status > 0) { - alert("Error: Could not rename contract source file. Please close the tab containing the contract's source code and try again."); + this.props.router.control._closeAnyContractItemsOpen(this.props.contract, false, (status) => { + if (status != 0) { + alert("Please close any editor, compile or deploy window which is open for this contract, then try again to rename it."); return; } - else { - alert("Warning: You must now manually rename the contract and the constructor in the source file to match the new file name, and finally the app.js file will need to be adjusted for the new contract name."); - } - finalize(); + // Rename the source file too. + const file=this.contract.get('source').match(".*/([^/]+$)")[1]; + this.props.project.renameFile(this._originalsourcepath, file, (status) => { + if (status == 4) { + // File doesn't exist (yet). + // Fall through + } + else if (status > 0) { + alert("Error: Could not rename contract source file. Please close the tab containing the contract's source code and try again."); + return; + } + else { + alert("Warning: You must now manually rename the contract and the constructor in the source file to match the new file name, if the contract is used as argument to any other contract that needs to be updated and finally the app.js content will need to be adjusted for the new contract name."); + } + finalize(); + }); }); } else { @@ -294,7 +299,6 @@ export default class ContractEditor extends Component {
{this.onChange(e, 'name')}} diff --git a/src/components/projecteditor/panes.js b/src/components/projecteditor/panes.js index f06c7309..d974c907 100644 --- a/src/components/projecteditor/panes.js +++ b/src/components/projecteditor/panes.js @@ -55,6 +55,11 @@ export default class Panes extends Component { pane.focusWindow(winId, rePerform, cb); }; + closeWindow = (paneId, winId, cb) => { + var {pane}=this.getPane(paneId); + pane.closeWindow(winId, cb); + }; + removePane = (id) => { this.panes = this.panes.filter((pane) => { return pane.id!=id;