From a62174b3ac4c9714f73b6860859e304b858f232b Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 11 May 2015 15:09:47 +0200 Subject: [PATCH 1/4] - Remove contract source. - Bug fix when when removing a project file. --- mix/ClientModel.cpp | 1 - mix/CodeModel.cpp | 13 +++++++++++++ mix/CodeModel.h | 2 ++ mix/FileIo.cpp | 6 ++++++ mix/FileIo.h | 2 ++ mix/qml/CodeEditorView.qml | 19 ++++++++++++++++--- mix/qml/FilesSection.qml | 20 ++++++++++++++++++-- mix/qml/js/ProjectModel.js | 16 +++++++++++----- mix/test/qml/TestMain.qml | 1 + mix/test/qml/js/TestProject.js | 14 ++++++++++++++ 10 files changed, 83 insertions(+), 11 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index c558c71f3..9da294458 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -315,7 +315,6 @@ void ClientModel::executeSequence(vector const& _sequence, TransactionSettings stdTransaction = transaction; stdTransaction.gasAuto = true; Address address = deployContract(stdContractCode, stdTransaction); - deployedContracts.push_back(address); m_stdContractAddresses[stdTransaction.contractId] = address; m_stdContractNames[address] = stdTransaction.contractId; } diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index 636a665e6..5c6ec07c0 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -219,6 +219,19 @@ void CodeModel::reset(QVariantMap const& _documents) 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) { { diff --git a/mix/CodeModel.h b/mix/CodeModel.h index 3f713a17b..a0b03951f 100644 --- a/mix/CodeModel.h +++ b/mix/CodeModel.h @@ -160,6 +160,8 @@ public: Q_INVOKABLE CompiledContract* contractByDocumentId(QString const& _documentId) const; /// Reset code model Q_INVOKABLE void reset() { reset(QVariantMap()); } + /// Delete a contract source + Q_INVOKABLE void unregisterContractSrc(QString const& _documentId); /// Convert solidity type info to mix type static SolidityType nodeType(dev::solidity::Type const* _type); /// Check if given location belongs to contract or function diff --git a/mix/FileIo.cpp b/mix/FileIo.cpp index 0991aa63d..22538194c 100644 --- a/mix/FileIo.cpp +++ b/mix/FileIo.cpp @@ -210,3 +210,9 @@ void FileIo::stopWatching(QString const& _path) { m_watcher->removePath(pathFromUrl(_path)); } + +void FileIo::deleteFile(QString const& _path) +{ + QFile file(pathFromUrl(_path)); + file.remove(); +} diff --git a/mix/FileIo.h b/mix/FileIo.h index 33c2bd5fd..90a143120 100644 --- a/mix/FileIo.h +++ b/mix/FileIo.h @@ -66,6 +66,8 @@ public: Q_INVOKABLE void watchFileChanged(QString const& _path); /// Stop Listenning for files change in @arg _path. Q_INVOKABLE void stopWatching(QString const& _path); + /// Delete a file + Q_INVOKABLE void deleteFile(QString const& _path); private: QString getHomePath() const; diff --git a/mix/qml/CodeEditorView.qml b/mix/qml/CodeEditorView.qml index e4d62ed81..bb7e203bf 100644 --- a/mix/qml/CodeEditorView.qml +++ b/mix/qml/CodeEditorView.qml @@ -190,9 +190,12 @@ Item { for (var i = 0; i < openDocCount; i++) { var doc = editorListModel.get(i); - var editor = editors.itemAt(i).item; - if (editor) - fileIo.writeFile(doc.path, editor.getText()); + if (editors.itemAt(i)) + { + var editor = editors.itemAt(i).item; + if (editor) + fileIo.writeFile(doc.path, editor.getText()); + } } } @@ -315,6 +318,16 @@ Item { break; } } + + onDocumentRemoved: { + for (var i = 0; i < editorListModel.count; i++) + if (editorListModel.get(i).documentId === documentId) + { + editorListModel.remove(i); + openDocCount--; + break; + } + } } function loadIfNotLoaded () { diff --git a/mix/qml/FilesSection.qml b/mix/qml/FilesSection.qml index d89875583..05ba5f897 100644 --- a/mix/qml/FilesSection.qml +++ b/mix/qml/FilesSection.qml @@ -241,8 +241,13 @@ Rectangle anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked:{ - if (mouse.button === Qt.RightButton && !isContract) - contextMenu.popup(); + if (mouse.button === Qt.RightButton) + { + if (isContract) + contextMenuContract.popup(); + else + contextMenu.popup(); + } else if (mouse.button === Qt.LeftButton) { rootItem.isSelected = true; @@ -268,6 +273,17 @@ Rectangle } } } + + Menu { + id: contextMenuContract + MenuItem { + text: qsTr("Delete") + onTriggered: { + projectModel.removeDocument(documentId); + wrapperItem.removeDocument(documentId); + } + } + } } } } diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js index 6ec906996..51036f9c2 100644 --- a/mix/qml/js/ProjectModel.js +++ b/mix/qml/js/ProjectModel.js @@ -294,7 +294,10 @@ function renameDocument(documentId, newName) { function getDocument(documentId) { var i = getDocumentIndex(documentId); - return projectListModel.get(i); + if (i === -1) + return null; + else + return projectListModel.get(i); } function getDocumentIdByName(fileName) @@ -308,10 +311,13 @@ function getDocumentIdByName(fileName) function removeDocument(documentId) { var i = getDocumentIndex(documentId); var document = projectListModel.get(i); - if (!document.isContract) { - projectListModel.remove(i); - documentRemoved(documentId); - } + fileIo.stopWatching(document.path); + fileIo.deleteFile(document.path); + if (document.isContract) + codeModel.unregisterContractSrc(documentId); + projectListModel.remove(i); + saveProjectFile(); + documentRemoved(documentId); } function newHtmlFile() { diff --git a/mix/test/qml/TestMain.qml b/mix/test/qml/TestMain.qml index 829364a99..727d90b25 100644 --- a/mix/test/qml/TestMain.qml +++ b/mix/test/qml/TestMain.qml @@ -113,5 +113,6 @@ TestCase function test_project_contractRename() { TestProject.test_contractRename(); } function test_project_multipleWebPages() { TestProject.test_multipleWebPages(); } function test_project_multipleContractsSameFile() { TestProject.test_multipleContractsSameFile(); } + function test_project_deleteFile() { TestProject.test_deleteFile(); } } diff --git a/mix/test/qml/js/TestProject.js b/mix/test/qml/js/TestProject.js index 49b5ea51f..7ff482c58 100644 --- a/mix/test/qml/js/TestProject.js +++ b/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(4), "contract", "C3"); } + +function test_deleteFile() +{ + /*newProject(); + var path = mainApplication.projectModel.projectPath; + createHtml("page1.html", "
Fail
"); + createHtml("page2.html", "
Fail
"); + createHtml("page3.html", "
Fail
"); + mainApplication.projectModel.removeDocument("page2.html"); + mainApplication.projectModel.closeProject(function(){}); + mainApplication.projectModel.loadProject(path); + var doc = mainApplication.projectModel.getDocument("page2.html"); + verify(doc, null)*/ +} From dba2756da8a5e8cebd5ee5457d8046c252cf0f3c Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 11 May 2015 16:49:52 +0200 Subject: [PATCH 2/4] add test --- mix/qml/js/ProjectModel.js | 2 +- mix/test/qml/js/TestDebugger.js | 7 +++++-- mix/test/qml/js/TestProject.js | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js index 51036f9c2..6fce7686d 100644 --- a/mix/qml/js/ProjectModel.js +++ b/mix/qml/js/ProjectModel.js @@ -295,7 +295,7 @@ function renameDocument(documentId, newName) { function getDocument(documentId) { var i = getDocumentIndex(documentId); if (i === -1) - return null; + return undefined; else return projectListModel.get(i); } diff --git a/mix/test/qml/js/TestDebugger.js b/mix/test/qml/js/TestDebugger.js index 4933136ff..4e295c46f 100644 --- a/mix/test/qml/js/TestDebugger.js +++ b/mix/test/qml/js/TestDebugger.js @@ -223,13 +223,16 @@ function test_ctrTypeAsParam() "}"); mainApplication.projectModel.stateListModel.editState(0); //C1 ctor already added var transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog; + mainApplication.projectModel.stateDialog.model.editTransaction(3); + ts.waitForRendering(transactionDialog, 3000); + clickElement(transactionDialog, 200, 300); + ts.typeString("", transactionDialog); + transactionDialog.acceptAndClose(); mainApplication.projectModel.stateDialog.model.addTransaction(); transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog; ts.waitForRendering(transactionDialog, 3000); transactionDialog.selectContract("C2"); transactionDialog.selectFunction("getFromC1"); - clickElement(transactionDialog, 406, 340); - clickElement(transactionDialog, 406, 366); transactionDialog.acceptAndClose(); mainApplication.projectModel.stateDialog.acceptAndClose(); mainApplication.mainContent.startQuickDebugging(); diff --git a/mix/test/qml/js/TestProject.js b/mix/test/qml/js/TestProject.js index 7ff482c58..fe1023f05 100644 --- a/mix/test/qml/js/TestProject.js +++ b/mix/test/qml/js/TestProject.js @@ -47,7 +47,7 @@ function test_multipleContractsSameFile() function test_deleteFile() { - /*newProject(); + newProject(); var path = mainApplication.projectModel.projectPath; createHtml("page1.html", "
Fail
"); createHtml("page2.html", "
Fail
"); @@ -56,5 +56,5 @@ function test_deleteFile() mainApplication.projectModel.closeProject(function(){}); mainApplication.projectModel.loadProject(path); var doc = mainApplication.projectModel.getDocument("page2.html"); - verify(doc, null)*/ + verify(!doc, "page2.html has not been removed"); } From 129a5d4f050489e559d6c505655eaae8c0eb95e4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 12 May 2015 09:42:10 +0200 Subject: [PATCH 3/4] add confirmation dialog --- mix/qml/FilesSection.qml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mix/qml/FilesSection.qml b/mix/qml/FilesSection.qml index 05ba5f897..5e49143a7 100644 --- a/mix/qml/FilesSection.qml +++ b/mix/qml/FilesSection.qml @@ -3,6 +3,7 @@ import QtQuick.Window 2.0 import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.3 +import QtQuick.Dialogs 1.2 import "." @@ -268,8 +269,7 @@ Rectangle MenuItem { text: qsTr("Delete") onTriggered: { - projectModel.removeDocument(documentId); - wrapperItem.removeDocument(documentId); + deleteConfirmation.open(); } } } @@ -279,11 +279,22 @@ Rectangle MenuItem { text: qsTr("Delete") onTriggered: { - projectModel.removeDocument(documentId); - wrapperItem.removeDocument(documentId); + deleteConfirmation.open(); } } } + + MessageDialog + { + id: deleteConfirmation + text: qsTr("Are you sure to delete this file ?") + standardButtons: StandardIcon.Ok | StandardIcon.Cancel + onAccepted: + { + projectModel.removeDocument(documentId); + wrapperItem.removeDocument(documentId); + } + } } } } From 6b74a4e96f03c0a6195a0954151a3a2c2a5bdda6 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 12 May 2015 12:42:29 +0200 Subject: [PATCH 4/4] Recover lost code after ethash merge - Recover installing ethash if ethash-cl is not built --- libethash/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libethash/CMakeLists.txt b/libethash/CMakeLists.txt index a65621c3e..907eccd40 100644 --- a/libethash/CMakeLists.txt +++ b/libethash/CMakeLists.txt @@ -42,3 +42,7 @@ add_library(${LIBRARY} ${FILES}) if (CRYPTOPP_FOUND) TARGET_LINK_LIBRARIES(${LIBRARY} ${CRYPTOPP_LIBRARIES}) endif() + +if (NOT ETHASHCL) + install( TARGETS ${LIBRARY} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +endif () \ No newline at end of file