Browse Source

- Remove contract source.

- Bug fix when when removing a project file.
cl-refactor
yann300 10 years ago
parent
commit
a62174b3ac
  1. 1
      mix/ClientModel.cpp
  2. 13
      mix/CodeModel.cpp
  3. 2
      mix/CodeModel.h
  4. 6
      mix/FileIo.cpp
  5. 2
      mix/FileIo.h
  6. 19
      mix/qml/CodeEditorView.qml
  7. 20
      mix/qml/FilesSection.qml
  8. 16
      mix/qml/js/ProjectModel.js
  9. 1
      mix/test/qml/TestMain.qml
  10. 14
      mix/test/qml/js/TestProject.js

1
mix/ClientModel.cpp

@ -315,7 +315,6 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
TransactionSettings stdTransaction = transaction; TransactionSettings stdTransaction = transaction;
stdTransaction.gasAuto = true; stdTransaction.gasAuto = true;
Address address = deployContract(stdContractCode, stdTransaction); Address address = deployContract(stdContractCode, stdTransaction);
deployedContracts.push_back(address);
m_stdContractAddresses[stdTransaction.contractId] = address; m_stdContractAddresses[stdTransaction.contractId] = address;
m_stdContractNames[address] = stdTransaction.contractId; m_stdContractNames[address] = stdTransaction.contractId;
} }

13
mix/CodeModel.cpp

@ -219,6 +219,19 @@ void CodeModel::reset(QVariantMap const& _documents)
emit scheduleCompilationJob(++m_backgroundJobId); emit scheduleCompilationJob(++m_backgroundJobId);
} }
void CodeModel::unregisterContractSrc(QString const& _documentId)
{
{
Guard pl(x_pendingContracts);
m_pendingContracts.erase(_documentId);
}
// launch the background thread
m_compiling = true;
emit stateChanged();
emit scheduleCompilationJob(++m_backgroundJobId);
}
void CodeModel::registerCodeChange(QString const& _documentId, QString const& _code) void CodeModel::registerCodeChange(QString const& _documentId, QString const& _code)
{ {
{ {

2
mix/CodeModel.h

@ -160,6 +160,8 @@ public:
Q_INVOKABLE CompiledContract* contractByDocumentId(QString const& _documentId) const; Q_INVOKABLE CompiledContract* contractByDocumentId(QString const& _documentId) const;
/// Reset code model /// Reset code model
Q_INVOKABLE void reset() { reset(QVariantMap()); } Q_INVOKABLE void reset() { reset(QVariantMap()); }
/// Delete a contract source
Q_INVOKABLE void unregisterContractSrc(QString const& _documentId);
/// Convert solidity type info to mix type /// Convert solidity type info to mix type
static SolidityType nodeType(dev::solidity::Type const* _type); static SolidityType nodeType(dev::solidity::Type const* _type);
/// Check if given location belongs to contract or function /// Check if given location belongs to contract or function

6
mix/FileIo.cpp

@ -210,3 +210,9 @@ void FileIo::stopWatching(QString const& _path)
{ {
m_watcher->removePath(pathFromUrl(_path)); m_watcher->removePath(pathFromUrl(_path));
} }
void FileIo::deleteFile(QString const& _path)
{
QFile file(pathFromUrl(_path));
file.remove();
}

2
mix/FileIo.h

@ -66,6 +66,8 @@ public:
Q_INVOKABLE void watchFileChanged(QString const& _path); Q_INVOKABLE void watchFileChanged(QString const& _path);
/// Stop Listenning for files change in @arg _path. /// Stop Listenning for files change in @arg _path.
Q_INVOKABLE void stopWatching(QString const& _path); Q_INVOKABLE void stopWatching(QString const& _path);
/// Delete a file
Q_INVOKABLE void deleteFile(QString const& _path);
private: private:
QString getHomePath() const; QString getHomePath() const;

19
mix/qml/CodeEditorView.qml

@ -190,9 +190,12 @@ Item {
for (var i = 0; i < openDocCount; i++) for (var i = 0; i < openDocCount; i++)
{ {
var doc = editorListModel.get(i); var doc = editorListModel.get(i);
var editor = editors.itemAt(i).item; if (editors.itemAt(i))
if (editor) {
fileIo.writeFile(doc.path, editor.getText()); var editor = editors.itemAt(i).item;
if (editor)
fileIo.writeFile(doc.path, editor.getText());
}
} }
} }
@ -315,6 +318,16 @@ Item {
break; break;
} }
} }
onDocumentRemoved: {
for (var i = 0; i < editorListModel.count; i++)
if (editorListModel.get(i).documentId === documentId)
{
editorListModel.remove(i);
openDocCount--;
break;
}
}
} }
function loadIfNotLoaded () { function loadIfNotLoaded () {

20
mix/qml/FilesSection.qml

@ -241,8 +241,13 @@ Rectangle
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked:{ onClicked:{
if (mouse.button === Qt.RightButton && !isContract) if (mouse.button === Qt.RightButton)
contextMenu.popup(); {
if (isContract)
contextMenuContract.popup();
else
contextMenu.popup();
}
else if (mouse.button === Qt.LeftButton) else if (mouse.button === Qt.LeftButton)
{ {
rootItem.isSelected = true; rootItem.isSelected = true;
@ -268,6 +273,17 @@ Rectangle
} }
} }
} }
Menu {
id: contextMenuContract
MenuItem {
text: qsTr("Delete")
onTriggered: {
projectModel.removeDocument(documentId);
wrapperItem.removeDocument(documentId);
}
}
}
} }
} }
} }

16
mix/qml/js/ProjectModel.js

@ -294,7 +294,10 @@ function renameDocument(documentId, newName) {
function getDocument(documentId) { function getDocument(documentId) {
var i = getDocumentIndex(documentId); var i = getDocumentIndex(documentId);
return projectListModel.get(i); if (i === -1)
return null;
else
return projectListModel.get(i);
} }
function getDocumentIdByName(fileName) function getDocumentIdByName(fileName)
@ -308,10 +311,13 @@ function getDocumentIdByName(fileName)
function removeDocument(documentId) { function removeDocument(documentId) {
var i = getDocumentIndex(documentId); var i = getDocumentIndex(documentId);
var document = projectListModel.get(i); var document = projectListModel.get(i);
if (!document.isContract) { fileIo.stopWatching(document.path);
projectListModel.remove(i); fileIo.deleteFile(document.path);
documentRemoved(documentId); if (document.isContract)
} codeModel.unregisterContractSrc(documentId);
projectListModel.remove(i);
saveProjectFile();
documentRemoved(documentId);
} }
function newHtmlFile() { function newHtmlFile() {

1
mix/test/qml/TestMain.qml

@ -113,5 +113,6 @@ TestCase
function test_project_contractRename() { TestProject.test_contractRename(); } function test_project_contractRename() { TestProject.test_contractRename(); }
function test_project_multipleWebPages() { TestProject.test_multipleWebPages(); } function test_project_multipleWebPages() { TestProject.test_multipleWebPages(); }
function test_project_multipleContractsSameFile() { TestProject.test_multipleContractsSameFile(); } function test_project_multipleContractsSameFile() { TestProject.test_multipleContractsSameFile(); }
function test_project_deleteFile() { TestProject.test_deleteFile(); }
} }

14
mix/test/qml/js/TestProject.js

@ -44,3 +44,17 @@ function test_multipleContractsSameFile()
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(3), "contract", "C2"); tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(3), "contract", "C2");
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(4), "contract", "C3"); tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(4), "contract", "C3");
} }
function test_deleteFile()
{
/*newProject();
var path = mainApplication.projectModel.projectPath;
createHtml("page1.html", "<html><body><div id='queryres'>Fail</div></body><script>if (web3) document.getElementById('queryres').innerText='OK'</script></html>");
createHtml("page2.html", "<html><body><div id='queryres'>Fail</div></body><script>if (web3) document.getElementById('queryres').innerText='OK'</script></html>");
createHtml("page3.html", "<html><body><div id='queryres'>Fail</div></body><script>if (web3) document.getElementById('queryres').innerText='OK'</script></html>");
mainApplication.projectModel.removeDocument("page2.html");
mainApplication.projectModel.closeProject(function(){});
mainApplication.projectModel.loadProject(path);
var doc = mainApplication.projectModel.getDocument("page2.html");
verify(doc, null)*/
}

Loading…
Cancel
Save