Пример #1
0
int ThreadSearch::GetInsertionMenuIndex(const wxMenu* const pCtxMenu)
{
    if ( !IsAttached() )
        return -1;

    // Looks after the "Find implementation of:" menu item
    const wxMenuItemList ItemsList = pCtxMenu->GetMenuItems();
    for (int i = 0; i < (int)ItemsList.GetCount(); ++i)
    {
        #if wxCHECK_VERSION(3, 0, 0)
        if (ItemsList[i]->GetItemLabelText().StartsWith(_("Find implementation of:")) )
        #else
        if (ItemsList[i]->GetLabel().StartsWith(_("Find implementation of:")) )
        #endif
        {
            return ++i;
        }
    }
    return -1;
}
void SpellCheckerPlugin::BuildModuleMenu(const ModuleType type, wxMenu* menu, cb_unused const FileTreeData* data)
{
    //Some library module is ready to display a pop-up menu.
    //Check the parameter \"type\" and see which module it is
    //and append any items you need in the menu...
    //TIP: for consistency, add a separator as the first item...
    if ( !IsAttached() ) return;
    if(type != mtEditorManager || !menu ) return;
    cbEditor *ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
    if ( !ed ) return;
    cbStyledTextCtrl *stc = ed->GetControl();
    if ( !stc ) return;

    const int id = menu->FindItem(_("Edit"));
    if (id != wxNOT_FOUND)
    {
        wxMenuItem* subMenuItem = menu->FindItem(id, 0);
        wxMenu* subMenu;
        if (subMenuItem)
            subMenu = subMenuItem->GetSubMenu();
        if (subMenu)
        {
            int insertPos = wxNOT_FOUND;
            const wxMenuItemList itemsList = subMenu->GetMenuItems();
            for (size_t i = 0; i < itemsList.GetCount(); ++i)
            {
                #if wxCHECK_VERSION(2, 9, 0)
                if (itemsList[i]->GetItemLabelText() == _("lowercase"))
                #else
                if (itemsList[i]->GetLabel() == _("lowercase"))
                #endif
                {
                    insertPos = i + 1;
                    break;
                }
            }
            wxMenuItem *item;
            if (insertPos != wxNOT_FOUND)
                item = subMenu->Insert(insertPos, idCamelCase, _("CamelCase"));
            else
                item = subMenu->Append(idCamelCase, _("CamelCase"));
            if( stc->GetSelectedText().IsEmpty() )
                item->Enable(false);
        }
    }

    int pos = stc->GetCurrentPos();
    //stc->GetIndicatorValue();
    m_wordstart = -1;
    m_wordend = -1;
    m_suggestions.Empty();
    int wordstart, wordend;
    //Manager::Get()->GetLogManager()->Log( wxString::Format(_T("SpellChecker indicator: %d"), indic) );
    if ( !stc->GetSelectedText().IsEmpty() )
    {
        // take only the first word from the selection
        wordstart = stc->GetSelectionStart();
        while ( wordstart < stc->GetLength() )
        {
            wxChar ch = stc->GetCharAt(wordstart);
            if ( !m_pSpellHelper->IsWhiteSpace( ch ))
                break;
            //else if ((ch >= _T('A') && ch <= _T('Z'))
            wordstart++;
        }
    }
    else if ( stc->IndicatorValueAt( m_pOnlineChecker->GetIndicator(), pos) )
    {

        wordstart = pos;
        while ( wordstart > 1 )
        {
            wxChar ch = stc->GetCharAt(wordstart-1);
            if ( m_pSpellHelper->IsWhiteSpace( ch ) )
                break;
            else if ( ch >= _T('A') && ch <= _T('Z') )
            {
                wordstart--;
                break;
            }
            wordstart--;
        }
    }
    else
        return;
    wordend = wordstart;
    while ( wordend < stc->GetLength()-1 )
    {
        wxChar ch = stc->GetCharAt(++wordend);
        if ( (ch >= _T('A') && ch <= _T('Z')) || m_pSpellHelper->IsWhiteSpace( ch ) )
            break;
    }

    wxString misspelledWord;
    if ( wordend - wordstart > 0 && wordend != -1)
        misspelledWord = stc->GetTextRange(wordstart, wordend);

    if ( !misspelledWord.IsEmpty() )
    {
        m_wordstart = wordstart;
        m_wordend   = wordend;

        menu->AppendSeparator();

        m_suggestions = m_pSpellChecker->GetSuggestions( misspelledWord );
        if ( m_suggestions.size() )
        {
            wxMenu *SuggestionsMenu = new wxMenu();
            for ( unsigned int i = 0 ; i < MaxSuggestEntries && i < m_suggestions.size() ; i++ )
                SuggestionsMenu->Append(idSuggest[i], m_suggestions[i] );
            SuggestionsMenu->AppendSeparator();
            if ( m_suggestions.size() > MaxSuggestEntries )
                SuggestionsMenu->Append(idMoreSuggestions, _("more..."));
            SuggestionsMenu->Append(idAddToDictionary, _("Add '") + misspelledWord + _("' to dictionary"));
            menu->AppendSubMenu(SuggestionsMenu, _("Spelling suggestions for '") + misspelledWord + _T("'") );
        }
        else
        {
            //menu->Append(idMoreSuggestions, _("No spelling suggestions for '") + misspelledWord + _T("'"))->Enable(false);
            menu->Append(idAddToDictionary, _("Add '") + misspelledWord + _("' to dictionary"));
        }
    }
}
Пример #3
0
void CscopePlugin::BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* /*data*/)
{
    if ( !IsAttached() || m_pProcess) return;

    if(type != mtEditorManager || !menu ) return;

    EditorManager* emngr = Manager::Get()->GetEditorManager();
    if ( !emngr ) return;

    EditorBase *edb = emngr->GetActiveEditor();
    if ( !edb || !edb->IsBuiltinEditor() ) return;

    cbStyledTextCtrl* stc = ((cbEditor*)edb)->GetControl();
    if ( !stc ) return;

    if ( stc->GetLexer()  != wxSCI_LEX_CPP) return;

    wxString word = GetWordAtCaret();
    if ( word.IsEmpty() ) return;


    // Looks after the "Find implementation of:" menu item
    const wxMenuItemList ItemsList = menu->GetMenuItems();
    int idximp=-1;
    int idxocc=-1;
    for (int idx = 0; idx < (int)ItemsList.GetCount(); ++idx)
    {
        #if wxCHECK_VERSION(2, 9, 0)
        if (ItemsList[idx]->GetItemLabelText().StartsWith(_("Find implementation of:")) )
        #else
        if (ItemsList[idx]->GetLabel().StartsWith(_("Find implementation of:")) )
        #endif
        {
            idximp = idx;
        }
        #if wxCHECK_VERSION(2, 9, 0)
        if (ItemsList[idx]->GetItemLabelText().StartsWith(_("Find occurrences of:")) )
        #else
        if (ItemsList[idx]->GetLabel().StartsWith(_("Find occurrences of:")) )
        #endif
        {
            idxocc = idx;
        }
    }

    if ( idxocc == -1 && idximp == -1 )
    {
        //for consistency, add a separator as the first item:
        menu->AppendSeparator();

        //menu->Append(idOnFindSymbol,                       _T("Find C symbol '") + word + _T("'"));
        //menu->Append(idOnFindGlobalDefinition,             _T("Find '") + word + _T("' global definition"));
        menu->Append(idOnFindFunctionsCalledByThisFuncion, _T("Find functions called by '") + word + _T("'"));
        menu->Append(idOnFindFunctionsCallingThisFunction, _T("Find functions calling '") + word + _T("'"));
    }
    else
    {
        if ( idxocc >= 0 ) // if find occurences
            idximp = idxocc;
        //menu->Insert(++idximp,idOnFindSymbol,                       _T("Find C symbol '") + word + _T("'"));
        //menu->Insert(++idximp,idOnFindGlobalDefinition,             _T("Find '") + word + _T("' global definition"));
        menu->Insert(++idximp,idOnFindFunctionsCalledByThisFuncion, _T("Find functions called by '") + word + _T("'"));
        menu->Insert(++idximp,idOnFindFunctionsCallingThisFunction, _T("Find functions calling '") + word + _T("'"));
    }
}