filemanager/qml/FolderPage.qml

418 lines
10 KiB
QML
Raw Normal View History

2021-05-24 04:01:26 -07:00
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: revenmartin <revenmartin@gmail.com>
*
* This program 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
* any later version.
*
* This program 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 <http://www.gnu.org/licenses/>.
*/
2021-03-29 01:51:34 -07:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
2021-07-24 12:50:15 -07:00
import QtGraphicalEffects 1.0
2021-06-23 02:29:47 -07:00
import Qt.labs.platform 1.0
2021-03-29 01:51:34 -07:00
2021-06-15 21:43:43 -07:00
import Cutefish.FileManager 1.0 as FM
2021-04-09 07:49:19 -07:00
import FishUI 1.0 as FishUI
2021-03-29 01:51:34 -07:00
import "./Dialogs"
Item {
id: folderPage
property alias currentUrl: dirModel.url
2021-09-12 04:30:01 -07:00
property alias model: dirModel
2021-03-29 01:51:34 -07:00
property Item currentView: _viewLoader.item
2021-04-14 19:26:54 -07:00
property int statusBarHeight: 22
2021-03-29 01:51:34 -07:00
signal requestPathEditor()
onCurrentUrlChanged: {
2021-04-04 13:06:24 -07:00
_viewLoader.item.reset()
2021-03-29 01:51:34 -07:00
_viewLoader.item.forceActiveFocus()
}
2021-06-23 02:29:47 -07:00
// Global Menu
MenuBar {
id: appMenu
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("New Folder")
onTriggered: dirModel.newFolder()
}
MenuSeparator {}
MenuItem {
text: qsTr("Properties")
onTriggered: dirModel.openPropertiesDialog()
}
MenuSeparator {}
MenuItem {
text: qsTr("Quit")
onTriggered: root.close()
2021-06-23 02:29:47 -07:00
}
}
Menu {
title: qsTr("Edit")
MenuItem {
text: qsTr("Select All")
onTriggered: dirModel.selectAll()
}
2021-08-03 01:02:24 -07:00
MenuSeparator {}
MenuItem {
text: qsTr("Cut")
onTriggered: dirModel.cut()
}
MenuItem {
text: qsTr("Copy")
onTriggered: dirModel.copy()
}
MenuItem {
text: qsTr("Paste")
onTriggered: dirModel.paste()
}
2021-06-23 02:29:47 -07:00
}
Menu {
title: qsTr("Help")
MenuItem {
text: qsTr("About")
}
}
}
2021-03-29 01:51:34 -07:00
Rectangle {
id: _background
anchors.fill: parent
2021-09-10 23:41:22 -07:00
anchors.rightMargin: 1
radius: FishUI.Theme.mediumRadius
2021-07-08 08:48:56 -07:00
color: FishUI.Theme.secondBackgroundColor
2021-07-24 12:50:15 -07:00
Rectangle {
id: _topRightRect
anchors.right: parent.right
anchors.top: parent.top
height: FishUI.Theme.mediumRadius
width: FishUI.Theme.mediumRadius
2021-07-24 12:50:15 -07:00
color: FishUI.Theme.secondBackgroundColor
}
Rectangle {
id: _bottomLeftRect
anchors.left: parent.left
anchors.bottom: parent.bottom
height: FishUI.Theme.mediumRadius
width: FishUI.Theme.mediumRadius
2021-07-24 12:50:15 -07:00
color: FishUI.Theme.secondBackgroundColor
}
2021-03-29 01:51:34 -07:00
}
Label {
id: _fileTips
2021-04-04 13:06:24 -07:00
text: qsTr("Empty folder")
2021-04-14 19:26:54 -07:00
font.pointSize: 15
2021-03-29 01:51:34 -07:00
anchors.centerIn: parent
visible: false
}
2021-06-15 21:43:43 -07:00
FM.FolderModel {
id: dirModel
2021-03-29 01:51:34 -07:00
viewAdapter: viewAdapter
2021-08-31 13:39:44 -07:00
sortMode: settings.sortMode
2021-09-12 04:30:01 -07:00
// showHiddenFiles: settings.showHiddenFiles
2021-03-29 01:51:34 -07:00
Component.onCompleted: {
2021-03-30 21:45:51 -07:00
if (arg)
dirModel.url = arg
2021-03-30 21:45:51 -07:00
else
dirModel.url = dirModel.homePath()
2021-03-29 01:51:34 -07:00
}
}
2021-08-31 14:31:38 -07:00
Connections {
target: dirModel
function onNotification(text) {
root.showPassiveNotification(text, 3000)
}
}
2021-06-15 21:43:43 -07:00
FM.ItemViewAdapter {
2021-03-29 01:51:34 -07:00
id: viewAdapter
adapterView: _viewLoader.item
adapterModel: _viewLoader.item.positioner ? _viewLoader.item.positioner : dirModel
2021-03-29 01:51:34 -07:00
adapterIconSize: 40
adapterVisibleArea: Qt.rect(_viewLoader.item.contentX, _viewLoader.item.contentY,
_viewLoader.item.contentWidth, _viewLoader.item.contentHeight)
}
2021-04-09 07:49:19 -07:00
FishUI.DesktopMenu {
id: folderMenu
MenuItem {
text: qsTr("Open")
onTriggered: dirModel.openSelected()
}
MenuItem {
text: qsTr("Properties")
onTriggered: dirModel.openPropertiesDialog()
}
}
2021-03-29 01:51:34 -07:00
ColumnLayout {
anchors.fill: parent
2021-07-24 12:50:15 -07:00
anchors.bottomMargin: 2
2021-03-29 01:51:34 -07:00
spacing: 0
Loader {
id: _viewLoader
Layout.fillWidth: true
Layout.fillHeight: true
sourceComponent: switch (settings.viewMethod) {
case 0: return _listViewComponent
case 1: return _gridViewComponent
}
2021-04-04 13:06:24 -07:00
onSourceComponentChanged: {
2021-06-15 21:43:43 -07:00
// Focus
2021-04-04 13:06:24 -07:00
_viewLoader.item.forceActiveFocus()
2021-06-15 21:43:43 -07:00
// ShortCut
shortCut.install(_viewLoader.item)
2021-04-04 13:06:24 -07:00
}
2021-03-29 01:51:34 -07:00
}
2021-07-24 12:50:15 -07:00
Item {
2021-07-28 12:44:29 -07:00
visible: true
2021-07-24 12:50:15 -07:00
height: statusBarHeight
2021-03-29 01:51:34 -07:00
}
}
2021-07-24 12:50:15 -07:00
Item {
id: _statusBar
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: statusBarHeight
z: 999
2021-08-16 18:53:52 -07:00
// Rectangle {
// anchors.fill: parent
// color: FishUI.Theme.backgroundColor
// opacity: 0.7
// }
2021-03-30 18:22:32 -07:00
2021-07-24 12:50:15 -07:00
MouseArea {
anchors.fill: parent
}
2021-03-30 18:22:32 -07:00
2021-07-24 12:50:15 -07:00
RowLayout {
anchors.fill: parent
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
// anchors.bottomMargin: 1
spacing: FishUI.Units.largeSpacing
2021-03-29 01:51:34 -07:00
2021-07-24 12:50:15 -07:00
Label {
Layout.alignment: Qt.AlignLeft
font.pointSize: 10
text: dirModel.count === 1 ? qsTr("%1 item").arg(dirModel.count)
: qsTr("%1 items").arg(dirModel.count)
}
2021-04-01 01:05:15 -07:00
2021-07-24 12:50:15 -07:00
Label {
Layout.alignment: Qt.AlignLeft
font.pointSize: 10
text: qsTr("%1 selected").arg(dirModel.selectionCount)
visible: dirModel.selectionCount >= 1
}
2021-04-01 01:05:15 -07:00
2021-09-05 14:39:56 -07:00
Label {
text: dirModel.selectedItemSize
}
2021-07-24 12:50:15 -07:00
Item {
Layout.fillWidth: true
}
2021-03-29 01:51:34 -07:00
2021-07-24 12:50:15 -07:00
Button {
Layout.fillHeight: true
Layout.alignment: Qt.AlignRight
text: qsTr("Empty Trash")
font.pointSize: 10
onClicked: dirModel.emptyTrash()
visible: dirModel.url === "trash:///"
focusPolicy: Qt.NoFocus
2021-03-29 01:51:34 -07:00
}
}
}
2021-07-24 12:50:15 -07:00
function rename() {
_viewLoader.item.rename()
}
Component.onCompleted: {
dirModel.requestRename.connect(rename)
}
2021-03-29 01:51:34 -07:00
Component {
id: _gridViewComponent
FolderGridView {
id: _gridView
model: dirModel
2021-03-29 01:51:34 -07:00
delegate: FolderGridItem {}
2021-04-14 19:26:54 -07:00
leftMargin: FishUI.Units.smallSpacing
2021-04-09 07:49:19 -07:00
rightMargin: FishUI.Units.largeSpacing
2021-04-18 03:52:00 -07:00
topMargin: 0
2021-04-09 07:49:19 -07:00
bottomMargin: FishUI.Units.smallSpacing
2021-03-29 07:53:21 -07:00
onIconSizeChanged: {
// Save
settings.gridIconSize = _gridView.iconSize
}
2021-03-29 01:51:34 -07:00
onCountChanged: {
_fileTips.visible = count === 0
}
}
}
Component {
id: _listViewComponent
FolderListView {
id: _folderListView
model: dirModel
2021-03-29 01:51:34 -07:00
2021-04-12 19:46:20 -07:00
topMargin: FishUI.Units.smallSpacing
2021-04-09 07:49:19 -07:00
leftMargin: FishUI.Units.largeSpacing
2021-07-24 12:50:15 -07:00
rightMargin: FishUI.Units.largeSpacing
2021-07-25 10:34:33 -07:00
bottomMargin: FishUI.Units.smallSpacing
2021-04-09 07:49:19 -07:00
spacing: FishUI.Units.largeSpacing
2021-03-29 01:51:34 -07:00
onCountChanged: {
_fileTips.visible = count === 0
}
delegate: FolderListItem {}
}
}
Component {
id: rubberBandObject
2021-06-15 21:43:43 -07:00
FM.RubberBand {
2021-03-29 01:51:34 -07:00
id: rubberBand
width: 0
height: 0
z: 99999
2021-04-09 07:49:19 -07:00
color: FishUI.Theme.highlightColor
2021-03-29 01:51:34 -07:00
function close() {
opacityAnimation.restart()
}
OpacityAnimator {
id: opacityAnimation
target: rubberBand
to: 0
from: 1
duration: 150
easing {
bezierCurve: [0.4, 0.0, 1, 1]
type: Easing.Bezier
}
onFinished: {
rubberBand.visible = false
rubberBand.enabled = false
rubberBand.destroy()
}
}
}
}
2021-06-15 21:43:43 -07:00
FM.ShortCut {
id: shortCut
onOpen: {
dirModel.openSelected()
}
onCopy: {
dirModel.copy()
}
onCut: {
dirModel.cut()
}
onPaste: {
dirModel.paste()
}
onRename: {
dirModel.requestRename()
}
onOpenPathEditor: {
folderPage.requestPathEditor()
}
onSelectAll: {
dirModel.selectAll()
}
onBackspace: {
dirModel.up()
}
onDeleteFile: {
dirModel.keyDeletePress()
2021-03-29 01:51:34 -07:00
}
2021-08-31 13:39:44 -07:00
onRefresh: {
dirModel.refresh()
}
2021-09-27 21:00:19 -07:00
onKeyPressed: {
dirModel.keyboardSearch(text)
}
2021-10-22 07:25:16 -07:00
onShowHidden: {
dirModel.showHiddenFiles = !dirModel.showHiddenFiles
}
2021-03-29 01:51:34 -07:00
}
function openUrl(url) {
dirModel.url = url
2021-03-29 01:51:34 -07:00
_viewLoader.item.forceActiveFocus()
}
function goBack() {
dirModel.goBack()
2021-03-29 01:51:34 -07:00
}
function goForward() {
dirModel.goForward()
2021-03-29 01:51:34 -07:00
}
}