File indexing completed on 2024-04-28 15:30:54

0001 /*
0002     SPDX-FileCopyrightText: 2003 Christoph Cullmann <cullmann@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KATE_CONFIG_H
0008 #define KATE_CONFIG_H
0009 
0010 #include <ktexteditor_export.h>
0011 
0012 #include <ktexteditor/markinterface.h>
0013 #include <ktexteditor/view.h>
0014 
0015 #include <KEncodingProber>
0016 
0017 #include <functional>
0018 #include <map>
0019 #include <memory>
0020 
0021 #include <QBitRef>
0022 #include <QColor>
0023 #include <QObject>
0024 #include <QVector>
0025 
0026 class KConfigGroup;
0027 namespace KTextEditor
0028 {
0029 class ViewPrivate;
0030 }
0031 namespace KTextEditor
0032 {
0033 class DocumentPrivate;
0034 }
0035 class KateRenderer;
0036 
0037 namespace KTextEditor
0038 {
0039 class EditorPrivate;
0040 }
0041 
0042 class KConfig;
0043 
0044 class QTextCodec;
0045 
0046 /**
0047  * Base Class for the Kate Config Classes
0048  * Current childs are KateDocumentConfig/KateDocumentConfig/KateDocumentConfig
0049  */
0050 class KTEXTEDITOR_EXPORT KateConfig
0051 {
0052 public:
0053     /**
0054      * Start some config changes.
0055      * This method is needed to init some kind of transaction for config changes,
0056      * update will only be done once, at configEnd() call.
0057      */
0058     void configStart();
0059 
0060     /**
0061      * End a config change transaction, update the concerned
0062      * KateDocumentConfig/KateDocumentConfig/KateDocumentConfig
0063      */
0064     void configEnd();
0065 
0066     /**
0067      * Is this a global config object?
0068      * @return true when this is a global config object
0069      */
0070     bool isGlobal() const
0071     {
0072         return !m_parent;
0073     }
0074 
0075     /**
0076      * All known config keys.
0077      * This will use the knowledge about all registered keys of the global object.
0078      * @return all known config keys
0079      */
0080     QStringList configKeys() const
0081     {
0082         return m_parent ? m_parent->configKeys() : *m_configKeys.get();
0083     }
0084 
0085     /**
0086      * Is given key set in this config object?
0087      * @param key config key, aka enum from KateConfig* classes
0088      * @return is the wanted key set?
0089      */
0090     bool isSet(const int key) const
0091     {
0092         return m_configEntries.find(key) != m_configEntries.end();
0093     }
0094 
0095     /**
0096      * Get a config value.
0097      * @param key config key, aka enum from KateConfig* classes
0098      * @return value for the wanted key, will assert if key is not valid
0099      */
0100     QVariant value(const int key) const;
0101 
0102     /**
0103      * Set a config value.
0104      * Will assert if key is invalid.
0105      * Might not alter the value if given value fails validation.
0106      * @param key config key, aka enum from KateConfig* classes
0107      * @param value value to set
0108      * @return true on success
0109      */
0110     bool setValue(const int key, const QVariant &value);
0111 
0112     /**
0113      * Get a config value for the string key.
0114      * @param key config key, aka commandName from KateConfig* classes
0115      * @return value for the wanted key, will return invalid variant if key is not known
0116      */
0117     QVariant value(const QString &key) const;
0118 
0119     /**
0120      * Set a config value.
0121      * Will do nothing if key is not known or the given value fails validation.
0122      * @param key config key, aka commandName from KateConfig* classes
0123      * @param value value to set
0124      * @return true on success
0125      */
0126     bool setValue(const QString &key, const QVariant &value);
0127 
0128 protected:
0129     /**
0130      * Construct a KateConfig.
0131      * @param parent parent config object, if any
0132      */
0133     KateConfig(const KateConfig *parent = nullptr);
0134 
0135     /**
0136      * Virtual Destructor
0137      */
0138     virtual ~KateConfig();
0139 
0140     /**
0141      * One config entry.
0142      */
0143     class ConfigEntry
0144     {
0145     public:
0146         /**
0147          * Construct one config entry.
0148          * @param enumId value of the enum for this config entry
0149          * @param configId value of the key for the KConfig file for this config entry
0150          * @param command command name
0151          * @param defaultVal default value
0152          * @param valid validator function, default none
0153          */
0154         ConfigEntry(int enumId, const char *configId, QString command, QVariant defaultVal, std::function<bool(const QVariant &)> valid = nullptr)
0155             : enumKey(enumId)
0156             , configKey(configId)
0157             , commandName(command)
0158             , defaultValue(defaultVal)
0159             , value(defaultVal)
0160             , validator(valid)
0161         {
0162         }
0163 
0164         /**
0165          * Enum key for this config entry, shall be unique
0166          */
0167         const int enumKey;
0168 
0169         /**
0170          * KConfig entry key for this config entry, shall be unique in its group
0171          * e.g. "Tab Width"
0172          */
0173         const char *const configKey;
0174 
0175         /**
0176          * Command name as used in e.g. ConfigInterface or modeline/command line
0177          * e.g. tab-width
0178          */
0179         const QString commandName;
0180 
0181         /**
0182          * Default value if nothing special was configured
0183          */
0184         const QVariant defaultValue;
0185 
0186         /**
0187          * The concrete value, per default == defaultValue
0188          */
0189         QVariant value;
0190 
0191         /**
0192          * An optional validator function, only when these returns true
0193          * we accept a given new value.
0194          * Is no validator set, we accept any value.
0195          */
0196         std::function<bool(const QVariant &)> validator;
0197     };
0198 
0199     /**
0200      * Read all config entries from given config group.
0201      * @param config config group to read from
0202      */
0203     void readConfigEntries(const KConfigGroup &config);
0204 
0205     /**
0206      * Write all config entries to given config group.
0207      * @param config config group to write to
0208      */
0209     void writeConfigEntries(KConfigGroup &config) const;
0210 
0211     /**
0212      * Register a new config entry.
0213      * Used by the sub classes to register all there known ones.
0214      * @param entry new entry to add
0215      */
0216     void addConfigEntry(ConfigEntry &&entry);
0217 
0218     /**
0219      * Finalize the config entries.
0220      * Called by the sub classes after all entries are registered
0221      */
0222     void finalizeConfigEntries();
0223 
0224     /**
0225      * do the real update
0226      */
0227     virtual void updateConfig() = 0;
0228 
0229 private:
0230     /**
0231      * Get full map of config entries, aka the m_configEntries of the top config object
0232      * @return full map with all config entries
0233      */
0234     const std::map<int, ConfigEntry> &fullConfigEntries() const
0235     {
0236         return m_parent ? m_parent->fullConfigEntries() : m_configEntries;
0237     }
0238     /**
0239      * Get hash of config entries, aka the m_configKeyToEntry of the top config object
0240      * @return full hash with all config entries
0241      */
0242     const QHash<QString, const ConfigEntry *> &fullConfigKeyToEntry() const
0243     {
0244         return m_parent ? m_parent->fullConfigKeyToEntry() : *m_configKeyToEntry.get();
0245     }
0246 
0247 private:
0248     /**
0249      * parent config object, if any
0250      */
0251     const KateConfig *const m_parent = nullptr;
0252 
0253     /**
0254      * recursion depth
0255      */
0256     uint configSessionNumber = 0;
0257 
0258     /**
0259      * is a config session running
0260      */
0261     bool configIsRunning = false;
0262 
0263     /**
0264      * two cases:
0265      *   - we have m_parent == nullptr => this contains all known config entries
0266      *   - we have m_parent != nullptr => this contains all set config entries for this level of configuration
0267      *
0268      * uses a map ATM for deterministic iteration e.g. for read/writeConfig
0269      */
0270     std::map<int, ConfigEntry> m_configEntries;
0271 
0272     /**
0273      * All known config keys, filled only for the object with m_parent == nullptr
0274      */
0275     std::unique_ptr<QStringList> m_configKeys;
0276 
0277     /**
0278      * Hash of config keys => config entry, filled only for the object with m_parent == nullptr
0279      */
0280     std::unique_ptr<QHash<QString, const ConfigEntry *>> m_configKeyToEntry;
0281 };
0282 
0283 class KTEXTEDITOR_EXPORT KateGlobalConfig : public KateConfig
0284 {
0285 private:
0286     friend class KTextEditor::EditorPrivate;
0287 
0288     /**
0289      * only used in KTextEditor::EditorPrivate for the static global fallback !!!
0290      */
0291     KateGlobalConfig();
0292 
0293 public:
0294     static KateGlobalConfig *global()
0295     {
0296         return s_global;
0297     }
0298 
0299     /**
0300      * Known config entries
0301      */
0302     enum ConfigEntryTypes {
0303         /**
0304          * Encoding prober
0305          */
0306         EncodingProberType,
0307 
0308         /**
0309          * Fallback encoding
0310          */
0311         FallbackEncoding
0312     };
0313 
0314 public:
0315     /**
0316      * Read config from object
0317      */
0318     void readConfig(const KConfigGroup &config);
0319 
0320     /**
0321      * Write config to object
0322      */
0323     void writeConfig(KConfigGroup &config);
0324 
0325 protected:
0326     void updateConfig() override;
0327 
0328 public:
0329     KEncodingProber::ProberType proberType() const
0330     {
0331         return KEncodingProber::ProberType(value(EncodingProberType).toInt());
0332     }
0333 
0334     bool setProberType(KEncodingProber::ProberType type)
0335     {
0336         return setValue(EncodingProberType, type);
0337     }
0338 
0339     /**
0340      * Fallback codec.
0341      * Based on fallback encoding.
0342      * @return fallback codec
0343      */
0344     QTextCodec *fallbackCodec() const;
0345 
0346     QString fallbackEncoding() const
0347     {
0348         return value(FallbackEncoding).toString();
0349     }
0350 
0351     bool setFallbackEncoding(const QString &encoding)
0352     {
0353         return setValue(FallbackEncoding, encoding);
0354     }
0355 
0356 private:
0357     static KateGlobalConfig *s_global;
0358 };
0359 
0360 class KTEXTEDITOR_EXPORT KateDocumentConfig : public KateConfig
0361 {
0362 private:
0363     friend class KTextEditor::EditorPrivate;
0364 
0365     KTEXTEDITOR_NO_EXPORT
0366     KateDocumentConfig();
0367 
0368 public:
0369     /**
0370      * Construct a DocumentConfig
0371      */
0372     explicit KateDocumentConfig(KTextEditor::DocumentPrivate *doc);
0373 
0374     inline static KateDocumentConfig *global()
0375     {
0376         return s_global;
0377     }
0378 
0379     /**
0380      * Known config entries
0381      */
0382     enum ConfigEntryTypes {
0383         /**
0384          * Tabulator width
0385          */
0386         TabWidth,
0387 
0388         /**
0389          * Indentation width
0390          */
0391         IndentationWidth,
0392 
0393         /**
0394          * On-the-fly spellcheck enabled?
0395          */
0396         OnTheFlySpellCheck,
0397 
0398         /**
0399          * Indent pasted text?
0400          */
0401         IndentOnTextPaste,
0402 
0403         /**
0404          * Replace tabs with spaces?
0405          */
0406         ReplaceTabsWithSpaces,
0407 
0408         /**
0409          * Backup files for local files?
0410          */
0411         BackupOnSaveLocal,
0412 
0413         /**
0414          * Backup files for remote files?
0415          */
0416         BackupOnSaveRemote,
0417 
0418         /**
0419          * Prefix for backup files
0420          */
0421         BackupOnSavePrefix,
0422 
0423         /**
0424          * Suffix for backup files
0425          */
0426         BackupOnSaveSuffix,
0427 
0428         /**
0429          * Indentation mode, like "normal"
0430          */
0431         IndentationMode,
0432 
0433         /**
0434          * Tab handling, like indent, insert tab, smart
0435          */
0436         TabHandlingMode,
0437 
0438         /**
0439          * Static word wrap?
0440          */
0441         StaticWordWrap,
0442 
0443         /**
0444          * Static word wrap column
0445          */
0446         StaticWordWrapColumn,
0447 
0448         /**
0449          * PageUp/Down moves cursor?
0450          */
0451         PageUpDownMovesCursor,
0452 
0453         /**
0454          * Smart Home key?
0455          */
0456         SmartHome,
0457 
0458         /**
0459          * Show Tabs?
0460          */
0461         ShowTabs,
0462 
0463         /**
0464          * Indent on tab?
0465          */
0466         IndentOnTab,
0467 
0468         /**
0469          * Keep extra space?
0470          */
0471         KeepExtraSpaces,
0472 
0473         /**
0474          * Backspace key indents?
0475          */
0476         BackspaceIndents,
0477 
0478         /**
0479          * Show spaces mode like none, all, ...
0480          */
0481         ShowSpacesMode,
0482 
0483         /**
0484          * Trailing Marker Size
0485          */
0486         TrailingMarkerSize,
0487 
0488         /**
0489          * Remove spaces mode
0490          */
0491         RemoveSpacesMode,
0492 
0493         /**
0494          * Ensure newline at end of file
0495          */
0496         NewlineAtEOF,
0497 
0498         /**
0499          * Overwrite mode?
0500          */
0501         OverwriteMode,
0502 
0503         /**
0504          * Encoding
0505          */
0506         Encoding,
0507 
0508         /**
0509          * End of line mode: dos, mac, unix
0510          */
0511         EndOfLine,
0512 
0513         /**
0514          * Allow EOL detection
0515          */
0516         AllowEndOfLineDetection,
0517 
0518         /**
0519          * Use Byte Order Mark
0520          */
0521         ByteOrderMark,
0522 
0523         /**
0524          * Swap file mode
0525          */
0526         SwapFile,
0527 
0528         /**
0529          * Swap file directory
0530          */
0531         SwapFileDirectory,
0532 
0533         /**
0534          * Swap file sync interval
0535          */
0536         SwapFileSyncInterval,
0537 
0538         /**
0539          * Line length limit
0540          */
0541         LineLengthLimit,
0542 
0543         /**
0544          * Camel Cursor Movement?
0545          */
0546         CamelCursor,
0547 
0548         /**
0549          * Automatically detect file indentation
0550          */
0551         AutoDetectIndent,
0552 
0553         /**
0554          * Automatically save?
0555          */
0556         AutoSave,
0557         /**
0558          * Automatically save on focus lost
0559          */
0560         AutoSaveOnFocusOut,
0561         /**
0562          * Auto save interval
0563          */
0564         AutoSaveInteral,
0565 
0566         /**
0567          * Should we auto-reload if the old state is in version control?
0568          */
0569         AutoReloadIfStateIsInVersionControl
0570     };
0571 
0572 public:
0573     /**
0574      * Read config from object
0575      */
0576     void readConfig(const KConfigGroup &config);
0577 
0578     /**
0579      * Write config to object
0580      */
0581     void writeConfig(KConfigGroup &config);
0582 
0583 protected:
0584     void updateConfig() override;
0585 
0586 public:
0587     int tabWidth() const
0588     {
0589         return value(TabWidth).toInt();
0590     }
0591 
0592     void setTabWidth(int tabWidth)
0593     {
0594         setValue(TabWidth, QVariant(tabWidth));
0595     }
0596 
0597     int indentationWidth() const
0598     {
0599         return value(IndentationWidth).toInt();
0600     }
0601 
0602     void setIndentationWidth(int indentationWidth)
0603     {
0604         setValue(IndentationWidth, QVariant(indentationWidth));
0605     }
0606 
0607     bool onTheFlySpellCheck() const
0608     {
0609         return value(OnTheFlySpellCheck).toBool();
0610     }
0611 
0612     void setOnTheFlySpellCheck(bool on)
0613     {
0614         setValue(OnTheFlySpellCheck, QVariant(on));
0615     }
0616 
0617     bool indentPastedText() const
0618     {
0619         return value(IndentOnTextPaste).toBool();
0620     }
0621 
0622     void setIndentPastedText(bool on)
0623     {
0624         setValue(IndentOnTextPaste, QVariant(on));
0625     }
0626 
0627     bool replaceTabsDyn() const
0628     {
0629         return value(ReplaceTabsWithSpaces).toBool();
0630     }
0631 
0632     void setReplaceTabsDyn(bool on)
0633     {
0634         setValue(ReplaceTabsWithSpaces, QVariant(on));
0635     }
0636 
0637     bool backupOnSaveLocal() const
0638     {
0639         return value(BackupOnSaveLocal).toBool();
0640     }
0641 
0642     void setBackupOnSaveLocal(bool on)
0643     {
0644         setValue(BackupOnSaveLocal, QVariant(on));
0645     }
0646 
0647     bool backupOnSaveRemote() const
0648     {
0649         return value(BackupOnSaveRemote).toBool();
0650     }
0651 
0652     void setBackupOnSaveRemote(bool on)
0653     {
0654         setValue(BackupOnSaveRemote, QVariant(on));
0655     }
0656 
0657     QString backupPrefix() const
0658     {
0659         return value(BackupOnSavePrefix).toString();
0660     }
0661 
0662     void setBackupPrefix(const QString &prefix)
0663     {
0664         setValue(BackupOnSavePrefix, QVariant(prefix));
0665     }
0666 
0667     QString backupSuffix() const
0668     {
0669         return value(BackupOnSaveSuffix).toString();
0670     }
0671 
0672     void setBackupSuffix(const QString &suffix)
0673     {
0674         setValue(BackupOnSaveSuffix, QVariant(suffix));
0675     }
0676 
0677     QString indentationMode() const
0678     {
0679         return value(IndentationMode).toString();
0680     }
0681 
0682     void setIndentationMode(const QString &identationMode)
0683     {
0684         setValue(IndentationMode, identationMode);
0685     }
0686 
0687     enum TabHandling {
0688         tabInsertsTab = 0,
0689         tabIndents = 1,
0690         tabSmart = 2 //!< indents in leading space, otherwise inserts tab
0691     };
0692 
0693     enum WhitespaceRendering { None, Trailing, All };
0694 
0695     int tabHandling() const
0696     {
0697         return value(TabHandlingMode).toInt();
0698     }
0699 
0700     void setTabHandling(int tabHandling)
0701     {
0702         setValue(TabHandlingMode, tabHandling);
0703     }
0704 
0705     bool wordWrap() const
0706     {
0707         return value(StaticWordWrap).toBool();
0708     }
0709 
0710     void setWordWrap(bool on)
0711     {
0712         setValue(StaticWordWrap, on);
0713     }
0714 
0715     int wordWrapAt() const
0716     {
0717         return value(StaticWordWrapColumn).toInt();
0718     }
0719 
0720     void setWordWrapAt(int col)
0721     {
0722         setValue(StaticWordWrapColumn, col);
0723     }
0724 
0725     bool pageUpDownMovesCursor() const
0726     {
0727         return value(PageUpDownMovesCursor).toBool();
0728     }
0729 
0730     void setPageUpDownMovesCursor(bool on)
0731     {
0732         setValue(PageUpDownMovesCursor, on);
0733     }
0734 
0735     void setKeepExtraSpaces(bool on)
0736     {
0737         setValue(KeepExtraSpaces, on);
0738     }
0739 
0740     bool keepExtraSpaces() const
0741     {
0742         return value(KeepExtraSpaces).toBool();
0743     }
0744 
0745     void setBackspaceIndents(bool on)
0746     {
0747         setValue(BackspaceIndents, on);
0748     }
0749 
0750     bool backspaceIndents() const
0751     {
0752         return value(BackspaceIndents).toBool();
0753     }
0754 
0755     void setSmartHome(bool on)
0756     {
0757         setValue(SmartHome, on);
0758     }
0759 
0760     bool smartHome() const
0761     {
0762         return value(SmartHome).toBool();
0763     }
0764 
0765     void setShowTabs(bool on)
0766     {
0767         setValue(ShowTabs, on);
0768     }
0769 
0770     bool showTabs() const
0771     {
0772         return value(ShowTabs).toBool();
0773     }
0774 
0775     void setShowSpaces(WhitespaceRendering mode)
0776     {
0777         setValue(ShowSpacesMode, mode);
0778     }
0779 
0780     WhitespaceRendering showSpaces() const
0781     {
0782         return WhitespaceRendering(value(ShowSpacesMode).toInt());
0783     }
0784 
0785     void setMarkerSize(int markerSize)
0786     {
0787         setValue(TrailingMarkerSize, markerSize);
0788     }
0789 
0790     int markerSize() const
0791     {
0792         return value(TrailingMarkerSize).toInt();
0793     }
0794 
0795     /**
0796      * Remove trailing spaces on save.
0797      * triState = 0: never remove trailing spaces
0798      * triState = 1: remove trailing spaces of modified lines (line modification system)
0799      * triState = 2: remove trailing spaces in entire document
0800      */
0801     void setRemoveSpaces(int triState)
0802     {
0803         setValue(RemoveSpacesMode, triState);
0804     }
0805 
0806     int removeSpaces() const
0807     {
0808         return value(RemoveSpacesMode).toInt();
0809     }
0810 
0811     void setNewLineAtEof(bool on)
0812     {
0813         setValue(NewlineAtEOF, on);
0814     }
0815 
0816     bool newLineAtEof() const
0817     {
0818         return value(NewlineAtEOF).toBool();
0819     }
0820 
0821     void setOvr(bool on)
0822     {
0823         setValue(OverwriteMode, on);
0824     }
0825 
0826     bool ovr() const
0827     {
0828         return value(OverwriteMode).toBool();
0829     }
0830 
0831     void setTabIndents(bool on)
0832     {
0833         setValue(IndentOnTab, on);
0834     }
0835 
0836     bool tabIndentsEnabled() const
0837     {
0838         return value(IndentOnTab).toBool();
0839     }
0840 
0841     /**
0842      * Get current text codec.
0843      * Based on current set encoding
0844      * @return current text codec.
0845      */
0846     QTextCodec *codec() const;
0847 
0848     QString encoding() const
0849     {
0850         return value(Encoding).toString();
0851     }
0852 
0853     bool setEncoding(const QString &encoding)
0854     {
0855         return setValue(Encoding, encoding);
0856     }
0857 
0858     enum Eol { eolUnix = 0, eolDos = 1, eolMac = 2 };
0859 
0860     int eol() const
0861     {
0862         return value(EndOfLine).toInt();
0863     }
0864 
0865     /**
0866      * Get current end of line string.
0867      * Based on current set eol mode.
0868      * @return current end of line string
0869      */
0870     QString eolString() const;
0871 
0872     void setEol(int mode)
0873     {
0874         setValue(EndOfLine, mode);
0875     }
0876 
0877     bool bom() const
0878     {
0879         return value(ByteOrderMark).toBool();
0880     }
0881 
0882     void setBom(bool bom)
0883     {
0884         setValue(ByteOrderMark, bom);
0885     }
0886 
0887     bool allowEolDetection() const
0888     {
0889         return value(AllowEndOfLineDetection).toBool();
0890     }
0891 
0892     void setAllowEolDetection(bool on)
0893     {
0894         setValue(AllowEndOfLineDetection, on);
0895     }
0896 
0897     QString swapDirectory() const
0898     {
0899         return value(SwapFileDirectory).toString();
0900     }
0901 
0902     void setSwapDirectory(const QString &directory)
0903     {
0904         setValue(SwapFileDirectory, directory);
0905     }
0906 
0907     enum SwapFileMode { DisableSwapFile = 0, EnableSwapFile, SwapFilePresetDirectory };
0908 
0909     SwapFileMode swapFileMode() const
0910     {
0911         return SwapFileMode(value(SwapFile).toInt());
0912     }
0913 
0914     void setSwapFileMode(int mode)
0915     {
0916         setValue(SwapFile, mode);
0917     }
0918 
0919     int swapSyncInterval() const
0920     {
0921         return value(SwapFileSyncInterval).toInt();
0922     }
0923 
0924     void setSwapSyncInterval(int interval)
0925     {
0926         setValue(SwapFileSyncInterval, interval);
0927     }
0928 
0929     int lineLengthLimit() const
0930     {
0931         return value(LineLengthLimit).toInt();
0932     }
0933 
0934     void setLineLengthLimit(int limit)
0935     {
0936         setValue(LineLengthLimit, limit);
0937     }
0938 
0939     void setCamelCursor(bool on)
0940     {
0941         setValue(CamelCursor, on);
0942     }
0943 
0944     bool camelCursor() const
0945     {
0946         return value(CamelCursor).toBool();
0947     }
0948 
0949     void setAutoDetectIndent(bool on)
0950     {
0951         setValue(AutoDetectIndent, on);
0952     }
0953 
0954     bool autoDetectIndent() const
0955     {
0956         return value(AutoDetectIndent).toBool();
0957     }
0958 
0959     bool autoSave() const
0960     {
0961         return value(AutoSave).toBool();
0962     }
0963 
0964     bool autoSaveOnFocusOut() const
0965     {
0966         return value(AutoSaveOnFocusOut).toBool();
0967     }
0968 
0969     int autoSaveInterval() const
0970     {
0971         return value(AutoSaveInteral).toInt();
0972     }
0973 
0974 private:
0975     static KateDocumentConfig *s_global;
0976     KTextEditor::DocumentPrivate *m_doc = nullptr;
0977 };
0978 
0979 class KTEXTEDITOR_EXPORT KateViewConfig : public KateConfig
0980 {
0981 private:
0982     friend class KTextEditor::EditorPrivate;
0983 
0984     /**
0985      * only used in KTextEditor::EditorPrivate for the static global fallback !!!
0986      */
0987     KTEXTEDITOR_NO_EXPORT
0988     KateViewConfig();
0989 
0990 public:
0991     /**
0992      * Construct a ViewConfig
0993      */
0994     explicit KateViewConfig(KTextEditor::ViewPrivate *view);
0995 
0996     /**
0997      * Cu ViewConfig
0998      */
0999     ~KateViewConfig() override;
1000 
1001     inline static KateViewConfig *global()
1002     {
1003         return s_global;
1004     }
1005 
1006     /**
1007      * All known config keys
1008      * Keep them sorted alphabetically for our convenience.
1009      * Keep the same order when adding config entries with addConfigEntry() in
1010      * KateViewConfig::KateViewConfig() otherwise the code will assert.
1011      */
1012     enum ConfigEntryTypes {
1013         AllowMarkMenu,
1014         AutoBrackets,
1015         AutoCenterLines,
1016         AutomaticCompletionInvocation,
1017         AutomaticCompletionPreselectFirst,
1018         BackspaceRemoveComposedCharacters,
1019         BookmarkSorting,
1020         CharsToEncloseSelection,
1021         ClipboardHistoryEntries,
1022         DefaultMarkType,
1023         DynWordWrapAlignIndent,
1024         DynWordWrapIndicators,
1025         DynWrapAnywhere,
1026         DynWrapAtStaticMarker,
1027         DynamicWordWrap,
1028         FoldFirstLine,
1029         InputMode,
1030         KeywordCompletion,
1031         MaxHistorySize,
1032         MousePasteAtCursorPosition,
1033         PersistentSelection,
1034         ScrollBarMiniMapWidth,
1035         ScrollPastEnd,
1036         SearchFlags,
1037         TabCompletion,
1038         ShowBracketMatchPreview,
1039         ShowFoldingBar,
1040         ShowFoldingPreview,
1041         ShowIconBar,
1042         ShowLineCount,
1043         ShowLineModification,
1044         ShowLineNumbers,
1045         ShowScrollBarMarks,
1046         ShowScrollBarMiniMap,
1047         ShowScrollBarMiniMapAll,
1048         ShowScrollBarPreview,
1049         ShowScrollbars,
1050         ShowWordCount,
1051         TextDragAndDrop,
1052         SmartCopyCut,
1053         UserSetsOfCharsToEncloseSelection,
1054         ViInputModeStealKeys,
1055         ViRelativeLineNumbers,
1056         WordCompletion,
1057         WordCompletionMinimalWordLength,
1058         WordCompletionRemoveTail,
1059         ShowFocusFrame,
1060         ShowDocWithCompletion,
1061         MultiCursorModifier,
1062         ShowFoldingOnHoverOnly,
1063         ShowStatusbarLineColumn,
1064         ShowStatusbarDictionary,
1065         ShowStatusbarInputMode,
1066         ShowStatusbarHighlightingMode,
1067         ShowStatusbarTabSettings,
1068         ShowStatusbarFileEncoding,
1069         StatusbarLineColumnCompact,
1070         ShowStatusbarEOL,
1071     };
1072 
1073 public:
1074     /**
1075      * Read config from object
1076      */
1077     void readConfig(const KConfigGroup &config);
1078 
1079     /**
1080      * Write config to object
1081      */
1082     void writeConfig(KConfigGroup &config);
1083 
1084 protected:
1085     void updateConfig() override;
1086 
1087 public:
1088     bool dynWordWrap() const
1089     {
1090         return value(DynamicWordWrap).toBool();
1091     }
1092     void setDynWordWrap(bool on)
1093     {
1094         setValue(DynamicWordWrap, on);
1095     }
1096     bool dynWrapAnywhere() const
1097     {
1098         return value(DynWrapAnywhere).toBool();
1099     }
1100 
1101     bool dynWrapAtStaticMarker() const
1102     {
1103         return value(DynWrapAtStaticMarker).toBool();
1104     }
1105 
1106     int dynWordWrapIndicators() const
1107     {
1108         return value(DynWordWrapIndicators).toInt();
1109     }
1110 
1111     int dynWordWrapAlignIndent() const
1112     {
1113         return value(DynWordWrapAlignIndent).toInt();
1114     }
1115 
1116     bool lineNumbers() const
1117     {
1118         return value(ShowLineNumbers).toBool();
1119     }
1120 
1121     bool scrollBarMarks() const
1122     {
1123         return value(ShowScrollBarMarks).toBool();
1124     }
1125 
1126     bool scrollBarPreview() const
1127     {
1128         return value(ShowScrollBarPreview).toBool();
1129     }
1130 
1131     bool scrollBarMiniMap() const
1132     {
1133         return value(ShowScrollBarMiniMap).toBool();
1134     }
1135 
1136     bool scrollBarMiniMapAll() const
1137     {
1138         return value(ShowScrollBarMiniMapAll).toBool();
1139     }
1140 
1141     int scrollBarMiniMapWidth() const
1142     {
1143         return value(ScrollBarMiniMapWidth).toInt();
1144     }
1145 
1146     /* Whether to show scrollbars */
1147     enum ScrollbarMode { AlwaysOn = 0, ShowWhenNeeded, AlwaysOff };
1148 
1149     int showScrollbars() const
1150     {
1151         return value(ShowScrollbars).toInt();
1152     }
1153 
1154     bool showFocusFrame() const
1155     {
1156         return value(ShowFocusFrame).toBool();
1157     }
1158 
1159     bool showDocWithCompletion() const
1160     {
1161         return value(ShowDocWithCompletion).toBool();
1162     }
1163 
1164     Qt::KeyboardModifiers multiCursorModifiers() const
1165     {
1166         return static_cast<Qt::KeyboardModifiers>(value(MultiCursorModifier).toInt());
1167     }
1168 
1169     void setMultiCursorModifiers(Qt::KeyboardModifiers m)
1170     {
1171         setValue(MultiCursorModifier, (int)m);
1172     }
1173 
1174     bool iconBar() const
1175     {
1176         return value(ShowIconBar).toBool();
1177     }
1178 
1179     bool foldingBar() const
1180     {
1181         return value(ShowFoldingBar).toBool();
1182     }
1183 
1184     bool foldingPreview() const
1185     {
1186         return value(ShowFoldingPreview).toBool();
1187     }
1188 
1189     bool lineModification() const
1190     {
1191         return value(ShowLineModification).toBool();
1192     }
1193 
1194     int bookmarkSort() const
1195     {
1196         return value(BookmarkSorting).toInt();
1197     }
1198 
1199     int autoCenterLines() const
1200     {
1201         return value(AutoCenterLines).toInt();
1202     }
1203 
1204     enum SearchFlags {
1205         IncMatchCase = 1 << 0,
1206         IncHighlightAll = 1 << 1,
1207         IncFromCursor = 1 << 2,
1208         PowerMatchCase = 1 << 3,
1209         PowerHighlightAll = 1 << 4,
1210         PowerFromCursor = 1 << 5,
1211         // PowerSelectionOnly = 1 << 6, Better not save to file // Sebastian
1212         PowerModePlainText = 1 << 7,
1213         PowerModeWholeWords = 1 << 8,
1214         PowerModeEscapeSequences = 1 << 9,
1215         PowerModeRegularExpression = 1 << 10,
1216         PowerUsePlaceholders = 1 << 11
1217     };
1218 
1219     uint searchFlags() const
1220     {
1221         return value(SearchFlags).toUInt();
1222     }
1223     void setSearchFlags(uint flags)
1224     {
1225         setValue(SearchFlags, flags);
1226     }
1227 
1228     int maxHistorySize() const
1229     {
1230         return value(MaxHistorySize).toInt();
1231     }
1232 
1233     uint defaultMarkType() const
1234     {
1235         return value(DefaultMarkType).toUInt();
1236     }
1237 
1238     bool allowMarkMenu() const
1239     {
1240         return value(AllowMarkMenu).toBool();
1241     }
1242 
1243     bool persistentSelection() const
1244     {
1245         return value(PersistentSelection).toBool();
1246     }
1247 
1248     KTextEditor::View::InputMode inputMode() const
1249     {
1250         return static_cast<KTextEditor::View::InputMode>(value(InputMode).toUInt());
1251     }
1252 
1253     bool viInputModeStealKeys() const
1254     {
1255         return value(ViInputModeStealKeys).toBool();
1256     }
1257 
1258     bool viRelativeLineNumbers() const
1259     {
1260         return value(ViRelativeLineNumbers).toBool();
1261     }
1262 
1263     // Do we still need the enum and related functions below?
1264     enum TextToSearch { Nowhere = 0, SelectionOnly = 1, SelectionWord = 2, WordOnly = 3, WordSelection = 4 };
1265 
1266     bool automaticCompletionInvocation() const
1267     {
1268         return value(AutomaticCompletionInvocation).toBool();
1269     }
1270 
1271     bool automaticCompletionPreselectFirst() const
1272     {
1273         return value(AutomaticCompletionPreselectFirst).toBool();
1274     }
1275 
1276     bool tabCompletion() const
1277     {
1278         return value(TabCompletion).toBool();
1279     }
1280 
1281     bool wordCompletion() const
1282     {
1283         return value(WordCompletion).toBool();
1284     }
1285 
1286     bool keywordCompletion() const
1287     {
1288         return value(KeywordCompletion).toBool();
1289     }
1290 
1291     int wordCompletionMinimalWordLength() const
1292     {
1293         return value(WordCompletionMinimalWordLength).toInt();
1294     }
1295 
1296     bool wordCompletionRemoveTail() const
1297     {
1298         return value(WordCompletionRemoveTail).toBool();
1299     }
1300 
1301     bool textDragAndDrop() const
1302     {
1303         return value(TextDragAndDrop).toBool();
1304     }
1305 
1306     bool smartCopyCut() const
1307     {
1308         return value(SmartCopyCut).toBool();
1309     }
1310 
1311     bool mousePasteAtCursorPosition() const
1312     {
1313         return value(MousePasteAtCursorPosition).toBool();
1314     }
1315 
1316     int clipboardHistoryEntries() const
1317     {
1318         return value(ClipboardHistoryEntries).toInt();
1319     }
1320 
1321     bool scrollPastEnd() const
1322     {
1323         return value(ScrollPastEnd).toBool();
1324     }
1325 
1326     bool foldFirstLine() const
1327     {
1328         return value(FoldFirstLine).toBool();
1329     }
1330 
1331     bool showWordCount() const
1332     {
1333         return value(ShowWordCount).toBool();
1334     }
1335     void setShowWordCount(bool on)
1336     {
1337         setValue(ShowWordCount, on);
1338     }
1339 
1340     bool showLineCount() const
1341     {
1342         return value(ShowLineCount).toBool();
1343     }
1344 
1345     void setShowLineCount(bool on)
1346     {
1347         setValue(ShowLineCount, on);
1348     }
1349 
1350     bool autoBrackets() const
1351     {
1352         return value(AutoBrackets).toBool();
1353     }
1354 
1355     bool encloseSelectionInChars() const
1356     {
1357         return !value(CharsToEncloseSelection).toString().isEmpty();
1358     }
1359 
1360     QString charsToEncloseSelection() const
1361     {
1362         return value(CharsToEncloseSelection).toString();
1363     }
1364 
1365     bool backspaceRemoveComposed() const
1366     {
1367         return value(BackspaceRemoveComposedCharacters).toBool();
1368     }
1369 
1370     bool showFoldingOnHoverOnly() const
1371     {
1372         return value(ShowFoldingOnHoverOnly).toBool();
1373     }
1374 
1375 private:
1376     static KateViewConfig *s_global;
1377     KTextEditor::ViewPrivate *m_view = nullptr;
1378 };
1379 
1380 class KTEXTEDITOR_EXPORT KateRendererConfig : public KateConfig
1381 {
1382 private:
1383     friend class KTextEditor::EditorPrivate;
1384 
1385     /**
1386      * only used in KTextEditor::EditorPrivate for the static global fallback !!!
1387      */
1388     KTEXTEDITOR_NO_EXPORT
1389     KateRendererConfig();
1390 
1391 public:
1392     /**
1393      * Construct a RendererConfig
1394      */
1395     explicit KateRendererConfig(KateRenderer *renderer);
1396 
1397     /**
1398      * Cu RendererConfig
1399      */
1400     ~KateRendererConfig() override;
1401 
1402     inline static KateRendererConfig *global()
1403     {
1404         return s_global;
1405     }
1406 
1407     /**
1408      * All known config keys
1409      * Keep them sorted alphabetic for our convenience
1410      */
1411     enum ConfigEntryTypes {
1412         /**
1413          * auto-select the color theme based on application palette
1414          */
1415         AutoColorThemeSelection
1416     };
1417 
1418 public:
1419     /**
1420      * Read config from object
1421      */
1422     void readConfig(const KConfigGroup &config);
1423 
1424     /**
1425      * Write config to object
1426      */
1427     void writeConfig(KConfigGroup &config);
1428 
1429 protected:
1430     void updateConfig() override;
1431 
1432 public:
1433     const QString &schema() const;
1434     void setSchema(QString schema);
1435 
1436     /**
1437      * Reload the schema from the schema manager.
1438      * For the global instance, have all other instances reload.
1439      * Used by the schema config page to apply changes.
1440      */
1441     void reloadSchema();
1442 
1443     /**
1444      * Base font to use for the views and co.
1445      * Will be adjusted there to avoid rendering artifacts for HiDPI stuff.
1446      * @return base font to use
1447      */
1448     const QFont &baseFont() const;
1449 
1450     void setFont(const QFont &font);
1451 
1452     bool wordWrapMarker() const;
1453     void setWordWrapMarker(bool on);
1454 
1455     const QColor &backgroundColor() const;
1456     void setBackgroundColor(const QColor &col);
1457 
1458     const QColor &selectionColor() const;
1459     void setSelectionColor(const QColor &col);
1460 
1461     const QColor &highlightedLineColor() const;
1462     void setHighlightedLineColor(const QColor &col);
1463 
1464     const QColor &lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type = KTextEditor::MarkInterface::markType01) const; // markType01 == Bookmark
1465 
1466     const QColor &highlightedBracketColor() const;
1467     void setHighlightedBracketColor(const QColor &col);
1468 
1469     const QColor &wordWrapMarkerColor() const;
1470     void setWordWrapMarkerColor(const QColor &col);
1471 
1472     const QColor &tabMarkerColor() const;
1473     void setTabMarkerColor(const QColor &col);
1474 
1475     const QColor &indentationLineColor() const;
1476     void setIndentationLineColor(const QColor &col);
1477 
1478     const QColor &iconBarColor() const;
1479     void setIconBarColor(const QColor &col);
1480 
1481     const QColor &foldingColor() const;
1482     void setFoldingColor(const QColor &col);
1483 
1484     // the line number color is used for the line numbers on the left bar
1485     const QColor &lineNumberColor() const;
1486     void setLineNumberColor(const QColor &col);
1487     const QColor &currentLineNumberColor() const;
1488     void setCurrentLineNumberColor(const QColor &col);
1489 
1490     // the color of the separator between line numbers and icon bar
1491     const QColor &separatorColor() const;
1492     void setSeparatorColor(const QColor &col);
1493 
1494     const QColor &spellingMistakeLineColor() const;
1495     void setSpellingMistakeLineColor(const QColor &col);
1496 
1497     bool showIndentationLines() const;
1498     void setShowIndentationLines(bool on);
1499 
1500     bool showWholeBracketExpression() const;
1501     void setShowWholeBracketExpression(bool on);
1502 
1503     static bool animateBracketMatching();
1504     void setAnimateBracketMatching(bool on);
1505 
1506     const QColor &templateBackgroundColor() const;
1507     const QColor &templateEditablePlaceholderColor() const;
1508     const QColor &templateFocusedEditablePlaceholderColor() const;
1509     const QColor &templateNotEditablePlaceholderColor() const;
1510 
1511     const QColor &modifiedLineColor() const;
1512     void setModifiedLineColor(const QColor &col);
1513 
1514     const QColor &savedLineColor() const;
1515     void setSavedLineColor(const QColor &col);
1516 
1517     const QColor &searchHighlightColor() const;
1518     void setSearchHighlightColor(const QColor &col);
1519 
1520     const QColor &replaceHighlightColor() const;
1521     void setReplaceHighlightColor(const QColor &col);
1522 
1523     void setLineHeightMultiplier(qreal value);
1524 
1525     qreal lineHeightMultiplier() const
1526     {
1527         return s_global->m_lineHeightMultiplier;
1528     }
1529 
1530 private:
1531     /**
1532      * Read the schema properties from the config file.
1533      */
1534     KTEXTEDITOR_NO_EXPORT
1535     void setSchemaInternal(const QString &schema);
1536 
1537     QString m_schema;
1538     QFont m_font;
1539     QColor m_backgroundColor;
1540     QColor m_selectionColor;
1541     QColor m_highlightedLineColor;
1542     QColor m_highlightedBracketColor;
1543     QColor m_wordWrapMarkerColor;
1544     QColor m_tabMarkerColor;
1545     QColor m_indentationLineColor;
1546     QColor m_iconBarColor;
1547     QColor m_foldingColor;
1548     QColor m_lineNumberColor;
1549     QColor m_currentLineNumberColor;
1550     QColor m_separatorColor;
1551     QColor m_spellingMistakeLineColor;
1552     QVector<QColor> m_lineMarkerColor;
1553 
1554     QColor m_templateBackgroundColor;
1555     QColor m_templateEditablePlaceholderColor;
1556     QColor m_templateFocusedEditablePlaceholderColor;
1557     QColor m_templateNotEditablePlaceholderColor;
1558 
1559     QColor m_modifiedLineColor;
1560     QColor m_savedLineColor;
1561     QColor m_searchHighlightColor;
1562     QColor m_replaceHighlightColor;
1563 
1564     qreal m_lineHeightMultiplier = 1.0;
1565 
1566     bool m_wordWrapMarker = false;
1567     bool m_showIndentationLines = false;
1568     bool m_showWholeBracketExpression = false;
1569     bool m_animateBracketMatching = false;
1570 
1571     bool m_schemaSet : 1;
1572     bool m_fontSet : 1;
1573     bool m_wordWrapMarkerSet : 1;
1574     bool m_showIndentationLinesSet : 1;
1575     bool m_showWholeBracketExpressionSet : 1;
1576     bool m_backgroundColorSet : 1;
1577     bool m_selectionColorSet : 1;
1578     bool m_highlightedLineColorSet : 1;
1579     bool m_highlightedBracketColorSet : 1;
1580     bool m_wordWrapMarkerColorSet : 1;
1581     bool m_tabMarkerColorSet : 1;
1582     bool m_indentationLineColorSet : 1;
1583     bool m_iconBarColorSet : 1;
1584     bool m_foldingColorSet : 1;
1585     bool m_lineNumberColorSet : 1;
1586     bool m_currentLineNumberColorSet : 1;
1587     bool m_separatorColorSet : 1;
1588     bool m_spellingMistakeLineColorSet : 1;
1589     bool m_templateColorsSet : 1;
1590     bool m_modifiedLineColorSet : 1;
1591     bool m_savedLineColorSet : 1;
1592     bool m_searchHighlightColorSet : 1;
1593     bool m_replaceHighlightColorSet : 1;
1594     QBitArray m_lineMarkerColorSet;
1595 
1596 private:
1597     static KateRendererConfig *s_global;
1598     KateRenderer *m_renderer = nullptr;
1599 };
1600 
1601 #endif