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