From af6cdc90136ce6b485a385ca32debeb0d3ebb173 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 27 Mar 2020 05:05:25 -0400 Subject: [PATCH] Rename HListView checking-related functions --- TODO.md | 1 + src/gui/Base/HListView.qml | 32 +++++++++---------- src/gui/Pages/Chat/Timeline/EventContent.qml | 8 ++--- src/gui/Pages/Chat/Timeline/EventDelegate.qml | 14 ++++---- src/gui/Pages/Chat/Timeline/EventImage.qml | 2 +- src/gui/Pages/Chat/Timeline/EventList.qml | 6 ++-- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/TODO.md b/TODO.md index 88bcee26..7238615e 100644 --- a/TODO.md +++ b/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 diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index 185f5e6f..345969e7 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -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 ) } diff --git a/src/gui/Pages/Chat/Timeline/EventContent.qml b/src/gui/Pages/Chat/Timeline/EventContent.qml index 47fc2696..fdc9a837 100644 --- a/src/gui/Pages/Chat/Timeline/EventContent.qml +++ b/src/gui/Pages/Chat/Timeline/EventContent.qml @@ -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) } } } diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index c684c5fa..7833b39d 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -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 { diff --git a/src/gui/Pages/Chat/Timeline/EventImage.qml b/src/gui/Pages/Chat/Timeline/EventImage.qml index 230b46cb..248fedfd 100644 --- a/src/gui/Pages/Chat/Timeline/EventImage.qml +++ b/src/gui/Pages/Chat/Timeline/EventImage.qml @@ -94,7 +94,7 @@ HMxcImage { TapHandler { acceptedModifiers: Qt.ShiftModifier onTapped: - eventList.delegatesFromLastToHereChecked(singleMediaInfo.index) + eventList.checkFromLastToHere(singleMediaInfo.index) gesturePolicy: TapHandler.ReleaseWithinBounds } diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index 0218e437..ea293bf6 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -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) }