File indexing completed on 2024-05-05 05:51:22

0001 /* This file is part of the KDE project
0002  *
0003  *  SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 #include "kateexternaltoolscommand.h"
0008 #include "externaltoolsplugin.h"
0009 #include "kateexternaltool.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 KateExternalToolsCommand::KateExternalToolsCommand(KateExternalToolsPlugin *plugin)
0014     : KTextEditor::Command(plugin->commands())
0015     , m_plugin(plugin)
0016 {
0017 }
0018 
0019 bool KateExternalToolsCommand::exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range)
0020 {
0021     Q_UNUSED(msg)
0022     Q_UNUSED(range)
0023 
0024     const QString command = cmd.trimmed();
0025     const auto tool = m_plugin->toolForCommand(command);
0026     if (tool) {
0027         m_plugin->runTool(*tool, view);
0028         return true;
0029     }
0030     return false;
0031 }
0032 
0033 bool KateExternalToolsCommand::help(KTextEditor::View *, const QString &cmd, QString &msg)
0034 {
0035     const QString command = cmd.trimmed();
0036     const auto tool = m_plugin->toolForCommand(command);
0037     if (tool) {
0038         msg = i18n("Starts the external tool '%1'", tool->name);
0039         return true;
0040     }
0041 
0042     return false;
0043 }
0044 
0045 // kate: space-indent on; indent-width 4; replace-tabs on;