Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions src/FileRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ Item {
// it in place (or closes it).
property bool tree: false

// Model roles change on reuse; drag assets belong to the old file.
property bool pooled: false
property int dragGeneration: 0
function clearDragAssets() {
++dragGeneration
Drag.imageSource = ""
Drag.mimeData = ({})
}
onPathChanged: clearDragAssets()
ListView.onPooled: {
pooled = true
clearDragAssets()
}
ListView.onReused: pooled = false

function captureDragPicture() {
const target = row
const generation = ++dragGeneration
const path = row.path
return grabToImage(result => {
if (target && !target.pooled && target.path === path && target.dragGeneration === generation) {
target.Drag.imageSource = ""
target.Drag.imageSource = result.url
}
})
}

signal clicked(int modifiers)
signal activated()
signal toggled()
Expand All @@ -56,7 +83,7 @@ Item {
DropArea {
id: folderDrop
anchors.fill: parent
enabled: row.isDir
enabled: !row.pooled && row.isDir
keys: ["text/uri-list"]
onEntered: (drag) => { drag.accepted = fileOps.canDrop(drag.urls, row.path) }
onDropped: (drop) => { fileOps.dropInto(drop.urls, row.path); drop.accept(Qt.MoveAction) }
Expand Down Expand Up @@ -96,12 +123,15 @@ Item {
rotation: row.expanded ? (row.LayoutMirroring.enabled ? -90 : 90) : 0
color: arrowHover.hovered ? theme.foreground : theme.secondaryForeground
}
HoverHandler { id: arrowHover; enabled: row.isDir }
HoverHandler { id: arrowHover; enabled: !row.pooled && row.isDir }
TapHandler {
enabled: row.isDir
property string pressedPath: ""
enabled: !row.pooled && row.isDir
onPressedChanged: if (pressed) pressedPath = row.path
onEnabledChanged: if (!enabled) pressedPath = ""
// Before the row's own tap, which would select it instead.
grabPermissions: PointerHandler.CanTakeOverFromAnything
onTapped: row.toggled()
onTapped: if (pressedPath.length > 0 && pressedPath === row.path) row.toggled()
}
}

Expand All @@ -124,7 +154,7 @@ Item {
// A small picture of any file there's one of, as the tiles
// have; a text's opening lines would be unreadable this
// small, and folders and plugins' items keep their glyph.
source: row.isDir || row.kind === "item" || row.kind === "text" ? "" : Format.thumb(row.path, row.mime, 128, row.modified)
source: row.pooled || row.isDir || row.kind === "item" || row.kind === "text" ? "" : Format.thumb(row.path, row.mime, 128, row.modified)
visible: status === Image.Ready
}
Rectangle {
Expand Down Expand Up @@ -189,14 +219,18 @@ Item {

HoverHandler {
id: hover
// Cleared first: Qt (6.12) reloads a new picture at the size of the
// one before, which for a grab only warns ("Ignoring sourceSize").
onHoveredChanged: if (hovered) row.grabToImage(result => { row.Drag.imageSource = ""; row.Drag.imageSource = result.url })
enabled: !row.pooled
onHoveredChanged: if (hovered) row.captureDragPicture()
}
TapHandler {
id: tap
onTapped: row.clicked(tap.point.modifiers)
onDoubleTapped: row.activated()
// Tap history belongs to a file, not to the next file using its row.
Loader {
active: !row.pooled
sourceComponent: TapHandler {
id: tap
parent: row
onTapped: row.clicked(tap.point.modifiers)
onDoubleTapped: row.activated()
}
}

// Like the tiles: dragged, a row is a file for the sidebar or another app.
Expand All @@ -207,7 +241,7 @@ Item {
Drag.hotSpot.x: LayoutMirroring.enabled ? row.width : 0
DragHandler {
target: null
enabled: row.kind !== "item"
enabled: !row.pooled && row.kind !== "item"
// Dragging a selected item takes the whole selection along. The list
// is built as the drag starts, not again on every change of selection.
onActiveChanged: {
Expand Down
9 changes: 9 additions & 0 deletions src/FolderList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ FileListView {
onTapped: (point) => list.contextMenu(selecting.menuAt(point), backend.path, point.scenePosition)
}

// Keep an active drag on its original file, following the existing
// non-reusing behavior until it ends.
property Item dragSource: null
reuseItems: dragSource === null
focus: true
keyNavigationEnabled: true
// No cursor of its own to start with: the pane puts it back where the
Expand All @@ -81,6 +85,11 @@ FileListView {
model: backend.folder

delegate: FileRow {
id: entry
Drag.onActiveChanged: {
if (Drag.active) list.dragSource = entry
else if (list.dragSource === entry) list.dragSource = null
}
width: list.width
detailed: true
tree: backend.folder.expandable
Expand Down
Loading
Loading