Files
qt-creator/doc/pluginhowto/examples/menu/addingmenu/donothingplugin.cpp

72 lines
1.8 KiB
C++
Raw Normal View History

#include "donothingplugin.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
2010-07-15 20:28:53 +02:00
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/icore.h>
2010-07-15 20:28:53 +02:00
#include <coreplugin/icontext.h>
2010-07-15 20:28:53 +02:00
#include <QKeySequence>
#include <QStringList>
#include <QMessageBox>
2010-07-15 20:28:53 +02:00
#include <QAction>
#include <QMenu>
#include <QtPlugin>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
// Fetch the action manager
Core::ActionManager* am = Core::ICore::instance()->actionManager();
// Create a DoNothing menu
Core::ActionContainer* ac = am->createMenu("DoNothingPlugin.DoNothingMenu");
ac->menu()->setTitle("DoNothing");
2010-07-15 20:28:53 +02:00
// Create a command for "DoNothing".
QAction *action = new QAction(tr("DoNothing"),this);
Core::Command* cmd = am->registerAction(action,
QLatin1String("DoNothingPlugin.DoNothing"),
Core::Context(Core::Constants::C_GLOBAL));
// Add DoNothing menu to the menubar
2010-07-15 20:28:53 +02:00
am->actionContainer(Core::Constants::M_TOOLS)->addMenu(ac, Core::Constants::G_DEFAULT_THREE);
2010-07-15 20:28:53 +02:00
// Add the "DoNothing" action to the DoNothing menu
ac->addAction(cmd);
// Connect the action
2010-07-15 20:28:53 +02:00
connect(action, SIGNAL(triggered(bool)), this, SLOT(performAction()));
return true;
}
2010-07-15 20:28:53 +02:00
ExtensionSystem::IPlugin::ShutdownFlag DoNothingPlugin::shutdown()
{
2010-07-15 20:28:53 +02:00
return SynchronousShutdown;
}
2010-07-15 20:28:53 +02:00
void DoNothingPlugin::performAction()
{
2010-07-15 20:28:53 +02:00
QMessageBox::information(0, tr("DoNothing Plugin"),
tr("Seriously dude, this plugin does nothing"));
}
Q_EXPORT_PLUGIN(DoNothingPlugin)