QML UI: simplify the code to cancel edit / add

This way we have one function that correctly ends both modes.
As a positive side effect this fixes a bug where one could exit the
add mode by tapping Dive list in the main menu which would not delete
the partially created dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-03-30 20:48:50 -05:00
parent 6a3e761d8f
commit cc2b815a4d

View file

@ -50,13 +50,6 @@ MobileComponents.Page {
]
function endAddMode() {
// edit was canceled - so remove the dive from the dive list
manager.addDiveAborted(dive_id)
state = "view"
Qt.inputMethod.hide()
}
property QtObject deleteAction: Action {
text: "Delete dive"
iconName: "trash-empty"
@ -77,12 +70,10 @@ MobileComponents.Page {
iconName: "dialog-cancel"
onTriggered: {
contextDrawer.close()
if (state === "edit") {
endEditMode()
} else if (state === "add") {
endAddMode()
if (state === "add")
returnTopPage()
}
else
endEditMode()
}
}
@ -111,7 +102,7 @@ MobileComponents.Page {
endEditMode()
event.accepted = true;
} else if (state === "add") {
endAddMode()
endEditMode()
stackView.pop()
event.accepted = true;
}
@ -124,7 +115,10 @@ MobileComponents.Page {
}
function endEditMode() {
// just cancel the edit state
// if we were adding a dive, we need to remove it
if (state === "add")
manager.addDiveAborted(dive_id)
// just cancel the edit/add state
state = "view";
Qt.inputMethod.hide();
}