Move Qt Creator plugin wizard to JSON

Change-Id: Ida52d0998739db76a1a1d61da9271d2989a27649
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2020-01-02 16:31:23 +01:00
parent 806b190723
commit 8b143d5f5a
8 changed files with 287 additions and 167 deletions

View File

@@ -1,11 +1,11 @@
{
\\"Name\\" : \\"%PluginName%\\",
\\"Name\\" : \\"%{PluginName}\\",
\\"Version\\" : \\"0.0.1\\",
\\"CompatVersion\\" : \\"0.0.1\\",
\\"Vendor\\" : \\"%VendorName%\\",
\\"Copyright\\" : \\"%Copyright%\\",
\\"License\\" : \\"%License%\\",
\\"Description\\" : \\"%Description%\\",
\\"Url\\" : \\"%URL%\\",
\\"Vendor\\" : \\"%{VendorName}\\",
\\"Copyright\\" : \\"%{Copyright}\\",
\\"License\\" : \\"%{License}\\",
\\"Description\\" : \\"%{Description}\\",
\\"Url\\" : \\"%{Url}\\",
$$dependencyList
}

View File

@@ -1,5 +1,5 @@
#include "%PluginName:l%plugin.%CppHeaderSuffix%"
#include "%PluginName:l%constants.%CppHeaderSuffix%"
#include "%{HdrFileName}"
#include "%{ConstantsHdrFileName}"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
@@ -13,21 +13,21 @@
#include <QMainWindow>
#include <QMenu>
namespace %PluginName% {
namespace %{PluginName} {
namespace Internal {
%PluginName%Plugin::%PluginName%Plugin()
%{CN}::%{CN}()
{
// Create your members
}
%PluginName%Plugin::~%PluginName%Plugin()
%{CN}::~%{CN}()
{
// Unregister objects from the plugin manager's object pool
// Delete members
}
bool %PluginName%Plugin::initialize(const QStringList &arguments, QString *errorString)
bool %{CN}::initialize(const QStringList &arguments, QString *errorString)
{
// Register objects in the plugin manager's object pool
// Load settings
@@ -39,28 +39,28 @@ bool %PluginName%Plugin::initialize(const QStringList &arguments, QString *error
Q_UNUSED(arguments)
Q_UNUSED(errorString)
auto action = new QAction(tr("%PluginName% Action"), this);
auto action = new QAction(tr("%{PluginName} Action"), this);
Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
Core::Context(Core::Constants::C_GLOBAL));
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A")));
connect(action, &QAction::triggered, this, &%PluginName%Plugin::triggerAction);
connect(action, &QAction::triggered, this, &%{CN}::triggerAction);
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
menu->menu()->setTitle(tr("%PluginName%"));
menu->menu()->setTitle(tr("%{PluginName}"));
menu->addAction(cmd);
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
return true;
}
void %PluginName%Plugin::extensionsInitialized()
void %{CN}::extensionsInitialized()
{
// Retrieve objects from the plugin manager's object pool
// In the extensionsInitialized function, a plugin can be sure that all
// plugins that depend on it are completely initialized.
}
ExtensionSystem::IPlugin::ShutdownFlag %PluginName%Plugin::aboutToShutdown()
ExtensionSystem::IPlugin::ShutdownFlag %{CN}::aboutToShutdown()
{
// Save settings
// Disconnect from signals that are not needed during shutdown
@@ -68,12 +68,12 @@ ExtensionSystem::IPlugin::ShutdownFlag %PluginName%Plugin::aboutToShutdown()
return SynchronousShutdown;
}
void %PluginName%Plugin::triggerAction()
void %{CN}::triggerAction()
{
QMessageBox::information(Core::ICore::mainWindow(),
tr("Action Triggered"),
tr("This is an action from %PluginName%."));
tr("This is an action from %{PluginName}."));
}
} // namespace Internal
} // namespace %PluginName%
} // namespace %{PluginName}

View File

@@ -1,25 +1,25 @@
@if '%{Cpp:PragmaOnce}'
#pragma once
@else
#ifndef %ProjectName:h%_H
#define %ProjectName:h%_H
#ifndef %{GUARD}
#define %{GUARD}
@endif
#include "%PluginName:l%_global.%CppHeaderSuffix%"
#include "%{GlobalHdrFileName}"
#include <extensionsystem/iplugin.h>
namespace %PluginName% {
namespace %{PluginName} {
namespace Internal {
class %PluginName%Plugin : public ExtensionSystem::IPlugin
class %{CN} : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "%PluginName%.json")
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "%{PluginName}.json")
public:
%PluginName%Plugin();
~%PluginName%Plugin() override;
%{CN}();
~%{CN}() override;
bool initialize(const QStringList &arguments, QString *errorString) override;
void extensionsInitialized() override;
@@ -30,8 +30,8 @@ private:
};
} // namespace Internal
} // namespace %PluginName%
} // namespace %{PluginName}
@if ! '%{Cpp:PragmaOnce}'
#endif // %ProjectName:h%_H
#endif // %{GUARD}
@endif

View File

@@ -1,26 +1,26 @@
DEFINES += %PluginName:u%_LIBRARY
DEFINES += %{LibraryDefine}
# %PluginName% files
# %{PluginName} files
SOURCES += \
%PluginName:l%plugin.%CppSourceSuffix%
SOURCES += \\
%{SrcFileName}
HEADERS += \
%PluginName:l%plugin.%CppHeaderSuffix% \
%PluginName:l%_global.%CppHeaderSuffix% \
%PluginName:l%constants.%CppHeaderSuffix%
HEADERS += \\
%{HdrFileName} \\
%{GlobalHdrFileName} \\
%{ConstantsHdrFileName}
# Qt Creator linking
## Either set the IDE_SOURCE_TREE when running qmake,
## or set the QTC_SOURCE environment variable, to override the default setting
isEmpty(IDE_SOURCE_TREE): IDE_SOURCE_TREE = $$(QTC_SOURCE)
isEmpty(IDE_SOURCE_TREE): IDE_SOURCE_TREE = "%QtCreatorSources%"
isEmpty(IDE_SOURCE_TREE): IDE_SOURCE_TREE = "%{QtCreatorSources}"
## Either set the IDE_BUILD_TREE when running qmake,
## or set the QTC_BUILD environment variable, to override the default setting
isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = $$(QTC_BUILD)
isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = "%QtCreatorBuild%"
isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = "%{QtCreatorBuild}"
## uncomment to build plugin into user config directory
## <localappdata>/plugins/<ideversion>
@@ -28,20 +28,20 @@ isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = "%QtCreatorBuild%"
## "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later
## "$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux
## "~/Library/Application Support/QtProject/Qt Creator" on OS X
%DestDir%USE_USER_DESTDIR = yes
%{DestDir}USE_USER_DESTDIR = yes
###### If the plugin can be depended upon by other plugins, this code needs to be outsourced to
###### <dirname>_dependencies.pri, where <dirname> is the name of the directory containing the
###### plugin's sources.
QTC_PLUGIN_NAME = %PluginName%
QTC_LIB_DEPENDS += \
QTC_PLUGIN_NAME = %{PluginName}
QTC_LIB_DEPENDS += \\
# nothing here at this time
QTC_PLUGIN_DEPENDS += \
QTC_PLUGIN_DEPENDS += \\
coreplugin
QTC_PLUGIN_RECOMMENDS += \
QTC_PLUGIN_RECOMMENDS += \\
# optional plugin dependencies. nothing here at this time
###### End _dependencies.pri contents ######

View File

@@ -1,18 +1,17 @@
%{Cpp:LicenseTemplate}\
@if '%{Cpp:PragmaOnce}'
#pragma once
@else
#ifndef %ProjectName:h%_GLOBAL_H
#define %ProjectName:h%_GLOBAL_H
#ifndef %{GLOBAL_GUARD}
#define %{GLOBAL_GUARD}
@endif
#include <QtGlobal>
#if defined(%PluginName:u%_LIBRARY)
# define %PluginName:u%SHARED_EXPORT Q_DECL_EXPORT
#if defined(%{LibraryDefine})
# define %{LibraryExport} Q_DECL_EXPORT
#else
# define %PluginName:u%SHARED_EXPORT Q_DECL_IMPORT
# define %{LibraryExport} Q_DECL_IMPORT
#endif
@if ! '%{Cpp:PragmaOnce}'
#endif // %ProjectName:h%_GLOBAL_H
#endif // %{GLOBAL_GUARD}
@endif

View File

@@ -1,19 +1,20 @@
%{Cpp:LicenseTemplate}\
@if '%{Cpp:PragmaOnce}'
#pragma once
@else
#ifndef %ProjectName:h%_CONSTANTS_H
#define %ProjectName:h%_CONSTANTS_H
#ifndef %{CONSTANTS_GUARD}
#define %{CONSTANTS_GUARD}
@endif
namespace %PluginName% {
namespace %{PluginName} {
namespace Constants {
const char ACTION_ID[] = "%PluginName%.Action";
const char MENU_ID[] = "%PluginName%.Menu";
const char ACTION_ID[] = "%{PluginName}.Action";
const char MENU_ID[] = "%{PluginName}.Menu";
} // namespace %PluginName%
} // namespace Constants
} // namespace %{PluginName}
@if ! '%{Cpp:PragmaOnce}'
#endif // %ProjectName:h%_CONSTANTS_H
#endif // %{CONSTANTS_GUARD}
@endif

View File

@@ -0,0 +1,226 @@
{
"version": 1,
"supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ],
"id": "R.QtCreatorPlugin",
"category": "G.Library",
"trDescription": "Creates a custom Qt Creator plugin.",
"trDisplayName": "Qt Creator Plugin",
"trDisplayCategory": "Library",
"icon": "qtcreatorplugin.png",
"featuresRequired": [ "QtSupport.Wizards.FeatureQt", "QtSupport.Wizards.FeatureDesktop" ],
"enabled": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}",
"options":
[
{ "key": "ProjectFile", "value": "%{ProFile}" },
{ "key": "PluginNameLower", "value": "%{JS: value('PluginName').toLowerCase()}"},
{ "key": "ProFile", "value": "%{JS: Util.fileName(value('ProjectDirectory') + '/' + value('PluginNameLower'), 'pro')}" },
{ "key": "PluginJsonFile", "value": "%{JS: Util.fileName(value('PluginName'), 'json.in')}" },
{ "key": "LibraryDefine", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_LIBRARY'}" },
{ "key": "LibraryExport", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_EXPORT'}" },
{ "key": "SrcFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), Util.preferredSuffix('text/x-c++src'))}" },
{ "key": "HdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "GlobalHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + '_global', Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "ConstantsHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + 'constants', Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "CN", "value": "%{JS: Cpp.className(value('PluginName') + 'Plugin')}" },
{ "key": "GUARD", "value": "%{JS: Cpp.classToHeaderGuard(value('CN'), Util.suffix(value('HdrFileName')))}" },
{ "key": "HasTranslation", "value": "%{JS: value('TsFileName') !== ''}" },
{ "key": "GLOBAL_GUARD", "value": "%{JS: Cpp.headerGuard(value('GlobalHdrFileName'))}" },
{ "key": "CONSTANTS_GUARD", "value": "%{JS: Cpp.headerGuard(value('ConstantsHdrFileName'))}" }
],
"pages":
[
{
"trDisplayName": "Project Location",
"trShortTitle": "Location",
"typeId": "Project",
"data": { "trDescription": "This wizard creates a custom Qt Creator plugin." }
},
{
"trDisplayName": "Define Project Details",
"trShortTitle": "Details",
"typeId": "Fields",
"data":
[
{
"name": "ClassPageDescription",
"type": "Label",
"data":
{
"trText": "Specify details about your custom Qt Creator plugin.",
"wordWrap": true
}
},
{
"name": "PluginName",
"trDisplayName": "Plugin name:",
"mandatory": true,
"type": "LineEdit",
"data":
{
"validator": "[a-zA-Z_][a-zA-Z_0-9]*",
"trText": "%{JS: value('ProjectName').charAt(0).toUpperCase() + value('ProjectName').slice(1)}"
}
},
{
"name": "VendorName",
"persistenceKey": "VendorName",
"trDisplayName": "Vendor name:",
"mandatory": true,
"type": "LineEdit",
"data":
{
"trText": "MyCompany"
}
},
{
"name": "Copyright",
"trDisplayName": "Copyright:",
"mandatory": true,
"type": "LineEdit",
"data":
{
"trText": "(C) %{VendorName}"
}
},
{
"name": "License",
"trDisplayName": "License:",
"mandatory": true,
"type": "LineEdit",
"data":
{
"trText": "Put short license information here"
}
},
{
"name": "Description",
"trDisplayName": "Description:",
"mandatory": true,
"type": "LineEdit",
"data":
{
"trText": "Put a short description of your plugin here"
}
},
{
"name": "Url",
"persistenceKey": "VendorUrl",
"trDisplayName": "URL:",
"mandatory": true,
"type": "LineEdit",
"data":
{
"trText": "https://www.%{JS: encodeURIComponent(value('VendorName').toLowerCase())}.com"
}
},
{
"name": "QtCreatorSources",
"persistenceKey": "QtCreatorSources",
"trDisplayName": "Qt Creator sources:",
"mandatory": true,
"type": "PathChooser",
"data":
{
"kind": "existingDirectory"
}
},
{
"name": "QtCreatorBuild",
"persistenceKey": "QtCreatorBuild",
"trDisplayName": "Qt Creator build:",
"mandatory": true,
"type": "PathChooser",
"data":
{
"kind": "existingDirectory"
}
},
{
"name": "DestDir",
"persistenceKey": "QtCreatorPluginDestDir",
"trDisplayName": "Deploy into:",
"type": "ComboBox",
"data":
{
"index": 0,
"items":
[
{
"trKey": "Qt Creator Build",
"value": "# "
},
{
"trKey": "Local User Settings",
"value": ""
}
]
}
}
]
},
{
"trDisplayName": "Translation File",
"trShortTitle": "Translation",
"typeId": "QtTranslation"
},
{
"trDisplayName": "Kit Selection",
"trShortTitle": "Kits",
"typeId": "Kits",
"enabled": "%{JS: !value('IsSubproject')}",
"data": { "projectFilePath": "%{ProjectFile}" }
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators":
[
{
"typeId": "File",
"data":
[
{
"source": "myplugin.pro",
"target": "%{ProFile}",
"openAsProject": true
},
{
"source": "myplugin.cpp",
"target": "%{SrcFileName}",
"openInEditor": true
},
{
"source": "myplugin.h",
"target": "%{HdrFileName}"
},
{
"source": "myplugin_global.h",
"target": "%{GlobalHdrFileName}"
},
{
"source": "mypluginconstants.h",
"target": "%{ConstantsHdrFileName}"
},
{
"source": "MyPlugin.json.in",
"target": "%{PluginJsonFile}"
},
{
"source": "../projects/translation.ts",
"target": "%{TsFileName}",
"condition": "%{HasTranslation}"
},
{
"source": "../projects/git.ignore",
"target": ".gitignore",
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
}
]
}
]
}

View File

@@ -1,106 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
Custom project wizard configuration example file. Note that by convention,
the project file goes last.
The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and
leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project"
class="qmakeproject" firstpage="10"
id="R.QtCreatorPlugin" category="G.Library"
featuresRequired="QtSupport.Wizards.FeatureQt,QtSupport.Wizards.FeatureDesktop">
<icon>qtcreatorplugin.png</icon>
<description>Creates a custom Qt Creator plugin.</description>
<displayname>Qt Creator Plugin</displayname>;
<displaycategory>Library</displaycategory>
<files>
<file source="myplugin.pro" target="%PluginName:l%.pro" openproject="true"/>
<file source="MyPlugin.json.in" target="%PluginName%.json.in" openeditor="true"/>
<file source="myplugin_global.h" target="%PluginName:l%_global.%CppHeaderSuffix%" openeditor="true"/>
<file source="mypluginconstants.h" target="%PluginName:l%constants.%CppHeaderSuffix%" openeditor="true"/>
<file source="myplugin.h" target="%PluginName:l%plugin.%CppHeaderSuffix%" openeditor="true"/>
<file source="myplugin.cpp" target="%PluginName:l%plugin.%CppSourceSuffix%" openeditor="true"/>
</files>
<!-- Create a 2nd wizard page with parameters -->
<fieldpagetitle>Plugin Information</fieldpagetitle>
<fields>
<field mandatory="true" name="PluginName">
<fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$"
defaulttext="MyPlugin" />
<fielddescription>Plugin name:</fielddescription>
</field>
<field mandatory="true" name="VendorName">
<fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$"
defaulttext="MyCompany" />
<fielddescription>Vendor name:</fielddescription>
</field>
<field name="Copyright">
<fieldcontrol class="QLineEdit"
defaulttext="(C) MyCompany" />
<fielddescription>Copyright:</fielddescription>
</field>
<field name="License">
<fieldcontrol class="QLineEdit"
defaulttext="Put your license information here" />
<fielddescription>License:</fielddescription>
</field>
<field name="Description">
<fieldcontrol class="QLineEdit"
defaulttext="Put a short description of your plugin here"/>
<fielddescription>Description:</fielddescription>
</field>
<field name="URL">
<fieldcontrol class="QLineEdit"
defaulttext="http://www.mycompany.com" />
<fielddescription>URL:</fielddescription>
</field>
<field mandatory="true" name="QtCreatorSources">
<fieldcontrol class="Utils::PathChooser"
defaulttext="" />
<fielddescription>Qt Creator sources:</fielddescription>
</field>
<field mandatory="true" name="QtCreatorBuild">
<fieldcontrol class="Utils::PathChooser"
defaulttext="" />
<fielddescription>Qt Creator build:</fielddescription>
</field>
<field name="DestDir">
<fieldcontrol class="QComboBox" defaultindex="0">
<comboentries>
<comboentry value="# ">
<comboentrytext>Qt Creator build</comboentrytext>
</comboentry>
<comboentry value="">
<comboentrytext>Local user settings</comboentrytext>
</comboentry>
</comboentries>
</fieldcontrol>
<fielddescription>Deploy into:</fielddescription>
</field>
</fields>
</wizard>