void WordCompletionSettingsDlg::OnValueChanged(wxPropertyGridEvent& event)
{
    event.Skip();
    WordCompletionSettings settings;
    settings.Load();
    settings.SetCompleteTypes(m_pgPropTypes->GetValue().GetInteger());
    settings.SetComparisonMethod(m_pgPropComparisonMethod->GetChoiceSelection());
    settings.Save();
}
void WordCompletionSettingsDlg::OnOk(wxCommandEvent& event)
{
    event.Skip();
    WordCompletionSettings settings;
    settings.Load();
    settings.SetComparisonMethod(m_pgPropComparisonMethod->GetChoiceSelection());
    settings.SetEnabled(m_pgPropEnabled->GetValue().GetBool());
    settings.Save();
    EndModal(wxID_OK);
}
WordCompletionSettingsDlg::WordCompletionSettingsDlg(wxWindow* parent)
    : WordCompletionSettingsBaseDlg(parent)
{
    ::wxPGPropertyBooleanUseCheckbox(m_pgMgr->GetGrid());
    WordCompletionSettings settings;
    size_t completeTypes = settings.Load().GetCompleteTypes();
    m_pgPropTypes->SetValueFromInt(completeTypes);
    m_pgPropComparisonMethod->SetChoiceSelection(settings.GetComparisonMethod());
    SetName("WordCompletionSettingsDlg");
    WindowAttrManager::Load(this);
}
WordCompletionSettingsDlg::WordCompletionSettingsDlg(wxWindow* parent)
    : WordCompletionSettingsBaseDlg(parent)
    , m_modified(false)
{
    ::wxPGPropertyBooleanUseCheckbox(m_pgMgr->GetGrid());
    WordCompletionSettings settings;
    settings.Load();
    m_pgPropComparisonMethod->SetChoiceSelection(settings.GetComparisonMethod());
    m_pgPropEnabled->SetValue(settings.IsEnabled());
    SetName("WordCompletionSettingsDlg");
    WindowAttrManager::Load(this);
}
Beispiel #5
0
void WordCompletionPlugin::OnWordComplete(wxCommandEvent& event)
{
    event.Skip();
    IEditor* activeEditor = m_mgr->GetActiveEditor();
    CHECK_PTR_RET(activeEditor);

    WordCompletionSettings settings;
    settings.Load();

    // Enabled?
    if(!settings.IsEnabled()) return;

    // Build the suggetsion list
    wxString suggestString;
    wxCodeCompletionBoxEntry::Vec_t entries;
    wxCodeCompletionBox::BmpVec_t bitmaps;
    bitmaps.push_back(m_images.Bitmap("m_bmpWord"));

    // Filter (what the user has typed so far)
    wxStyledTextCtrl* stc = activeEditor->GetCtrl();
    int curPos = stc->GetCurrentPos();
    int start = stc->WordStartPosition(stc->GetCurrentPos(), true);
    if(curPos < start) return;

    wxString filter = stc->GetTextRange(start, curPos);
    wxString lcFilter = filter.Lower();

    wxStringSet_t words = m_dictionary->GetWords();
    // Parse the current bufer (if modified), to include non saved words
    if(activeEditor->IsModified()) {
        wxStringSet_t unsavedBufferWords;
        WordCompletionThread::ParseBuffer(stc->GetText(), unsavedBufferWords);

        // Merge the results
        words.insert(unsavedBufferWords.begin(), unsavedBufferWords.end());
    }

    // Get the editor keywords and add them
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexerForFile(activeEditor->GetFileName().GetFullName());
    if(lexer) {
        wxString keywords;
        for(size_t i = 0; i < wxSTC_KEYWORDSET_MAX; ++i) {
            keywords << lexer->GetKeyWords(i) << " ";
        }
        wxArrayString langWords = ::wxStringTokenize(keywords, "\n\t \r", wxTOKEN_STRTOK);
        words.insert(langWords.begin(), langWords.end());
    }

    wxStringSet_t filterdSet;
    if(lcFilter.IsEmpty()) {
        filterdSet.swap(words);
    } else {
        for(wxStringSet_t::iterator iter = words.begin(); iter != words.end(); ++iter) {
            wxString word = *iter;
            wxString lcWord = word.Lower();
            if(settings.GetComparisonMethod() == WordCompletionSettings::kComparisonStartsWith) {
                if(lcWord.StartsWith(lcFilter) && filter != word) {
                    filterdSet.insert(word);
                }
            } else {
                if(lcWord.Contains(lcFilter) && filter != word) {
                    filterdSet.insert(word);
                }
            }
        }
    }
    for(wxStringSet_t::iterator iter = filterdSet.begin(); iter != filterdSet.end(); ++iter) {
        entries.push_back(wxCodeCompletionBoxEntry::New(*iter, 0));
    }

    wxCodeCompletionBoxManager::Get().ShowCompletionBox(activeEditor->GetCtrl(),
                                                        entries,
                                                        bitmaps,
                                                        event.GetId() == XRCID("text_word_complete") ?
                                                            wxCodeCompletionBox::kInsertSingleMatch :
                                                            wxCodeCompletionBox::kNone,
                                                        wxNOT_FOUND);
}
Beispiel #6
0
void WordCompletionPlugin::OnWordComplete(clCodeCompletionEvent& event)
{
    event.Skip(); // Always skip this

    IEditor* activeEditor = dynamic_cast<IEditor*>(event.GetEditor());
    CHECK_PTR_RET(activeEditor);

    WordCompletionSettings settings;
    settings.Load();

    // Enabled?
    if(!settings.IsEnabled()) {
        return;
    }

    // Build the suggetsion list
    static wxBitmap sBmp = wxNullBitmap;
    if(!sBmp.IsOk()) {
        sBmp = m_mgr->GetStdIcons()->LoadBitmap("word");
    }

    // Filter (what the user has typed so far)
    // wxStyledTextCtrl* stc = activeEditor->GetCtrl();
    // int curPos = stc->GetCurrentPos();
    // int start = stc->WordStartPosition(stc->GetCurrentPos(), true);
    // if(curPos < start) return;

    wxString filter = event.GetWord().Lower(); // stc->GetTextRange(start, curPos);

    wxStringSet_t words = m_dictionary->GetWords();
    // Parse the current bufer (if modified), to include non saved words
    if(activeEditor->IsModified()) {
        // For performance (this parsing is done in the main thread)
        // only parse the visible area of the document
        wxStringSet_t unsavedBufferWords;
        wxStyledTextCtrl* stc = activeEditor->GetCtrl();
        int startPos = stc->PositionFromLine(stc->GetFirstVisibleLine());
        int endPos = stc->GetCurrentPos();

        wxString buffer = stc->GetTextRange(startPos, endPos);
        WordCompletionThread::ParseBuffer(buffer, unsavedBufferWords);

        // Merge the results
        words.insert(unsavedBufferWords.begin(), unsavedBufferWords.end());
    }

    // Get the editor keywords and add them
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexerForFile(activeEditor->GetFileName().GetFullName());
    if(lexer) {
        wxString keywords;
        for(size_t i = 0; i < wxSTC_KEYWORDSET_MAX; ++i) {
            keywords << lexer->GetKeyWords(i) << " ";
        }
        wxArrayString langWords = ::wxStringTokenize(keywords, "\n\t \r", wxTOKEN_STRTOK);
        words.insert(langWords.begin(), langWords.end());
    }

    wxStringSet_t filterdSet;
    if(filter.IsEmpty()) {
        filterdSet.swap(words);
    } else {
        for(wxStringSet_t::iterator iter = words.begin(); iter != words.end(); ++iter) {
            wxString word = *iter;
            wxString lcWord = word.Lower();
            if(settings.GetComparisonMethod() == WordCompletionSettings::kComparisonStartsWith) {
                if(lcWord.StartsWith(filter) && filter != word) {
                    filterdSet.insert(word);
                }
            } else {
                if(lcWord.Contains(filter) && filter != word) {
                    filterdSet.insert(word);
                }
            }
        }
    }
    wxCodeCompletionBoxEntry::Vec_t entries;
    for(wxStringSet_t::iterator iter = filterdSet.begin(); iter != filterdSet.end(); ++iter) {
        entries.push_back(wxCodeCompletionBoxEntry::New(*iter, sBmp));
    }
    event.GetEntries().insert(event.GetEntries().end(), entries.begin(), entries.end());
}