From b9f9cf3d79bfac287def555f73cd1d0eed91e394 Mon Sep 17 00:00:00 2001 From: con Date: Thu, 6 Jan 2011 11:01:57 +0100 Subject: [PATCH] Also look for tools in user's resource path --- src/plugins/coreplugin/externaltool.cpp | 78 ++++++++++++++----------- src/plugins/coreplugin/externaltool.h | 3 + 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index 3806175dea2..f1ad60023a1 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -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,43 +445,14 @@ 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 > categoryMenus; - QDir dir(m_core->resourcePath() + QLatin1String("/externaltools"), - QLatin1String("*.xml"), QDir::Unsorted, QDir::Files | QDir::Readable); - foreach (const QFileInfo &info, dir.entryInfoList()) { - QFile file(info.absoluteFilePath()); - if (file.open(QIODevice::ReadOnly)) { - const QByteArray &bytes = file.readAll(); - file.close(); - QString error; - ExternalTool *tool = ExternalTool::createFromXml(bytes, &error, m_core->userInterfaceLanguage()); - if (!tool) { - // TODO error handling - qDebug() << tr("Error while parsing external tool %1: %2").arg(file.fileName(), error); - continue; - } - if (m_tools.contains(tool->id())) { - // TODO error handling - qDebug() << tr("Error: External tool in %1 has duplicate id").arg(file.fileName()); - delete tool; - continue; - } - m_tools.insert(tool->id(), tool); - - // tool action and command - QAction *action = new QAction(tool->displayName(), this); - action->setToolTip(tool->description()); - action->setWhatsThis(tool->description()); - 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); - } - } + 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 > it(categoryMenus); @@ -502,6 +472,46 @@ void ExternalToolManager::initialize() } } +void ExternalToolManager::parseDirectory(const QString &directory, QMap > *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)) { + const QByteArray &bytes = file.readAll(); + file.close(); + QString error; + ExternalTool *tool = ExternalTool::createFromXml(bytes, &error, m_core->userInterfaceLanguage()); + if (!tool) { + // TODO error handling + qDebug() << tr("Error while parsing external tool %1: %2").arg(file.fileName(), error); + continue; + } + if (m_tools.contains(tool->id())) { + // TODO error handling + if (!ignoreDuplicates) + qDebug() << tr("Error: External tool in %1 has duplicate id").arg(file.fileName()); + delete tool; + continue; + } + m_tools.insert(tool->id(), tool); + + // tool action and command + QAction *action = new QAction(tool->displayName(), this); + action->setToolTip(tool->description()); + action->setWhatsThis(tool->description()); + 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); + } + } +} + void ExternalToolManager::menuActivated() { QAction *action = qobject_cast(sender()); diff --git a/src/plugins/coreplugin/externaltool.h b/src/plugins/coreplugin/externaltool.h index a5b307c6f14..53b02b712a3 100644 --- a/src/plugins/coreplugin/externaltool.h +++ b/src/plugins/coreplugin/externaltool.h @@ -32,6 +32,7 @@ #include "icore.h" #include "core_global.h" +#include "actionmanager/command.h" #include @@ -138,6 +139,8 @@ private slots: private: void initialize(); + void parseDirectory(const QString &directory, QMap > *categoryMenus, + bool ignoreDuplicates = false); static ExternalToolManager *m_instance; Core::ICore *m_core;