LexerConf::Ptr_t ColoursAndFontsManager::DoAddLexer(JSONElement json) { LexerConf::Ptr_t lexer(new LexerConf()); lexer->FromJSON(json); wxString lexerName = lexer->GetName().Lower(); if(lexerName.IsEmpty()) return NULL; // ensure that the theme name is capitalized - this helps // when displaying the content in a wxListBox sorted wxString themeName = lexer->GetThemeName(); themeName = themeName.Mid(0, 1).Capitalize() + themeName.Mid(1); lexer->SetThemeName(themeName); CL_DEBUG("Loading lexer: %s [%s]", lexerName, lexer->GetName()); if(lexer->GetName() == "c++" && !lexer->GetKeyWords(0).Contains("final")) { lexer->SetKeyWords(lexer->GetKeyWords(0) + " final", 0); } // Add Arduino sketches files as C++ (*.ino) if(lexer->GetName() == "c++" && !lexer->GetFileSpec().Contains(".ino")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.ino"); } // Hack: fix Java lexer which is using the same // file extensions as C++... if(lexer->GetName() == "java" && lexer->GetFileSpec().Contains(".cpp")) { lexer->SetFileSpec("*.java"); } // Append *.sqlite to the SQL lexer if missing if(lexer->GetName() == "sql" && !lexer->GetFileSpec().Contains(".sqlite")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.sqlite"); } // Hack2: since we now provide our own PHP and javaScript lexer, remove the PHP/JS extensions from // the HTML lexer if(lexer->GetName() == "html" && (lexer->GetFileSpec().Contains(".php") || lexer->GetFileSpec().Contains("*.js"))) { lexer->SetFileSpec("*.htm;*.html;*.xhtml"); } // Hack3: all the HTML support to PHP which have much more colour themes if(lexer->GetName() == "html" && lexer->GetFileSpec().Contains(".html")) { lexer->SetFileSpec("*.vbs;*.vbe;*.wsf;*.wsc;*.asp;*.aspx"); } // Hack4: all the HTML support to PHP which have much more colour themes if(lexer->GetName() == "javascript" && !lexer->GetFileSpec().Contains(".qml")) { lexer->SetFileSpec("*.js;*.javascript;*.qml;*.json"); } // Hack5: all the remove *.scss from the css lexer (it now has its own lexer) if(lexer->GetName() == "css" && lexer->GetFileSpec().Contains(".scss")) { lexer->SetFileSpec("*.css"); } // Add *.less file extension to the css lexer if(lexer->GetName() == "css" && !lexer->GetFileSpec().Contains(".less")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.less"); } if(lexer->GetName() == "php" && !lexer->GetFileSpec().Contains(".html")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.html;*.htm;*.xhtml"); } if(lexer->GetName() == "php" && !lexer->GetKeyWords(4).Contains("<?php")) { lexer->SetKeyWords(lexer->GetKeyWords(4) + " <?php <? ", 4); } if(lexer->GetName() == "php" && !lexer->GetFileSpec().Contains(".php5")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.php5"); } if(lexer->GetName() == "php" && !lexer->GetFileSpec().Contains(".ctp")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.ctp"); } // Add wxcp file extension to the JavaScript lexer if(lexer->GetName() == "javascript" && !lexer->GetFileSpec().Contains(".wxcp")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.wxcp"); } // Upgrade the lexer colours UpdateLexerColours(lexer, false); if(m_lexersMap.count(lexerName) == 0) { m_lexersMap.insert(std::make_pair(lexerName, ColoursAndFontsManager::Vec_t())); } ColoursAndFontsManager::Vec_t& vec = m_lexersMap.find(lexerName)->second; // Locate an instance with this name and theme in // both the m_alllexers and vector for this lexer // name ColoursAndFontsManager::Vec_t::iterator iter = std::find_if(vec.begin(), vec.end(), LexerConf::FindByNameAndTheme(lexer->GetName(), lexer->GetThemeName())); if(iter != vec.end()) { vec.erase(iter); } iter = std::find_if( m_allLexers.begin(), m_allLexers.end(), LexerConf::FindByNameAndTheme(lexer->GetName(), lexer->GetThemeName())); if(iter != m_allLexers.end()) { m_allLexers.erase(iter); } vec.push_back(lexer); m_allLexers.push_back(lexer); return lexer; }
LexerConf::Ptr_t ColoursAndFontsManager::DoAddLexer(wxXmlNode* node) { wxString lexerName = XmlUtils::ReadString(node, "Name"); lexerName.MakeLower(); if(lexerName.IsEmpty()) return NULL; LexerConf::Ptr_t lexer(new LexerConf); lexer->FromXml(node); // ensure that the theme name is capitalized - this helps // when displaying the content in a wxListBox sorted wxString themeName = lexer->GetThemeName(); themeName = themeName.Mid(0, 1).Capitalize() + themeName.Mid(1); lexer->SetThemeName(themeName); // Hack: fix Java lexer which is using the same // file extensions as C++... if(lexer->GetName() == "java" && lexer->GetFileSpec().Contains(".cpp")) { lexer->SetFileSpec("*.java"); } // Hack2: since we now provide our own PHP and javaScript lexer, remove the PHP/JS extensions from // the HTML lexer if(lexer->GetName() == "html" && (lexer->GetFileSpec().Contains(".php") || lexer->GetFileSpec().Contains("*.js"))) { lexer->SetFileSpec("*.htm;*.html;*.xhtml"); } // Hack3: all the HTML support to PHP which have much more colour themes if(lexer->GetName() == "html" && lexer->GetFileSpec().Contains(".html")) { lexer->SetFileSpec("*.vbs;*.vbe;*.wsf;*.wsc;*.asp;*.aspx"); } // Hack4: all the HTML support to PHP which have much more colour themes if(lexer->GetName() == "javascript" && !lexer->GetFileSpec().Contains(".qml")) { lexer->SetFileSpec("*.js;*.javascript;*.qml;*.json"); } if(lexer->GetName() == "php" && !lexer->GetFileSpec().Contains(".html")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.html;*.htm;*.xhtml"); } // Add wxcp file extension to the JavaScript lexer if(lexer->GetName() == "javascript" && !lexer->GetFileSpec().Contains(".wxcp")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.wxcp"); } // Add *.scss file extension to the css lexer if(lexer->GetName() == "css" && !lexer->GetFileSpec().Contains(".scss")) { lexer->SetFileSpec(lexer->GetFileSpec() + ";*.scss"); } // Upgrade the lexer colours UpdateLexerColours(lexer, false); if(m_lexersMap.count(lexerName) == 0) { m_lexersMap.insert(std::make_pair(lexerName, ColoursAndFontsManager::Vec_t())); } ColoursAndFontsManager::Vec_t& vec = m_lexersMap.find(lexerName)->second; // Locate an instance with this name and theme in // both the m_alllexers and vector for this lexer // name ColoursAndFontsManager::Vec_t::iterator iter = std::find_if(vec.begin(), vec.end(), LexerConf::FindByNameAndTheme(lexer->GetName(), lexer->GetThemeName())); if(iter != vec.end()) { vec.erase(iter); } iter = std::find_if( m_allLexers.begin(), m_allLexers.end(), LexerConf::FindByNameAndTheme(lexer->GetName(), lexer->GetThemeName())); if(iter != m_allLexers.end()) { m_allLexers.erase(iter); } vec.push_back(lexer); m_allLexers.push_back(lexer); return lexer; }