forked from karip/harbour-file-browser
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ClipboardPage.qml
278 lines (247 loc) · 10.8 KB
/
ClipboardPage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* This file is part of File Browser.
*
* SPDX-FileCopyrightText: 2022 Mirian Margiani
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* File Browser is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* File Browser is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import SortFilterProxyModel 0.2
import harbour.file.browser.FileData 1.0
import harbour.file.browser.Settings 1.0
import harbour.file.browser.FileClipboard 1.0
import "../components"
import "../js/paths.js" as Paths
Page {
id: root
// TODO
// - store clipboard contents somewhere and share the clipboard with
// other windows of File Browser (through dconf?)
readonly property string _fnElide: GlobalSettings.generalFilenameElideMode
readonly property int _nameTruncMode: _fnElide === 'fade' ? TruncationMode.Fade : TruncationMode.Elide
readonly property int _nameElideMode: _nameTruncMode === TruncationMode.Fade ?
Text.ElideNone : (_fnElide === 'middle' ?
Text.ElideMiddle : Text.ElideRight)
/* Button {
z: 100000
anchors {
top: parent.top
left: parent.left
margins: Theme.horizontalPageMargin
}
text: "DEBUG!"
onClicked: {
FileClipboard.setPaths(["/home/nemo/Documents", "/home/nemo/Videos", "/home/nemo/Downloads"], FileClipMode.Copy)
FileClipboard.setPaths(["/usr", "/etc", "/bin"], FileClipMode.Link)
FileClipboard.setPaths(["/usr/lib", "/usr/share", "/usr/lib/qt5"], FileClipMode.Cut)
}
} */
SilicaListView {
id: list
anchors.fill: parent
model: FileClipboard.pathsModel
header: Column {
width: parent ? parent.width : Screen.width
PageHeader {
title: qsTr("Clipboard")
description: {
if (FileClipboard.count == 0) {
return ""
} else if (FileClipboard.mode === FileClipMode.Copy) {
return qsTr("%n item(s) to be copied", "", FileClipboard.count)
} else if (FileClipboard.mode === FileClipMode.Cut) {
return qsTr("%n item(s) to be moved", "", FileClipboard.count)
} else if (FileClipboard.mode === FileClipMode.Link) {
return qsTr("%n item(s) to be linked", "", FileClipboard.count)
} else {
return ""
}
}
}
FileClipModePicker {
id: modePicker
visible: FileClipboard.count > 0
selectedMode: FileClipboard.mode
width: parent.width
Connections {
// TODO selecting a mode breaks the binding between
// selectedMode and FileClipboard.mode. This means clipboard
// changes are not properly synchronised. Refactoring this
// in FileClipModePicker requires changes in TransferActionBar though.
target: FileClipboard
onModeChanged: modePicker.selectedMode = FileClipboard.mode
}
onSelectedModeChanged: {
if (selectedMode != FileClipboard.mode) {
FileClipboard.mode = selectedMode
}
}
}
}
PullDownMenu {
enabled: visible
visible: FileClipboard.count > 0
MenuItem {
visible: FileClipboard.count > 0
text: qsTr("Clear", "verb as in 'clear all contents from the clipboard'")
onClicked: {
var remorse = Remorse.popupAction(root, qsTr("Clipboard cleared"), function () {
FileClipboard.clear() })
}
}
}
VerticalScrollDecorator { flickable: list }
section {
property: "directory"
criteria: ViewSection.FullString
labelPositioning: ViewSection.InlineLabels
delegate: SectionHeader {
text: section
}
}
delegate: ListItem {
id: item
property int index: model.index
property string path: model.path
property string directory: model.directory
width: ListView.view.width
contentHeight: Theme.itemSizeMedium
menu: contextMenu
property color _detailsColor: highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
property alias _listLabelWidth: listLabel.width
FileData {
id: fileData
file: path
property string category
Component.onCompleted: category = typeCategory()
}
onClicked: {
pageStack.animatorPush(Qt.resolvedUrl("FilePage.qml"), {
'file': path,
'allowMoveDelete': false,
'enableOpenFolder': true,
})
}
Loader {
id: listIcon
x: Theme.paddingLarge
width: Theme.itemSizeMedium
height: width
anchors.verticalCenter: parent.verticalCenter
sourceComponent: Component {
id: listIconComponent
FileIcon {
showThumbnail: true
highlighted: item.highlighted
file: fileData.file
isDirectory: fileData.isDir
mimeTypeCallback: function() { return fileData.mimeType; }
fileIconCallback: function() { return fileData.icon; }
}
}
asynchronous: index > 20
}
Label {
id: listLabel
y: Theme.paddingSmall
anchors {
left: listIcon.right; leftMargin: Theme.paddingMedium
right: parent.right; rightMargin: Theme.paddingLarge
top: parent.top; topMargin: Theme.paddingSmall
}
text: fileData.name
textFormat: Text.PlainText
truncationMode: _nameTruncMode
elide: _nameElideMode
}
Flow {
anchors {
left: listIcon.right; leftMargin: Theme.paddingMedium
right: parent.right; rightMargin: Theme.paddingLarge
top: listLabel.bottom; bottom: parent.bottom
}
Label {
id: sizeLabel
property string size: fileData.isDir ? fileData.dirSize : fileData.size
text: fileData.isSymLink ? (size + " " + Paths.unicodeArrow() + " " + fileData.symLinkTarget) : size
color: _detailsColor
truncationMode: TruncationMode.Fade
elide: Text.ElideMiddle
font.pixelSize: Theme.fontSizeExtraSmall
}
Label {
id: permsLabel
visible: !fileData.isSymLink
text: fileData.kind + fileData.permissions
color: _detailsColor
truncationMode: TruncationMode.Fade
font.pixelSize: Theme.fontSizeExtraSmall
}
Label {
id: datesLabel
text: fileData.modified
color: _detailsColor
font.pixelSize: Theme.fontSizeExtraSmall
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
states: [
State {
when: _listLabelWidth >= 2*item.width/3
PropertyChanges { target: listLabel; wrapMode: Text.NoWrap; maximumLineCount: 1 }
PropertyChanges { target: sizeLabel; width: (fileData.isSymLink ? _listLabelWidth/3*2 : _listLabelWidth/3); horizontalAlignment: Text.AlignLeft }
PropertyChanges { target: permsLabel; width: _listLabelWidth/3; horizontalAlignment: Text.AlignHCenter }
PropertyChanges { target: datesLabel; width: _listLabelWidth/3; horizontalAlignment: Text.AlignRight }
},
State {
when: _listLabelWidth < 2*item.width/3
PropertyChanges { target: listLabel; wrapMode: Text.WrapAtWordBoundaryOrAnywhere; maximumLineCount: 2 }
PropertyChanges { target: sizeLabel; width: _listLabelWidth; horizontalAlignment: Text.AlignLeft }
PropertyChanges { target: permsLabel; width: _listLabelWidth; horizontalAlignment: Text.AlignLeft }
PropertyChanges { target: datesLabel; width: _listLabelWidth; horizontalAlignment: Text.AlignLeft }
}
]
}
Component {
id: contextMenu
ContextMenu {
MenuItem {
visible: fileData.isDir
text: qsTr("Open this folder")
onClicked: navigate_goToFolder(item.path)
}
MenuItem {
text: qsTr("Open containing folder")
onClicked: navigate_goToFolder(item.directory)
}
MenuItem {
text: qsTr("Remove from clipboard")
onClicked: {
var path = item.path
var forget = FileClipboard.forgetPath
item.remorseDelete(function() { forget(path) })
}
}
}
}
}
ViewPlaceholder {
id: viewPlaceholder
enabled: FileClipboard.count === 0
text: qsTr("Empty")
hintText: qsTr("Cut or copied files will be shown here.")
}
}
}