Commit 84119585 authored by Martin Straka's avatar Martin Straka

Added support for folder selection into QML FileDialog.

parent 3a68ad1f
......@@ -43,8 +43,8 @@ Dialog {
}
AccessibleButton {
text: qsTr("OK")
enabled: (selectedFileIndex != -1)
visible: (selectedFileIndex != -1)
enabled: (onlyDir || selectedFileIndex != -1)
visible: (onlyDir || selectedFileIndex != -1)
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
}
}
......@@ -60,6 +60,7 @@ Dialog {
property bool multiSelect: false
property int selectedFileIndex: -1
property bool onlyDir: false
signal finished(variant pathListModel)
......@@ -67,6 +68,7 @@ Dialog {
root.title = title
folderModel.folder = folderModel.folder
folderModel.showFiles = showFiles
onlyDir = !showFiles
if (filters !== "") {
folderModel.nameFilters = [filters]
}
......@@ -77,6 +79,11 @@ Dialog {
for (fileList.currentIndex = 0; fileList.currentIndex < fileList.count; ++fileList.currentIndex) {
fileList.currentItem.color = datovkaPalette.window
}
if (onlyDir) {
var path = stripUrlPrefix(folderModel.folder)
pathListModel.clear()
pathListModel.append({path: path})
}
root.open()
}
......@@ -237,13 +244,19 @@ Dialog {
}
function handleClick() {
var path
if (fileIsDir) {
/* Navigate to selected directory. */
folderModel.folder = fileURL
if (onlyDir) {
pathListModel.clear()
path = stripUrlPrefix(folderModel.folder)
pathListModel.append({path: path})
}
} else {
/* Select file. */
selectedFileIndex = index
var path = stripUrlPrefix(folderModel.folder) + "/" + folderModel.get(selectedFileIndex, "fileName")
path = stripUrlPrefix(folderModel.folder) + "/" + folderModel.get(selectedFileIndex, "fileName")
if (!multiSelect) {
// only one file can be selected and append to list
pathListModel.clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment