File wizards: Optionally show the default suffix

In wizards that create a single new file, there's almost always a
default suffix that gets appended if the user provides only the base
name. However, there's currently no visual indication on the page that
such a suffix will be appended. Therefore, we add an optional field to
the FileWizardPage that displays the default suffix if the wizard
provides one.

Change-Id: Ia1c8966e7de14b484d065dbd4a41aa74f484f085
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2020-02-28 15:33:25 +01:00
parent e35289243d
commit 829faf7eef
17 changed files with 72 additions and 21 deletions

View File

@@ -9,7 +9,10 @@
"iconText": "h", "iconText": "h",
"enabled": "%{JS: value('Plugins').indexOf('CppEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('CppEditor') >= 0}",
"options": { "key": "FileName", "value": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-c++hdr'))}" }, "options": [
{ "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-c++hdr')}" },
{ "key": "FileName", "value": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}" }
],
"pages" : "pages" :
[ [

View File

@@ -9,7 +9,10 @@
"iconText": "cpp", "iconText": "cpp",
"enabled": "%{JS: value('Plugins').indexOf('CppEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('CppEditor') >= 0}",
"options": { "key": "FileName", "value": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-c++src'))}" }, "options": [
{ "key": "FileName", "value": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}" },
{ "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-c++src')}" }
],
"pages" : "pages" :
[ [

View File

@@ -10,6 +10,8 @@
"platformIndependent": true, "platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-frag')}" },
"pages" : "pages" :
[ [
{ {
@@ -30,7 +32,7 @@
"data": "data":
{ {
"source": "file.frag", "source": "file.frag",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-glsl-frag'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -10,6 +10,8 @@
"platformIndependent": true, "platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-vert')}" },
"pages" : "pages" :
[ [
{ {
@@ -30,7 +32,7 @@
"data": "data":
{ {
"source": "file.vert", "source": "file.vert",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-glsl-vert'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -10,6 +10,8 @@
"platformIndependent": true, "platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-es-frag')}" },
"pages" : "pages" :
[ [
{ {
@@ -30,7 +32,7 @@
"data": "data":
{ {
"source": "file.fsh", "source": "file.fsh",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-glsl-es-frag'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -10,6 +10,8 @@
"platformIndependent": true, "platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-es-vert')}" },
"pages" : "pages" :
[ [
{ {
@@ -30,7 +32,7 @@
"data": "data":
{ {
"source": "file.vsh", "source": "file.vsh",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-glsl-es-vert'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,7 +9,10 @@
"iconText": "java", "iconText": "java",
"enabled": "%{JS: value('Plugins').indexOf('Android') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('Android') >= 0}",
"options": [ { "key": "ClassName", "value": "%{JS: value('FileName').charAt(0).toUpperCase() + value('FileName').substr(1).replace(/[.]java$/,'')}" } ], "options": [
{ "key": "ClassName", "value": "%{JS: value('FileName').charAt(0).toUpperCase() + value('FileName').substr(1).replace(/[.]java$/,'')}" }.
{ "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-java')}" }
],
"pages" : "pages" :
[ [
@@ -31,7 +34,7 @@
"data": "data":
{ {
"source": "source.java", "source": "source.java",
"target": "%{JS: Util.fileName(value('Path') + '/' + value('ClassName'), Util.preferredSuffix('text/x-java'))}", "target": "%{JS: Util.fileName(value('Path') + '/' + value('ClassName'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,6 +9,8 @@
"iconText": "js", "iconText": "js",
"enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('application/javascript')}" },
"pages" : "pages" :
[ [
{ {
@@ -47,7 +49,7 @@
"data": "data":
{ {
"source": "file.js", "source": "file.js",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('application/javascript'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,6 +9,8 @@
"icon": "../../projects/nim/icon.png", "icon": "../../projects/nim/icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Nim') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('Nim') >= 0}",
"options": { "key": "DefaultSuffix", "value": "nim" },
"pages" : "pages" :
[ [
{ {
@@ -29,7 +31,7 @@
"data": "data":
{ {
"source": "file.nim", "source": "file.nim",
"target": "%{JS: Util.fileName(value('TargetPath'), 'nim')}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,6 +9,8 @@
"icon": "../../projects/nim/icon.png", "icon": "../../projects/nim/icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Nim') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('Nim') >= 0}",
"options": { "key": "DefaultSuffix", "value": "nims" },
"pages" : "pages" :
[ [
{ {
@@ -29,7 +31,7 @@
"data": "data":
{ {
"source": "file.nims", "source": "file.nims",
"target": "%{JS: Util.fileName(value('TargetPath'), 'nims')}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,6 +9,8 @@
"icon": "icon.png", "icon": "icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-python')}" },
"pages" : "pages" :
[ [
{ {
@@ -29,7 +31,7 @@
"data": "data":
{ {
"source": "file.py", "source": "file.py",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-python'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,6 +9,8 @@
"iconText": "qrc", "iconText": "qrc",
"enabled": "%{JS: value('Plugins').indexOf('ResourceEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('ResourceEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('application/vnd.qt.xml.resource')}" },
"pages" : "pages" :
[ [
{ {
@@ -29,7 +31,7 @@
"data": "data":
{ {
"source": "file.qrc", "source": "file.qrc",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('application/vnd.qt.xml.resource'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -9,6 +9,8 @@
"iconText": "qml", "iconText": "qml",
"enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-qml')}" },
"pages" : "pages" :
[ [
{ {
@@ -29,7 +31,7 @@
"data": "data":
{ {
"source": "file.qml.tpl", "source": "file.qml.tpl",
"target": "%{JS: Util.fileName(value('TargetPath'), Util.preferredSuffix('text/x-qml'))}", "target": "%{JS: Util.fileName(value('TargetPath'), value('DefaultSuffix'))}",
"openInEditor": true "openInEditor": true
} }
} }

View File

@@ -110,6 +110,19 @@ void FileWizardPage::setPathLabel(const QString &label)
d->m_ui.pathLabel->setText(label); d->m_ui.pathLabel->setText(label);
} }
void FileWizardPage::setDefaultSuffix(const QString &suffix)
{
if (suffix.isEmpty()) {
const auto layout = qobject_cast<QFormLayout *>(this->layout());
if (layout->rowCount() == 3)
layout->removeRow(0);
} else {
d->m_ui.defaultSuffixLabel->setText(
tr("The default suffix if you do not explicitly specify a file extension is \".%1\".")
.arg(suffix));
}
}
bool FileWizardPage::forceFirstCapitalLetterForFileName() const bool FileWizardPage::forceFirstCapitalLetterForFileName() const
{ {
return d->m_ui.nameLineEdit->forceFirstCapitalLetter(); return d->m_ui.nameLineEdit->forceFirstCapitalLetter();

View File

@@ -50,6 +50,7 @@ public:
void setFileNameLabel(const QString &label); void setFileNameLabel(const QString &label);
void setPathLabel(const QString &label); void setPathLabel(const QString &label);
void setDefaultSuffix(const QString &suffix);
bool forceFirstCapitalLetterForFileName() const; bool forceFirstCapitalLetterForFileName() const;
void setForceFirstCapitalLetterForFileName(bool b); void setForceFirstCapitalLetterForFileName(bool b);

View File

@@ -6,34 +6,41 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>196</width> <width>368</width>
<height>68</height> <height>102</height>
</rect> </rect>
</property> </property>
<property name="title"> <property name="title">
<string>Choose the Location</string> <string>Choose the Location</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0"> <item row="1" column="0">
<widget class="QLabel" name="nameLabel"> <widget class="QLabel" name="nameLabel">
<property name="text"> <property name="text">
<string>Name:</string> <string>File name:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="1">
<widget class="Utils::FileNameValidatingLineEdit" name="nameLineEdit"/> <widget class="Utils::FileNameValidatingLineEdit" name="nameLineEdit"/>
</item> </item>
<item row="1" column="0"> <item row="3" column="0">
<widget class="QLabel" name="pathLabel"> <widget class="QLabel" name="pathLabel">
<property name="text"> <property name="text">
<string>Path:</string> <string>Path:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="3" column="1">
<widget class="Utils::PathChooser" name="pathChooser" native="true"/> <widget class="Utils::PathChooser" name="pathChooser" native="true"/>
</item> </item>
<item row="0" column="1">
<widget class="QLabel" name="defaultSuffixLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>

View File

@@ -45,6 +45,7 @@ void JsonFilePage::initializePage()
setFileName(wiz->stringValue(QLatin1String("InitialFileName"))); setFileName(wiz->stringValue(QLatin1String("InitialFileName")));
if (path().isEmpty()) if (path().isEmpty())
setPath(wiz->stringValue(QLatin1String("InitialPath"))); setPath(wiz->stringValue(QLatin1String("InitialPath")));
setDefaultSuffix(wiz->stringValue("DefaultSuffix"));
} }
bool JsonFilePage::validatePage() bool JsonFilePage::validatePage()