File: ThemeImporterBase.hpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (228 lines) | stat: -rw-r--r-- 8,472 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright            : (C) 2015 Eran Ifrah
// File name            : ThemeImporterBase.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#ifndef ECLIPSETHEMEIMPORTERBASE_H
#define ECLIPSETHEMEIMPORTERBASE_H

#include "JSON.h"
#include "codelite_exports.h"
#include "lexer_configuration.h"
#include "macros.h"
#include "smart_ptr.h"

#include <list>
#include <unordered_map>
#include <wx/filename.h>
#include <wx/string.h>
#include <wx/xml/xml.h>

class WXDLLIMPEXP_SDK ThemeImporterBase
{
public:
    struct Property {
        wxString fg_colour;
        wxString bg_colour;
        bool isBold = false;
        bool isItalic = false;
    };

    struct EclipseProperty {
        wxString color;
        bool isBold = false;
        bool isItalic = false;
    };

    typedef SmartPtr<ThemeImporterBase> Ptr_t;
    typedef std::list<ThemeImporterBase::Ptr_t> List_t;

protected:
    wxString m_keywords0;
    wxString m_keywords1;
    wxString m_keywords2;
    wxString m_keywords3;
    wxString m_keywords4;
    wxString m_keywords5;
    wxString m_fileExtensions;
    Property m_editor;
    Property m_lineNumber;
    Property m_lineNumberActive;
    Property m_selection;
    Property m_caret;
    Property m_singleLineComment;
    Property m_multiLineComment;
    Property m_number;
    Property m_string;
    Property m_oper;
    Property m_keyword;
    Property m_klass;
    Property m_variable;
    Property m_javadoc;
    Property m_javadocKeyword;
    Property m_function;
    Property m_field;
    Property m_enum;
    wxString m_langName;
    wxString m_themeName;
    bool m_isDarkTheme = false;
    std::unordered_map<wxString, EclipseProperty> m_xmlProperties;

private:
    // the index for special word sets
    WordSetIndex m_classesIndex;
    WordSetIndex m_functionsIndex;
    WordSetIndex m_localsIndex;
    WordSetIndex m_othersIndex;

protected:
    void AddProperty(LexerConf::Ptr_t lexer, const wxString& id, const wxString& name, const wxString& colour,
                     const wxString& bgColour, bool bold = false, bool italic = false, bool isEOLFilled = false);

    void AddPropertySubstyle(LexerConf::Ptr_t lexer, int id, const wxString& name, const Property& prop);

    void AddProperty(LexerConf::Ptr_t lexer, const wxString& id, const wxString& name, const Property& prop)
    {
        AddProperty(lexer, id, name, prop.fg_colour, prop.bg_colour.empty() ? m_editor.bg_colour : prop.bg_colour,
                    prop.isBold, prop.isItalic, false);
    }

    void AddProperty(LexerConf::Ptr_t lexer, int id, const wxString& name, const Property& prop)
    {
        AddProperty(lexer, wxString() << id, name, prop);
    }

    void AddProperty(LexerConf::Ptr_t lexer, int id, const wxString& name, const wxString& colour,
                     const wxString& bgColour, bool bold = false, bool italic = false, bool isEOLFilled = false)
    {
        AddProperty(lexer, wxString() << id, name, colour, bgColour, bold, italic, isEOLFilled);
    }

    void AddBaseProperties(LexerConf::Ptr_t lexer, const wxString& lang, const wxString& id);

    void AddCommonProperties(LexerConf::Ptr_t lexer);
    void DoSetKeywords(wxString& wordset, const wxString& words);
    LexerConf::Ptr_t ImportEclipseXML(const wxFileName& theme_file, const wxString& langName, int langId);
    LexerConf::Ptr_t ImportVSCodeJSON(const wxFileName& theme_file, const wxString& langName, int langId);
    void GetVSCodeColour(const wxStringMap_t& scopes_to_colours_map, const std::vector<wxString>& scopes,
                         Property& colour);
    void GetEditorVSCodeColour(JSONItem& colours, const wxString& bg_prop, const wxString& fg_prop, Property& colour);

private:
    /**
     * @brief read the background / foreground properties from the XML into `prop`
     * if a property is not found, we use the `m_editor` proprties
     */
    void GetEclipseXmlProperty(const wxString& bg_prop, const wxString& fg_prop,
                               ThemeImporterBase::Property& prop) const;

public:
    const wxString& GetLangName() const { return m_langName; }
    void SetLangName(const wxString& langName) { this->m_langName = langName; }

    // Setters/Getters
    void SetFileExtensions(const wxString& fileExtensions) { this->m_fileExtensions = fileExtensions; }
    const wxString& GetFileExtensions() const { return m_fileExtensions; }
    void SetKeywords0(const wxString& keywords0) { DoSetKeywords(this->m_keywords0, keywords0); }
    void SetKeywords1(const wxString& keywords1) { DoSetKeywords(this->m_keywords1, keywords1); }
    void SetKeywords2(const wxString& keywords2) { DoSetKeywords(this->m_keywords2, keywords2); }
    void SetKeywords3(const wxString& keywords3) { DoSetKeywords(this->m_keywords3, keywords3); }
    void SetKeywords4(const wxString& keywords4) { DoSetKeywords(this->m_keywords4, keywords4); }
    void SetKeywords5(const wxString& keywords4) { DoSetKeywords(this->m_keywords5, keywords4); }

    const wxString& GetKeywords0() const { return m_keywords0; }
    const wxString& GetKeywords1() const { return m_keywords1; }
    const wxString& GetKeywords2() const { return m_keywords2; }
    const wxString& GetKeywords3() const { return m_keywords3; }
    const wxString& GetKeywords4() const { return m_keywords4; }
    const wxString& GetKeywords5() const { return m_keywords5; }

    const WordSetIndex& GetClassWordSetIndex() const { return m_classesIndex; }
    const WordSetIndex& GetLocalsSetIndex() const { return m_localsIndex; }
    const WordSetIndex& GetFunctionWordSetIndex() const { return m_functionsIndex; }
    const WordSetIndex& GetOthersWordSetIndex() const { return m_othersIndex; }

    void SetClassWordSetIndex(int index, bool is_substyle = false)
    {
        m_classesIndex.is_substyle = is_substyle;
        m_classesIndex.index = index;
    }

    void SetLocalsWordSetIndex(int index, bool is_substyle = false)
    {
        m_localsIndex.is_substyle = is_substyle;
        m_localsIndex.index = index;
    }

    void SetFunctionsWordSetIndex(int index, bool is_substyle = false)
    {
        m_functionsIndex.is_substyle = is_substyle;
        m_functionsIndex.index = index;
    }

    void SetOthersWordSetIndex(int index, bool is_substyle = false)
    {
        m_othersIndex.is_substyle = is_substyle;
        m_othersIndex.index = index;
    }

public:
    ThemeImporterBase();
    virtual ~ThemeImporterBase();
    /**
     * @brief intiailise the import by reading base parts of the lexer
     */
    LexerConf::Ptr_t InitializeImport(const wxFileName& theme_file, const wxString& langName, int langId);

    /**
     * @brief Finalize the import by adding the common lexer part (such as the fold margin, text selection etc)
     * and saving it the file system
     */
    void FinalizeImport(LexerConf::Ptr_t lexer);

    /**
     * @brief return true if the loaded theme is dark or bright
     */
    bool IsDarkTheme() const;

    /**
     * @brief return the theme name
     */
    wxString GetName() const;

    /**
     * @brief get the lexer output file (name and extension only)
     * @param language
     * @return
     */
    wxString GetOutputFile(const wxString& language) const;

    /**
     * @brief import an eclipse XML colour theme
     * @param theme_file
     * @param codeliteXml [output] the output file name
     */
    virtual LexerConf::Ptr_t Import(const wxFileName& theme_file) = 0;
};

#endif // ECLIPSETHEMEIMPORTERBASE_H