forked from qt-creator/qt-creator
Since we also license under GPL-3.0 WITH Qt-GPL-exception-1.0,
this applies only to a hypothetical newer version of GPL, that doesn't
exist yet. If such a version emerges, we can still decide to relicense...
While at it, replace (deprecated) GPL-3.0 with more explicit GPL-3.0-only
Change was done by running
find . -type f -exec perl -pi -e "s/LicenseRef-Qt-Commercial OR GPL-3.0\+ OR GPL-3.0 WITH Qt-GPL-exception-1.0/LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0/g" {} \;
Change-Id: I5097e6ce8d10233993ee30d7e25120e2659eb10b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
126 lines
3.9 KiB
C++
126 lines
3.9 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
#include "helloworldplugin.h"
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
#include <coreplugin/coreconstants.h>
|
|
#include <coreplugin/icore.h>
|
|
#include <coreplugin/imode.h>
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
#include <QDebug>
|
|
#include <QAction>
|
|
#include <QMenu>
|
|
#include <QMessageBox>
|
|
#include <QPushButton>
|
|
|
|
namespace HelloWorld {
|
|
namespace Internal {
|
|
|
|
/*! A mode with a push button based on BaseMode. */
|
|
|
|
class HelloMode : public Core::IMode
|
|
{
|
|
public:
|
|
HelloMode()
|
|
{
|
|
setWidget(new QPushButton(tr("Hello World PushButton!")));
|
|
setContext(Core::Context("HelloWorld.MainView"));
|
|
setDisplayName(tr("Hello world!"));
|
|
setIcon(QIcon());
|
|
setPriority(0);
|
|
setId("HelloWorld.HelloWorldMode");
|
|
}
|
|
};
|
|
|
|
|
|
/*! Constructs the Hello World plugin. Normally plugins don't do anything in
|
|
their constructor except for initializing their member variables. The
|
|
actual work is done later, in the initialize() and extensionsInitialized()
|
|
functions.
|
|
*/
|
|
HelloWorldPlugin::HelloWorldPlugin()
|
|
{
|
|
}
|
|
|
|
/*! Plugins are responsible for deleting objects they created on the heap, and
|
|
to unregister objects from the plugin manager that they registered there.
|
|
*/
|
|
HelloWorldPlugin::~HelloWorldPlugin()
|
|
{
|
|
delete m_helloMode;
|
|
}
|
|
|
|
/*! Initializes the plugin. Returns true on success.
|
|
Plugins want to register objects with the plugin manager here.
|
|
|
|
\a errorMessage can be used to pass an error message to the plugin system,
|
|
if there was any.
|
|
*/
|
|
bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|
{
|
|
Q_UNUSED(arguments)
|
|
Q_UNUSED(errorMessage)
|
|
|
|
// Create a unique context for our own view, that will be used for the
|
|
// menu entry later.
|
|
Core::Context context("HelloWorld.MainView");
|
|
|
|
// Create an action to be triggered by a menu entry
|
|
auto helloWorldAction = new QAction(tr("Say \"&Hello World!\""), this);
|
|
connect(helloWorldAction, &QAction::triggered, this, &HelloWorldPlugin::sayHelloWorld);
|
|
|
|
// Register the action with the action manager
|
|
Core::Command *command =
|
|
Core::ActionManager::registerAction(
|
|
helloWorldAction, "HelloWorld.HelloWorldAction", context);
|
|
|
|
// Create our own menu to place in the Tools menu
|
|
Core::ActionContainer *helloWorldMenu =
|
|
Core::ActionManager::createMenu("HelloWorld.HelloWorldMenu");
|
|
QMenu *menu = helloWorldMenu->menu();
|
|
menu->setTitle(tr("&Hello World"));
|
|
menu->setEnabled(true);
|
|
|
|
// Add the Hello World action command to the menu
|
|
helloWorldMenu->addAction(command);
|
|
|
|
// Request the Tools menu and add the Hello World menu to it
|
|
Core::ActionContainer *toolsMenu =
|
|
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
|
toolsMenu->addMenu(helloWorldMenu);
|
|
|
|
// Add a mode with a push button based on BaseMode.
|
|
m_helloMode = new HelloMode;
|
|
|
|
return true;
|
|
}
|
|
|
|
/*! Notification that all extensions that this plugin depends on have been
|
|
initialized. The dependencies are defined in the plugins .json(.in) file.
|
|
|
|
Normally this function is used for things that rely on other plugins to have
|
|
added objects to the plugin manager, that implement interfaces that we're
|
|
interested in. These objects can now be requested through the
|
|
PluginManager.
|
|
|
|
The HelloWorldPlugin doesn't need things from other plugins, so it does
|
|
nothing here.
|
|
*/
|
|
void HelloWorldPlugin::extensionsInitialized()
|
|
{
|
|
}
|
|
|
|
void HelloWorldPlugin::sayHelloWorld()
|
|
{
|
|
// When passing nullptr for the parent, the message box becomes an
|
|
// application-global modal dialog box
|
|
QMessageBox::information(
|
|
nullptr, tr("Hello World!"), tr("Hello World! Beautiful day today, isn't it?"));
|
|
}
|
|
|
|
} // namespace Internal
|
|
} // namespace HelloWorld
|