File indexing completed on 2024-04-14 03:55:49

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 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     KTEXTEDITOR_EXPORT void add(MappingMode mode, const QString &from, const QString &to, MappingRecursion recursion);
0030     void remove(MappingMode mode, const QString &from);
0031     KTEXTEDITOR_EXPORT 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     KTEXTEDITOR_EXPORT bool isRecursive(MappingMode mode, const QString &from) const;
0036 
0037     KTEXTEDITOR_EXPORT 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     void writeMappings(KConfigGroup &config, const QString &mappingModeName, MappingMode mappingMode) const;
0048     void readMappings(const KConfigGroup &config, const QString &mappingModeName, MappingMode mappingMode);
0049 
0050 private:
0051     typedef struct {
0052         // The real value of the mapping.
0053         QString encoded;
0054 
0055         // True if it's recursive, false otherwise.
0056         bool recursive;
0057 
0058         // True if this mapping should not be read/written in the config.
0059         // Used for temporary mapping (e.g. mappings with <leader>).
0060         bool temporary;
0061     } Mapping;
0062     typedef QHash<QString, Mapping> MappingList;
0063 
0064     MappingList m_mappings[4];
0065     QChar m_leader;
0066 };
0067 
0068 }
0069 
0070 #endif // KATEVI_MAPPINGS_H