File indexing completed on 2024-04-28 15:31:20
0001 /* 0002 SPDX-FileCopyrightText: KDE Developers 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KATEVI_MAPPINGS_H 0008 #define KATEVI_MAPPINGS_H 0009 0010 #include <QHash> 0011 #include <ktexteditor_export.h> 0012 0013 class KConfigGroup; 0014 class KateViInputMode; 0015 0016 namespace KateVi 0017 { 0018 class KTEXTEDITOR_EXPORT Mappings 0019 { 0020 public: 0021 enum MappingRecursion { Recursive, NonRecursive }; 0022 0023 enum MappingMode { NormalModeMapping = 0, VisualModeMapping, InsertModeMapping, CommandModeMapping }; 0024 0025 public: 0026 void writeConfig(KConfigGroup &config) const; 0027 void readConfig(const KConfigGroup &config); 0028 0029 void add(MappingMode mode, const QString &from, const QString &to, MappingRecursion recursion); 0030 void remove(MappingMode mode, const QString &from); 0031 void clear(MappingMode mode); 0032 0033 QString get(MappingMode mode, const QString &from, bool decode = false, bool includeTemporary = false) const; 0034 QStringList getAll(MappingMode mode, bool decode = false, bool includeTemporary = false) const; 0035 bool isRecursive(MappingMode mode, const QString &from) const; 0036 0037 void setLeader(const QChar &leader); 0038 0039 public: 0040 /** 0041 * Returns CommandModeMapping if the emulated command bar is active, else the mapping mode 0042 * corresponding to the current Vi mode. 0043 */ 0044 static MappingMode mappingModeForCurrentViMode(KateViInputMode *viInputMode); 0045 0046 private: 0047 KTEXTEDITOR_NO_EXPORT 0048 void writeMappings(KConfigGroup &config, const QString &mappingModeName, MappingMode mappingMode) const; 0049 KTEXTEDITOR_NO_EXPORT 0050 void readMappings(const KConfigGroup &config, const QString &mappingModeName, MappingMode mappingMode); 0051 0052 private: 0053 typedef struct { 0054 // The real value of the mapping. 0055 QString encoded; 0056 0057 // True if it's recursive, false otherwise. 0058 bool recursive; 0059 0060 // True if this mapping should not be read/written in the config. 0061 // Used for temporary mapping (e.g. mappings with <leader>). 0062 bool temporary; 0063 } Mapping; 0064 typedef QHash<QString, Mapping> MappingList; 0065 0066 MappingList m_mappings[4]; 0067 QChar m_leader; 0068 }; 0069 0070 } 0071 0072 #endif // KATEVI_MAPPINGS_H