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

0001 /*
0002     SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KATE_MODEMANAGER_H
0008 #define KATE_MODEMANAGER_H
0009 
0010 #include "ktexteditor_export.h"
0011 
0012 #include <QHash>
0013 #include <QPointer>
0014 #include <QStringList>
0015 
0016 #include <KLocalizedString>
0017 
0018 namespace KTextEditor
0019 {
0020 class Document;
0021 }
0022 
0023 class KateFileType
0024 {
0025 public:
0026     QString name;
0027     QString section;
0028     QStringList wildcards;
0029     QStringList mimetypes;
0030     int priority = 0;
0031     QString varLine;
0032     QString hl;
0033     bool hlGenerated = false;
0034     QString version;
0035     QString indenter;
0036 
0037     QString translatedName;
0038     QString translatedSection;
0039 
0040     QString nameTranslated() const
0041     {
0042         return translatedName.isEmpty() ? name : translatedName;
0043     }
0044 
0045     QString sectionTranslated() const
0046     {
0047         return translatedSection.isEmpty() ? section : translatedSection;
0048     }
0049 
0050     KateFileType()
0051 
0052     {
0053     }
0054 };
0055 
0056 class KateModeManager
0057 {
0058 public:
0059     KateModeManager();
0060     ~KateModeManager();
0061 
0062     KateModeManager(const KateModeManager &) = delete;
0063     KateModeManager &operator=(const KateModeManager &) = delete;
0064 
0065     /**
0066      * File Type Config changed, update all docs (which will take care of views/renderers)
0067      */
0068     void update();
0069 
0070     void save(const QList<KateFileType *> &v);
0071 
0072     /**
0073      * @return the right KateFileType name for the given document or an empty string if none found
0074      */
0075     QString fileType(KTextEditor::Document *doc, const QString &fileToReadFrom);
0076 
0077     /**
0078      * Don't store the pointer somewhere longer times, won't be valid after the next update()
0079      */
0080     const KateFileType &fileType(const QString &name) const;
0081 
0082     /**
0083      * Don't modify
0084      */
0085     const QList<KateFileType *> &list() const
0086     {
0087         return m_types;
0088     }
0089 
0090 private:
0091     friend class KateModeManagerTest;
0092     friend class KateModeManagerBenchmark;
0093 
0094     KTEXTEDITOR_EXPORT QString wildcardsFind(const QString &fileName) const; // exported for testing
0095     KTEXTEDITOR_EXPORT QString mimeTypesFind(const QString &mimeTypeName) const; // exported for testing
0096 
0097     QList<KateFileType *> m_types;
0098     QHash<QString, KateFileType *> m_name2Type;
0099 };
0100 
0101 #endif