Commit 989ed95c authored by Tobias Hunger's avatar Tobias Hunger Committed by Tobias Hunger

CppEditor: Replace CppFileWizard with two JsonWizards

Change-Id: If39ed6d2711fa4cc144d1b1f9738acf3d04ac225
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 335e625b
%{Cpp:LicenseTemplate}
#ifndef %{JS: Cpp.headerGuard('%{FileName}')}
#define %{JS: Cpp.headerGuard('%{FileName}')}
#endif // %{JS: Cpp.headerGuard('%{FileName}')}
{
"version": 1,
"kind": "file",
"id": "C.Header",
"category": "O.C++",
"trDescription": "Creates a C++ header file that you can add to a C++ project.",
"trDisplayName": "C++ Header File",
"trDisplayCategory": "C++",
"icon": "../../global/genericfilewizard.png",
"featuresRequired": [ "Plugin.CppEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.h",
"target": "%{JS: Cpp.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('text/x-c++hdr')}')}",
"openInEditor": true
}
}
]
}
{
"version": 1,
"kind": "file",
"id": "B.Source",
"category": "O.C++",
"trDescription": "Creates a C++ source file that you can add to a C++ project.",
"trDisplayName": "C++ Source File",
"trDisplayCategory": "C++",
"icon": "../../global/genericfilewizard.png",
"featuresRequired": [ "Plugin.CppEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.cpp",
"target": "%{JS: Cpp.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('text/x-c++src')}')}",
"openInEditor": true
}
}
]
}
......@@ -15,7 +15,6 @@ HEADERS += \
cppeditoroutline.h \
cppeditorplugin.h \
cppelementevaluator.h \
cppfilewizard.h \
cppfollowsymbolundercursor.h \
cppfunctiondecldeflink.h \
cpphighlighter.h \
......@@ -48,7 +47,6 @@ SOURCES += \
cppeditoroutline.cpp \
cppeditorplugin.cpp \
cppelementevaluator.cpp \
cppfilewizard.cpp \
cppfollowsymbolundercursor.cpp \
cppfunctiondecldeflink.cpp \
cpphighlighter.cpp \
......
......@@ -33,7 +33,6 @@ QtcPlugin {
"cppeditoroutline.cpp", "cppeditoroutline.h",
"cppeditorplugin.cpp", "cppeditorplugin.h",
"cppelementevaluator.cpp", "cppelementevaluator.h",
"cppfilewizard.cpp", "cppfilewizard.h",
"cppfollowsymbolundercursor.cpp", "cppfollowsymbolundercursor.h",
"cppfunctiondecldeflink.cpp", "cppfunctiondecldeflink.h",
"cpphighlighter.cpp", "cpphighlighter.h",
......
......@@ -36,7 +36,6 @@
#include "cppeditor.h"
#include "cppeditordocument.h"
#include "cppeditoroutline.h"
#include "cppfilewizard.h"
#include "cpphighlighter.h"
#include "cpphoverhandler.h"
#include "cppincludehierarchy.h"
......@@ -184,25 +183,6 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
wizard->setDescription(tr("Creates a C++ header and a source file for a new class that you can add to a C++ project."));
addAutoReleasedObject(wizard);
wizard = new CppFileWizard(Source);
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
wizard->setDisplayCategory(trCat);
wizard->setDisplayName(tr("C++ Class"));
wizard->setDescription(tr("Creates a C++ source file that you can add to a C++ project."));
wizard->setDisplayName(tr("C++ Source File"));
wizard->setId(QLatin1String("B.Source"));
addAutoReleasedObject(wizard);
wizard = new CppFileWizard(Header);
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
wizard->setDisplayCategory(trCat);
wizard->setDescription(tr("Creates a C++ header file that you can add to a C++ project."));
wizard->setDisplayName(tr("C++ Header File"));
wizard->setId(QLatin1String("C.Header"));
addAutoReleasedObject(wizard);
Context context(Constants::CPPEDITOR_ID);
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cppfilewizard.h"
#include "cppeditorconstants.h"
#include <cpptools/abstracteditorsupport.h>
#include <utils/codegeneration.h>
#include <QTextStream>
#include <QDebug>
using namespace CppEditor;
using namespace CppEditor::Internal;
enum { debugWizard = 0 };
CppFileWizard::CppFileWizard(FileType type)
: m_type(type)
{
}
Core::GeneratedFiles CppFileWizard::generateFilesFromPath(const QString &path,
const QString &name,
QString * /*errorMessage*/) const
{
const QString mimeType = m_type == Source ? QLatin1String(Constants::CPP_SOURCE_MIMETYPE) : QLatin1String(Constants::CPP_HEADER_MIMETYPE);
const QString fileName = Core::BaseFileWizardFactory::buildFileName(path, name, preferredSuffix(mimeType));
Core::GeneratedFile file(fileName);
file.setContents(fileContents(m_type, fileName));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file;
}
QString CppFileWizard::fileContents(FileType type, const QString &fileName) const
{
QString contents;
QTextStream str(&contents);
str << CppTools::AbstractEditorSupport::licenseTemplate(fileName);
switch (type) {
case Header: {
const QString guard = Utils::headerGuard(fileName);
str << QLatin1String("#ifndef ") << guard
<< QLatin1String("\n#define ") << guard << QLatin1String("\n\n#endif // ")
<< guard << QLatin1String("\n");
}
break;
case Source:
str << '\n';
break;
}
return contents;
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CPPFILEWIZARD_H
#define CPPFILEWIZARD_H
#include "cppeditorenums.h"
#include <coreplugin/basefilewizardfactory.h>
namespace CppEditor {
namespace Internal {
class CppFileWizard : public Core::StandardFileWizardFactory
{
Q_OBJECT
public:
explicit CppFileWizard(FileType type);
private:
QString fileContents(FileType type, const QString &baseName) const;
Core::GeneratedFiles generateFilesFromPath(const QString &path,
const QString &fileName,
QString *errorMessage) const;
private:
const FileType m_type;
};
} // namespace Internal
} // namespace CppEditor
#endif // CPPFILEWIZARD_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment