Changeset View
Changeset View
Standalone View
Standalone View
addons/externaltools/kateexternaltool.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This file is part of the Kate text editor of the KDE project. | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License version 2 as published by the Free Software Foundation. | ||||
7 | | ||||
8 | This library is distributed in the hope that it will be useful, | ||||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
11 | Library General Public License for more details. | ||||
12 | | ||||
13 | You should have received a copy of the GNU Library General Public License | ||||
14 | along with this library; see the file COPYING.LIB. If not, write to | ||||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
16 | Boston, MA 02110-1301, USA. | ||||
17 | | ||||
18 | --- | ||||
19 | Copyright (C) 2019 Dominik Haumann <dhaumann@kde.org> | ||||
20 | */ | ||||
21 | #include "kateexternaltool.h" | ||||
22 | | ||||
23 | #include <KConfigGroup> | ||||
24 | #include <QStandardPaths> | ||||
25 | | ||||
26 | KateExternalTool::KateExternalTool(const QString& name, const QString& command, const QString& icon, | ||||
27 | const QString& executable, const QStringList& mimetypes, const QString& actionName, | ||||
28 | const QString& cmdname, SaveMode saveMode) | ||||
29 | : name(name) | ||||
30 | , icon(icon) | ||||
31 | , executable(executable) | ||||
32 | , command(command) | ||||
33 | , mimetypes(mimetypes) | ||||
34 | , actionName(actionName) | ||||
35 | , cmdname(cmdname) | ||||
36 | , saveMode(saveMode) | ||||
37 | { | ||||
38 | // if ( ! executable.isEmpty() ) | ||||
39 | hasexec = checkExec(); | ||||
40 | } | ||||
41 | | ||||
42 | bool KateExternalTool::checkExec() | ||||
43 | { | ||||
44 | m_exec = QStandardPaths::findExecutable(executable); | ||||
45 | return !m_exec.isEmpty(); | ||||
46 | } | ||||
47 | | ||||
48 | bool KateExternalTool::valid(const QString& mt) const | ||||
49 | { | ||||
50 | return mimetypes.isEmpty() || mimetypes.contains(mt); | ||||
51 | } | ||||
52 | | ||||
53 | void KateExternalTool::load(const KConfigGroup & cg) | ||||
54 | { | ||||
55 | name = cg.readEntry("name", ""); | ||||
56 | command = cg.readEntry("command", ""); | ||||
57 | icon = cg.readEntry("icon", ""); | ||||
58 | executable = cg.readEntry("executable", ""); | ||||
59 | mimetypes = cg.readEntry("mimetypes", QStringList()); | ||||
60 | actionName = cg.readEntry("actionName"); | ||||
61 | cmdname = cg.readEntry("cmdname"); | ||||
62 | saveMode = static_cast<KateExternalTool::SaveMode>(cg.readEntry("save", 0)); | ||||
63 | includeStderr = cg.readEntry("includeStderr", false); | ||||
64 | | ||||
65 | hasexec = checkExec(); | ||||
66 | } | ||||
67 | | ||||
68 | void KateExternalTool::save(KConfigGroup & cg) | ||||
69 | { | ||||
70 | cg.writeEntry("name", name); | ||||
71 | cg.writeEntry("command", command); | ||||
72 | cg.writeEntry("icon", icon); | ||||
73 | cg.writeEntry("executable", executable); | ||||
74 | cg.writeEntry("mimetypes", mimetypes); | ||||
75 | cg.writeEntry("actionName", actionName); | ||||
76 | cg.writeEntry("cmdname", cmdname); | ||||
77 | cg.writeEntry("save", static_cast<int>(saveMode)); | ||||
78 | cg.writeEntry("includeStderr", includeStderr); | ||||
79 | } | ||||
80 | | ||||
81 | // kate: space-indent on; indent-width 4; replace-tabs on; |