2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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>
|
2009-01-05 12:21:32 +01:00
|
|
|
#include <coreplugin/basemode.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>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2009-01-05 12:21:32 +01:00
|
|
|
#include <QtCore/QtPlugin>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
|
|
|
|
|
using namespace HelloWorld::Internal;
|
|
|
|
|
|
|
|
|
|
/*! 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()
|
|
|
|
|
methods.
|
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
\a error_message can be used to pass an error message to the plugin system,
|
|
|
|
|
if there was any.
|
|
|
|
|
*/
|
2009-01-05 12:21:32 +01:00
|
|
|
bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *error_message)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-05 12:21:32 +01:00
|
|
|
Q_UNUSED(arguments)
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_UNUSED(error_message)
|
|
|
|
|
|
|
|
|
|
// Get the primary access point to the workbench.
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Create a unique context id for our own view, that will be used for the
|
|
|
|
|
// menu entry later.
|
|
|
|
|
QList<int> context = QList<int>()
|
|
|
|
|
<< core->uniqueIDManager()->uniqueIdentifier(
|
|
|
|
|
QLatin1String("HelloWorld.MainView"));
|
|
|
|
|
|
|
|
|
|
// Create an action to be triggered by a menu entry
|
|
|
|
|
QAction *helloWorldAction = new QAction("Say \"&Hello World!\"", this);
|
|
|
|
|
connect(helloWorldAction, SIGNAL(triggered()), SLOT(sayHelloWorld()));
|
|
|
|
|
|
|
|
|
|
// Register the action with the action manager
|
2009-01-13 13:39:31 +01:00
|
|
|
Core::ActionManager *actionManager = core->actionManager();
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *command =
|
2008-12-02 12:01:29 +01:00
|
|
|
actionManager->registerAction(
|
|
|
|
|
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 =
|
2008-12-02 12:01:29 +01:00
|
|
|
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
|
2009-01-14 13:28:46 +01:00
|
|
|
Core::ActionContainer *toolsMenu =
|
2008-12-02 12:01:29 +01:00
|
|
|
actionManager->actionContainer(Core::Constants::M_TOOLS);
|
|
|
|
|
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.
|
|
|
|
|
Core::BaseMode *baseMode = new Core::BaseMode;
|
|
|
|
|
baseMode->setUniqueModeName("HelloWorld.HelloWorldMode");
|
|
|
|
|
baseMode->setName(tr("Hello world!"));
|
|
|
|
|
baseMode->setIcon(QIcon());
|
|
|
|
|
baseMode->setPriority(0);
|
|
|
|
|
baseMode->setWidget(new QPushButton(tr("Hello World PushButton!")));
|
|
|
|
|
addAutoReleasedObject(baseMode);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Add the Hello World action command to the mode manager (with 0 priority)
|
|
|
|
|
Core::ModeManager *modeManager = core->modeManager();
|
|
|
|
|
modeManager->addAction(command, 0);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! Notification that all extensions that this plugin depends on have been
|
|
|
|
|
initialized. The dependencies are defined in the plugins .qwp file.
|
|
|
|
|
|
|
|
|
|
Normally this method 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
|
|
|
|
|
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(
|
|
|
|
|
0, "Hello World!", "Hello World! Beautiful day today, isn't it?");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(HelloWorldPlugin)
|