Rename HListView checking-related functions
This commit is contained in:
parent
3f69710813
commit
af6cdc9013
1
TODO.md
1
TODO.md
|
@ -1,5 +1,6 @@
|
|||
# TODO
|
||||
|
||||
- focus color
|
||||
- Long-press-drag to select multiple messages on touch
|
||||
- Drag to select multiple messages on non-touch
|
||||
|
||||
|
|
|
@ -71,33 +71,33 @@ ListView {
|
|||
property alias cursorShape: mouseArea.cursorShape
|
||||
property int currentItemHeight: currentItem ? currentItem.height : 0
|
||||
|
||||
property var checkedDelegates: ({})
|
||||
property var checked: ({})
|
||||
property int lastCheckedDelegateIndex: 0
|
||||
property int selectedCount: Object.keys(checkedDelegates).length
|
||||
property int selectedCount: Object.keys(checked).length
|
||||
|
||||
|
||||
function delegatesChecked(...indices) {
|
||||
function check(...indices) {
|
||||
for (const i of indices) {
|
||||
const model = listView.model.get(i)
|
||||
checkedDelegates[model.id] = model
|
||||
checked[model.id] = model
|
||||
}
|
||||
|
||||
lastCheckedDelegateIndex = indices.slice(-1)[0]
|
||||
checkedDelegatesChanged()
|
||||
checkedChanged()
|
||||
}
|
||||
|
||||
function delegatesFromLastToHereChecked(here) {
|
||||
function checkFromLastToHere(here) {
|
||||
const indices = utils.range(lastCheckedDelegateIndex, here)
|
||||
eventList.delegatesChecked(...indices)
|
||||
eventList.check(...indices)
|
||||
}
|
||||
|
||||
function delegatesUnchecked(...indices) {
|
||||
function uncheck(...indices) {
|
||||
for (const i of indices) {
|
||||
const model = listView.model.get(i)
|
||||
delete checkedDelegates[model.id]
|
||||
delete checked[model.id]
|
||||
}
|
||||
|
||||
checkedDelegatesChanged()
|
||||
checkedChanged()
|
||||
}
|
||||
|
||||
function toggleCheck(...indices) {
|
||||
|
@ -106,10 +106,10 @@ ListView {
|
|||
for (const i of indices) {
|
||||
const model = listView.model.get(i)
|
||||
|
||||
if (model.id in checkedDelegates) {
|
||||
delete checkedDelegates[model.id]
|
||||
if (model.id in checked) {
|
||||
delete checked[model.id]
|
||||
} else {
|
||||
checkedDelegates[model.id] = model
|
||||
checked[model.id] = model
|
||||
checkedIndices.push(i)
|
||||
}
|
||||
}
|
||||
|
@ -117,11 +117,11 @@ ListView {
|
|||
if (checkedIndices.length > 0)
|
||||
lastCheckedDelegateIndex = checkedIndices.slice(-1)[0]
|
||||
|
||||
checkedDelegatesChanged()
|
||||
checkedChanged()
|
||||
}
|
||||
|
||||
function getSortedCheckedDelegates() {
|
||||
return Object.values(checkedDelegates).sort(
|
||||
function getSortedChecked() {
|
||||
return Object.values(checked).sort(
|
||||
(a, b) => a.date > b.date ? 1 : -1
|
||||
)
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ HRowLayout {
|
|||
|
||||
Connections {
|
||||
target: eventList
|
||||
onCheckedDelegatesChanged: contentLabel.deselect()
|
||||
onCheckedChanged: contentLabel.deselect()
|
||||
onDelegateWithSelectedTextChanged:
|
||||
if (eventList.delegateWithSelectedText !== model.id)
|
||||
contentLabel.deselect()
|
||||
|
@ -193,14 +193,14 @@ HRowLayout {
|
|||
(! parent.hoveredLink ||
|
||||
! parent.enableLinkActivation)) {
|
||||
|
||||
eventList.delegatesChecked(model.index)
|
||||
eventList.check(model.index)
|
||||
checkedNow = true
|
||||
}
|
||||
|
||||
if (! active && eventDelegate.checked) {
|
||||
checkedNow ?
|
||||
checkedNow = false :
|
||||
eventList.delegatesUnchecked(model.index)
|
||||
eventList.uncheck(model.index)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ HRowLayout {
|
|||
(! parent.hoveredLink ||
|
||||
! parent.enableLinkActivation)) {
|
||||
|
||||
eventList.delegatesFromLastToHereChecked(model.index)
|
||||
eventList.checkFromLastToHere(model.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ HColumnLayout {
|
|||
id: eventDelegate
|
||||
width: eventList.width
|
||||
|
||||
ListView.onRemove: eventList.delegatesUnchecked(model.id)
|
||||
ListView.onRemove: eventList.uncheck(model.id)
|
||||
|
||||
|
||||
enum Media { Page, File, Image, Video, Audio }
|
||||
|
@ -22,7 +22,7 @@ HColumnLayout {
|
|||
readonly property var nextModel: eventList.model.get(model.index - 1)
|
||||
readonly property QtObject currentModel: model
|
||||
|
||||
property bool checked: model.id in eventList.checkedDelegates
|
||||
property bool checked: model.id in eventList.checked
|
||||
property bool compact: window.settings.compactMode
|
||||
property bool isOwn: chat.userId === model.sender_id
|
||||
property bool onRight: eventList.ownEventsOnRight && isOwn
|
||||
|
@ -79,9 +79,7 @@ HColumnLayout {
|
|||
}
|
||||
|
||||
function toggleChecked() {
|
||||
eventDelegate.checked ?
|
||||
eventList.delegatesUnchecked(model.index) :
|
||||
eventList.delegatesChecked(model.index)
|
||||
eventList.toggleCheck(model.index)
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,7 +120,7 @@ HColumnLayout {
|
|||
TapHandler {
|
||||
acceptedButtons: Qt.LeftButton
|
||||
acceptedModifiers: Qt.ShiftModifier
|
||||
onTapped: eventList.delegatesFromLastToHereChecked(model.index)
|
||||
onTapped: eventList.checkFromLastToHere(model.index)
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
|
@ -154,14 +152,14 @@ HColumnLayout {
|
|||
visible: eventList.selectedCount >= 2
|
||||
icon.name: "unselect-all-messages"
|
||||
text: qsTr("Unselect all")
|
||||
onTriggered: eventList.checkedDelegates = {}
|
||||
onTriggered: eventList.checked = {}
|
||||
}
|
||||
|
||||
HMenuItem {
|
||||
visible: model.index !== 0
|
||||
icon.name: "select-until-here"
|
||||
text: qsTr("Select until here")
|
||||
onTriggered: eventList.delegatesFromLastToHereChecked(model.index)
|
||||
onTriggered: eventList.checkFromLastToHere(model.index)
|
||||
}
|
||||
|
||||
HMenuItem {
|
||||
|
|
|
@ -94,7 +94,7 @@ HMxcImage {
|
|||
TapHandler {
|
||||
acceptedModifiers: Qt.ShiftModifier
|
||||
onTapped:
|
||||
eventList.delegatesFromLastToHereChecked(singleMediaInfo.index)
|
||||
eventList.checkFromLastToHere(singleMediaInfo.index)
|
||||
|
||||
gesturePolicy: TapHandler.ReleaseWithinBounds
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ Rectangle {
|
|||
onActivated: {
|
||||
eventList.currentIndex !== -1 ?
|
||||
eventList.currentIndex = -1 :
|
||||
eventList.checkedDelegates = {}
|
||||
eventList.checked = {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ Rectangle {
|
|||
enabled: eventList.currentItem
|
||||
sequences: window.settings.keys.selectMessagesUntilHere
|
||||
onActivated:
|
||||
eventList.delegatesFromLastToHereChecked(eventList.currentIndex)
|
||||
eventList.checkFromLastToHere(eventList.currentIndex)
|
||||
}
|
||||
|
||||
HShortcut {
|
||||
|
@ -139,7 +139,7 @@ Rectangle {
|
|||
|
||||
const contents = []
|
||||
|
||||
for (const model of eventList.getSortedCheckedDelegates()) {
|
||||
for (const model of eventList.getSortedChecked()) {
|
||||
contents.push(JSON.parse(model.source).body)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user