more efficient desktop icons
This commit is contained in:
@@ -6,227 +6,264 @@ import qs.Components
|
||||
import qs.Config
|
||||
|
||||
Item {
|
||||
id: contextMenu
|
||||
id: contextMenu
|
||||
|
||||
anchors.fill: parent
|
||||
z: 999
|
||||
visible: false
|
||||
property real menuX: 0
|
||||
property real menuY: 0
|
||||
property var targetAppEntry: null
|
||||
property string targetFilePath: ""
|
||||
property bool targetIsDir: false
|
||||
property var targetPaths: []
|
||||
|
||||
property string targetFilePath: ""
|
||||
property bool targetIsDir: false
|
||||
property var targetAppEntry: null
|
||||
signal openFileRequested(string path, bool isDir)
|
||||
signal renameRequested(string path)
|
||||
|
||||
property var targetPaths: []
|
||||
function close() {
|
||||
visible = false;
|
||||
}
|
||||
|
||||
signal openFileRequested(string path, bool isDir)
|
||||
signal renameRequested(string path)
|
||||
function openAt(mouseX, mouseY, path, isDir, appEnt, parentW, parentH, selectionArray) {
|
||||
targetFilePath = path;
|
||||
targetIsDir = isDir;
|
||||
targetAppEntry = appEnt;
|
||||
|
||||
property real menuX: 0
|
||||
property real menuY: 0
|
||||
targetPaths = (selectionArray && selectionArray.length > 0) ? selectionArray : [path];
|
||||
|
||||
CustomClippingRect {
|
||||
id: popupBackground
|
||||
readonly property real padding: Appearance.padding.small
|
||||
menuX = Math.floor(Math.min(mouseX, parentW - popupBackground.implicitWidth));
|
||||
menuY = Math.floor(Math.min(mouseY, parentH - popupBackground.implicitHeight));
|
||||
|
||||
x: contextMenu.menuX
|
||||
y: contextMenu.menuY
|
||||
visible = true;
|
||||
}
|
||||
|
||||
color: DynamicColors.tPalette.m3surface
|
||||
radius: Appearance.rounding.normal
|
||||
anchors.fill: parent
|
||||
visible: false
|
||||
z: 999
|
||||
|
||||
implicitWidth: menuLayout.implicitWidth + padding * 2
|
||||
implicitHeight: menuLayout.implicitHeight + padding * 2
|
||||
CustomClippingRect {
|
||||
id: popupBackground
|
||||
|
||||
Behavior on opacity { Anim {} }
|
||||
opacity: contextMenu.visible ? 1 : 0
|
||||
readonly property real padding: Appearance.padding.small
|
||||
|
||||
ColumnLayout {
|
||||
id: menuLayout
|
||||
anchors.centerIn: parent
|
||||
spacing: 0
|
||||
color: DynamicColors.tPalette.m3surface
|
||||
implicitHeight: menuLayout.implicitHeight + padding * 2
|
||||
implicitWidth: menuLayout.implicitWidth + padding * 2
|
||||
opacity: contextMenu.visible ? 1 : 0
|
||||
radius: Appearance.rounding.normal
|
||||
x: contextMenu.menuX
|
||||
y: contextMenu.menuY
|
||||
|
||||
CustomRect {
|
||||
Layout.preferredWidth: 160
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
implicitHeight: openRow.implicitHeight + Appearance.padding.small * 2
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: openRow
|
||||
spacing: 8
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
ColumnLayout {
|
||||
id: menuLayout
|
||||
|
||||
MaterialIcon { text: "open_in_new"; font.pointSize: 20 }
|
||||
CustomText { text: "Open"; Layout.fillWidth: true }
|
||||
}
|
||||
anchors.centerIn: parent
|
||||
spacing: 0
|
||||
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
CustomRect {
|
||||
Layout.preferredWidth: 160
|
||||
implicitHeight: openRow.implicitHeight + Appearance.padding.small * 2
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
|
||||
onClicked: {
|
||||
for (let i = 0; i < contextMenu.targetPaths.length; i++) {
|
||||
let p = contextMenu.targetPaths[i];
|
||||
if (p === contextMenu.targetFilePath) {
|
||||
if (p.endsWith(".desktop") && contextMenu.targetAppEntry) contextMenu.targetAppEntry.execute()
|
||||
else contextMenu.openFileRequested(p, contextMenu.targetIsDir)
|
||||
} else {
|
||||
Quickshell.execDetached(["xdg-open", p])
|
||||
}
|
||||
}
|
||||
contextMenu.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
id: openRow
|
||||
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
implicitHeight: openWithRow.implicitHeight + Appearance.padding.small * 2
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
spacing: 8
|
||||
|
||||
RowLayout {
|
||||
id: openWithRow
|
||||
spacing: 8
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
MaterialIcon {
|
||||
font.pointSize: 20
|
||||
text: "open_in_new"
|
||||
}
|
||||
|
||||
MaterialIcon { text: contextMenu.targetIsDir ? "terminal" : "apps"; font.pointSize: 20 }
|
||||
CustomText { text: contextMenu.targetIsDir ? "Open in terminal" : "Open with..."; Layout.fillWidth: true }
|
||||
}
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
text: "Open"
|
||||
}
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
|
||||
onClicked: {
|
||||
for (let i = 0; i < contextMenu.targetPaths.length; i++) {
|
||||
let p = contextMenu.targetPaths[i];
|
||||
if (p === contextMenu.targetFilePath) {
|
||||
if (p.endsWith(".desktop") && contextMenu.targetAppEntry)
|
||||
contextMenu.targetAppEntry.execute();
|
||||
else
|
||||
contextMenu.openFileRequested(p, contextMenu.targetIsDir);
|
||||
} else {
|
||||
Quickshell.execDetached(["xdg-open", p]);
|
||||
}
|
||||
}
|
||||
contextMenu.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: openWithRow.implicitHeight + Appearance.padding.small * 2
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
|
||||
RowLayout {
|
||||
id: openWithRow
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
spacing: 8
|
||||
|
||||
MaterialIcon {
|
||||
font.pointSize: 20
|
||||
text: contextMenu.targetIsDir ? "terminal" : "apps"
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
text: contextMenu.targetIsDir ? "Open in terminal" : "Open with..."
|
||||
}
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
|
||||
onClicked: {
|
||||
if (contextMenu.targetIsDir) {
|
||||
Quickshell.execDetached([Config.general.apps.terminal, "--working-directory", contextMenu.targetFilePath])
|
||||
Quickshell.execDetached([Config.general.apps.terminal, "--working-directory", contextMenu.targetFilePath]);
|
||||
} else {
|
||||
Quickshell.execDetached(["xdg-open", contextMenu.targetFilePath])
|
||||
Quickshell.execDetached(["xdg-open", contextMenu.targetFilePath]);
|
||||
}
|
||||
contextMenu.close()
|
||||
contextMenu.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: 1
|
||||
color: DynamicColors.palette.m3outlineVariant
|
||||
Layout.topMargin: 4
|
||||
Layout.bottomMargin: 4
|
||||
}
|
||||
CustomRect {
|
||||
Layout.bottomMargin: 4
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 4
|
||||
color: DynamicColors.palette.m3outlineVariant
|
||||
implicitHeight: 1
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
implicitHeight: copyPathRow.implicitHeight + Appearance.padding.small * 2
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: copyPathRow.implicitHeight + Appearance.padding.small * 2
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
|
||||
RowLayout {
|
||||
id: copyPathRow
|
||||
spacing: 8
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
RowLayout {
|
||||
id: copyPathRow
|
||||
|
||||
MaterialIcon { text: "content_copy"; font.pointSize: 20 }
|
||||
CustomText { text: "Copy path"; Layout.fillWidth: true }
|
||||
}
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
spacing: 8
|
||||
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
MaterialIcon {
|
||||
font.pointSize: 20
|
||||
text: "content_copy"
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
Quickshell.execDetached(["wl-copy", contextMenu.targetPaths.join("\n")])
|
||||
contextMenu.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
text: "Copy path"
|
||||
}
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
visible: contextMenu.targetPaths.length === 1
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
implicitHeight: renameRow.implicitHeight + Appearance.padding.small * 2
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
|
||||
RowLayout {
|
||||
id: renameRow
|
||||
spacing: 8
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
onClicked: {
|
||||
Quickshell.execDetached(["wl-copy", contextMenu.targetPaths.join("\n")]);
|
||||
contextMenu.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MaterialIcon { text: "edit"; font.pointSize: 20 }
|
||||
CustomText { text: "Rename"; Layout.fillWidth: true }
|
||||
}
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: renameRow.implicitHeight + Appearance.padding.small * 2
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
visible: contextMenu.targetPaths.length === 1
|
||||
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
RowLayout {
|
||||
id: renameRow
|
||||
|
||||
onClicked: {
|
||||
contextMenu.renameRequested(contextMenu.targetFilePath)
|
||||
contextMenu.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
spacing: 8
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: 1
|
||||
color: DynamicColors.palette.m3outlineVariant
|
||||
Layout.topMargin: 4
|
||||
Layout.bottomMargin: 4
|
||||
}
|
||||
MaterialIcon {
|
||||
font.pointSize: 20
|
||||
text: "edit"
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
implicitHeight: deleteRow.implicitHeight + Appearance.padding.small * 2
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
text: "Rename"
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: deleteRow
|
||||
spacing: 8
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
|
||||
MaterialIcon {
|
||||
text: "delete"
|
||||
font.pointSize: 20
|
||||
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
|
||||
}
|
||||
onClicked: {
|
||||
contextMenu.renameRequested(contextMenu.targetFilePath);
|
||||
contextMenu.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
text: "Move to trash"
|
||||
Layout.fillWidth: true
|
||||
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
Layout.bottomMargin: 4
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 4
|
||||
color: DynamicColors.palette.m3outlineVariant
|
||||
implicitHeight: 1
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
id: deleteButton
|
||||
anchors.fill: parent
|
||||
color: DynamicColors.tPalette.m3error
|
||||
CustomRect {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: deleteRow.implicitHeight + Appearance.padding.small * 2
|
||||
radius: popupBackground.radius - popupBackground.padding
|
||||
|
||||
onClicked: {
|
||||
let cmd = ["gio", "trash"].concat(contextMenu.targetPaths)
|
||||
Quickshell.execDetached(cmd)
|
||||
contextMenu.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
id: deleteRow
|
||||
|
||||
function openAt(mouseX, mouseY, path, isDir, appEnt, parentW, parentH, selectionArray) {
|
||||
targetFilePath = path
|
||||
targetIsDir = isDir
|
||||
targetAppEntry = appEnt
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Appearance.padding.smaller
|
||||
spacing: 8
|
||||
|
||||
targetPaths = (selectionArray && selectionArray.length > 0) ? selectionArray : [path]
|
||||
MaterialIcon {
|
||||
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
|
||||
font.pointSize: 20
|
||||
text: "delete"
|
||||
}
|
||||
|
||||
menuX = Math.floor(Math.min(mouseX, parentW - popupBackground.implicitWidth))
|
||||
menuY = Math.floor(Math.min(mouseY, parentH - popupBackground.implicitHeight))
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
|
||||
text: "Move to trash"
|
||||
}
|
||||
}
|
||||
|
||||
visible = true
|
||||
}
|
||||
StateLayer {
|
||||
id: deleteButton
|
||||
|
||||
function close() {
|
||||
visible = false
|
||||
}
|
||||
anchors.fill: parent
|
||||
color: DynamicColors.tPalette.m3error
|
||||
|
||||
onClicked: {
|
||||
let cmd = ["gio", "trash"].concat(contextMenu.targetPaths);
|
||||
Quickshell.execDetached(cmd);
|
||||
contextMenu.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,19 @@ import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
id: delegateRoot
|
||||
id: root
|
||||
|
||||
property var appEntry: fileName.endsWith(".desktop") ? DesktopEntries.byId(DesktopUtils.getAppId(fileName)) : null
|
||||
property bool fileIsDir: model.isDir
|
||||
property string fileName: model.fileName
|
||||
property string filePath: model.filePath
|
||||
property int gridX: model.gridX
|
||||
property int gridY: model.gridY
|
||||
required property var contextMenu
|
||||
property bool fileIsDir: modelData.isDir
|
||||
property string fileName: modelData.fileName
|
||||
property string filePath: modelData.filePath
|
||||
property int gridX: modelData.gridX
|
||||
property int gridY: modelData.gridY
|
||||
required property Item iconsRoot
|
||||
property bool isSnapping: snapAnimX.running || snapAnimY.running
|
||||
property bool lassoActive
|
||||
required property var modelData
|
||||
property string resolvedIcon: {
|
||||
if (fileName.endsWith(".desktop")) {
|
||||
if (appEntry && appEntry.icon && appEntry.icon !== "")
|
||||
@@ -29,8 +32,8 @@ Item {
|
||||
}
|
||||
|
||||
function compensateAndSnap(absVisX, absVisY) {
|
||||
dragContainer.x = absVisX - delegateRoot.x;
|
||||
dragContainer.y = absVisY - delegateRoot.y;
|
||||
dragContainer.x = absVisX - root.x;
|
||||
dragContainer.y = absVisY - root.y;
|
||||
snapAnimX.start();
|
||||
snapAnimY.start();
|
||||
}
|
||||
@@ -43,19 +46,19 @@ Item {
|
||||
return dragContainer.y;
|
||||
}
|
||||
|
||||
height: root.cellHeight
|
||||
width: root.cellWidth
|
||||
x: gridX * root.cellWidth
|
||||
y: gridY * root.cellHeight
|
||||
height: root.iconsRoot.cellHeight
|
||||
width: root.iconsRoot.cellWidth
|
||||
x: gridX * root.iconsRoot.cellWidth
|
||||
y: gridY * root.iconsRoot.cellHeight
|
||||
|
||||
Behavior on x {
|
||||
enabled: !mouseArea.drag.active && !isSnapping && !root.selectedIcons.includes(filePath)
|
||||
enabled: !mouseArea.drag.active && !root.isSnapping && !root.iconsRoot.selectedIcons.includes(root.filePath)
|
||||
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on y {
|
||||
enabled: !mouseArea.drag.active && !isSnapping && !root.selectedIcons.includes(filePath)
|
||||
enabled: !mouseArea.drag.active && !root.isSnapping && !root.iconsRoot.selectedIcons.includes(root.filePath)
|
||||
|
||||
Anim {
|
||||
}
|
||||
@@ -78,8 +81,8 @@ Item {
|
||||
}
|
||||
}
|
||||
transform: Translate {
|
||||
x: (root.selectedIcons.includes(filePath) && root.dragLeader !== "" && root.dragLeader !== filePath) ? root.groupDragX : 0
|
||||
y: (root.selectedIcons.includes(filePath) && root.dragLeader !== "" && root.dragLeader !== filePath) ? root.groupDragY : 0
|
||||
x: (root.iconsRoot.selectedIcons.includes(root.filePath) && root.iconsRoot.dragLeader !== "" && root.iconsRoot.dragLeader !== root.filePath) ? root.iconsRoot.groupDragX : 0
|
||||
y: (root.iconsRoot.selectedIcons.includes(root.filePath) && root.iconsRoot.dragLeader !== "" && root.iconsRoot.dragLeader !== root.filePath) ? root.iconsRoot.groupDragY : 0
|
||||
}
|
||||
transitions: Transition {
|
||||
Anim {
|
||||
@@ -88,14 +91,14 @@ Item {
|
||||
|
||||
onXChanged: {
|
||||
if (mouseArea.drag.active) {
|
||||
root.dragLeader = filePath;
|
||||
root.groupDragX = x;
|
||||
root.iconsRoot.dragLeader = root.filePath;
|
||||
root.iconsRoot.groupDragX = x;
|
||||
}
|
||||
}
|
||||
onYChanged: {
|
||||
if (mouseArea.drag.active) {
|
||||
root.dragLeader = filePath;
|
||||
root.groupDragY = y;
|
||||
root.iconsRoot.dragLeader = root.filePath;
|
||||
root.iconsRoot.groupDragY = y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +130,10 @@ Item {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
implicitSize: 48
|
||||
source: {
|
||||
if (delegateRoot.resolvedIcon.startsWith("file://") || delegateRoot.resolvedIcon.startsWith("/")) {
|
||||
return delegateRoot.resolvedIcon;
|
||||
if (root.resolvedIcon.startsWith("file://") || root.resolvedIcon.startsWith("/")) {
|
||||
return root.resolvedIcon;
|
||||
} else {
|
||||
return Quickshell.iconPath(delegateRoot.resolvedIcon, fileIsDir ? "folder" : "text-x-generic");
|
||||
return Quickshell.iconPath(root.resolvedIcon, root.fileIsDir ? "folder" : "text-x-generic");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,7 +150,7 @@ Item {
|
||||
maximumLineCount: 2
|
||||
style: Text.Outline
|
||||
styleColor: "black"
|
||||
text: (appEntry && appEntry.name !== "") ? appEntry.name : fileName
|
||||
text: (root.appEntry && root.appEntry.name !== "") ? root.appEntry.name : root.fileName
|
||||
visible: !renameLoader.active
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
@@ -155,7 +158,7 @@ Item {
|
||||
Loader {
|
||||
id: renameLoader
|
||||
|
||||
active: root.editingFilePath === filePath
|
||||
active: root.iconsRoot.editingFilePath === root.filePath
|
||||
anchors.centerIn: parent
|
||||
height: 24
|
||||
width: 110
|
||||
@@ -165,7 +168,7 @@ Item {
|
||||
anchors.margins: 2
|
||||
color: "white"
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: fileName
|
||||
text: root.fileName
|
||||
wrapMode: Text.Wrap
|
||||
|
||||
Component.onCompleted: {
|
||||
@@ -174,22 +177,22 @@ Item {
|
||||
}
|
||||
Keys.onPressed: function (event) {
|
||||
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
||||
if (text.trim() !== "" && text !== fileName) {
|
||||
if (text.trim() !== "" && text !== root.fileName) {
|
||||
let newName = text.trim();
|
||||
let newPath = filePath.substring(0, filePath.lastIndexOf('/') + 1) + newName;
|
||||
let newPath = root.filePath.substring(0, root.filePath.lastIndexOf('/') + 1) + newName;
|
||||
|
||||
Quickshell.execDetached(["mv", filePath, newPath]);
|
||||
Quickshell.execDetached(["mv", root.filePath, newPath]);
|
||||
}
|
||||
root.editingFilePath = "";
|
||||
root.iconsRoot.editingFilePath = "";
|
||||
event.accepted = true;
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
root.editingFilePath = "";
|
||||
root.iconsRoot.editingFilePath = "";
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
onActiveFocusChanged: {
|
||||
if (!activeFocus && root.editingFilePath === filePath) {
|
||||
root.editingFilePath = "";
|
||||
if (!activeFocus && root.iconsRoot.editingFilePath === root.filePath) {
|
||||
root.iconsRoot.editingFilePath = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,7 +204,7 @@ Item {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 4
|
||||
color: "white"
|
||||
opacity: root.selectedIcons.includes(filePath) ? 0.2 : 0.0
|
||||
opacity: root.iconsRoot.selectedIcons.includes(root.filePath) ? 0.2 : 0.0
|
||||
radius: Appearance.rounding.smallest
|
||||
|
||||
Behavior on opacity {
|
||||
@@ -215,45 +218,45 @@ Item {
|
||||
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
anchors.fill: parent
|
||||
cursorShape: root.lassoActive ? undefined : Qt.PointingHandCursor
|
||||
cursorShape: root.iconsRoot.lassoActive ? undefined : Qt.PointingHandCursor
|
||||
drag.target: dragContainer
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: mouse => {
|
||||
root.forceActiveFocus();
|
||||
root.iconsRoot.forceActiveFocus();
|
||||
|
||||
if (mouse.button === Qt.RightButton) {
|
||||
if (!root.selectedIcons.includes(filePath)) {
|
||||
root.selectedIcons = [filePath];
|
||||
if (!root.iconsRoot.selectedIcons.includes(root.filePath)) {
|
||||
root.iconsRoot.selectedIcons = [root.filePath];
|
||||
}
|
||||
let pos = mapToItem(root, mouse.x, mouse.y);
|
||||
root.contextMenu.openAt(pos.x, pos.y, filePath, fileIsDir, appEntry, root.width, root.height, root.selectedIcons);
|
||||
let pos = mapToItem(root.iconsRoot, mouse.x, mouse.y);
|
||||
root.contextMenu.openAt(pos.x, pos.y, root.filePath, root.fileIsDir, root.appEntry, root.iconsRoot.width, root.iconsRoot.height, root.iconsRoot.selectedIcons);
|
||||
} else {
|
||||
root.selectedIcons = [filePath];
|
||||
root.iconsRoot.selectedIcons = [root.filePath];
|
||||
root.contextMenu.close();
|
||||
}
|
||||
}
|
||||
onDoubleClicked: mouse => {
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
if (filePath.endsWith(".desktop") && appEntry)
|
||||
appEntry.execute();
|
||||
if (root.filePath.endsWith(".desktop") && root.appEntry)
|
||||
root.appEntry.execute();
|
||||
else
|
||||
root.exec(filePath, fileIsDir);
|
||||
root.iconsRoot.exec(root.filePath, root.fileIsDir);
|
||||
}
|
||||
}
|
||||
onPressed: mouse => {
|
||||
if (mouse.button === Qt.LeftButton && !root.selectedIcons.includes(filePath)) {
|
||||
root.selectedIcons = [filePath];
|
||||
if (mouse.button === Qt.LeftButton && !root.iconsRoot.selectedIcons.includes(root.filePath)) {
|
||||
root.iconsRoot.selectedIcons = [root.filePath];
|
||||
}
|
||||
}
|
||||
onReleased: {
|
||||
if (drag.active) {
|
||||
let absoluteX = delegateRoot.x + dragContainer.x;
|
||||
let absoluteY = delegateRoot.y + dragContainer.y;
|
||||
let snapX = Math.max(0, Math.round(absoluteX / root.cellWidth));
|
||||
let snapY = Math.max(0, Math.round(absoluteY / root.cellHeight));
|
||||
let absoluteX = root.x + dragContainer.x;
|
||||
let absoluteY = root.y + dragContainer.y;
|
||||
let snapX = Math.max(0, Math.round(absoluteX / root.iconsRoot.cellWidth));
|
||||
let snapY = Math.max(0, Math.round(absoluteY / root.iconsRoot.cellHeight));
|
||||
|
||||
root.performMassDrop(filePath, snapX, snapY);
|
||||
root.iconsRoot.performMassDrop(root.filePath, snapX, snapY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import qs.Modules
|
||||
import ZShell.Services
|
||||
import qs.Helpers
|
||||
import qs.Config
|
||||
import qs.Components
|
||||
import qs.Paths
|
||||
import ZShell.Services
|
||||
|
||||
Item {
|
||||
id: root
|
||||
@@ -23,7 +24,34 @@ Item {
|
||||
property real startY: 0
|
||||
|
||||
function exec(filePath, isDir) {
|
||||
const cmd = ["xdg-open", filePath];
|
||||
let type = DesktopUtils.getFileType(filePath, isDir);
|
||||
let cmd = [];
|
||||
switch (type) {
|
||||
case "image":
|
||||
cmd = [Config.options.apps.imageViewer, filePath];
|
||||
break;
|
||||
case "video":
|
||||
cmd = [Config.options.apps.videoPlayer, filePath];
|
||||
break;
|
||||
case "audio":
|
||||
cmd = [Config.options.apps.audioPlayer, filePath];
|
||||
break;
|
||||
case "archive":
|
||||
cmd = [Config.options.apps.archiveManager, filePath];
|
||||
break;
|
||||
case "directory":
|
||||
cmd = [Config.options.apps.fileManager, filePath];
|
||||
break;
|
||||
case "code":
|
||||
case "text":
|
||||
cmd = [Config.options.apps.textEditor, filePath];
|
||||
break;
|
||||
case "document":
|
||||
cmd = [Config.options.apps.documentViewer, filePath];
|
||||
break;
|
||||
default:
|
||||
cmd = ["xdg-open", filePath];
|
||||
}
|
||||
Quickshell.execDetached(cmd);
|
||||
}
|
||||
|
||||
@@ -57,6 +85,7 @@ Item {
|
||||
root.groupDragY = 0;
|
||||
}
|
||||
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
|
||||
Keys.onPressed: event => {
|
||||
@@ -67,6 +96,8 @@ Item {
|
||||
DesktopModel {
|
||||
id: desktopModel
|
||||
|
||||
rows: Math.max(1, Math.floor(gridArea.height / root.cellHeight))
|
||||
|
||||
Component.onCompleted: loadDirectory(FileUtils.trimFileProtocol(Paths.desktop))
|
||||
}
|
||||
|
||||
@@ -133,10 +164,10 @@ Item {
|
||||
lasso.width = Math.abs(mouse.x - root.startX);
|
||||
lasso.height = Math.abs(mouse.y - root.startY);
|
||||
|
||||
let minCol = Math.floor((lasso.x - gridArea.x) / cellWidth);
|
||||
let maxCol = Math.floor((lasso.x + lasso.width - gridArea.x) / cellWidth);
|
||||
let minRow = Math.floor((lasso.y - gridArea.y) / cellHeight);
|
||||
let maxRow = Math.floor((lasso.y + lasso.height - gridArea.y) / cellHeight);
|
||||
let minCol = Math.floor((lasso.x - gridArea.x) / root.cellWidth);
|
||||
let maxCol = Math.floor((lasso.x + lasso.width - gridArea.x) / root.cellWidth);
|
||||
let minRow = Math.floor((lasso.y - gridArea.y) / root.cellHeight);
|
||||
let maxRow = Math.floor((lasso.y + lasso.height - gridArea.y) / root.cellHeight);
|
||||
|
||||
let newSelection = [];
|
||||
for (let i = 0; i < gridArea.children.length; i++) {
|
||||
@@ -158,10 +189,10 @@ Item {
|
||||
} else {
|
||||
bgContextMenu.close();
|
||||
root.selectedIcons = [];
|
||||
root.startX = Math.floor(mouse.x);
|
||||
root.startY = Math.floor(mouse.y);
|
||||
lasso.x = Math.floor(mouse.x);
|
||||
lasso.y = Math.floor(mouse.y);
|
||||
root.startX = mouse.x;
|
||||
root.startY = mouse.y;
|
||||
lasso.x = mouse.x;
|
||||
lasso.y = mouse.y;
|
||||
lasso.width = 0;
|
||||
lasso.height = 0;
|
||||
lasso.showLasso();
|
||||
@@ -178,15 +209,15 @@ Item {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 20
|
||||
anchors.topMargin: 40
|
||||
visible: true
|
||||
|
||||
Repeater {
|
||||
model: desktopModel
|
||||
|
||||
delegate: DesktopIconDelegate {
|
||||
property int itemIndex: index
|
||||
required property int index
|
||||
|
||||
lassoActive: root.lassoActive
|
||||
contextMenu: desktopMenu
|
||||
iconsRoot: root
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,6 +233,5 @@ Item {
|
||||
|
||||
BackgroundContextMenu {
|
||||
id: bgContextMenu
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user