Пример #1
0
void CodeEdit::UncommentSelection()
{

    if (GetLexer() == wxSTC_LEX_LUA)
    {
        UncommentSelection("--");
    }

}
Пример #2
0
void ColoursAndFontsManager::SetActiveTheme(const wxString& lexerName, const wxString& themeName)
{
    wxArrayString themes = GetAvailableThemesForLexer(lexerName);
    for(size_t i = 0; i < themes.GetCount(); ++i) {
        LexerConf::Ptr_t lexer = GetLexer(lexerName, themes.Item(i));
        if(lexer && lexer->GetName() == lexerName) {
            lexer->SetIsActive(lexer->GetThemeName() == themeName);
        }
    }
}
Пример #3
0
LexerConf::Ptr_t
ColoursAndFontsManager::CopyTheme(const wxString& lexerName, const wxString& themeName, const wxString& sourceTheme)
{
    LexerConf::Ptr_t sourceLexer = GetLexer(lexerName, sourceTheme);
    CHECK_PTR_RET_NULL(sourceLexer);

    JSONElement json = sourceLexer->ToJSON();
    LexerConf::Ptr_t newLexer(new LexerConf());
    newLexer->FromJSON(json);

    // Update the theme name
    newLexer->SetThemeName(themeName);

    // Add it
    return DoAddLexer(newLexer->ToJSON());
}
Пример #4
0
LexerConf::Ptr_t
ColoursAndFontsManager::CopyTheme(const wxString& lexerName, const wxString& themeName, const wxString& sourceTheme)
{
    LexerConf::Ptr_t sourceLexer = GetLexer(lexerName, sourceTheme);
    CHECK_PTR_RET_NULL(sourceLexer);

    wxXmlNode* sourceLexerXml = sourceLexer->ToXml();
    LexerConf::Ptr_t newLexer(new LexerConf());
    newLexer->FromXml(sourceLexerXml);

    // Update the theme name
    newLexer->SetThemeName(themeName);

    // Add it
    return DoAddLexer(newLexer->ToXml());
}
LexerConf::Ptr_t ColoursAndFontsManager::GetLexerForBuffer(const wxString& buffer) const
{
    // Try this:
    // Use the FileExtManager to get the file type by examinig its content
    LexerConf::Ptr_t lexerByContent; // Null by default
    FileExtManager::FileType fileType = FileExtManager::TypeOther;
    if(FileExtManager::AutoDetectByBuffer(buffer, fileType) && fileType != FileExtManager::TypeOther) {
        switch(fileType) {
        case FileExtManager::TypeScript:
            lexerByContent = GetLexer("script");
            break;
        case FileExtManager::TypePhp:
            lexerByContent = GetLexer("php");
            break;
        case FileExtManager::TypeSourceCpp:
            lexerByContent = GetLexer("c++");
            break;
        case FileExtManager::TypeXml:
            lexerByContent = GetLexer("xml");
            break;
        case FileExtManager::TypePython:
            lexerByContent = GetLexer("python");
            break;
        default:
            break;
        }
    }

    // If we managed to find a lexer by content, use it
    if(lexerByContent) return lexerByContent;

    if (buffer.Contains("#include"))
    {
        return GetLexer("c++");
    }
    else if (buffer.Contains("import "))
    {
        return GetLexer("python");
    }
    else
    {
        return GetLexer("text");
    }
}
Пример #6
0
void ColoursAndFontsManager::SetTheme(const wxString& themeName)
{
    LexerConf::Ptr_t lexer = GetLexer("c++", themeName);
    CHECK_PTR_RET(lexer);

    bool isDark = lexer->IsDark();
    wxString fallbackTheme;
    if(isDark) {
        fallbackTheme = "Zmrok-like";
    } else {
        fallbackTheme = "Default";
    }

    const wxArrayString& lexers = GetAllLexersNames();
    for(size_t i = 0; i < lexers.size(); ++i) {
        wxArrayString themesForLexer = GetAvailableThemesForLexer(lexers.Item(i));
        if(themesForLexer.Index(themeName) == wxNOT_FOUND) {
            SetActiveTheme(lexers.Item(i), fallbackTheme);
        } else {
            SetActiveTheme(lexers.Item(i), themeName);
        }
    }
    SetGlobalTheme(themeName);
}
Пример #7
0
LexerConf::Ptr_t ColoursAndFontsManager::GetLexerForFile(const wxString& filename) const
{
    if(filename.IsEmpty()) return GetLexer("text");

    wxFileName fnFileName(filename);
    wxString fileNameLowercase = fnFileName.GetFullName();
    fileNameLowercase.MakeLower();

    LexerConf::Ptr_t defaultLexer(NULL);
    LexerConf::Ptr_t firstLexer(NULL);

    // Scan the list of lexers, locate the active lexer for it and return it
    ColoursAndFontsManager::Vec_t::const_iterator iter = m_allLexers.begin();
    for(; iter != m_allLexers.end(); ++iter) {
        wxString fileMask = (*iter)->GetFileSpec();
        if(FileUtils::WildMatch(fileMask, filename)) {
            if((*iter)->IsActive()) {
                return *iter;

            } else if(!firstLexer) {
                firstLexer = *iter;

            } else if(!defaultLexer && (*iter)->GetThemeName() == "Default") {
                defaultLexer = *iter;
            }
        }
    }

    // If we got here, it means that we could not find an active lexer that matches
    // the file mask. However, if we did find a "firstLexer" it means
    // that we do have a lexer that matches the file extension, its just that it is not
    // set as active
    if(firstLexer) {
        return firstLexer;
    }

    // Try this:
    // Use the FileExtManager to get the file type by examinig its content
    LexerConf::Ptr_t lexerByContent; // Null by default
    FileExtManager::FileType fileType = FileExtManager::TypeOther;
    if(FileExtManager::AutoDetectByContent(filename, fileType) && fileType != FileExtManager::TypeOther) {
        switch(fileType) {
        case FileExtManager::TypeScript:
            lexerByContent = GetLexer("script");
            break;
        case FileExtManager::TypePhp:
            lexerByContent = GetLexer("php");
            break;
        case FileExtManager::TypeSourceCpp:
            lexerByContent = GetLexer("c++");
            break;
        case FileExtManager::TypeXml:
            lexerByContent = GetLexer("xml");
            break;
        case FileExtManager::TypePython:
            lexerByContent = GetLexer("python");
            break;
        default:
            break;
        }
    }

    // If we managed to find a lexer by content, use it
    if(lexerByContent) return lexerByContent;

    // If we reached here, it means we could not locate an active lexer for this file type
    if(defaultLexer) {
        return defaultLexer;

    } else if(firstLexer) {
        return firstLexer;

    } else {
        // Return the "Text" lexer
        return GetLexer("text");
    }
}
bool cbStyledTextCtrl::IsComment(int style)
{
    return CommentLexerStyles[GetLexer()].find(style) != CommentLexerStyles[GetLexer()].end();
}
bool cbStyledTextCtrl::IsPreprocessor(int style)
{
    return PreprocessorLexerStyles[GetLexer()].find(style) != PreprocessorLexerStyles[GetLexer()].end();
}
bool cbStyledTextCtrl::IsString(int style)
{
    return StringLexerStyles[GetLexer()].find(style) != StringLexerStyles[GetLexer()].end();
}
bool cbStyledTextCtrl::IsCharacter(int style)
{
    return CharacterLexerStyles[GetLexer()].find(style) != CharacterLexerStyles[GetLexer()].end();
}
Пример #12
0
LexerConf::Ptr_t ColoursAndFontsManager::GetLexerForFile(const wxString& filename) const
{
    wxFileName fnFileName(filename);
    wxString fileNameLowercase = fnFileName.GetFullName();
    fileNameLowercase.MakeLower();

    LexerConf::Ptr_t defaultLexer(NULL);
    LexerConf::Ptr_t firstLexer(NULL);

    // Scan the list of lexers, locate the active lexer for it and return it
    ColoursAndFontsManager::Vec_t::const_iterator iter = m_allLexers.begin();
    for(; iter != m_allLexers.end(); ++iter) {
        wxString fileMask = (*iter)->GetFileSpec().Lower();
        wxArrayString masks = ::wxStringTokenize(fileMask, ";", wxTOKEN_STRTOK);
        for(size_t i = 0; i < masks.GetCount(); ++i) {
            if(::wxMatchWild(masks.Item(i), fileNameLowercase)) {
                if((*iter)->IsActive()) {
                    return *iter;

                } else if(!firstLexer) {
                    firstLexer = *iter;

                } else if(!defaultLexer && (*iter)->GetThemeName() == "Default") {
                    defaultLexer = *iter;
                }
            }
        }
    }

    // Try this:
    // Use the FileExtManager to get the file type by examinig its content
    LexerConf::Ptr_t lexerByContent; // Null by default
    FileExtManager::FileType fileType = FileExtManager::TypeOther;
    if(FileExtManager::AutoDetectByContent(filename, fileType) && fileType != FileExtManager::TypeOther) {
        switch(fileType) {
        case FileExtManager::TypeScript:
            lexerByContent = GetLexer("script");
            break;
        case FileExtManager::TypePhp:
            lexerByContent = GetLexer("php");
            break;
        case FileExtManager::TypeSourceCpp:
            lexerByContent = GetLexer("c++");
            break;
        case FileExtManager::TypeXml:
            lexerByContent = GetLexer("xml");
            break;
        case FileExtManager::TypePython:
            lexerByContent = GetLexer("python");
            break;
        default:
            break;
        }
    }

    // If we managed to find a lexer by content, use it
    if(lexerByContent) return lexerByContent;

    // If we reached here, it means we could not locate an active lexer for this file type
    if(defaultLexer) {
        return defaultLexer;

    } else if(firstLexer) {
        return firstLexer;

    } else {
        // Return the "Text" lexer
        return GetLexer("text");
    }
}
Пример #13
0
void CodeEdit::StartAutoCompletion(const wxString& token)
{

    wxASSERT(m_autoCompleteManager != NULL);

    wxString items;

    // Get the actual prefix of the thing we're trying to match for autocompletion.
    // If the token refers to a member, the prefix is the member name.

    wxString prefix;
    wxString newToken;
    bool member = false;
    bool function = false;

    if (GetLexer() == wxSTC_LEX_LUA)
    {

        int end1 = token.Find('.', true);

        if (end1 == wxNOT_FOUND)
        {
            end1 = 0;
        }
        else
        {
            // Skip the '.' character.
            ++end1;
            member = true;
        }

        int end2 = token.Find(':', true);

        if (end2 == wxNOT_FOUND)
        {
            end2 = 0;
        }
        else
        {
            // Skip the ':' character.
            ++end2;
            member = true;
        }

        int end = std::max(end1, end2);
        newToken = token.Right(token.Length() - end);
        prefix = token.Left(end - 1);

        if (end != 0 && token[end - 1] == ':')
          function = true;
    }
    else
    {
        // No autocompletion when using the default lexer.
        return;
    }

    if (!member && newToken.Length() < m_minAutoCompleteLength)
    {
        // Don't pop up the auto completion if the user hasn't typed in very
        // much yet.
        return;
    }

    wxVector<wxString> prefixes;

    m_autoCompleteManager->ParsePrefix(prefix, file, GetCurrentLine(), prefixes);
    m_autoCompleteManager->GetMatchingItems(newToken, prefixes, member, function, items);

    if (!AutoCompActive() || m_autoCompleteItems != items)
    {

        // Remember the items in the list so that we don't redisplay the list
        // with the same set of items (reduces flickering).
        m_autoCompleteItems = items;

        if (!items.IsEmpty())
        {
            // Show the autocomplete selection list.
          AutoCompShow(newToken.Length(), items);
        }
        else
        {
            // We have no matching items, so hide the autocompletion selection.
            AutoCompCancel();
        }

    }

}