Browse Source

Merge pull request #1859 from yann300/bugFix2

Mix - Remove contract source
cl-refactor
Arkadiy Paronyan 10 years ago
parent
commit
2e0818bee0
  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. 35
      mix/qml/FilesSection.qml
  8. 16
      mix/qml/js/ProjectModel.js
  9. 1
      mix/test/qml/TestMain.qml
  10. 7
      mix/test/qml/js/TestDebugger.js
  11. 14
      mix/test/qml/js/TestProject.js

1
mix/ClientModel.cpp

@ -316,7 +316,6 @@ void ClientModel::executeSequence(vector<TransactionSettings> 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;
}

13
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)
{
{

2
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

6
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();
}

2
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;

19
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 () {

35
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 "."
@ -241,8 +242,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;
@ -263,11 +269,32 @@ Rectangle
MenuItem {
text: qsTr("Delete")
onTriggered: {
projectModel.removeDocument(documentId);
wrapperItem.removeDocument(documentId);
deleteConfirmation.open();
}
}
}
Menu {
id: contextMenuContract
MenuItem {
text: qsTr("Delete")
onTriggered: {
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);
}
}
}
}
}

16
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 undefined;
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() {

1
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(); }
}

7
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("<C1 - 0>", 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();

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(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, "page2.html has not been removed");
}

Loading…
Cancel
Save