1/*
2 SPDX-FileCopyrightText: KDE Developers
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KATEVI_MAPPINGS_H
8#define KATEVI_MAPPINGS_H
9
10#include <QHash>
11#include <ktexteditor_export.h>
12
13class KConfigGroup;
14class KateViInputMode;
15
16namespace KateVi
17{
18class Mappings
19{
20public:
21 enum MappingRecursion { Recursive, NonRecursive };
22
23 enum MappingMode { NormalModeMapping = 0, VisualModeMapping, InsertModeMapping, CommandModeMapping };
24
25public:
26 void writeConfig(KConfigGroup &config) const;
27 void readConfig(const KConfigGroup &config);
28
29 KTEXTEDITOR_EXPORT void add(MappingMode mode, const QString &from, const QString &to, MappingRecursion recursion);
30 void remove(MappingMode mode, const QString &from);
31 KTEXTEDITOR_EXPORT void clear(MappingMode mode);
32
33 QString get(MappingMode mode, const QString &from, bool decode = false, bool includeTemporary = false) const;
34 QStringList getAll(MappingMode mode, bool decode = false, bool includeTemporary = false) const;
35 KTEXTEDITOR_EXPORT bool isRecursive(MappingMode mode, const QString &from) const;
36
37 KTEXTEDITOR_EXPORT void setLeader(const QChar &leader);
38
39public:
40 /**
41 * Returns CommandModeMapping if the emulated command bar is active, else the mapping mode
42 * corresponding to the current Vi mode.
43 */
44 static MappingMode mappingModeForCurrentViMode(KateViInputMode *viInputMode);
45
46private:
47 void writeMappings(KConfigGroup &config, const QString &mappingModeName, MappingMode mappingMode) const;
48 void readMappings(const KConfigGroup &config, const QString &mappingModeName, MappingMode mappingMode);
49
50private:
51 typedef struct {
52 // The real value of the mapping.
53 QString encoded;
54
55 // True if it's recursive, false otherwise.
56 bool recursive;
57
58 // True if this mapping should not be read/written in the config.
59 // Used for temporary mapping (e.g. mappings with <leader>).
60 bool temporary;
61 } Mapping;
62 typedef QHash<QString, Mapping> MappingList;
63
64 MappingList m_mappings[4];
65 QChar m_leader;
66};
67
68}
69
70#endif // KATEVI_MAPPINGS_H
71

source code of ktexteditor/src/vimode/mappings.h