void ColoursAndFontsManager::Load()
{
    if(m_initialized) return;

    m_lexersMap.clear();
    m_initialized = true;

// Always load first the installation lexers
#ifdef USE_POSIX_LAYOUT
    wxFileName defaultLexersPath(clStandardPaths::Get().GetDataDir() + wxT(INSTALL_DIR), "");
#else
    wxFileName defaultLexersPath(clStandardPaths::Get().GetDataDir(), "");
#endif
    defaultLexersPath.AppendDir("lexers");
    LoadNewXmls(defaultLexersPath.GetPath());

    //+++----------------------------------
    // Now handle user lexers
    //+++----------------------------------

    // Check to see if we have the new configuration files format (we break them from the unified XML file)
    // The naming convention used is:
    // lexer_<language>_<theme-name>.xml
    wxFileName cppLexerDefault(clStandardPaths::Get().GetUserDataDir(), "lexers_default.xml");
    cppLexerDefault.AppendDir("lexers");

    if(cppLexerDefault.FileExists()) {
        // We found the old lexer style here (single XML file for all the lexers)
        // Merge them with the installation lexers
        CL_DEBUG("Migrating old lexers XML files ...");
        LoadOldXmls(cppLexerDefault.GetPath());

    } else {
        // search for the new format in the user data folder
        cppLexerDefault.SetName("lexer_c++_default");
        if(cppLexerDefault.FileExists()) {
            CL_DEBUG("Using user lexer XML files from %s ...", cppLexerDefault.GetPath());
            // this function loads and delete the old xml files so they won't be located
            // next time we search for them
            LoadNewXmls(cppLexerDefault.GetPath());
        }
    }

    // Load the global settings
    if(GetConfigFile().FileExists()) {
        JSONRoot root(GetConfigFile());
        if(root.isOk()) {
            m_globalBgColour = root.toElement().namedObject("m_globalBgColour").toColour(m_globalBgColour);
            m_globalFgColour = root.toElement().namedObject("m_globalFgColour").toColour(m_globalFgColour);
        }
    }
}
void ColoursAndFontsManager::OnLexerFilesLoaded(const std::vector<wxXmlDocument*>& userLexers)
{
    // User lexers
    wxFileName fnUserLexers(clStandardPaths::Get().GetUserDataDir(), "lexers.json");
    fnUserLexers.AppendDir("lexers");

// Default installation lexers
#ifdef USE_POSIX_LAYOUT
    wxFileName defaultLexersFileName(clStandardPaths::Get().GetDataDir() + wxT(INSTALL_DIR), "");
#else
    wxFileName defaultLexersFileName(clStandardPaths::Get().GetDataDir(), "");
#endif
    defaultLexersFileName.AppendDir("lexers");
    defaultLexersFileName.SetFullName("lexers.json");
    
    wxString str_defaultLexersFileName = defaultLexersFileName.GetFullPath();
    wxUnusedVar(str_defaultLexersFileName);
    
    m_allLexers.clear();
    m_lexersMap.clear();

    if(!fnUserLexers.FileExists()) {
        // Load default settings
        LoadJSON(defaultLexersFileName);

        // Use old XML files
        LoadOldXmls(userLexers);

        // Call save to create an initial user settings
        Save();

    } else {
        // Load the user settings
        LoadJSON(fnUserLexers);
    }
    // Update lexers versions
    clConfig::Get().Write(LEXERS_VERSION_STRING, LEXERS_VERSION);
}