Android: set EXTRA_TITLE to the initially selected file in save dialog
The extra data EXTRA_TITLE is only documented to be used to provide the initially selected file name in the context of file dialog [1]. So, let's stick to setting it only in save mode. This also now allows the save dialog to set an initial file name which wasn't possible before. [1] https://developer.android.com/reference/kotlin/android/content/ Intent#action_create_document Change-Id: Ib55191a7269bfad28af4928f4e74d87981bdd574 Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit cbc29dc16c4e08d6e399c7c26a38736bff80d6e6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
98edfa18c1
commit
cae5e3c348
@ -46,6 +46,7 @@
|
|||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
#include <QMimeType>
|
#include <QMimeType>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ void QAndroidPlatformFileDialogHelper::takePersistableUriPermission(const QJniOb
|
|||||||
uri.object(), modeFlags);
|
uri.object(), modeFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAndroidPlatformFileDialogHelper::setIntentTitle(const QString &title)
|
void QAndroidPlatformFileDialogHelper::setInitialFileName(const QString &title)
|
||||||
{
|
{
|
||||||
const QJniObject extraTitle = QJniObject::getStaticObjectField(
|
const QJniObject extraTitle = QJniObject::getStaticObjectField(
|
||||||
JniIntentClass, "EXTRA_TITLE", "Ljava/lang/String;");
|
JniIntentClass, "EXTRA_TITLE", "Ljava/lang/String;");
|
||||||
@ -209,6 +210,12 @@ bool QAndroidPlatformFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::Win
|
|||||||
|
|
||||||
if (options()->acceptMode() == QFileDialogOptions::AcceptSave) {
|
if (options()->acceptMode() == QFileDialogOptions::AcceptSave) {
|
||||||
m_intent = getFileDialogIntent("ACTION_CREATE_DOCUMENT");
|
m_intent = getFileDialogIntent("ACTION_CREATE_DOCUMENT");
|
||||||
|
const QList<QUrl> selectedFiles = options()->initiallySelectedFiles();
|
||||||
|
if (selectedFiles.size() > 0) {
|
||||||
|
// TODO: The initial folder to show at the start should be handled by EXTRA_INITIAL_URI
|
||||||
|
// Take only the file name.
|
||||||
|
setInitialFileName(selectedFiles.first().fileName());
|
||||||
|
}
|
||||||
} else if (options()->acceptMode() == QFileDialogOptions::AcceptOpen) {
|
} else if (options()->acceptMode() == QFileDialogOptions::AcceptOpen) {
|
||||||
switch (options()->fileMode()) {
|
switch (options()->fileMode()) {
|
||||||
case QFileDialogOptions::FileMode::DirectoryOnly:
|
case QFileDialogOptions::FileMode::DirectoryOnly:
|
||||||
@ -232,8 +239,6 @@ bool QAndroidPlatformFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::Win
|
|||||||
setMimeTypes();
|
setMimeTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
setIntentTitle(options()->windowTitle());
|
|
||||||
|
|
||||||
QtAndroidPrivate::registerActivityResultListener(this);
|
QtAndroidPrivate::registerActivityResultListener(this);
|
||||||
m_activity.callMethod<void>("startActivityForResult", "(Landroid/content/Intent;I)V",
|
m_activity.callMethod<void>("startActivityForResult", "(Landroid/content/Intent;I)V",
|
||||||
m_intent.object(), REQUEST_CODE);
|
m_intent.object(), REQUEST_CODE);
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QJniObject getFileDialogIntent(const QString &intentType);
|
QJniObject getFileDialogIntent(const QString &intentType);
|
||||||
void takePersistableUriPermission(const QJniObject &uri);
|
void takePersistableUriPermission(const QJniObject &uri);
|
||||||
void setIntentTitle(const QString &title);
|
void setInitialFileName(const QString &title);
|
||||||
void setOpenableCategory();
|
void setOpenableCategory();
|
||||||
void setAllowMultipleSelections(bool allowMultiple);
|
void setAllowMultipleSelections(bool allowMultiple);
|
||||||
void setMimeTypes();
|
void setMimeTypes();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user