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

Renaming issue #168

Merged
merged 7 commits into from
Sep 17, 2018
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
1 change: 0 additions & 1 deletion src/components/projecteditor/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/components/projecteditor/contractinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 45 additions & 20 deletions src/components/projecteditor/control/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<items.length;index++) {
const item = items[index];
if (this.props.router.panes.getWindowByItem(item).pane) {
return true;
const close = (items, cb) => {
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 = () => {
Expand Down Expand Up @@ -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);
});
});
};

Expand Down
1 change: 0 additions & 1 deletion src/components/projecteditor/deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/components/projecteditor/editor-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/projecteditor/editor-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/projecteditor/editor-constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
46 changes: 25 additions & 21 deletions src/components/projecteditor/editor-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bashlund I still believe we shouldn't make the decision for the user, restricting how long SC name can it be.

alert('Illegal contract name. Only A-Za-z0-9, dash (-) and underscore (_) allowed. Max 16 characters.');
return;
}
for(var index=0;index<this.contract.obj.args.length;index++) {
Expand Down Expand Up @@ -187,26 +191,27 @@ export default class ContractEditor extends Component {
return;
}
// Check if any affected windows are open.
if (this.props.router.control._anyContractItemsOpen(this.props.contract)) {
alert("Please close any editor, compile or deploy window which is open for this contract, then try again to rename it.");
return;
}

// 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.");
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 {
Expand Down Expand Up @@ -294,7 +299,6 @@ export default class ContractEditor extends Component {
<div class="superInputDark">
<label for="name">Name</label>
<input
disabled
id="name"
type="text"
onKeyUp={(e)=>{this.onChange(e, 'name')}}
Expand Down
5 changes: 5 additions & 0 deletions src/components/projecteditor/panes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down