|
| 1 | +#include "gistplugin.h" |
| 2 | +#include "gistpluginconstants.h" |
| 3 | + |
| 4 | +#include <coreplugin/icore.h> |
| 5 | +#include <coreplugin/icontext.h> |
| 6 | +#include <coreplugin/actionmanager/actionmanager.h> |
| 7 | +#include <coreplugin/actionmanager/command.h> |
| 8 | +#include <coreplugin/actionmanager/actioncontainer.h> |
| 9 | +#include <coreplugin/coreconstants.h> |
| 10 | + |
| 11 | +#include <QAction> |
| 12 | +#include <QMessageBox> |
| 13 | +#include <QMainWindow> |
| 14 | +#include <QMenu> |
| 15 | + |
| 16 | +#include <QtPlugin> |
| 17 | + |
| 18 | +using namespace GistPlugin::Internal; |
| 19 | + |
| 20 | +GistPluginPlugin::GistPluginPlugin() |
| 21 | +{ |
| 22 | + // Create your members |
| 23 | +} |
| 24 | + |
| 25 | +GistPluginPlugin::~GistPluginPlugin() |
| 26 | +{ |
| 27 | + // Unregister objects from the plugin manager's object pool |
| 28 | + // Delete members |
| 29 | +} |
| 30 | + |
| 31 | +bool GistPluginPlugin::initialize(const QStringList &arguments, QString *errorString) |
| 32 | +{ |
| 33 | + // Register objects in the plugin manager's object pool |
| 34 | + // Load settings |
| 35 | + // Add actions to menus |
| 36 | + // Connect to other plugins' signals |
| 37 | + // In the initialize function, a plugin can be sure that the plugins it |
| 38 | + // depends on have initialized their members. |
| 39 | + |
| 40 | + Q_UNUSED(arguments) |
| 41 | + Q_UNUSED(errorString) |
| 42 | + |
| 43 | + QAction *action = new QAction(tr("GistPlugin action"), this); |
| 44 | + Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID, |
| 45 | + Core::Context(Core::Constants::C_GLOBAL)); |
| 46 | + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A"))); |
| 47 | + connect(action, SIGNAL(triggered()), this, SLOT(triggerAction())); |
| 48 | + |
| 49 | + Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID); |
| 50 | + menu->menu()->setTitle(tr("GistPlugin")); |
| 51 | + menu->addAction(cmd); |
| 52 | + Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu); |
| 53 | + |
| 54 | + return true; |
| 55 | +} |
| 56 | + |
| 57 | +void GistPluginPlugin::extensionsInitialized() |
| 58 | +{ |
| 59 | + // Retrieve objects from the plugin manager's object pool |
| 60 | + // In the extensionsInitialized function, a plugin can be sure that all |
| 61 | + // plugins that depend on it are completely initialized. |
| 62 | +} |
| 63 | + |
| 64 | +ExtensionSystem::IPlugin::ShutdownFlag GistPluginPlugin::aboutToShutdown() |
| 65 | +{ |
| 66 | + // Save settings |
| 67 | + // Disconnect from signals that are not needed during shutdown |
| 68 | + // Hide UI (if you add UI that is not in the main window directly) |
| 69 | + return SynchronousShutdown; |
| 70 | +} |
| 71 | + |
| 72 | +void GistPluginPlugin::triggerAction() |
| 73 | +{ |
| 74 | + QMessageBox::information(Core::ICore::mainWindow(), |
| 75 | + tr("Action triggered"), |
| 76 | + tr("This is an action from GistPlugin.")); |
| 77 | +} |
0 commit comments