Exemplo n.º 1
0
void AbbreviationPlugin::OnAbbrevSelected(clCodeCompletionEvent& e)
{
    if(e.GetEventObject() != this) {
        e.Skip();
        return;
    }

    wxString wordAtCaret = e.GetWord();
    InsertExpansion( wordAtCaret );
}
Exemplo n.º 2
0
void AbbreviationPlugin::OnAbbreviations(wxCommandEvent& e)
{
    IEditor *editor = m_mgr->GetActiveEditor();
    if (!editor) {
        return;
    }

    AbbreviationJSONEntry jsonData;
    if ( !m_config.ReadItem( &jsonData ) ) {
        // merge the data from the old configuration
        AbbreviationEntry data;
        m_mgr->GetConfigTool()->ReadObject(wxT("AbbreviationsData"), &data);
    
        jsonData.SetAutoInsert( data.GetAutoInsert() );
        jsonData.SetEntries( data.GetEntries() );
        m_config.WriteItem( &jsonData );
    }
    
    wxString wordAtCaret = editor->GetWordAtCaret();
    
    bool autoInsert = (jsonData.IsAutoInsert() && wordAtCaret.IsEmpty() == false);
    if  ( autoInsert ){
        autoInsert = InsertExpansion(wordAtCaret);
    }
    
    if ( !autoInsert ) {
        static wxBitmap bmp = LoadBitmapFile(wxT("abbrev.png")) ;
        if (bmp.IsOk()) {
            editor->RegisterImageForKind(wxT("Abbreviation"), bmp);
            std::vector<TagEntryPtr> tags;

            // search for the old item
            const JSONElement::wxStringMap_t& entries = jsonData.GetEntries();
            JSONElement::wxStringMap_t::const_iterator iter = entries.begin();
            for (; iter != entries.end(); ++iter) {
                TagEntryPtr t(new TagEntry());
                t->SetName(iter->first);
                t->SetKind(wxT("Abbreviation"));
                tags.push_back(t);
            }
            editor->ShowCompletionBox(tags, editor->GetWordAtCaret(), false, this);
        }
    }
}
Exemplo n.º 3
0
void AbbreviationPlugin::OnAbbreviations(wxCommandEvent& e)
{
    IEditor* editor = m_mgr->GetActiveEditor();
    if(!editor) {
        return;
    }

    AbbreviationJSONEntry jsonData;
    if(!m_config.ReadItem(&jsonData)) {
        // merge the data from the old configuration
        AbbreviationEntry data;
        m_mgr->GetConfigTool()->ReadObject(wxT("AbbreviationsData"), &data);

        jsonData.SetAutoInsert(data.GetAutoInsert());
        jsonData.SetEntries(data.GetEntries());
        m_config.WriteItem(&jsonData);
    }

    wxString wordAtCaret = editor->GetWordAtCaret();

    bool autoInsert = (jsonData.IsAutoInsert() && wordAtCaret.IsEmpty() == false);
    if(autoInsert) {
        autoInsert = InsertExpansion(wordAtCaret);
    }

    if(!autoInsert) {
        static wxBitmap bmp = LoadBitmapFile(wxT("abbrev.png"));
        if(bmp.IsOk()) {
            wxCodeCompletionBoxEntry::Vec_t ccEntries;
            wxCodeCompletionBox::BmpVec_t bitmaps;
            bitmaps.push_back(bmp);

            // search for the old item
            const JSONElement::wxStringMap_t& entries = jsonData.GetEntries();
            JSONElement::wxStringMap_t::const_iterator iter = entries.begin();
            for(; iter != entries.end(); ++iter) {
                ccEntries.push_back(wxCodeCompletionBoxEntry::New(iter->first, 0));
            }
            wxCodeCompletionBoxManager::Get().ShowCompletionBox(
                editor->GetCtrl(), ccEntries, bitmaps, wxCodeCompletionBox::kNone, wxNOT_FOUND, this);
        }
    }
}