Commit cd0ff57e authored by Tobias Hunger's avatar Tobias Hunger

JsonWizard: Replace JsFileWizard with a JsonWizard

Change-Id: I4da3485ed83fda7f17f3fa9a1f3d59bfabb7ea4d
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 86ecc7d1
@if '%{Stateless}'
.pragma library
@endif
function func() {
}
{
"version": 1,
"kind": "file",
"id": "Z.Js",
"category": "R.Qt",
"trDescription": "Creates a JavaScript file.",
"trDisplayName": "JS File",
"trDisplayCategory": "Qt",
"icon": "../../global/genericfilewizard.png",
"featuresRequired": [ "Plugin.QmlJSEditor" ],
"pages" :
[
{
"trDisplayName": "Location",
"trShortTitle": "Location",
"typeId": "File"
},
{
"trDisplayName": "Options",
"trShortTitle": "Options",
"typeId": "Fields",
"data":
[
{
"name": "Stateless",
"trDisplayName": "Stateless library",
"type": "CheckBox",
"span": true,
"data":
{
"checkedValue": "yes",
"uncheckedValue": "",
"checked": false
}
}
]
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.js",
"target": "%{JS: Util.fileName('%{TargetPath}', '%{JS: Util.preferredSuffix('application/javascript')}')}",
"openInEditor": true
}
}
]
}
/****************************************************************************
**
** 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 "jsfilewizard.h"
#include <qmljstools/qmljstoolsconstants.h>
#include <coreplugin/basefilewizard.h>
#include <utils/filewizardpage.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
#include <QTextStream>
#include <QWizard>
#include <QPushButton>
#include <QBoxLayout>
#include <QCheckBox>
namespace {
class JsFileOptionsPage : public QWizardPage
{
Q_OBJECT
public:
JsFileOptionsPage()
{
setTitle(tr("Options"));
QVBoxLayout *layout = new QVBoxLayout;
m_library = new QCheckBox(tr("JavaScript library"));
m_library->setToolTip(
tr("Usually each QML component instance has a unique copy of\n"
"imported JavaScript libraries. Indicating that a JavaScript file is\n"
"a library means that a single instance will be shared among\n"
"all components. JavaScript libraries will not be able to access\n"
"QML component instance objects and properties directly."));
layout->addWidget(m_library);
setLayout(layout);
}
bool isLibrary() const
{
return m_library->isChecked();
}
private:
QCheckBox *m_library;
};
class JsFileWizardDialog : public Core::BaseFileWizard
{
Q_OBJECT
public:
JsFileWizardDialog(QWidget *parent = 0) :
Core::BaseFileWizard(parent)
{
addPage(new Utils::FileWizardPage);
addPage(new JsFileOptionsPage);
}
};
} // anonymous namespace
using namespace QmlJSEditor;
JsFileWizard::JsFileWizard()
{
}
Core::GeneratedFiles JsFileWizard::generateFiles(const QWizard *w,
QString * /*errorMessage*/) const
{
const Core::BaseFileWizard *wizard = qobject_cast<const Core::BaseFileWizard *>(w);
Utils::FileWizardPage *filePage = wizard->find<Utils::FileWizardPage>();
QTC_ASSERT(filePage, return Core::GeneratedFiles());
JsFileOptionsPage *optionPage = wizard->find<JsFileOptionsPage>();
QTC_ASSERT(optionPage, return Core::GeneratedFiles());
const QString path = filePage->path();
const QString name = filePage->fileName();
const QString mimeType = QLatin1String(QmlJSTools::Constants::JS_MIMETYPE);
const QString fileName = Core::BaseFileWizardFactory::buildFileName(path, name, preferredSuffix(mimeType));
Core::GeneratedFile file(fileName);
file.setContents(fileContents(fileName, optionPage->isLibrary()));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file;
}
QString JsFileWizard::fileContents(const QString &, bool isLibrary) const
{
QString contents;
QTextStream str(&contents);
if (isLibrary)
str << QLatin1String(".pragma library\n\n");
str << QLatin1String("function func() {\n")
<< QLatin1String("\n")
<< QLatin1String("}\n");
return contents;
}
Core::BaseFileWizard *JsFileWizard::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const
{
JsFileWizardDialog *wizard = new JsFileWizardDialog(parent);
wizard->setWindowTitle(tr("New %1").arg(displayName()));
Utils::FileWizardPage *page = wizard->find<Utils::FileWizardPage>();
page->setPath(parameters.defaultPath());
foreach (QWizardPage *p, parameters.extensionPages())
wizard->addPage(p);
return wizard;
}
#include "jsfilewizard.moc"
/****************************************************************************
**
** 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 JSFILEWIZARD_H
#define JSFILEWIZARD_H
#include <coreplugin/basefilewizardfactory.h>
namespace QmlJSEditor {
class JsFileWizard: public Core::BaseFileWizardFactory
{
Q_OBJECT
public:
JsFileWizard();
private:
QString fileContents(const QString &baseName, bool isLibrary) const;
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const;
Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
};
} // namespace QmlJSEditor
#endif // JSFILEWIZARD_H
......@@ -23,7 +23,6 @@ HEADERS += \
qmljscomponentnamedialog.h \
qmljsfindreferences.h \
qmljsautocompleter.h \
jsfilewizard.h \
qmljssnippetprovider.h \
qmljsreuse.h \
qmljsquickfixassist.h \
......@@ -53,7 +52,6 @@ SOURCES += \
qmljscomponentnamedialog.cpp \
qmljsfindreferences.cpp \
qmljsautocompleter.cpp \
jsfilewizard.cpp \
qmljssnippetprovider.cpp \
qmljsreuse.cpp \
qmljsquickfixassist.cpp \
......
......@@ -18,8 +18,6 @@ QtcPlugin {
Depends { name: "QmlJSTools" }
files: [
"jsfilewizard.cpp",
"jsfilewizard.h",
"qmlexpressionundercursor.cpp",
"qmlexpressionundercursor.h",
"qmljsautocompleter.cpp",
......
......@@ -33,7 +33,6 @@
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljseditordocument.h"
#include "jsfilewizard.h"
#include "qmljsoutline.h"
#include "qmljspreviewrunner.h"
#include "qmljssnippetprovider.h"
......@@ -124,15 +123,6 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
addAutoReleasedObject(new QmlJSEditorFactory);
IWizardFactory *wizard = new JsFileWizard;
wizard->setWizardKind(Core::IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
wizard->setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Core::Constants::WIZARD_TR_CATEGORY_QT));
wizard->setDescription(tr("Creates a JavaScript file."));
wizard->setDisplayName(tr("JS File"));
wizard->setId(QLatin1String("Z.Js"));
addAutoReleasedObject(wizard);
Core::ActionContainer *contextMenu = Core::ActionManager::createMenu(Constants::M_CONTEXT);
Core::ActionContainer *qmlToolsMenu = Core::ActionManager::actionContainer(Core::Id(QmlJSTools::Constants::M_TOOLS_QMLJS));
......
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