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",
"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" :
[

View File

@@ -9,7 +9,10 @@
"iconText": "cpp",
"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" :
[

View File

@@ -10,6 +10,8 @@
"platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-frag')}" },
"pages" :
[
{
@@ -30,7 +32,7 @@
"data":
{
"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
}
}

View File

@@ -10,6 +10,8 @@
"platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-vert')}" },
"pages" :
[
{
@@ -30,7 +32,7 @@
"data":
{
"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
}
}

View File

@@ -10,6 +10,8 @@
"platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-es-frag')}" },
"pages" :
[
{
@@ -30,7 +32,7 @@
"data":
{
"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
}
}

View File

@@ -10,6 +10,8 @@
"platformIndependent": true,
"enabled": "%{JS: value('Plugins').indexOf('GLSLEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-glsl-es-vert')}" },
"pages" :
[
{
@@ -30,7 +32,7 @@
"data":
{
"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
}
}

View File

@@ -9,7 +9,10 @@
"iconText": "java",
"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" :
[
@@ -31,7 +34,7 @@
"data":
{
"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
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,6 +9,8 @@
"iconText": "qrc",
"enabled": "%{JS: value('Plugins').indexOf('ResourceEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('application/vnd.qt.xml.resource')}" },
"pages" :
[
{
@@ -29,7 +31,7 @@
"data":
{
"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
}
}

View File

@@ -9,6 +9,8 @@
"iconText": "qml",
"enabled": "%{JS: value('Plugins').indexOf('QmlJSEditor') >= 0}",
"options": { "key": "DefaultSuffix", "value": "%{JS: Util.preferredSuffix('text/x-qml')}" },
"pages" :
[
{
@@ -29,7 +31,7 @@
"data":
{
"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
}
}

View File

@@ -110,6 +110,19 @@ void FileWizardPage::setPathLabel(const QString &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
{
return d->m_ui.nameLineEdit->forceFirstCapitalLetter();

View File

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

View File

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

View File

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