2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#ifndef BASEFILEWIZARD_H
|
|
|
|
|
#define BASEFILEWIZARD_H
|
|
|
|
|
|
|
|
|
|
#include "core_global.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/dialogs/iwizard.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QSharedDataPointer>
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2010-03-18 10:59:06 +01:00
|
|
|
class QIcon;
|
2008-12-02 12:01:29 +01:00
|
|
|
class QWizard;
|
|
|
|
|
class QWizardPage;
|
2010-03-12 11:20:32 +01:00
|
|
|
class QDebug;
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2010-03-31 14:48:08 +02:00
|
|
|
namespace Utils {
|
|
|
|
|
class Wizard;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
class IEditor;
|
|
|
|
|
class IFileWizardExtension;
|
|
|
|
|
|
|
|
|
|
class BaseFileWizardParameterData;
|
|
|
|
|
struct BaseFileWizardPrivate;
|
|
|
|
|
class GeneratedFilePrivate;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Represents a file generated by a wizard. The Wizard class will check for
|
|
|
|
|
* each file whether it already exists and will report any errors that may
|
|
|
|
|
* occur during creation of the files.
|
|
|
|
|
*/
|
2008-12-02 14:09:21 +01:00
|
|
|
class CORE_EXPORT GeneratedFile
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2010-04-16 15:55:32 +02:00
|
|
|
enum Attribute { OpenEditorAttribute = 0x01, OpenProjectAttribute = 0x02 };
|
|
|
|
|
Q_DECLARE_FLAGS(Attributes, Attribute)
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
GeneratedFile();
|
|
|
|
|
explicit GeneratedFile(const QString &path);
|
|
|
|
|
GeneratedFile(const GeneratedFile &);
|
2009-01-20 15:31:33 +01:00
|
|
|
GeneratedFile &operator=(const GeneratedFile &);
|
2008-12-02 12:01:29 +01:00
|
|
|
~GeneratedFile();
|
|
|
|
|
|
|
|
|
|
// Full path of the file should be created, or the suggested file name
|
|
|
|
|
QString path() const;
|
|
|
|
|
void setPath(const QString &p);
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
// Contents of the file (UTF8)
|
2008-12-02 12:01:29 +01:00
|
|
|
QString contents() const;
|
|
|
|
|
void setContents(const QString &c);
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
QByteArray binaryContents() const;
|
|
|
|
|
void setBinaryContents(const QByteArray &c);
|
|
|
|
|
|
|
|
|
|
// Defaults to false (Text file).
|
|
|
|
|
bool isBinary() const;
|
|
|
|
|
void setBinary(bool b);
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
// Id of editor to open the file with
|
|
|
|
|
QString editorId() const;
|
|
|
|
|
void setEditorId(const QString &k);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
bool write(QString *errorMessage) const;
|
|
|
|
|
|
2010-04-16 15:55:32 +02:00
|
|
|
Attributes attributes() const;
|
|
|
|
|
void setAttributes(Attributes a);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
|
|
|
|
QSharedDataPointer<GeneratedFilePrivate> m_d;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef QList<GeneratedFile> GeneratedFiles;
|
|
|
|
|
|
|
|
|
|
/* Parameter class for passing parameters to instances of class Wizard
|
|
|
|
|
* containing name, icon and such. */
|
|
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
class CORE_EXPORT BaseFileWizardParameters
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2010-01-14 14:14:39 +01:00
|
|
|
explicit BaseFileWizardParameters(IWizard::WizardKind kind = IWizard::FileWizard);
|
2008-12-02 12:01:29 +01:00
|
|
|
BaseFileWizardParameters(const BaseFileWizardParameters &);
|
|
|
|
|
BaseFileWizardParameters &operator=(const BaseFileWizardParameters&);
|
|
|
|
|
~BaseFileWizardParameters();
|
|
|
|
|
|
2010-03-12 11:20:32 +01:00
|
|
|
void clear();
|
|
|
|
|
|
2010-01-14 14:14:39 +01:00
|
|
|
IWizard::WizardKind kind() const;
|
|
|
|
|
void setKind(IWizard::WizardKind k);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QIcon icon() const;
|
2009-01-20 15:31:33 +01:00
|
|
|
void setIcon(const QIcon &icon);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QString description() const;
|
2009-01-20 15:31:33 +01:00
|
|
|
void setDescription(const QString &description);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString displayName() const;
|
|
|
|
|
void setDisplayName(const QString &name);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-27 10:33:24 +01:00
|
|
|
QString id() const;
|
|
|
|
|
void setId(const QString &id);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString category() const;
|
2009-01-20 15:31:33 +01:00
|
|
|
void setCategory(const QString &category);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString displayCategory() const;
|
|
|
|
|
void setDisplayCategory(const QString &trCategory);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedDataPointer<BaseFileWizardParameterData> m_d;
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-12 11:20:32 +01:00
|
|
|
CORE_EXPORT QDebug operator<<(QDebug d, const BaseFileWizardParameters &);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/* A generic wizard for creating files.
|
|
|
|
|
*
|
|
|
|
|
* The abstract methods:
|
|
|
|
|
*
|
|
|
|
|
* createWizardDialog() : Called to create the QWizard dialog to be shown
|
|
|
|
|
* generateFiles() : Generate file content
|
|
|
|
|
*
|
|
|
|
|
* must be implemented. The behaviour can be further customized by overwriting
|
|
|
|
|
* the virtual method:
|
|
|
|
|
* postGenerateFiles() : Called after generating the files.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class CORE_EXPORT BaseFileWizard : public IWizard
|
|
|
|
|
{
|
|
|
|
|
Q_DISABLE_COPY(BaseFileWizard)
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual ~BaseFileWizard();
|
|
|
|
|
|
|
|
|
|
// IWizard
|
2010-01-14 14:14:39 +01:00
|
|
|
virtual WizardKind kind() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual QIcon icon() const;
|
|
|
|
|
virtual QString description() const;
|
2010-01-07 18:17:24 +01:00
|
|
|
virtual QString displayName() const;
|
2009-11-27 10:33:24 +01:00
|
|
|
virtual QString id() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
virtual QString category() const;
|
2010-01-07 18:17:24 +01:00
|
|
|
virtual QString displayCategory() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
virtual QStringList runWizard(const QString &path, QWidget *parent);
|
|
|
|
|
|
|
|
|
|
// Build a file name, adding the extension unless baseName already has one
|
|
|
|
|
static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
|
|
|
|
|
|
2010-02-18 16:07:34 +01:00
|
|
|
// Sets some standard options on a QWizard
|
2008-12-02 12:01:29 +01:00
|
|
|
static void setupWizard(QWizard *);
|
|
|
|
|
|
2010-03-31 14:48:08 +02:00
|
|
|
// Read "shortTitle" dynamic property of the pageId and apply it as the title of corresponding progress item
|
|
|
|
|
static void applyExtensionPageShortTitle(Utils::Wizard *wizard, int pageId);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
|
|
|
|
typedef QList<QWizardPage *> WizardPageList;
|
|
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
explicit BaseFileWizard(const BaseFileWizardParameters ¶meters, QObject *parent = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Overwrite to create the wizard dialog on the parent, adding
|
|
|
|
|
// the extension pages.
|
|
|
|
|
virtual QWizard *createWizardDialog(QWidget *parent,
|
|
|
|
|
const QString &defaultPath,
|
|
|
|
|
const WizardPageList &extensionPages) const = 0;
|
|
|
|
|
|
|
|
|
|
// Overwrite to query the parameters from the dialog and generate the files.
|
|
|
|
|
virtual GeneratedFiles generateFiles(const QWizard *w,
|
|
|
|
|
QString *errorMessage) const = 0;
|
|
|
|
|
|
|
|
|
|
/* Overwrite to perform steps to be done after files are actually created.
|
|
|
|
|
* The default implementation opens editors with the newly generated files. */
|
2010-02-17 16:18:21 +01:00
|
|
|
virtual bool postGenerateFiles(const QWizard *w, const GeneratedFiles &l, QString *errorMessage);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Utility that returns the preferred suffix for a mime type
|
2009-12-16 14:19:34 +01:00
|
|
|
static QString preferredSuffix(const QString &mimeType);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Utility that performs an overwrite check on a set of files. It checks if
|
|
|
|
|
// the file exists, can be overwritten at all and prompts the user.
|
|
|
|
|
enum OverwriteResult { OverwriteOk, OverwriteError, OverwriteCanceled };
|
|
|
|
|
OverwriteResult promptOverwrite(const QString &location,
|
|
|
|
|
const QStringList &files,
|
|
|
|
|
QString *errorMessage) const;
|
2010-04-16 15:55:32 +02:00
|
|
|
|
|
|
|
|
// Utility to open the editors for the files whose attribute is set accordingly.
|
|
|
|
|
static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = 0);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
|
|
|
|
BaseFileWizardPrivate *m_d;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// StandardFileWizard convenience class for creating one file. It uses
|
2009-10-05 11:06:05 +02:00
|
|
|
// Utils::FileWizardDialog and introduces a new virtual to generate the
|
2008-12-02 12:01:29 +01:00
|
|
|
// files from path and name.
|
|
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
class CORE_EXPORT StandardFileWizard : public BaseFileWizard
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_DISABLE_COPY(StandardFileWizard)
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
protected:
|
2009-01-20 15:31:33 +01:00
|
|
|
explicit StandardFileWizard(const BaseFileWizardParameters ¶meters, QObject *parent = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
// Implemented to create a Utils::FileWizardDialog
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual QWizard *createWizardDialog(QWidget *parent,
|
|
|
|
|
const QString &defaultPath,
|
|
|
|
|
const WizardPageList &extensionPages) const;
|
|
|
|
|
// Implemented to retrieve path and name and call generateFilesFromPath()
|
|
|
|
|
virtual GeneratedFiles generateFiles(const QWizard *w,
|
|
|
|
|
QString *errorMessage) const;
|
|
|
|
|
|
|
|
|
|
// Newly introduced virtual that creates a file from a path
|
|
|
|
|
virtual GeneratedFiles generateFilesFromPath(const QString &path,
|
|
|
|
|
const QString &name,
|
|
|
|
|
QString *errorMessage) const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|
|
|
|
|
|
2010-04-16 15:55:32 +02:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::GeneratedFile::Attributes)
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif // BASEFILEWIZARD_H
|