2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02: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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "helloworldplugin.h"
|
|
|
|
|
|
2009-01-14 13:28:46 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-09-06 14:10:30 +02:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-01-05 12:21:32 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2010-12-06 14:12:38 +01:00
|
|
|
#include <coreplugin/imode.h>
|
2009-01-05 12:21:32 +01:00
|
|
|
#include <coreplugin/modemanager.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPushButton>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-12-06 14:12:38 +01:00
|
|
|
namespace HelloWorld {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
/*! A mode with a push button based on BaseMode. */
|
|
|
|
|
|
|
|
|
|
class HelloMode : public Core::IMode
|
|
|
|
|
{
|
|
|
|
|
public:
|
2011-04-13 13:00:30 +02:00
|
|
|
HelloMode()
|
|
|
|
|
{
|
|
|
|
|
setWidget(new QPushButton(tr("Hello World PushButton!")));
|
|
|
|
|
setContext(Core::Context("HelloWorld.MainView"));
|
2011-04-13 16:09:04 +02:00
|
|
|
setDisplayName(tr("Hello world!"));
|
|
|
|
|
setIcon(QIcon());
|
|
|
|
|
setPriority(0);
|
2012-05-07 18:28:03 +02:00
|
|
|
setId("HelloWorld.HelloWorldMode");
|
2011-04-13 16:09:04 +02:00
|
|
|
setContextHelpId(QString());
|
2011-04-13 13:00:30 +02:00
|
|
|
}
|
2010-12-06 14:12:38 +01:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/*! 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()
|
2013-10-07 13:34:40 +02:00
|
|
|
functions.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! Initializes the plugin. Returns true on success.
|
|
|
|
|
Plugins want to register objects with the plugin manager here.
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
\a errorMessage can be used to pass an error message to the plugin system,
|
2008-12-02 12:01:29 +01:00
|
|
|
if there was any.
|
|
|
|
|
*/
|
2011-09-21 13:05:15 +02:00
|
|
|
bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-05 12:21:32 +01:00
|
|
|
Q_UNUSED(arguments)
|
2011-09-21 13:05:15 +02:00
|
|
|
Q_UNUSED(errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-12-06 14:12:38 +01:00
|
|
|
// Create a unique context for our own view, that will be used for the
|
2008-12-02 12:01:29 +01:00
|
|
|
// menu entry later.
|
2010-09-06 14:10:30 +02:00
|
|
|
Core::Context context("HelloWorld.MainView");
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Create an action to be triggered by a menu entry
|
2009-04-17 21:11:52 +02:00
|
|
|
QAction *helloWorldAction = new QAction(tr("Say \"&Hello World!\""), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(helloWorldAction, SIGNAL(triggered()), SLOT(sayHelloWorld()));
|
|
|
|
|
|
|
|
|
|
// Register the action with the action manager
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *command =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::registerAction(
|
2008-12-02 12:01:29 +01:00
|
|
|
helloWorldAction, "HelloWorld.HelloWorldAction", context);
|
|
|
|
|
|
|
|
|
|
// Create our own menu to place in the Tools menu
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::ActionContainer *helloWorldMenu =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::createMenu("HelloWorld.HelloWorldMenu");
|
2008-12-02 12:01:29 +01:00
|
|
|
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
|
2009-01-14 13:28:46 +01:00
|
|
|
Core::ActionContainer *toolsMenu =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
2008-12-02 12:01:29 +01:00
|
|
|
toolsMenu->addMenu(helloWorldMenu);
|
|
|
|
|
|
2009-01-05 12:21:32 +01:00
|
|
|
// Add a mode with a push button based on BaseMode. Like the BaseView,
|
|
|
|
|
// it will unregister itself from the plugin manager when it is deleted.
|
2010-12-06 14:12:38 +01:00
|
|
|
Core::IMode *helloMode = new HelloMode;
|
|
|
|
|
addAutoReleasedObject(helloMode);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! Notification that all extensions that this plugin depends on have been
|
2010-02-28 14:37:11 +01:00
|
|
|
initialized. The dependencies are defined in the plugins .pluginspec file.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
Normally this function is used for things that rely on other plugins to have
|
2008-12-02 12:01:29 +01:00
|
|
|
added objects to the plugin manager, that implement interfaces that we're
|
|
|
|
|
interested in. These objects can now be requested through the
|
|
|
|
|
PluginManagerInterface.
|
|
|
|
|
|
|
|
|
|
The HelloWorldPlugin doesn't need things from other plugins, so it does
|
|
|
|
|
nothing here.
|
|
|
|
|
*/
|
|
|
|
|
void HelloWorldPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelloWorldPlugin::sayHelloWorld()
|
|
|
|
|
{
|
|
|
|
|
// When passing 0 for the parent, the message box becomes an
|
|
|
|
|
// application-global modal dialog box
|
|
|
|
|
QMessageBox::information(
|
2009-04-17 21:11:52 +02:00
|
|
|
0, tr("Hello World!"), tr("Hello World! Beautiful day today, isn't it?"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-06 14:12:38 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace HelloWorld
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(HelloWorld::Internal::HelloWorldPlugin)
|