forked from qt-creator/qt-creator
Fix that save as from "file was removed" dialog didn't provide filters
Also removes some code duplication. Change-Id: I4f4616717f2eb37a1c73accdfa81e6d0dae6809f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -738,40 +738,36 @@ QString DocumentManager::getSaveFileNameWithExtension(const QString &title, cons
|
|||||||
/*!
|
/*!
|
||||||
Asks the user for a new file name (\gui {Save File As}) for \a document.
|
Asks the user for a new file name (\gui {Save File As}) for \a document.
|
||||||
*/
|
*/
|
||||||
QString DocumentManager::getSaveAsFileName(const IDocument *document, const QString &filter, QString *selectedFilter)
|
QString DocumentManager::getSaveAsFileName(const IDocument *document)
|
||||||
{
|
{
|
||||||
if (!document)
|
QTC_ASSERT(document, return QString());
|
||||||
return QLatin1String("");
|
Utils::MimeDatabase mdb;
|
||||||
QString absoluteFilePath = document->filePath().toString();
|
const QString filter = Utils::MimeDatabase::allFiltersString();
|
||||||
const QFileInfo fi(absoluteFilePath);
|
const QString filePath = document->filePath().toString();
|
||||||
QString path;
|
QString selectedFilter;
|
||||||
QString fileName;
|
QString fileDialogPath = filePath;
|
||||||
if (absoluteFilePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
fileName = document->fallbackSaveAsFileName();
|
selectedFilter = mdb.mimeTypeForFile(filePath).filterString();
|
||||||
|
} else {
|
||||||
|
const QString suggestedName = document->fallbackSaveAsFileName();
|
||||||
|
if (!suggestedName.isEmpty()) {
|
||||||
|
const QList<MimeType> types = mdb.mimeTypesForFileName(suggestedName);
|
||||||
|
if (!types.isEmpty())
|
||||||
|
selectedFilter = types.first().filterString();
|
||||||
|
}
|
||||||
const QString defaultPath = document->fallbackSaveAsPath();
|
const QString defaultPath = document->fallbackSaveAsPath();
|
||||||
if (!defaultPath.isEmpty())
|
if (!defaultPath.isEmpty())
|
||||||
path = defaultPath;
|
fileDialogPath = defaultPath + (suggestedName.isEmpty()
|
||||||
} else {
|
? QString()
|
||||||
path = fi.absolutePath();
|
: '/' + suggestedName);
|
||||||
fileName = fi.fileName();
|
|
||||||
}
|
}
|
||||||
|
if (selectedFilter.isEmpty())
|
||||||
|
selectedFilter = mdb.mimeTypeForName(document->mimeType()).filterString();
|
||||||
|
|
||||||
QString filterString;
|
return getSaveFileName(tr("Save File As"),
|
||||||
if (filter.isEmpty()) {
|
fileDialogPath,
|
||||||
Utils::MimeDatabase mdb;
|
filter,
|
||||||
const Utils::MimeType &mt = mdb.mimeTypeForFile(fi);
|
&selectedFilter);
|
||||||
if (mt.isValid())
|
|
||||||
filterString = mt.filterString();
|
|
||||||
selectedFilter = &filterString;
|
|
||||||
} else {
|
|
||||||
filterString = filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
absoluteFilePath = getSaveFileName(tr("Save File As"),
|
|
||||||
path + QLatin1Char('/') + fileName,
|
|
||||||
filterString,
|
|
||||||
selectedFilter);
|
|
||||||
return absoluteFilePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -92,8 +92,7 @@ public:
|
|||||||
const QString &filter = QString(), QString *selectedFilter = 0);
|
const QString &filter = QString(), QString *selectedFilter = 0);
|
||||||
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
|
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
|
||||||
const QString &filter);
|
const QString &filter);
|
||||||
static QString getSaveAsFileName(const IDocument *document, const QString &filter = QString(),
|
static QString getSaveAsFileName(const IDocument *document);
|
||||||
QString *selectedFilter = 0);
|
|
||||||
|
|
||||||
static bool saveAllModifiedDocumentsSilently(bool *canceled = 0,
|
static bool saveAllModifiedDocumentsSilently(bool *canceled = 0,
|
||||||
QList<IDocument *> *failedToClose = 0);
|
QList<IDocument *> *failedToClose = 0);
|
||||||
|
@@ -2100,24 +2100,8 @@ bool EditorManagerPrivate::saveDocumentAs(IDocument *document)
|
|||||||
if (!document)
|
if (!document)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Utils::MimeDatabase mdb;
|
|
||||||
const QString filter = Utils::MimeDatabase::allFiltersString();
|
|
||||||
QString selectedFilter;
|
|
||||||
const QString filePath = document->filePath().toString();
|
|
||||||
if (!filePath.isEmpty()) {
|
|
||||||
selectedFilter = mdb.mimeTypeForFile(filePath).filterString();
|
|
||||||
} else {
|
|
||||||
const QString suggestedName = document->fallbackSaveAsFileName();
|
|
||||||
if (!suggestedName.isEmpty()) {
|
|
||||||
const QList<MimeType> types = mdb.mimeTypesForFileName(suggestedName);
|
|
||||||
if (!types.isEmpty())
|
|
||||||
selectedFilter = types.first().filterString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (selectedFilter.isEmpty())
|
|
||||||
selectedFilter = mdb.mimeTypeForName(document->mimeType()).filterString();
|
|
||||||
const QString &absoluteFilePath =
|
const QString &absoluteFilePath =
|
||||||
DocumentManager::getSaveAsFileName(document, filter, &selectedFilter);
|
DocumentManager::getSaveAsFileName(document);
|
||||||
|
|
||||||
if (absoluteFilePath.isEmpty())
|
if (absoluteFilePath.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user