Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0d1c47d1 authored by Dominik Haumann's avatar Dominik Haumann

External Tools: Read tools from defaultexternaltoolsrc on first start

The file 'defaultexternaltoolsrc' is available via the Qt resource
system for KConfig via ":/kconfig/defaultexternaltoolsrc". On first
start, if no tools are around yet, all tools in the defaultexternaltoolsrc
file will be added as external tools.
parent e8f0822f
......@@ -136,18 +136,3 @@ output=ReplaceSelectedText
reload=false
save=None
workingDir=%{Document:Path}
[Tool 9]
actionName=externaltool_perl
arguments=%{ENV:KATE_PID
category=Tools
cmdname=perl
executable=echo
icon=
input=
mimetypes=
name=perl
output=DisplayInPane
reload=false
save=None
workingDir=
......@@ -40,12 +40,32 @@
#include <KPluginFactory>
#include <KXMLGUIFactory>
static QVector<KateExternalTool> readDefaultTools()
{
QVector<KateExternalTool> tools;
KConfig systemConfig(QStringLiteral("defaultexternaltoolsrc"));
KConfigGroup config(&systemConfig, "Global");
const int toolCount = config.readEntry("tools", 0);
for (int i = 0; i < toolCount; ++i) {
config = KConfigGroup(&systemConfig, QStringLiteral("Tool %1").arg(i));
KateExternalTool t;
t.load(config);
tools.push_back(t);
}
return tools;
}
K_PLUGIN_FACTORY_WITH_JSON(KateExternalToolsFactory, "externaltoolsplugin.json",
registerPlugin<KateExternalToolsPlugin>();)
KateExternalToolsPlugin::KateExternalToolsPlugin(QObject* parent, const QList<QVariant>&)
: KTextEditor::Plugin(parent)
{
// read built-in external tools from compiled-in resource file
m_defaultTools = readDefaultTools();
// load config from disk
reload();
}
......@@ -73,17 +93,28 @@ void KateExternalToolsPlugin::reload()
KConfig _config(QStringLiteral("externaltools"), KConfig::NoGlobals, QStandardPaths::ApplicationsLocation);
KConfigGroup config(&_config, "Global");
const int toolCount = config.readEntry("tools", 0);
const bool firstStart = config.readEntry("firststart", true);
for (int i = 0; i < toolCount; ++i) {
config = KConfigGroup(&_config, QStringLiteral("Tool %1").arg(i));
if (!firstStart || toolCount > 0) {
// read user config
for (int i = 0; i < toolCount; ++i) {
config = KConfigGroup(&_config, QStringLiteral("Tool %1").arg(i));
auto t = new KateExternalTool();
t->load(config);
m_tools.push_back(t);
auto t = new KateExternalTool();
t->load(config);
m_tools.push_back(t);
}
} else {
// first start -> use system config
for (const auto & tool : m_defaultTools) {
m_tools.push_back(new KateExternalTool(tool));
}
}
// FIXME test for a command name first!
if (t->hasexec && (!t->cmdname.isEmpty())) {
m_commands.push_back(t->cmdname);
// FIXME test for a command name first!
for (auto tool : m_tools) {
if (tool->hasexec && (!tool->cmdname.isEmpty())) {
m_commands.push_back(tool->cmdname);
}
}
......
......@@ -109,18 +109,17 @@ public:
KateExternalToolsPluginView *viewForMainWindow(KTextEditor::MainWindow *mainWindow) const;
private:
QVector<KateExternalTool> m_defaultTools;
QVector<KateExternalToolsPluginView *> m_views;
QVector<KateExternalTool *> m_tools;
QStringList m_commands;
KateExternalToolsCommand *m_command = nullptr;
private
Q_SLOT :
/**
* Called whenever an external tool is done.
*/
void
handleToolFinished(KateToolRunner *runner, int exitCode, bool crashed);
private Q_SLOTS:
/**
* Called whenever an external tool is done.
*/
void handleToolFinished(KateToolRunner *runner, int exitCode, bool crashed);
};
#endif
......
......@@ -270,6 +270,7 @@ void KateExternalToolsConfigWidget::apply()
}
// write tool configuration to disk
m_config->group("Global").writeEntry("firststart", false);
m_config->group("Global").writeEntry("tools", static_cast<int>(tools.size()));
for (size_t i = 0; i < tools.size(); i++) {
const QString section = QStringLiteral("Tool ") + QString::number(i);
......
......@@ -3,7 +3,7 @@
<qresource prefix="/kxmlgui5/externaltools">
<file>ui.rc</file>
</qresource>
<qresource prefix="/externaltools">
<file>tools.cfg</file>
<qresource prefix="/kconfig">
<file>defaultexternaltoolsrc</file>
</qresource>
</RCC>
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