From d9f0245c1b0c52eca42a2dcb08f6080a1967dfcc Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Sun, 9 Jul 2023 13:05:06 -0400 Subject: [PATCH] Fix problems with browse of folder in settings dialog. --- gpt4all-chat/qml/ApplicationSettings.qml | 14 +++++--------- gpt4all-chat/qml/LocalDocsSettings.qml | 13 +++---------- gpt4all-chat/qml/MySettingsStack.qml | 14 ++++++++++++++ gpt4all-chat/qml/MySettingsTab.qml | 1 + 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/gpt4all-chat/qml/ApplicationSettings.qml b/gpt4all-chat/qml/ApplicationSettings.qml index 4e475ac3..b0208aac 100644 --- a/gpt4all-chat/qml/ApplicationSettings.qml +++ b/gpt4all-chat/qml/ApplicationSettings.qml @@ -53,14 +53,6 @@ MySettingsTab { MySettings.userDefaultModel = comboBox.currentText } } - FolderDialog { - id: modelPathDialog - title: "Please choose a directory" - currentFolder: "file://" + MySettings.modelPath - onAccepted: { - MySettings.modelPath = selectedFolder - } - } Label { id: modelPathLabel text: qsTr("Download path:") @@ -93,7 +85,11 @@ MySettingsTab { Layout.column: 2 text: qsTr("Browse") 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 { id: nThreadsLabel diff --git a/gpt4all-chat/qml/LocalDocsSettings.qml b/gpt4all-chat/qml/LocalDocsSettings.qml index 242be8e1..a1719230 100644 --- a/gpt4all-chat/qml/LocalDocsSettings.qml +++ b/gpt4all-chat/qml/LocalDocsSettings.qml @@ -21,15 +21,6 @@ MySettingsTab { property alias collection: collection.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 { Layout.fillWidth: true height: row.height @@ -79,7 +70,9 @@ MySettingsTab { id: browseButton text: qsTr("Browse") onClicked: { - folderDialog.open(); + openFolderDialog(StandardPaths.writableLocation(StandardPaths.HomeLocation), function(selectedFolder) { + root.folder_path = selectedFolder + }) } } diff --git a/gpt4all-chat/qml/MySettingsStack.qml b/gpt4all-chat/qml/MySettingsStack.qml index fba9fe07..1d179c38 100644 --- a/gpt4all-chat/qml/MySettingsStack.qml +++ b/gpt4all-chat/qml/MySettingsStack.qml @@ -3,6 +3,8 @@ import QtQuick import QtQuick.Controls import QtQuick.Controls.Basic import QtQuick.Layouts +import QtQuick.Dialogs +import Qt.labs.folderlistmodel import mysettings Item { @@ -91,6 +93,17 @@ Item { 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 { id: stackLayout anchors.top: tabTitlesModel.count > 1 ? dividerTabBar.bottom : titleLabel.bottom @@ -106,6 +119,7 @@ Item { sourceComponent: model.modelData onLoaded: { settingsStack.tabTitlesModel.append({ "title": loader.item.title }); + item.openFolderDialog = settingsStack.openFolderDialog; } } } diff --git a/gpt4all-chat/qml/MySettingsTab.qml b/gpt4all-chat/qml/MySettingsTab.qml index 9593564e..fd7ba83d 100644 --- a/gpt4all-chat/qml/MySettingsTab.qml +++ b/gpt4all-chat/qml/MySettingsTab.qml @@ -9,6 +9,7 @@ Item { property string title: "" property Item contentItem: null property Item advancedSettings: null + property var openFolderDialog signal restoreDefaultsClicked onContentItemChanged: function() {