1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "helloworldplugin.h"
36 #include <coreplugin/actionmanager/actionmanager.h>
37 #include <coreplugin/actionmanager/actioncontainer.h>
38 #include <coreplugin/coreconstants.h>
39 #include <coreplugin/icore.h>
40 #include <coreplugin/imode.h>
41 #include <coreplugin/modemanager.h>
42 #include <coreplugin/uniqueidmanager.h>
44 #include <QtCore/QDebug>
45 #include <QtCore/QtPlugin>
46 #include <QtGui/QAction>
47 #include <QtGui/QMenu>
48 #include <QtGui/QMessageBox>
49 #include <QtGui/QPushButton>
51 namespace HelloWorld {
54 /*! A mode with a push button based on BaseMode. */
56 class HelloMode : public Core::IMode
59 HelloMode() : m_widget(new QPushButton(tr("Hello World PushButton!"))) {}
61 QString displayName() const { return tr("Hello world!"); }
62 QIcon icon() const { return QIcon(); }
63 int priority() const { return 0; }
64 QWidget *widget() { return m_widget; }
65 QString id() const { return QLatin1String("HelloWorld.HelloWorldMode"); }
66 QString type() const { return QLatin1String("HelloWorld.HelloWorldMode"); }
67 Core::Context context() const { return Core::Context("HelloWorld.MainView"); };
68 QString contextHelpId() const { return QString(); }
75 /*! Constructs the Hello World plugin. Normally plugins don't do anything in
76 their constructor except for initializing their member variables. The
77 actual work is done later, in the initialize() and extensionsInitialized()
80 HelloWorldPlugin::HelloWorldPlugin()
84 /*! Plugins are responsible for deleting objects they created on the heap, and
85 to unregister objects from the plugin manager that they registered there.
87 HelloWorldPlugin::~HelloWorldPlugin()
91 /*! Initializes the plugin. Returns true on success.
92 Plugins want to register objects with the plugin manager here.
94 \a error_message can be used to pass an error message to the plugin system,
97 bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *error_message)
100 Q_UNUSED(error_message)
102 // Get the primary access point to the workbench.
103 Core::ICore *core = Core::ICore::instance();
105 // Create a unique context for our own view, that will be used for the
107 Core::Context context("HelloWorld.MainView");
109 // Create an action to be triggered by a menu entry
110 QAction *helloWorldAction = new QAction(tr("Say \"&Hello World!\""), this);
111 connect(helloWorldAction, SIGNAL(triggered()), SLOT(sayHelloWorld()));
113 // Register the action with the action manager
114 Core::ActionManager *actionManager = core->actionManager();
115 Core::Command *command =
116 actionManager->registerAction(
117 helloWorldAction, "HelloWorld.HelloWorldAction", context);
119 // Create our own menu to place in the Tools menu
120 Core::ActionContainer *helloWorldMenu =
121 actionManager->createMenu("HelloWorld.HelloWorldMenu");
122 QMenu *menu = helloWorldMenu->menu();
123 menu->setTitle(tr("&Hello World"));
124 menu->setEnabled(true);
126 // Add the Hello World action command to the menu
127 helloWorldMenu->addAction(command);
129 // Request the Tools menu and add the Hello World menu to it
130 Core::ActionContainer *toolsMenu =
131 actionManager->actionContainer(Core::Constants::M_TOOLS);
132 toolsMenu->addMenu(helloWorldMenu);
134 // Add a mode with a push button based on BaseMode. Like the BaseView,
135 // it will unregister itself from the plugin manager when it is deleted.
136 Core::IMode *helloMode = new HelloMode;
137 addAutoReleasedObject(helloMode);
139 // Add the Hello World action command to the mode manager (with 0 priority)
140 Core::ModeManager *modeManager = core->modeManager();
141 modeManager->addAction(command, 0);
146 /*! Notification that all extensions that this plugin depends on have been
147 initialized. The dependencies are defined in the plugins .pluginspec file.
149 Normally this method is used for things that rely on other plugins to have
150 added objects to the plugin manager, that implement interfaces that we're
151 interested in. These objects can now be requested through the
152 PluginManagerInterface.
154 The HelloWorldPlugin doesn't need things from other plugins, so it does
157 void HelloWorldPlugin::extensionsInitialized()
161 void HelloWorldPlugin::sayHelloWorld()
163 // When passing 0 for the parent, the message box becomes an
164 // application-global modal dialog box
165 QMessageBox::information(
166 0, tr("Hello World!"), tr("Hello World! Beautiful day today, isn't it?"));
169 } // namespace Internal
170 } // namespace HelloWorld
172 Q_EXPORT_PLUGIN(HelloWorld::Internal::HelloWorldPlugin)