1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef CUSTOMPROJECTWIZARDPARAMETERS_H
34 #define CUSTOMPROJECTWIZARDPARAMETERS_H
36 #include <coreplugin/basefilewizard.h>
38 #include <QtCore/QStringList>
39 #include <QtCore/QMap>
40 #include <QtCore/QSharedPointer>
49 namespace ProjectExplorer {
52 struct CustomWizardField {
53 // Parameters of the widget control are stored as map
54 typedef QMap<QString, QString> ControlAttributeMap;
58 // Attribute map keys for combo entries
59 static QString comboEntryValueKey(int i);
60 static QString comboEntryTextKey(int i);
64 ControlAttributeMap controlAttributes;
68 struct CustomWizardFile {
78 // A validation rule based on Javascript-expressions over the field placeholders.
79 // Placeholder replacement is performed on the condition and it is evaluated
80 // using Javascript. So, for example '"%ProjectName%" != "untitled" would block
81 // default names. On failure, the message is displayed in a red warning label
82 // in the wizard page. Placeholder replacement is also performed on the message
83 // prior to displaying.
84 struct CustomWizardValidationRule {
85 // Validate a set of rules and return false + message on the first failing one.
86 static bool validateRules(const QList<CustomWizardValidationRule> &rules,
87 const QMap<QString, QString> &replacementMap,
88 QString *errorMessage);
89 bool validate(QScriptEngine &, const QMap<QString, QString> &replacementMap) const;
94 // Argument to the generator script containing placeholders to
95 // be replaced by field values or file names
96 // as in '--class-name=%ClassName%' or '--description=%Description%'.
97 struct GeneratorScriptArgument {
99 // Omit this arguments if all field placeholders expanded to empty strings.
101 // Do use the actual field value, but write it to a temporary
102 // text file and inserts its file name (suitable for multiline texts).
105 explicit GeneratorScriptArgument(const QString &value = QString());
111 struct CustomWizardParameters
114 enum ParseResult { ParseOk, ParseDisabled, ParseFailed };
116 CustomWizardParameters();
118 ParseResult parse(QIODevice &device, const QString &configFileFullPath,
119 Core::BaseFileWizardParameters *bp, QString *errorMessage);
120 ParseResult parse(const QString &configFileFullPath,
121 Core::BaseFileWizardParameters *bp, QString *errorMessage);
122 QString toString() const;
126 QList<CustomWizardFile> files;
127 QStringList filesGeneratorScript; // Complete binary, such as 'cmd /c myscript.pl'.
128 QString filesGeneratorScriptWorkingDirectory;
129 QList<GeneratorScriptArgument> filesGeneratorScriptArguments;
131 QString fieldPageTitle;
132 QList<CustomWizardField> fields;
133 QList<CustomWizardValidationRule> rules;
137 // Context used for one wizard run, shared between CustomWizard
138 // and the CustomWizardPage as it is used for the QLineEdit-type fields'
139 // default texts as well. Contains basic replacement fields
140 // like '%CppSourceSuffix%', '%CppHeaderSuffix%' (settings-dependent)
141 // reset() should be called before each wizard run to refresh them.
142 // CustomProjectWizard additionally inserts '%ProjectName%' from
143 // the intro page to have it available for default texts.
145 struct CustomWizardContext {
146 typedef QMap<QString, QString> FieldReplacementMap;
147 typedef QSharedPointer<QTemporaryFile> TemporaryFilePtr;
148 typedef QList<TemporaryFilePtr> TemporaryFilePtrList;
152 // Replace field values delimited by '%' with special modifiers:
153 // %Field% -> simple replacement
154 // %Field:l% -> replace with everything changed to lower case
155 // %Field:u% -> replace with everything changed to upper case
156 // %Field:c% -> replace with first character capitalized
157 // %Field:h% -> replace with something usable as header guard
158 // %Field:s% -> replace with something usable as structure or class name
159 // The return value indicates whether non-empty
160 // replacements were encountered.
161 static bool replaceFields(const FieldReplacementMap &fm, QString *s);
163 // Special replaceFields() overload used for the arguments of a generator
164 // script: Write the expanded field values out to temporary files and
165 // inserts file names instead of the expanded fields in string 's'.
166 static bool replaceFields(const FieldReplacementMap &fm, QString *s,
167 TemporaryFilePtrList *files);
169 static QString processFile(const FieldReplacementMap &fm, QString in);
171 FieldReplacementMap baseReplacements;
172 FieldReplacementMap replacements;
175 // Where files should be created, that is, 'path' for simple wizards
176 // or "path + project" for project wizards.
180 extern const char customWizardFileOpenEditorAttributeC[];
181 extern const char customWizardFileOpenProjectAttributeC[];
183 } // namespace Internal
184 } // namespace ProjectExplorer
186 #endif // CUSTOMPROJECTWIZARDPARAMETERS_H