forked from qt-creator/qt-creator
Also look for tools in user's resource path
This commit is contained in:
@@ -30,7 +30,6 @@
|
|||||||
#include "externaltool.h"
|
#include "externaltool.h"
|
||||||
#include "actionmanager/actionmanager.h"
|
#include "actionmanager/actionmanager.h"
|
||||||
#include "actionmanager/actioncontainer.h"
|
#include "actionmanager/actioncontainer.h"
|
||||||
#include "actionmanager/command.h"
|
|
||||||
#include "coreconstants.h"
|
#include "coreconstants.h"
|
||||||
#include "variablemanager.h"
|
#include "variablemanager.h"
|
||||||
|
|
||||||
@@ -446,43 +445,14 @@ void ExternalToolManager::initialize()
|
|||||||
ActionContainer *mexternaltools = am->createMenu(Id(Constants::M_TOOLS_EXTERNAL));
|
ActionContainer *mexternaltools = am->createMenu(Id(Constants::M_TOOLS_EXTERNAL));
|
||||||
mexternaltools->menu()->setTitle(tr("External"));
|
mexternaltools->menu()->setTitle(tr("External"));
|
||||||
ActionContainer *mtools = am->actionContainer(Constants::M_TOOLS);
|
ActionContainer *mtools = am->actionContainer(Constants::M_TOOLS);
|
||||||
Command *cmd;
|
|
||||||
|
|
||||||
mtools->addMenu(mexternaltools, Constants::G_DEFAULT_THREE);
|
mtools->addMenu(mexternaltools, Constants::G_DEFAULT_THREE);
|
||||||
|
|
||||||
QMap<QString, QMultiMap<int, Command*> > categoryMenus;
|
QMap<QString, QMultiMap<int, Command*> > categoryMenus;
|
||||||
QDir dir(m_core->resourcePath() + QLatin1String("/externaltools"),
|
parseDirectory(m_core->userResourcePath() + QLatin1String("/externaltools"),
|
||||||
QLatin1String("*.xml"), QDir::Unsorted, QDir::Files | QDir::Readable);
|
&categoryMenus);
|
||||||
foreach (const QFileInfo &info, dir.entryInfoList()) {
|
parseDirectory(m_core->resourcePath() + QLatin1String("/externaltools"),
|
||||||
QFile file(info.absoluteFilePath());
|
&categoryMenus, true);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add all the category menus, QMap is nicely sorted
|
// add all the category menus, QMap is nicely sorted
|
||||||
QMapIterator<QString, QMultiMap<int, Command*> > it(categoryMenus);
|
QMapIterator<QString, QMultiMap<int, Command*> > it(categoryMenus);
|
||||||
@@ -502,6 +472,46 @@ void ExternalToolManager::initialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
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()
|
void ExternalToolManager::menuActivated()
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "icore.h"
|
#include "icore.h"
|
||||||
#include "core_global.h"
|
#include "core_global.h"
|
||||||
|
#include "actionmanager/command.h"
|
||||||
|
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
@@ -138,6 +139,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void initialize();
|
void initialize();
|
||||||
|
void parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, Command*> > *categoryMenus,
|
||||||
|
bool ignoreDuplicates = false);
|
||||||
|
|
||||||
static ExternalToolManager *m_instance;
|
static ExternalToolManager *m_instance;
|
||||||
Core::ICore *m_core;
|
Core::ICore *m_core;
|
||||||
|
|||||||
Reference in New Issue
Block a user