Browse Source

Merge pull request #934 from yann300/ui_improvement

mix: F5 crashes if default state is deleted
cl-refactor
Arkadiy Paronyan 10 years ago
parent
commit
c1985df01e
  1. 4
      mix/qml/StateDialog.qml
  2. 1
      mix/qml/StateList.qml
  3. 52
      mix/qml/StateListModel.qml
  4. 17
      mix/qml/main.qml

4
mix/qml/StateDialog.qml

@ -33,9 +33,10 @@ Window {
transactionsModel.append(item.transactions[t]);
stateTransactions.push(item.transactions[t]);
}
isDefault = setDefault;
visible = true;
isDefault = setDefault;
titleField.focus = true;
defaultCheckBox.enabled = !isDefault;
}
function close() {
@ -167,6 +168,7 @@ Window {
onClicked: transactionsModel.editTransaction(index)
}
ToolButton {
visible: index >= 0 ? !transactionsModel.get(index).executeConstructor : false
text: qsTr("Delete");
Layout.fillHeight: true
onClicked: transactionsModel.deleteTransaction(index)

1
mix/qml/StateList.qml

@ -48,6 +48,7 @@ Rectangle {
onClicked: list.model.editState(index);
}
ToolButton {
visible: list.model.count - 1 != index
text: qsTr("Delete");
Layout.fillHeight: true
onClicked: list.model.deleteState(index);

52
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: []
@ -105,20 +105,7 @@ Item {
stateListModel.clear();
stateList = [];
}
onProjectLoading: {
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);
}
}
onProjectLoading: stateListModel.loadStatesFromProject(projectData);
onProjectSaving: {
projectData.states = []
for(var i = 0; i < stateListModel.count; i++) {
@ -149,7 +136,8 @@ Item {
stateList.push(item);
stateListModel.append(item);
}
if (stateDialog.isDefault)
stateListModel.defaultStateChanged();
stateListModel.save();
}
}
@ -161,6 +149,9 @@ Item {
ListModel {
id: stateListModel
signal defaultStateChanged;
signal stateListModelReady;
function defaultTransactionItem() {
return {
value: QEtherHelper.createEther("100", QEther.Wei),
@ -199,7 +190,7 @@ Item {
function addState() {
var item = createDefaultState();
stateDialog.open(stateListModel.count, item, defaultStateIndex === -1);
stateDialog.open(stateListModel.count, item, false);
}
function editState(index) {
@ -220,12 +211,37 @@ Item {
stateListModel.remove(index);
stateList.splice(index, 1);
if (index === defaultStateIndex)
defaultStateIndex = -1;
{
defaultStateIndex = 0;
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();
}
}
}

17
mix/qml/main.qml

@ -34,7 +34,7 @@ ApplicationWindow {
MenuItem { action: exitAppAction }
}
Menu {
title: qsTr("Debug")
title: qsTr("Deploy")
MenuItem { action: debugRunAction }
MenuItem { action: mineAction }
MenuSeparator {}
@ -89,9 +89,22 @@ ApplicationWindow {
onTriggered: clientModel.mine();
enabled: codeModel.hasContract && !clientModel.running
}
Connections {
target: projectModel.stateListModel
function updateRunLabel()
{
debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\"";
}
onDefaultStateChanged: updateRunLabel()
onStateListModelReady: updateRunLabel()
}
Action {
id: debugRunAction
text: qsTr("Run")
text: qsTr("Deploy")
shortcut: "F5"
onTriggered: mainContent.startQuickDebugging()
enabled: codeModel.hasContract && !clientModel.running

Loading…
Cancel
Save