forked from qt-creator/qt-creator
Utils: Allow full file paths with directory parts
... when creating a new empty file. This simplifies file creation with file paths cut&paste from external applications as it removes the need to split it into a directory part and the file name. Change-Id: I3f81db89d5ae7db4117c29a4f947cdf92dc4d50c Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -95,6 +95,11 @@ void FileWizardPage::setFileName(const QString &name)
|
||||
d->m_ui.nameLineEdit->setText(name);
|
||||
}
|
||||
|
||||
void FileWizardPage::setAllowDirectoriesInFileSelector(bool allow)
|
||||
{
|
||||
d->m_ui.nameLineEdit->setAllowDirectories(allow);
|
||||
}
|
||||
|
||||
bool FileWizardPage::isComplete() const
|
||||
{
|
||||
return d->m_complete;
|
||||
|
@@ -54,6 +54,7 @@ public:
|
||||
|
||||
bool forceFirstCapitalLetterForFileName() const;
|
||||
void setForceFirstCapitalLetterForFileName(bool b);
|
||||
void setAllowDirectoriesInFileSelector(bool allow);
|
||||
|
||||
// Validate a base name entry field (potentially containing extension)
|
||||
static bool validateBaseName(const QString &name, QString *errorMessage = nullptr);
|
||||
|
@@ -27,13 +27,17 @@
|
||||
|
||||
#include "jsonwizard.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QVariant>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
JsonFilePage::JsonFilePage(QWidget *parent) : Utils::FileWizardPage(parent)
|
||||
{ }
|
||||
JsonFilePage::JsonFilePage(QWidget *parent)
|
||||
: FileWizardPage(parent)
|
||||
{
|
||||
setAllowDirectoriesInFileSelector(true);
|
||||
}
|
||||
|
||||
void JsonFilePage::initializePage()
|
||||
{
|
||||
@@ -53,16 +57,13 @@ bool JsonFilePage::validatePage()
|
||||
if (path().isEmpty() || fileName().isEmpty())
|
||||
return false;
|
||||
|
||||
QFileInfo d(path());
|
||||
if (!d.isDir())
|
||||
const FilePath dir = FilePath::fromString(path());
|
||||
if (!dir.isDir())
|
||||
return false;
|
||||
|
||||
QString target = d.absoluteFilePath();
|
||||
if (!target.endsWith(QLatin1Char('/')))
|
||||
target += QLatin1Char('/');
|
||||
target += fileName();
|
||||
const FilePath target = dir.resolvePath(fileName());
|
||||
|
||||
wizard()->setProperty("TargetPath", target);
|
||||
wizard()->setProperty("TargetPath", target.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user