mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
NFilePicker: renamed NFileManager to NFilePicker, update grid hover
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
// Function to open a file manager dialog
|
||||
function open(options) {
|
||||
var component = Qt.createComponent(Qt.resolvedUrl(Quickshell.shellDir + "/Widgets/NFilePicker.qml"))
|
||||
if (component.status === Component.Ready) {
|
||||
// Extract directory from file path if it's a file
|
||||
var initialPath = options.initialPath || Quickshell.env("HOME")
|
||||
if (options.selectFiles && initialPath !== Quickshell.env("HOME")) {
|
||||
// If selecting files and path is not home, extract directory
|
||||
var pathParts = initialPath.split('/')
|
||||
if (pathParts.length > 1) {
|
||||
pathParts.pop() // Remove filename
|
||||
initialPath = pathParts.join('/') || '/'
|
||||
}
|
||||
}
|
||||
|
||||
var dialog = component.createObject(options.parent || Overlay.overlay, {
|
||||
"title": options.title || "Select File/Folder",
|
||||
"initialPath": initialPath,
|
||||
"selectFiles": options.selectFiles || false,
|
||||
"selectFolders": !options.selectFiles || false,
|
||||
"scaling": options.scaling || 1.0
|
||||
})
|
||||
if (dialog) {
|
||||
if (options.onSelected) {
|
||||
if (options.selectFiles) {
|
||||
dialog.fileSelected.connect(options.onSelected)
|
||||
} else {
|
||||
dialog.folderSelected.connect(options.onSelected)
|
||||
}
|
||||
}
|
||||
dialog.open()
|
||||
return dialog
|
||||
}
|
||||
} else {
|
||||
console.error("Component error:", component.errorString())
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user