Commit b9f9cf3d authored by con's avatar con
Browse files

Also look for tools in user's resource path

parent dd87e964
......@@ -30,7 +30,6 @@
#include "externaltool.h"
#include "actionmanager/actionmanager.h"
#include "actionmanager/actioncontainer.h"
#include "actionmanager/command.h"
#include "coreconstants.h"
#include "variablemanager.h"
......@@ -446,13 +445,40 @@ void ExternalToolManager::initialize()
ActionContainer *mexternaltools = am->createMenu(Id(Constants::M_TOOLS_EXTERNAL));
mexternaltools->menu()->setTitle(tr("External"));
ActionContainer *mtools = am->actionContainer(Constants::M_TOOLS);
Command *cmd;
mtools->addMenu(mexternaltools, Constants::G_DEFAULT_THREE);
QMap<QString, QMultiMap<int, Command*> > categoryMenus;
QDir dir(m_core->resourcePath() + QLatin1String("/externaltools"),
QLatin1String("*.xml"), QDir::Unsorted, QDir::Files | QDir::Readable);
parseDirectory(m_core->userResourcePath() + QLatin1String("/externaltools"),
&categoryMenus);
parseDirectory(m_core->resourcePath() + QLatin1String("/externaltools"),
&categoryMenus, true);
// add all the category menus, QMap is nicely sorted
QMapIterator<QString, QMultiMap<int, Command*> > it(categoryMenus);
while (it.hasNext()) {
it.next();
ActionContainer *container = 0;
if (it.key() == QString()) { // no displayCategory, so put into external tools menu directly
container = mexternaltools;
} else {
container = am->createMenu(Id("Tools.External.Category." + it.key()));
mexternaltools->addMenu(container, Constants::G_DEFAULT_ONE);
container->menu()->setTitle(it.key());
}
foreach (Command *cmd, it.value().values()) {
container->addAction(cmd, Constants::G_DEFAULT_TWO);
}
}
}
void ExternalToolManager::parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, Command*> > *categoryMenus,
bool ignoreDuplicates)
{
QTC_ASSERT(categoryMenus, return);
ActionManager *am = m_core->actionManager();
Command *cmd;
QDir dir(directory, QLatin1String("*.xml"), QDir::Unsorted, QDir::Files | QDir::Readable);
foreach (const QFileInfo &info, dir.entryInfoList()) {
QFile file(info.absoluteFilePath());
if (file.open(QIODevice::ReadOnly)) {
......@@ -467,7 +493,8 @@ void ExternalToolManager::initialize()
}
if (m_tools.contains(tool->id())) {
// TODO error handling
qDebug() << tr("Error: External tool in %1 has duplicate id").arg(file.fileName());
if (!ignoreDuplicates)
qDebug() << tr("Error: External tool in %1 has duplicate id").arg(file.fileName());
delete tool;
continue;
}
......@@ -480,24 +507,7 @@ void ExternalToolManager::initialize()
action->setData(tool->id());
cmd = am->registerAction(action, Id("Tools.External." + tool->id()), Context(Constants::C_GLOBAL));
connect(action, SIGNAL(triggered()), this, SLOT(menuActivated()));
categoryMenus[tool->displayCategory()].insert(tool->order(), cmd);
}
}
// add all the category menus, QMap is nicely sorted
QMapIterator<QString, QMultiMap<int, Command*> > it(categoryMenus);
while (it.hasNext()) {
it.next();
ActionContainer *container = 0;
if (it.key() == QString()) { // no displayCategory, so put into external tools menu directly
container = mexternaltools;
} else {
container = am->createMenu(Id("Tools.External.Category." + it.key()));
mexternaltools->addMenu(container, Constants::G_DEFAULT_ONE);
container->menu()->setTitle(it.key());
}
foreach (Command *cmd, it.value().values()) {
container->addAction(cmd, Constants::G_DEFAULT_TWO);
(*categoryMenus)[tool->displayCategory()].insert(tool->order(), cmd);
}
}
}
......
......@@ -32,6 +32,7 @@
#include "icore.h"
#include "core_global.h"
#include "actionmanager/command.h"
#include <utils/qtcprocess.h>
......@@ -138,6 +139,8 @@ private slots:
private:
void initialize();
void parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, Command*> > *categoryMenus,
bool ignoreDuplicates = false);
static ExternalToolManager *m_instance;
Core::ICore *m_core;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment