Newer
Older
/**************************************************************************
** Contact: Nokia Corporation (qt-info@nokia.com)
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
** 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 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**************************************************************************/
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/imode.h>
#include <coreplugin/uniqueidmanager.h>
#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
namespace HelloWorld {
namespace Internal {
/*! A mode with a push button based on BaseMode. */
class HelloMode : public Core::IMode
{
public:
HelloMode() : m_widget(new QPushButton(tr("Hello World PushButton!"))) {}
QString displayName() const { return tr("Hello world!"); }
QIcon icon() const { return QIcon(); }
int priority() const { return 0; }
QWidget *widget() { return m_widget; }
QString id() const { return QLatin1String("HelloWorld.HelloWorldMode"); }
QString type() const { return QLatin1String("HelloWorld.HelloWorldMode"); }
Core::Context context() const { return Core::Context("HelloWorld.MainView"); };
QString contextHelpId() const { return QString(); }
private:
QWidget *m_widget;
};
/*! 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.
*/
bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *error_message)
Q_UNUSED(error_message)
// Get the primary access point to the workbench.
Core::ICore *core = Core::ICore::instance();
// Create a unique context for our own view, that will be used for the
Core::Context context("HelloWorld.MainView");
QAction *helloWorldAction = new QAction(tr("Say \"&Hello World!\""), this);
connect(helloWorldAction, SIGNAL(triggered()), SLOT(sayHelloWorld()));
// Register the action with the action manager
Core::ActionManager *actionManager = core->actionManager();
actionManager->registerAction(
helloWorldAction, "HelloWorld.HelloWorldAction", context);
// Create our own menu to place in the Tools menu
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
actionManager->actionContainer(Core::Constants::M_TOOLS);
toolsMenu->addMenu(helloWorldMenu);
// 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::IMode *helloMode = new HelloMode;
addAutoReleasedObject(helloMode);
return true;
}
/*! Notification that all extensions that this plugin depends on have been
initialized. The dependencies are defined in the plugins .pluginspec 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, tr("Hello World!"), tr("Hello World! Beautiful day today, isn't it?"));