Changeset View
Changeset View
Standalone View
Standalone View
addons/externaltools/kateexternaltoolscommand.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright 2019 Dominik Haumann <dhaumann@kde.org> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Library General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2 of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This library is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | * Library General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library General Public License | ||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | * Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | #include "kateexternaltoolscommand.h" | ||||
21 | #include "externaltoolsplugin.h" | ||||
22 | #include "kateexternaltool.h" | ||||
23 | | ||||
24 | #include <KLocalizedString> | ||||
25 | | ||||
26 | KateExternalToolsCommand::KateExternalToolsCommand(KateExternalToolsPlugin* plugin) | ||||
27 | : KTextEditor::Command(plugin->commands()) | ||||
28 | , m_plugin(plugin) | ||||
29 | { | ||||
30 | } | ||||
31 | | ||||
32 | bool KateExternalToolsCommand::exec(KTextEditor::View* view, const QString& cmd, QString& msg, | ||||
33 | const KTextEditor::Range& range) | ||||
34 | { | ||||
35 | Q_UNUSED(msg) | ||||
36 | Q_UNUSED(range) | ||||
37 | | ||||
38 | const QString command = cmd.trimmed(); | ||||
39 | const auto tool = m_plugin->toolForCommand(command); | ||||
40 | if (tool) { | ||||
41 | m_plugin->runTool(*tool, view); | ||||
42 | return true; | ||||
43 | } | ||||
44 | return false; | ||||
45 | } | ||||
46 | | ||||
47 | bool KateExternalToolsCommand::help(KTextEditor::View*, const QString& cmd, QString& msg) | ||||
48 | { | ||||
49 | const QString command = cmd.trimmed(); | ||||
50 | const auto tool = m_plugin->toolForCommand(command); | ||||
51 | if (tool) { | ||||
52 | msg = i18n("Starts the external tool '%1'", tool->name); | ||||
53 | return true; | ||||
54 | } | ||||
55 | | ||||
56 | return false; | ||||
57 | } | ||||
58 | | ||||
59 | // kate: space-indent on; indent-width 4; replace-tabs on; |