| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  | #include "exampleplugin.h"
 | 
					
						
							|  |  |  | #include "exampleconstants.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <coreplugin/icore.h>
 | 
					
						
							|  |  |  | #include <coreplugin/icontext.h>
 | 
					
						
							|  |  |  | #include <coreplugin/actionmanager/actionmanager.h>
 | 
					
						
							|  |  |  | #include <coreplugin/actionmanager/command.h>
 | 
					
						
							|  |  |  | #include <coreplugin/actionmanager/actioncontainer.h>
 | 
					
						
							|  |  |  | #include <coreplugin/coreconstants.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QAction>
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | #include <QMainWindow>
 | 
					
						
							|  |  |  | #include <QMenu>
 | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QtPlugin>
 | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-15 10:08:56 +01:00
										 |  |  | namespace Example { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ExamplePlugin::ExamplePlugin() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Create your members
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExamplePlugin::~ExamplePlugin() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Unregister objects from the plugin manager's object pool
 | 
					
						
							|  |  |  |     // Delete members
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ExamplePlugin::initialize(const QStringList &arguments, QString *errorString) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Register objects in the plugin manager's object pool
 | 
					
						
							|  |  |  |     // Load settings
 | 
					
						
							|  |  |  |     // Add actions to menus
 | 
					
						
							|  |  |  |     // Connect to other plugins' signals
 | 
					
						
							| 
									
										
										
										
											2013-10-07 13:34:40 +02:00
										 |  |  |     // In the initialize function, a plugin can be sure that the plugins it
 | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  |     // depends on have initialized their members.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Q_UNUSED(arguments) | 
					
						
							|  |  |  |     Q_UNUSED(errorString) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //! [add action]
 | 
					
						
							| 
									
										
										
										
											2016-02-16 10:13:40 +01:00
										 |  |  |     QAction *action = new QAction(tr("Example Action"), this); | 
					
						
							| 
									
										
										
										
											2013-10-23 12:53:10 +02:00
										 |  |  |     Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID, | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  |                                             Core::Context(Core::Constants::C_GLOBAL)); | 
					
						
							|  |  |  |     cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A"))); | 
					
						
							| 
									
										
										
										
											2016-03-15 10:08:56 +01:00
										 |  |  |     connect(action, &QAction::triggered, this, &ExamplePlugin::triggerAction); | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  | //! [add action]
 | 
					
						
							|  |  |  | //! [add menu]
 | 
					
						
							| 
									
										
										
										
											2013-10-23 12:53:10 +02:00
										 |  |  |     Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID); | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  |     menu->menu()->setTitle(tr("Example")); | 
					
						
							|  |  |  |     menu->addAction(cmd); | 
					
						
							| 
									
										
										
										
											2013-10-23 12:53:10 +02:00
										 |  |  |     Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu); | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  | //! [add menu]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ExamplePlugin::extensionsInitialized() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Retrieve objects from the plugin manager's object pool
 | 
					
						
							| 
									
										
										
										
											2013-10-07 13:34:40 +02:00
										 |  |  |     // In the extensionsInitialized function, a plugin can be sure that all
 | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  |     // plugins that depend on it are completely initialized.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExtensionSystem::IPlugin::ShutdownFlag ExamplePlugin::aboutToShutdown() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Save settings
 | 
					
						
							|  |  |  |     // Disconnect from signals that are not needed during shutdown
 | 
					
						
							|  |  |  |     // Hide UI (if you add UI that is not in the main window directly)
 | 
					
						
							|  |  |  |     return SynchronousShutdown; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //! [slot implementation]
 | 
					
						
							|  |  |  | void ExamplePlugin::triggerAction() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-31 11:04:17 +02:00
										 |  |  |     QMessageBox::information(Core::ICore::mainWindow(), | 
					
						
							| 
									
										
										
										
											2016-02-16 10:13:40 +01:00
										 |  |  |                              tr("Action Triggered"), | 
					
						
							| 
									
										
										
										
											2011-10-10 08:32:07 +02:00
										 |  |  |                              tr("This is an action from Example.")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //! [slot implementation]
 | 
					
						
							| 
									
										
										
										
											2016-03-15 10:08:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace Internal
 | 
					
						
							|  |  |  | } // namespace Example
 |