Fix problems with browse of folder in settings dialog.

This commit is contained in:
Adam Treat 2023-07-09 13:05:06 -04:00
parent 58d6f40f50
commit d9f0245c1b
4 changed files with 23 additions and 19 deletions

View File

@ -53,14 +53,6 @@ MySettingsTab {
MySettings.userDefaultModel = comboBox.currentText MySettings.userDefaultModel = comboBox.currentText
} }
} }
FolderDialog {
id: modelPathDialog
title: "Please choose a directory"
currentFolder: "file://" + MySettings.modelPath
onAccepted: {
MySettings.modelPath = selectedFolder
}
}
Label { Label {
id: modelPathLabel id: modelPathLabel
text: qsTr("Download path:") text: qsTr("Download path:")
@ -93,7 +85,11 @@ MySettingsTab {
Layout.column: 2 Layout.column: 2
text: qsTr("Browse") text: qsTr("Browse")
Accessible.description: qsTr("Opens a folder picker dialog to choose where to save model files") Accessible.description: qsTr("Opens a folder picker dialog to choose where to save model files")
onClicked: modelPathDialog.open() onClicked: {
openFolderDialog("file://" + MySettings.modelPath, function(selectedFolder) {
MySettings.modelPath = selectedFolder
})
}
} }
Label { Label {
id: nThreadsLabel id: nThreadsLabel

View File

@ -21,15 +21,6 @@ MySettingsTab {
property alias collection: collection.text property alias collection: collection.text
property alias folder_path: folderEdit.text property alias folder_path: folderEdit.text
FolderDialog {
id: folderDialog
title: "Please choose a directory"
currentFolder: StandardPaths.writableLocation(StandardPaths.HomeLocation)
onAccepted: {
root.folder_path = selectedFolder
}
}
Item { Item {
Layout.fillWidth: true Layout.fillWidth: true
height: row.height height: row.height
@ -79,7 +70,9 @@ MySettingsTab {
id: browseButton id: browseButton
text: qsTr("Browse") text: qsTr("Browse")
onClicked: { onClicked: {
folderDialog.open(); openFolderDialog(StandardPaths.writableLocation(StandardPaths.HomeLocation), function(selectedFolder) {
root.folder_path = selectedFolder
})
} }
} }

View File

@ -3,6 +3,8 @@ import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Dialogs
import Qt.labs.folderlistmodel
import mysettings import mysettings
Item { Item {
@ -91,6 +93,17 @@ Item {
border.color: theme.tabBorder border.color: theme.tabBorder
} }
FolderDialog {
id: folderDialog
title: qsTr("Please choose a directory")
}
function openFolderDialog(currentFolder, onAccepted) {
folderDialog.currentFolder = currentFolder;
folderDialog.accepted.connect(function() { onAccepted(folderDialog.currentFolder); });
folderDialog.open();
}
StackLayout { StackLayout {
id: stackLayout id: stackLayout
anchors.top: tabTitlesModel.count > 1 ? dividerTabBar.bottom : titleLabel.bottom anchors.top: tabTitlesModel.count > 1 ? dividerTabBar.bottom : titleLabel.bottom
@ -106,6 +119,7 @@ Item {
sourceComponent: model.modelData sourceComponent: model.modelData
onLoaded: { onLoaded: {
settingsStack.tabTitlesModel.append({ "title": loader.item.title }); settingsStack.tabTitlesModel.append({ "title": loader.item.title });
item.openFolderDialog = settingsStack.openFolderDialog;
} }
} }
} }

View File

@ -9,6 +9,7 @@ Item {
property string title: "" property string title: ""
property Item contentItem: null property Item contentItem: null
property Item advancedSettings: null property Item advancedSettings: null
property var openFolderDialog
signal restoreDefaultsClicked signal restoreDefaultsClicked
onContentItemChanged: function() { onContentItemChanged: function() {