From b7070ec12f4d112edfea9f5df79cd6b33656fc16 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Feb 2015 15:30:33 +0100 Subject: [PATCH 1/5] bug fixes https://www.pivotaltracker.com/n/projects/1265056/stories/87395458 --- mix/qml/StateDialog.qml | 1 + mix/qml/StateList.qml | 1 + mix/qml/StateListModel.qml | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index c00e3226f..37e36621e 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -167,6 +167,7 @@ Window { onClicked: transactionsModel.editTransaction(index) } ToolButton { + visible: !transactionsModel.get(index).executeConstructor text: qsTr("Delete"); Layout.fillHeight: true onClicked: transactionsModel.deleteTransaction(index) diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index ad14cf30e..c20d1379d 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -48,6 +48,7 @@ Rectangle { onClicked: list.model.editState(index); } ToolButton { + visible: !list.model.isDefaultState(index) text: qsTr("Delete"); Layout.fillHeight: true onClicked: list.model.deleteState(index); diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index c158112e1..5a4722e84 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -176,6 +176,11 @@ Item { runState(defaultStateIndex); } + function isDefaultState(index) + { + return index === defaultStateIndex; + } + function runState(index) { var item = stateList[index]; clientModel.setupState(item); From 51e2c1424d75317c791755e8ecf696f0b59c3729 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 11:38:25 +0100 Subject: [PATCH 2/5] Change behavior when running/deleting the default state. --- mix/qml/StateDialog.qml | 14 ++------ mix/qml/StateList.qml | 2 +- mix/qml/StateListModel.qml | 65 ++++++++++++++++++++------------------ mix/qml/main.qml | 17 ++++++++-- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index 37e36621e..9e5c60d3d 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -17,12 +17,11 @@ Window { property alias stateTitle: titleField.text property alias stateBalance: balanceField.value - property alias isDefault: defaultCheckBox.checked property int stateIndex property var stateTransactions: [] signal accepted - function open(index, item, setDefault) { + function open(index, item) { stateIndex = index; stateTitle = item.title; balanceField.value = item.balance; @@ -33,7 +32,6 @@ Window { transactionsModel.append(item.transactions[t]); stateTransactions.push(item.transactions[t]); } - isDefault = setDefault; visible = true; titleField.focus = true; } @@ -79,14 +77,6 @@ Window { Layout.fillWidth: true } - Label { - text: qsTr("Default") - } - CheckBox { - id: defaultCheckBox - Layout.fillWidth: true - } - Label { text: qsTr("Transactions") } @@ -167,7 +157,7 @@ Window { onClicked: transactionsModel.editTransaction(index) } ToolButton { - visible: !transactionsModel.get(index).executeConstructor + visible: index >= 0 ? !transactionsModel.get(index).executeConstructor : false text: qsTr("Delete"); Layout.fillHeight: true onClicked: transactionsModel.deleteTransaction(index) diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index c20d1379d..3674e0dbc 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -48,7 +48,7 @@ Rectangle { onClicked: list.model.editState(index); } ToolButton { - visible: !list.model.isDefaultState(index) + visible: list.model.count - 1 != index text: qsTr("Delete"); Layout.fillHeight: true onClicked: list.model.deleteState(index); diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index 5a4722e84..0b5645d37 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -8,7 +8,7 @@ import "js/QEtherHelper.js" as QEtherHelper Item { - property int defaultStateIndex: -1 + property int defaultStateIndex: 0 property alias model: stateListModel property var stateList: [] @@ -70,20 +70,7 @@ Item { stateListModel.clear(); stateList = []; } - onProjectLoaded: { - if (!projectData.states) - projectData.states = []; - if (projectData.defaultStateIndex !== undefined) - defaultStateIndex = projectData.defaultStateIndex; - else - defaultStateIndex = -1; - var items = projectData.states; - for(var i = 0; i < items.length; i++) { - var item = fromPlainStateItem(items[i]); - stateListModel.append(item); - stateList.push(item); - } - } + onProjectLoaded: stateListModel.loadStatesFromProject(projectData); onProjectSaving: { projectData.states = [] for(var i = 0; i < stateListModel.count; i++) { @@ -103,18 +90,16 @@ Item { id: stateDialog onAccepted: { var item = stateDialog.getItem(); - if (stateDialog.stateIndex < stateListModel.count) { - if (stateDialog.isDefault) - defaultStateIndex = stateIndex; + if (stateDialog.stateIndex < stateListModel.count) + { stateList[stateDialog.stateIndex] = item; stateListModel.set(stateDialog.stateIndex, item); - } else { - if (stateDialog.isDefault) - defaultStateIndex = 0; + } + else + { stateList.push(item); stateListModel.append(item); } - stateListModel.save(); } } @@ -126,6 +111,9 @@ Item { ListModel { id: stateListModel + signal defaultStateChanged; + signal stateListModelReady; + function defaultTransactionItem() { return { value: QEtherHelper.createEther("100", QEther.Wei), @@ -164,11 +152,11 @@ Item { function addState() { var item = createDefaultState(); - stateDialog.open(stateListModel.count, item, defaultStateIndex === -1); + stateDialog.open(stateListModel.count, item); } function editState(index) { - stateDialog.open(index, stateList[index], defaultStateIndex === index); + stateDialog.open(index, stateList[index]); } function debugDefaultState() { @@ -176,11 +164,6 @@ Item { runState(defaultStateIndex); } - function isDefaultState(index) - { - return index === defaultStateIndex; - } - function runState(index) { var item = stateList[index]; clientModel.setupState(item); @@ -190,12 +173,34 @@ Item { stateListModel.remove(index); stateList.splice(index, 1); if (index === defaultStateIndex) - defaultStateIndex = -1; + defaultStateChanged(); save(); } function save() { projectModel.saveProject(); } + + function defaultStateName() + { + return stateList[defaultStateIndex].title; + } + + function loadStatesFromProject(projectData) + { + if (!projectData.states) + projectData.states = []; + if (projectData.defaultStateIndex !== undefined) + defaultStateIndex = projectData.defaultStateIndex; + else + defaultStateIndex = 0; + var items = projectData.states; + for(var i = 0; i < items.length; i++) { + var item = fromPlainStateItem(items[i]); + stateListModel.append(item); + stateList.push(item); + } + stateListModelReady(); + } } } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index a0a4ba423..2e939fa12 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -34,7 +34,7 @@ ApplicationWindow { MenuItem { action: exitAppAction } } Menu { - title: qsTr("Debug") + title: qsTr("Deploy") MenuItem { action: debugRunAction } MenuItem { action: debugResetStateAction } MenuItem { action: mineAction } @@ -87,9 +87,22 @@ ApplicationWindow { onTriggered: clientModel.mine(); enabled: codeModel.hasContract && !clientModel.running } + + Connections { + target: projectModel.stateListModel + onDefaultStateChanged: + { + debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + } + onStateListModelReady: + { + debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + } + } + Action { id: debugRunAction - text: "&Run" + text: "&Deploy" shortcut: "F5" onTriggered: mainContent.startQuickDebugging() enabled: codeModel.hasContract && !clientModel.running From edea2145f9e62adbb94ea717cd49a807ba0c4f53 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 15:08:09 +0100 Subject: [PATCH 3/5] misc --- mix/qml/main.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix/qml/main.qml b/mix/qml/main.qml index 2ca2bc133..a90c90feb 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -94,11 +94,11 @@ ApplicationWindow { target: projectModel.stateListModel onDefaultStateChanged: { - debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; } onStateListModelReady: { - debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; } } From 1e60fb5d095d59e2bf9ab00182089227b0dbcce2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 16:05:52 +0100 Subject: [PATCH 4/5] add checkbox in statedialog. --- mix/qml/StateDialog.qml | 15 ++++++++++++++- mix/qml/StateListModel.qml | 20 +++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index 9e5c60d3d..a2f9b7fa8 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -17,11 +17,12 @@ Window { property alias stateTitle: titleField.text property alias stateBalance: balanceField.value + property alias isDefault: defaultCheckBox.checked property int stateIndex property var stateTransactions: [] signal accepted - function open(index, item) { + function open(index, item, setDefault) { stateIndex = index; stateTitle = item.title; balanceField.value = item.balance; @@ -33,7 +34,10 @@ Window { stateTransactions.push(item.transactions[t]); } visible = true; + isDefault = setDefault; titleField.focus = true; + defaultCheckBox.enabled = !isDefault; + } function close() { @@ -77,6 +81,15 @@ Window { Layout.fillWidth: true } + Label { + text: qsTr("Default") + } + CheckBox { + id: defaultCheckBox + Layout.fillWidth: true + } + + Label { text: qsTr("Transactions") } diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index f87ecbea0..a1b24fe0f 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -125,16 +125,19 @@ Item { id: stateDialog onAccepted: { var item = stateDialog.getItem(); - if (stateDialog.stateIndex < stateListModel.count) - { + if (stateDialog.stateIndex < stateListModel.count) { + if (stateDialog.isDefault) + defaultStateIndex = stateIndex; stateList[stateDialog.stateIndex] = item; stateListModel.set(stateDialog.stateIndex, item); - } - else - { + } else { + if (stateDialog.isDefault) + defaultStateIndex = 0; stateList.push(item); stateListModel.append(item); } + if (stateDialog.isDefault) + stateListModel.defaultStateChanged(); stateListModel.save(); } } @@ -187,11 +190,11 @@ Item { function addState() { var item = createDefaultState(); - stateDialog.open(stateListModel.count, item); + stateDialog.open(stateListModel.count, item, false); } function editState(index) { - stateDialog.open(index, stateList[index]); + stateDialog.open(index, stateList[index], defaultStateIndex === index); } function debugDefaultState() { @@ -208,7 +211,10 @@ Item { stateListModel.remove(index); stateList.splice(index, 1); if (index === defaultStateIndex) + { + defaultStateIndex = 0; defaultStateChanged(); + } save(); } From b0dd99ab13622560d75cf748b2f0e9c3721b822c Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 16:56:56 +0100 Subject: [PATCH 5/5] misc --- mix/qml/StateDialog.qml | 2 -- mix/qml/main.qml | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index a2f9b7fa8..fa48c640e 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -37,7 +37,6 @@ Window { isDefault = setDefault; titleField.focus = true; defaultCheckBox.enabled = !isDefault; - } function close() { @@ -89,7 +88,6 @@ Window { Layout.fillWidth: true } - Label { text: qsTr("Transactions") } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index a90c90feb..720d5070d 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -92,14 +92,14 @@ ApplicationWindow { Connections { target: projectModel.stateListModel - onDefaultStateChanged: - { - debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; - } - onStateListModelReady: + + function updateRunLabel() { debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; } + + onDefaultStateChanged: updateRunLabel() + onStateListModelReady: updateRunLabel() } Action {