forked from qt-creator/qt-creator
Use more FileUtils based file dialogs
Change-Id: I1e7ec0493c26afe58e17afb8923a2b1023f6dcd4 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -44,6 +44,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
@@ -97,7 +99,7 @@ private:
|
||||
|
||||
Ui::DocSettingsPage m_ui;
|
||||
|
||||
QString m_recentDialogPath;
|
||||
FilePath m_recentDialogPath;
|
||||
|
||||
using NameSpaceToPathHash = QMultiHash<QString, QString>;
|
||||
NameSpaceToPathHash m_filesToRegister;
|
||||
@@ -200,29 +202,29 @@ DocSettingsPageWidget::DocSettingsPageWidget()
|
||||
|
||||
void DocSettingsPageWidget::addDocumentation()
|
||||
{
|
||||
const QStringList &files =
|
||||
QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(),
|
||||
tr("Add Documentation"), m_recentDialogPath, tr("Qt Help Files (*.qch)"));
|
||||
const FilePaths files =
|
||||
FileUtils::getOpenFilePaths(m_ui.addButton->parentWidget(),
|
||||
tr("Add Documentation"), m_recentDialogPath, tr("Qt Help Files (*.qch)"));
|
||||
|
||||
if (files.isEmpty())
|
||||
return;
|
||||
m_recentDialogPath = QFileInfo(files.first()).canonicalPath();
|
||||
m_recentDialogPath = files.first().canonicalPath();
|
||||
|
||||
NameSpaceToPathHash docsUnableToRegister;
|
||||
for (const QString &file : files) {
|
||||
const QString filePath = QDir::cleanPath(file);
|
||||
for (const FilePath &file : files) {
|
||||
const QString filePath = file.cleanPath().toString();
|
||||
const QString &nameSpace = HelpManager::namespaceFromFile(filePath);
|
||||
if (nameSpace.isEmpty()) {
|
||||
docsUnableToRegister.insert("UnknownNamespace", QDir::toNativeSeparators(filePath));
|
||||
docsUnableToRegister.insert("UnknownNamespace", file.toUserOutput());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_filesToRegister.contains(nameSpace)) {
|
||||
docsUnableToRegister.insert(nameSpace, QDir::toNativeSeparators(filePath));
|
||||
docsUnableToRegister.insert(nameSpace, file.toUserOutput());
|
||||
continue;
|
||||
}
|
||||
|
||||
m_model.insertEntry(createEntry(nameSpace, file, true /* user managed */));
|
||||
m_model.insertEntry(createEntry(nameSpace, file.toString(), true /* user managed */));
|
||||
|
||||
m_filesToRegister.insert(nameSpace, filePath);
|
||||
m_filesToRegisterUserManaged.insert(nameSpace, true/*user managed*/);
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
@@ -46,10 +45,12 @@
|
||||
#include <QTextStream>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Help::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
GeneralSettingsPage::GeneralSettingsPage()
|
||||
{
|
||||
@@ -219,13 +220,13 @@ void GeneralSettingsPage::importBookmarks()
|
||||
{
|
||||
m_ui->errorLabel->setVisible(false);
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName(ICore::dialogParent(),
|
||||
tr("Import Bookmarks"), QDir::currentPath(), tr("Files (*.xbel)"));
|
||||
FilePath filePath = FileUtils::getOpenFilePath(nullptr,
|
||||
tr("Import Bookmarks"), FilePath::fromString(QDir::currentPath()), tr("Files (*.xbel)"));
|
||||
|
||||
if (fileName.isEmpty())
|
||||
if (filePath.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file(fileName);
|
||||
QFile file(filePath.toString());
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
const BookmarkManager &manager = LocalHelpManager::bookmarkManager();
|
||||
XbelReader reader(manager.treeBookmarkModel(), manager.listBookmarkModel());
|
||||
@@ -241,14 +242,14 @@ void GeneralSettingsPage::exportBookmarks()
|
||||
{
|
||||
m_ui->errorLabel->setVisible(false);
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(ICore::dialogParent(),
|
||||
FilePath filePath = FileUtils::getSaveFilePath(nullptr,
|
||||
tr("Save File"), "untitled.xbel", tr("Files (*.xbel)"));
|
||||
|
||||
QLatin1String suffix(".xbel");
|
||||
if (!fileName.endsWith(suffix))
|
||||
fileName.append(suffix);
|
||||
if (!filePath.endsWith(suffix))
|
||||
filePath = filePath + suffix;
|
||||
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName));
|
||||
Utils::FileSaver saver(filePath);
|
||||
if (!saver.hasError()) {
|
||||
XbelWriter writer(LocalHelpManager::bookmarkManager().treeBookmarkModel());
|
||||
writer.writeToFile(saver.file());
|
||||
@@ -366,3 +367,6 @@ void GeneralSettingsPage::finish()
|
||||
delete m_ui;
|
||||
m_ui = nullptr;
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Help
|
||||
|
||||
Reference in New Issue
Block a user