Skip to content

Commit

Permalink
make deleting history item a remorse action
Browse files Browse the repository at this point in the history
  • Loading branch information
rabauke committed Jan 27, 2024
1 parent 06bffb4 commit 3710f6c
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions qml/pages/History.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,46 @@ Page {
model: searchHistoryListModel

delegate: ListItem {
id: listItem
width: parent.width
contentWidth: parent.width
contentHeight: query_text.height + Theme.paddingLarge
menu: contextMenu

menu: ContextMenu {
MenuItem {
text: qsTr('Search again')
onClicked: {
queryFieldText = searchHistoryListModel.get(model.index).query
resultsListModel.clear()
var transAtoB = appModel.dictionary.translateAtoB(queryFieldText)
var transBtoA = appModel.dictionary.translateBtoA(queryFieldText)
var i
for (i in transAtoB)
resultsListModel.append({
'section': 'AtoB',
'lang1': transAtoB[i][0],
'lang2': transAtoB[i][1]
})
for (i in transBtoA)
resultsListModel.append({
'section': 'BtoA',
'lang1': transBtoA[i][0],
'lang2': transBtoA[i][1]
})
numberOfResultsAtoB = transAtoB.length
numberOfResultsBtoA = transBtoA.length
queryFieldText = searchHistoryListModel.get(model.index).query
pageStack.navigateBack()
}
}
MenuItem {
text: qsTr('Remove query')
onClicked: listItem.remorseDelete(function () {
searchHistoryListModel.remove(model.index)
})
}
}

Text {
id: query_text
x: Theme.horizontalPageMargin
Expand All @@ -54,41 +90,6 @@ Page {
horizontalAlignment: TextEdit.AlignLeft
text: query
}
Component {
id: contextMenu
ContextMenu {
MenuItem {
text: qsTr('Search again')
onClicked: {
queryFieldText = searchHistoryListModel.get(model.index).query
resultsListModel.clear()
var transAtoB = appModel.dictionary.translateAtoB(queryFieldText)
var transBtoA = appModel.dictionary.translateBtoA(queryFieldText)
var i
for (i in transAtoB)
resultsListModel.append({
'section': 'AtoB',
'lang1': transAtoB[i][0],
'lang2': transAtoB[i][1]
})
for (i in transBtoA)
resultsListModel.append({
'section': 'BtoA',
'lang1': transBtoA[i][0],
'lang2': transBtoA[i][1]
})
numberOfResultsAtoB = transAtoB.length
numberOfResultsBtoA = transBtoA.length
queryFieldText = searchHistoryListModel.get(model.index).query
pageStack.navigateBack()
}
}
MenuItem {
text: qsTr('Remove query')
onClicked: searchHistoryListModel.remove(model.index)
}
}
}
}
}
}

0 comments on commit 3710f6c

Please sign in to comment.