Browse Source

update states on contract rename

cl-refactor
arkpar 10 years ago
parent
commit
16a778073c
  1. 7
      mix/CodeModel.cpp
  2. 2
      mix/CodeModel.h
  3. 9
      mix/qml/ProjectList.qml
  4. 39
      mix/qml/StateListModel.qml

7
mix/CodeModel.cpp

@ -258,11 +258,16 @@ void CodeModel::runCompilationJob(int _jobId)
CompiledContract* contract = new CompiledContract(cs, name, source);
QQmlEngine::setObjectOwnership(contract, QQmlEngine::CppOwnership);
result[name] = contract;
CompiledContract* prevContract = m_contractMap.value(name);
CompiledContract* prevContract = nullptr;
for (ContractMap::const_iterator c = m_contractMap.cbegin(); c != m_contractMap.cend(); ++c)
if (c.value()->documentId() == contract->documentId())
prevContract = c.value();
if (prevContract != nullptr && prevContract->contractInterface() != result[name]->contractInterface())
emit contractInterfaceChanged(name);
if (prevContract == nullptr)
emit newContractCompiled(name);
else if (prevContract->contract()->name() != name)
emit contractRenamed(contract->documentId(), prevContract->contract()->name(), name);
}
releaseContracts();
m_contractMap.swap(result);

2
mix/CodeModel.h

@ -165,6 +165,8 @@ signals:
void contractInterfaceChanged(QString _documentId);
/// Emitted if there is a new contract compiled for the first time
void newContractCompiled(QString _documentId);
/// Emitted if a contract name has been changed
void contractRenamed(QString _documentId, QString _oldName, QString _newName);
public slots:
/// Update code model on source code change

9
mix/qml/ProjectList.qml

@ -111,15 +111,16 @@ Item {
Connections {
target: codeModel
onCompilationComplete: {
if (modelData === "Contracts") {
onContractRenamed: {
if (modelData === "Contracts")
{
var ci = 0;
for (var si = 0; si < projectModel.listModel.count; si++) {
var document = projectModel.listModel.get(si);
if (document.isContract) {
var compiledDoc = codeModel.contractByDocumentId(document.documentId);
if (compiledDoc && compiledDoc.documentId === document.documentId && compiledDoc.contract.name !== document.name) {
document.name = compiledDoc.contract.name;
if (_documentId === document.documentId && _newName !== document.name) {
document.name = _newName;
projectModel.listModel.set(si, document);
sectionModel.set(ci, document);
}

39
mix/qml/StateListModel.qml

@ -128,6 +128,9 @@ Item {
onNewContractCompiled: {
stateListModel.addNewContracts();
}
onContractRenamed: {
stateListModel.renameContracts(_oldName, _newName);
}
}
StateDialog {
@ -206,11 +209,36 @@ Item {
return item;
}
function renameContracts(oldName, newName) {
var changed = false;
for(var c in codeModel.contracts) {
for (var s = 0; s < stateListModel.count; s++) {
var state = stateList[s];
for (var t = 0; t < state.transactions.length; t++) {
var transaction = state.transactions[t];
if (transaction.contractId === oldName) {
transaction.contractId = newName;
if (transaction.functionId === oldName)
transaction.functionId = newName;
changed = true;
state.transactions[t] = transaction;
}
}
stateListModel.set(s, state);
stateList[s] = state;
}
}
if (changed)
save();
}
function addNewContracts() {
//add new contracts for all states
var changed = false;
for(var c in codeModel.contracts) {
for (var s = 0; s < stateListModel.count; s++) {
var state = stateList[s];//toPlainStateItem(stateListModel.get(s));
var state = stateList[s];
for (var t = 0; t < state.transactions.length; t++) {
var transaction = state.transactions[t];
if (transaction.functionId === c && transaction.contractId === c)
@ -223,13 +251,14 @@ Item {
ctorTr.contractId = c;
ctorTr.sender = state.accounts[0].secret;
state.transactions.push(ctorTr);
var item = state;//fromPlainStateItem(state);
stateListModel.set(s, item);
stateList[s] = item;
changed = true;
stateListModel.set(s, state);
stateList[s] = state;
}
}
}
save();
if (changed)
save();
}
function addState() {

Loading…
Cancel
Save