| 1 |
/* |
| 2 |
* Copyright (C) 2025 UBports Foundation |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License 3 as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see http://www.gnu.org/licenses/. |
| 16 |
*/ |
| 17 |
|
| 18 |
import QtQuick 2.12 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import QtQuick.Layouts 1.12 |
| 21 |
import Lomiri.Components.Popups 1.3 |
| 22 |
|
| 23 |
import "../components" as Components |
| 24 |
import "../actions" as FMActions |
| 25 |
import "../views" as Views |
| 26 |
import "../backend" |
| 27 |
|
| 28 |
Item { |
| 29 |
id: rootItem |
| 30 |
|
| 31 |
property var folderPage |
| 32 |
property FolderListModel folderModel |
| 33 |
property var selectionManager: folderModel.model.selectionObject |
| 34 |
property var openDefault |
| 35 |
property var fileOperationDialog |
| 36 |
property bool selectionMode: false |
| 37 |
property bool contentHubMode: false |
| 38 |
property bool importMode: false |
| 39 |
property bool narrowAspect: false |
| 40 |
property bool searchBarIsShown: false |
| 41 |
|
| 42 |
readonly property var defaultLeadingActions: folderPage.showPanelAction.visible ? folderPage.showPanelAction : placesBookmarkAction |
| 43 |
readonly property var defaultTrailingActions: { |
| 44 |
if (narrowAspect) { |
| 45 |
return [ |
| 46 |
searchAction, newAction |
| 47 |
, addBookmarkAction, propertiesAction |
| 48 |
, openInTerminalAction |
| 49 |
] |
| 50 |
} else { |
| 51 |
return [ |
| 52 |
openInTerminalAction, propertiesAction |
| 53 |
, addBookmarkAction, newAction, searchAction |
| 54 |
] |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
readonly property var defaultHeaderSecondaryTrailingActions: [ clearClipboardAction, pasteAction ] |
| 59 |
|
| 60 |
readonly property var extensionLeadingActions: [ goForwardAction, goBackAction ] |
| 61 |
|
| 62 |
readonly property var extensionTrailingActions: narrowAspect ? [ settingsAction ] |
| 63 |
: [ |
| 64 |
settingsAction, viewTypeAction |
| 65 |
] |
| 66 |
|
| 67 |
readonly property var selectionLeadingActions: [ |
| 68 |
cancelSelectionModeAction |
| 69 |
] |
| 70 |
|
| 71 |
readonly property var selectionTrailingActions: { |
| 72 |
if (narrowAspect) { |
| 73 |
return [ |
| 74 |
cutAction, copyAction, selectUnselectAllAction |
| 75 |
, openAdvancedAction, renameAction, deleteAction |
| 76 |
, propertiesAction |
| 77 |
] |
| 78 |
} else { |
| 79 |
return [ |
| 80 |
selectUnselectAllAction, copyAction |
| 81 |
, cutAction, openAdvancedAction, renameAction |
| 82 |
, deleteAction, propertiesAction |
| 83 |
] |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
readonly property var pickerModeTrailingActions: [ |
| 88 |
cancelPickerModeAction, selectAction, newAction, searchAction |
| 89 |
] |
| 90 |
|
| 91 |
property alias goBackAction: goBackAction |
| 92 |
property alias goForwardAction: goForwardAction |
| 93 |
property alias placesBookmarkAction: placesBookmarkAction |
| 94 |
property alias searchAction: searchAction |
| 95 |
property alias copyAction: copyAction |
| 96 |
|
| 97 |
property var __delegateActions: Views.FolderDelegateActions { |
| 98 |
folderListPage: rootItem.folderModel |
| 99 |
folderModel: rootItem.folderPage.folderModel |
| 100 |
fileOperationDialog: rootItem.fileOperationDialog |
| 101 |
openDefault: rootItem.openDefault |
| 102 |
} |
| 103 |
|
| 104 |
signal enterSearch |
| 105 |
|
| 106 |
function enterSelectionMode() { |
| 107 |
fileSelectorMode = true |
| 108 |
fileSelector.fileSelectorComponent = pageStack |
| 109 |
} |
| 110 |
|
| 111 |
ActionContext { |
| 112 |
id: globalContext |
| 113 |
|
| 114 |
active: true |
| 115 |
actions: [ |
| 116 |
FMActions.GoBack { |
| 117 |
id: goBackAction |
| 118 |
shortcut: "Alt+Left" |
| 119 |
enabled: folderModel.canGoBack |
| 120 |
onTriggered: folderModel.goBack() |
| 121 |
}, |
| 122 |
FMActions.GoForward { |
| 123 |
id: goForwardAction |
| 124 |
shortcut: "Alt+Right" |
| 125 |
enabled: folderModel.canGoForward |
| 126 |
onTriggered: folderModel.goForward() |
| 127 |
}, |
| 128 |
FMActions.GoUp { |
| 129 |
id: goUpAction |
| 130 |
visible: folderModel.canGoUp |
| 131 |
onTriggered: folderModel.goUp() |
| 132 |
}, |
| 133 |
FMActions.GoHome { |
| 134 |
id: goHomeAction |
| 135 |
visible: folderModel.canGoHome |
| 136 |
onTriggered: folderModel.goHome() |
| 137 |
}, |
| 138 |
FMActions.ViewType { |
| 139 |
id: viewTypeAction |
| 140 |
isGrid: globalSettings.viewMethod == 1 |
| 141 |
onTriggered: { |
| 142 |
if (isGrid) { |
| 143 |
globalSettings.viewMethod = 0 |
| 144 |
} else { |
| 145 |
globalSettings.viewMethod = 1 |
| 146 |
} |
| 147 |
} |
| 148 |
}, |
| 149 |
FMActions.Settings { |
| 150 |
id: settingsAction |
| 151 |
onTriggered: PopupUtils.open(Qt.resolvedUrl("ViewPopover.qml"), mainView, { folderListModel: folderModel.model }) |
| 152 |
}, |
| 153 |
FMActions.Properties { |
| 154 |
id: propertiesAction |
| 155 |
visible: !rootItem.searchBarIsShown |
| 156 |
shortcut: "Alt+Return" |
| 157 |
|
| 158 |
onTriggered: { |
| 159 |
if (selectionManager.counter == 1) { |
| 160 |
var props = { |
| 161 |
"model": folderModel.primSelItem |
| 162 |
} |
| 163 |
PopupUtils.open(Qt.resolvedUrl("FileDetailsPopover.qml"), mainView, props) |
| 164 |
} else { |
| 165 |
print(text) |
| 166 |
PopupUtils.open(Qt.resolvedUrl("FileDetailsPopover.qml"), mainView,{ "model": folderModel.model }) |
| 167 |
} |
| 168 |
} |
| 169 |
}, |
| 170 |
FMActions.Search { |
| 171 |
id: searchAction |
| 172 |
showSearchBar: rootItem.searchBarIsShown |
| 173 |
shortcut: rootItem.searchBarIsShown ? StandardKey.Cancel: StandardKey.Find |
| 174 |
enabled: rootItem.contentHubMode || !rootItem.selectionMode |
| 175 |
onTriggered: rootItem.enterSearch() |
| 176 |
}, |
| 177 |
FMActions.NewItem { |
| 178 |
id: newAction |
| 179 |
// Hide when in export mode since we don't expect users to create new folders in this case |
| 180 |
visible: !rootItem.searchBarIsShown && !(rootItem.contentHubMode && !rootItem.importMode) |
| 181 |
property bool smallText: true |
| 182 |
enabled: folderModel.model.isWritable |
| 183 |
shortcut: "Ctrl+Shift+N" |
| 184 |
onTriggered: { |
| 185 |
print(text) |
| 186 |
let props = { folderPage: folderListPage, folderModel: folderModel.model, folderOnly: rootItem.contentHubMode && rootItem.importMode } |
| 187 |
PopupUtils.open(Qt.resolvedUrl("../dialogs/CreateItemDialog.qml"), mainView, props) |
| 188 |
} |
| 189 |
}, |
| 190 |
FMActions.FileClearSelection { |
| 191 |
id: clearClipboardAction |
| 192 |
clipboardUrlsCounter: folderModel.model.clipboardUrlsCounter |
| 193 |
visible: folderModel.model.clipboardUrlsCounter > 0 && !rootItem.searchBarIsShown |
| 194 |
onTriggered: { |
| 195 |
console.log("Clearing clipboard") |
| 196 |
folderModel.model.clearClipboard() |
| 197 |
folderPage.tooltipMsg = i18n.tr("Cleared clipboard") |
| 198 |
} |
| 199 |
}, |
| 200 |
FMActions.FilePaste { |
| 201 |
id: pasteAction |
| 202 |
property bool smallText: true |
| 203 |
|
| 204 |
clipboardUrlsCounter: folderModel.model.clipboardUrlsCounter |
| 205 |
visible: folderModel.model.clipboardUrlsCounter > 0 && !rootItem.searchBarIsShown |
| 206 |
shortcut: StandardKey.Paste |
| 207 |
onTriggered: { |
| 208 |
console.log("Pasting to current folder items of count " + folderModel.model.clipboardUrlsCounter) |
| 209 |
fileOperationDialog.startOperation(i18n.tr("Paste files")) |
| 210 |
folderModel.model.paste() |
| 211 |
folderPage.tooltipMsg = i18n.tr("Pasted item", "Pasted items", folderModel.model.clipboardUrlsCounter) |
| 212 |
|
| 213 |
// We want this in a mobile environment. |
| 214 |
folderModel.model.clearClipboard() |
| 215 |
} |
| 216 |
}, |
| 217 |
FMActions.AddBookmark { |
| 218 |
id: addBookmarkAction |
| 219 |
visible: !folderModel.model.clipboardUrlsCounter > 0 && !rootItem.searchBarIsShown |
| 220 |
shortcut: "Ctrl+D" |
| 221 |
onTriggered: { |
| 222 |
print(text) |
| 223 |
folderModel.places.addLocation(folderModel.model.path) |
| 224 |
folderPage.tooltipMsg = i18n.tr("Added '%1' to Places").arg(folderModel.model.fileName) |
| 225 |
|
| 226 |
} |
| 227 |
}, |
| 228 |
FMActions.Terminal { |
| 229 |
id: openInTerminalAction |
| 230 |
visible: !rootItem.searchBarIsShown |
| 231 |
onTriggered: { |
| 232 |
print(text) |
| 233 |
Qt.openUrlExternally("terminal://?path=" + folderModel.model.path) |
| 234 |
} |
| 235 |
}, |
| 236 |
FMActions.PlacesBookmarks { |
| 237 |
id: placesBookmarkAction |
| 238 |
property var pushedPage |
| 239 |
|
| 240 |
shortcut: "Ctrl+Shift+O" |
| 241 |
enabled: !folderPage.sidebarActive |
| 242 |
|
| 243 |
onTriggered: { |
| 244 |
if (pushedPage) { |
| 245 |
pushedPage.pageStack.pop() |
| 246 |
pushedPage = null |
| 247 |
} else { |
| 248 |
const pp = pageStack.push(Qt.resolvedUrl("PlacesPage.qml"), { folderModel: rootItem.folderModel }) |
| 249 |
pushedPage = pp |
| 250 |
pp.pathClicked.connect(function() { |
| 251 |
pp.pageStack.pop() |
| 252 |
pushedPage = null |
| 253 |
}) |
| 254 |
} |
| 255 |
} |
| 256 |
}, |
| 257 |
FMActions.SelectUnselectAll { |
| 258 |
id: selectUnselectAllAction |
| 259 |
selectedAll: selectionManager.selectedAll |
| 260 |
shortcut: { |
| 261 |
if (rootItem.selectionMode && selectedAll) { |
| 262 |
return StandardKey.Deselect |
| 263 |
} |
| 264 |
|
| 265 |
return StandardKey.SelectAll |
| 266 |
|
| 267 |
} |
| 268 |
onTriggered: { |
| 269 |
if (selectionManager.selectedAll) { |
| 270 |
selectionManager.clear() |
| 271 |
} else { |
| 272 |
if (!rootItem.selectionMode) { |
| 273 |
rootItem.enterSelectionMode() |
| 274 |
} |
| 275 |
selectionManager.selectAll() |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
] |
| 280 |
} |
| 281 |
|
| 282 |
ActionContext { |
| 283 |
id: selectionContext |
| 284 |
|
| 285 |
property bool actionsEnabled: (rootItem.selectionManager.counter > 0) || (folderSelectorMode && folderModel.model.isWritable) |
| 286 |
property bool actionsVisible: selectionMode |
| 287 |
|
| 288 |
active: rootItem.selectionMode |
| 289 |
actions: [ |
| 290 |
Action { |
| 291 |
id: cancelSelectionModeAction |
| 292 |
text: i18n.tr("Cancel") |
| 293 |
iconName: "close" |
| 294 |
// TODO: This triggers first when closing a dialog with Escape |
| 295 |
shortcut: StandardKey.Cancel |
| 296 |
onTriggered: { |
| 297 |
console.log("FileSelector cancelled") |
| 298 |
rootItem.selectionManager.clear() |
| 299 |
fileSelectorMode = false |
| 300 |
fileSelector.fileSelectorComponent = null |
| 301 |
} |
| 302 |
}, |
| 303 |
FMActions.FileCopy { |
| 304 |
id: copyAction |
| 305 |
property bool smallText: true |
| 306 |
enabled: selectionContext.actionsEnabled |
| 307 |
visible: selectionContext.actionsVisible |
| 308 |
shortcut: StandardKey.Copy |
| 309 |
onTriggered: { |
| 310 |
var selectedAbsPaths = rootItem.selectionManager.selectedAbsFilePaths(); |
| 311 |
folderModel.model.copyPaths(selectedAbsPaths) |
| 312 |
rootItem.selectionManager.clear() |
| 313 |
fileSelectorMode = false |
| 314 |
fileSelector.fileSelectorComponent = null |
| 315 |
} |
| 316 |
}, |
| 317 |
FMActions.FileCut { |
| 318 |
id: cutAction |
| 319 |
property bool smallText: true |
| 320 |
enabled: selectionContext.actionsEnabled |
| 321 |
visible: selectionContext.actionsVisible && folderModel.model.isWritable |
| 322 |
shortcut: StandardKey.Cut |
| 323 |
onTriggered: { |
| 324 |
var selectedAbsPaths = rootItem.selectionManager.selectedAbsFilePaths(); |
| 325 |
folderModel.model.cutPaths(selectedAbsPaths) |
| 326 |
rootItem.selectionManager.clear() |
| 327 |
fileSelectorMode = false |
| 328 |
fileSelector.fileSelectorComponent = null |
| 329 |
} |
| 330 |
}, |
| 331 |
FMActions.Delete { |
| 332 |
id: deleteAction |
| 333 |
property bool smallText: true |
| 334 |
enabled: selectionContext.actionsEnabled |
| 335 |
visible: selectionContext.actionsVisible && folderModel.model.isWritable |
| 336 |
shortcut: StandardKey.Delete |
| 337 |
onTriggered: { |
| 338 |
var selectedAbsPaths = rootItem.selectionManager.selectedAbsFilePaths(); |
| 339 |
var props = { |
| 340 |
"paths" : selectedAbsPaths, |
| 341 |
"selectionManager" : rootItem.selectionManager, |
| 342 |
"folderModel": folderModel.model, |
| 343 |
"fileOperationDialog": fileOperationDialogObj |
| 344 |
} |
| 345 |
|
| 346 |
PopupUtils.open(Qt.resolvedUrl("../dialogs/ConfirmMultipleDeleteDialog.qml"), mainView, props) |
| 347 |
} |
| 348 |
}, |
| 349 |
FMActions.OpenAdvanced { |
| 350 |
id: openAdvancedAction |
| 351 |
property bool smallText: true |
| 352 |
enabled: selectionContext.actionsEnabled |
| 353 |
visible: selectionContext.actionsVisible && !folderModel.primSelItem.isBrowsable && rootItem.openDefault && rootItem.selectionManager.counter == 1 |
| 354 |
onTriggered: __delegateActions.openAdvanced(folderModel.primSelItem) |
| 355 |
}, |
| 356 |
FMActions.Rename { |
| 357 |
id: renameAction |
| 358 |
visible: selectionContext.actionsVisible && folderModel.model.isWritable && selectionManager.counter == 1 |
| 359 |
shortcut: "F2" |
| 360 |
onTriggered: { |
| 361 |
var props = { |
| 362 |
"modelRow" : folderModel.primSelItem.index, |
| 363 |
"inputText" : folderModel.primSelItem.fileName, |
| 364 |
"placeholderText" : folderModel.primSelItem.fileName, |
| 365 |
"folderModel": folderModel.model |
| 366 |
} |
| 367 |
|
| 368 |
var popup = PopupUtils.open(Qt.resolvedUrl("../dialogs/ConfirmRenameDialog.qml"), mainView, props) |
| 369 |
|
| 370 |
popup.accepted.connect(function(inputText) { |
| 371 |
console.log("Rename accepted", inputText) |
| 372 |
if (inputText !== '') { |
| 373 |
console.log("Rename commensed, modelRow/inputText", fileOperationDialog.index, inputText.trim()) |
| 374 |
if (folderModel.model.rename(folderModel.primSelItem.index, inputText.trim()) === false) { |
| 375 |
var props = { |
| 376 |
title: i18n.tr("Could not rename"), |
| 377 |
text: i18n.tr("Insufficient permissions, name contains special chars (e.g. '/'), or already exists") |
| 378 |
} |
| 379 |
PopupUtils.open(Qt.resolvedUrl("../dialogs/NotifyDialog.qml"), mainView, props) |
| 380 |
} |
| 381 |
selectionManager.clear() |
| 382 |
fileSelectorMode = false |
| 383 |
} else { |
| 384 |
console.log("Empty new name given, ignored") |
| 385 |
} |
| 386 |
}) |
| 387 |
} |
| 388 |
} |
| 389 |
] |
| 390 |
} |
| 391 |
|
| 392 |
ActionContext { |
| 393 |
id: pickerModeContext |
| 394 |
|
| 395 |
property bool actionsEnabled: (rootItem.selectionManager.counter > 0) || (folderSelectorMode && folderModel.model.isWritable) |
| 396 |
property bool actionsVisible: selectionMode |
| 397 |
|
| 398 |
active: rootItem.contentHubMode |
| 399 |
actions: [ |
| 400 |
FMActions.Cancel { |
| 401 |
id: cancelPickerModeAction |
| 402 |
text: i18n.tr("Cancel") |
| 403 |
iconName: "close" |
| 404 |
shortcut: StandardKey.Cancel |
| 405 |
onTriggered: { |
| 406 |
console.log("FileSelector cancelled") |
| 407 |
mainView.cancelFileSelector() |
| 408 |
rootItem.selectionManager.clear() |
| 409 |
} |
| 410 |
}, |
| 411 |
FMActions.Select { |
| 412 |
id: selectAction |
| 413 |
enabled: rootItem.selectionManager.counter > 0 || rootItem.importMode |
| 414 |
onTriggered: { |
| 415 |
var selectedAbsUrls = [] |
| 416 |
if (folderSelectorMode) { |
| 417 |
selectedAbsUrls = [ folderModel.path ] |
| 418 |
} else { |
| 419 |
var selectedAbsPaths = rootItem.selectionManager.selectedAbsFilePaths(); |
| 420 |
// For now support only selection in filesystem |
| 421 |
selectedAbsUrls = selectedAbsPaths.map(function(item) { |
| 422 |
return "file://" + item; |
| 423 |
}); |
| 424 |
} |
| 425 |
console.log("FileSelector OK clicked, selected items: " + selectedAbsUrls) |
| 426 |
acceptFileSelector(selectedAbsUrls) |
| 427 |
} |
| 428 |
} |
| 429 |
] |
| 430 |
} |
| 431 |
} |