void OccurrencesHighlighting::BuildModuleMenu(const ModuleType type, wxMenu* menu, 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;

    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;

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

    menu->AppendSeparator();

    if ( m_texts.find(word) == m_texts.end() )
        menu->Append(idMenuEntryPermanent, _("Permanently Highlight '") + word + _T("'"));
    else
        menu->Append(idMenuEntryRemove,    _("Don't Highlight '")       + word + _T("'"));

}
Esempio n. 2
0
void NassiPlugin::OnInsertCFromDiagram(wxCommandEvent &event)
{
    // check if user can isert an opened diagram
    unsigned idx = 0;
    for ( int i = 0 ; i < Manager::Get()->GetEditorManager()->GetEditorsCount() ; i++ )
    {
        EditorBase *ed = Manager::Get()->GetEditorManager()->GetEditor( i );
        if ( NassiEditorPanel::IsNassiEditor( ed ) )
        {
            NassiEditorPanel *ned = (NassiEditorPanel *)ed;
            if ( event.GetId() == insertCFromDiagram[idx] )
            {
                EditorManager* emngr = Manager::Get()->GetEditorManager();
                if ( !emngr ) return;
                EditorBase *edb = emngr->GetActiveEditor();
                if ( !edb || !edb->IsBuiltinEditor() ) return;
                unsigned int indent = ((cbEditor*)edb)->GetLineIndentInSpaces(); // from current line
                cbStyledTextCtrl *stc = ((cbEditor*)edb)->GetControl();
                if ( !stc ) return;

                wxStringOutputStream ostrstream;
                wxTextOutputStream text_stream(ostrstream);

                if ( !ned ) return;
                ned->GetCSource(text_stream, indent);

                stc->InsertText(wxSCI_INVALID_POSITION, ostrstream.GetString());

            }
            //some comment
            idx++;
        }
    }
}
Esempio n. 3
0
void NassiPlugin::ParseC(wxCommandEvent & /*event*/)
{
    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;


    NassiEditorPanel *panel = new NassiEditorPanel(_T(""), _T(""));

    switch ( stc->GetLexer() )
    {
        case wxSCI_LEX_CPP:
        {
            const wxString str = stc->GetSelectedText();
            if ( !panel->ParseC(str) )
            {
                panel->Close();
                wxMessageBox(_("unable to parse input"), _("Error!"));
            }
            //else stc->SetReadOnly(true);

        }
            break;
        default:
            break;
    }
}
Esempio n. 4
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;

    PluginManager *pluginManager = Manager::Get()->GetPluginManager();
    int idximp = pluginManager->GetFindMenuItemFirst() + pluginManager->GetFindMenuItemCount();
    menu->Insert(idximp++, idOnFindFunctionsCalledByThisFuncion, _("Find functions called by '") + word + _T("'"));
    menu->Insert(idximp++, idOnFindFunctionsCallingThisFunction, _("Find functions calling '") + word + _T("'"));
    pluginManager->RegisterFindMenuItems(false, 2);
}
Esempio n. 5
0
void cbDebuggerPlugin::OnEditorOpened(CodeBlocksEvent& event)
{
    // when an editor opens, look if we have breakpoints for it
    // and notify it...
    EditorBase* ed = event.GetEditor();
    if (ed && ed->IsBuiltinEditor())
    {
        cbEditor *editor = static_cast<cbEditor*>(ed);
        editor->RefreshBreakpointMarkers();

        if (IsRunning())
        {
            wxString filename;
            int line;
            GetCurrentPosition(filename, line);

            wxFileName edFileName(ed->GetFilename());
            edFileName.Normalize();

            wxFileName dbgFileName(filename);
            dbgFileName.Normalize();
            if (dbgFileName.GetFullPath().IsSameAs(edFileName.GetFullPath()) && line != -1)
            {
                editor->SetDebugLine(line - 1);
            }
        }
    }
    event.Skip(); // must do
}
Esempio n. 6
0
void cbSmartIndentPlugin::OnCCDoneEvent(CodeBlocksEvent& event)
{
    EditorBase* eb = event.GetEditor();
    if (eb && eb->IsBuiltinEditor())
    {
        cbEditor* ed = static_cast<cbEditor *>(eb);
        OnCCDone(ed);
    }
}
void PythonDebugger::SetWatchTooltip(const wxString &tip, int definition_length)
{
    EditorManager* edMan = Manager::Get()->GetEditorManager();
    EditorBase* base = edMan->GetActiveEditor();
    cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : 0;
    if (!ed)
        return;
    ed->GetControl()->CallTipShow(m_watch_tooltip_pos, tip);
    ed->GetControl()->CallTipSetHighlight(0,definition_length);

}
Esempio n. 8
0
inline void RefreshBreakpoints(cb_unused const cbDebuggerPlugin* plugin)
{
    EditorManager *editorManager = Manager::Get()->GetEditorManager();
    int count = editorManager->GetEditorsCount();
    for (int ii = 0; ii < count; ++ii)
    {
        EditorBase *editor = editorManager->GetEditor(ii);
        if (!editor->IsBuiltinEditor())
            continue;
        editor->RefreshBreakpointMarkers();
    }
}
Esempio n. 9
0
void CodeChecker::OnProcessTerminate(wxProcessEvent &e)
{
    if(m_processqueue.empty())
        return;
    wxString file(m_processqueue.begin()->file);
    wxString out=m_process->GetStdout();
    wxString err=m_process->GetStderr();
    LangData &ld=m_commands[m_processqueue.begin()->lang];
    wxRegEx re(ld.regexp,wxRE_ADVANCED);
    wxString data=out+err;
    if(m_issues.find(file)!=m_issues.end())
        m_issues[file].clear();
    while(re.Matches(data))
    {
        long linenum;
        if(re.GetMatch(data,ld.regexp_indline).ToLong(&linenum))
        {
            CodeIssue ci;
            ci.line=linenum-1;
            ci.msg=re.GetMatch(data,ld.regexp_indmsg);//_T("");
            m_issues[file].push_back(ci);
        }
        size_t start,end;
        re.GetMatch(&start,&end,0);
        data=data.Mid(end);
    }

    LogMessage(_("Syntax Check Results"));
    LogMessage(out);
    LogMessage(err);
    EditorManager* em = Manager::Get()->GetEditorManager();
    EditorBase* eb = em->IsOpen(file);
    if (eb && eb->IsBuiltinEditor())
    {
        cbEditor *ed=(cbEditor *)eb;
        cbStyledTextCtrl *control=ed->GetControl();
//        control->MarkerDefine(CHECK_MARKER, CHECK_STYLE);
//        control->MarkerSetForeground(CHECK_MARKER, wxColour(0xFF, 0xA0, 0xA0));
//        control->MarkerSetBackground(CHECK_MARKER, wxColour(0xA0, 0xA0, 0xA0));
        control->MarkerDeleteAll(CHECK_MARKER);
        CodeIssues::iterator iend=m_issues[file].end();
        for(CodeIssues::iterator it=m_issues[file].begin();it!=iend;++it)
            control->MarkerAdd(it->line,CHECK_MARKER);
    }

    //TODO: retrieve a handle to the editor control
    //TODO: Parse stdout/stderr
    //TODO: Define the marker (if not defined already)
//
//    if(!control->LineHasMarker(CHECK_MARKER,linenum))
//        control->MarkerAdd(CHECK_MARKER,linenum));
    m_processqueue.pop_front();
}
Esempio n. 10
0
void PythonDebugger::OnValueTooltip(CodeBlocksEvent& event)
{
    event.Skip();
    if (!m_DebuggerActive)
        return;
    if (!IsStopped())
        return;

    EditorBase* base = event.GetEditor();
    cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : 0;
    if (!ed)
        return;

    if(ed->IsContextMenuOpened())
    {
    	return;
    }

	// get rid of other calltips (if any) [for example the code completion one, at this time we
	// want the debugger value call/tool-tip to win and be shown]
    if(ed->GetControl()->CallTipActive())
    {
    	ed->GetControl()->CallTipCancel();
    }

    const int style = event.GetInt();
    if (style != wxSCI_P_DEFAULT && style != wxSCI_P_OPERATOR && style != wxSCI_P_IDENTIFIER && style != wxSCI_P_CLASSNAME)
        return;

    wxPoint pt;
    pt.x = event.GetX();
    pt.y = event.GetY();
    int pos = ed->GetControl()->PositionFromPoint(pt);
    int start = ed->GetControl()->WordStartPosition(pos, true);
    int end = ed->GetControl()->WordEndPosition(pos, true);
    while(ed->GetControl()->GetCharAt(start-1)==_T('.'))
        start=ed->GetControl()->WordStartPosition(start-2, true);
    wxString token;
    if (start >= ed->GetControl()->GetSelectionStart() &&
        end <= ed->GetControl()->GetSelectionEnd())
    {
        token = ed->GetControl()->GetSelectedText();
    }
    else
        token = ed->GetControl()->GetTextRange(start,end);
    if (token.IsEmpty())
        return;

    wxString cmd;
    cmd+=_T("pw ")+token+_T("\n");
    DispatchCommands(cmd,DBGCMDTYPE_WATCHTOOLTIP,true);
    m_watch_tooltip_pos=pos;
}
Esempio n. 11
0
void ReopenEditor::OnEditorClosed(CodeBlocksEvent& event)
{
    EditorBase* eb = event.GetEditor();

    if(eb && eb->IsBuiltinEditor())
    {
        cbProject* prj = nullptr;
        bool isPrjClosing = false;

        ProjectFile* prjf = ((cbEditor*)eb)->GetProjectFile();
        if(prjf)
            prj = prjf->GetParentProject();

        wxString name = wxEmptyString;
        if(prj)
        {
            isPrjClosing = (m_ClosedProjects.Index(prj) != wxNOT_FOUND);
            name = prj->GetTitle();
        }
        if(!prj || (prj && !isPrjClosing))
        {
            wxArrayString list;
            list.Add(eb->GetFilename());
            if(prj)
            {
                list.Add(prj->GetTitle());
                list.Add(prj->GetFilename());
            }
            else
            {
                list.Add(_("<none>"));
                list.Add(_("<none>"));
            }
            m_pListLog->Prepend(list);
            m_pListLog->SetProject(0, prj);
        }
    }
    wxMenuBar* menuBar = Manager::Get()->GetAppFrame()->GetMenuBar();
    menuBar->Enable(idReopenEditor, (m_pListLog->GetItemsCount() > 0));
    event.Skip();
}
Esempio n. 12
0
void cbDebuggerPlugin::ProcessValueTooltip(CodeBlocksEvent& event)
{
    event.Skip();
    if (cbDebuggerCommonConfig::GetFlag(cbDebuggerCommonConfig::RequireCtrlForTooltips))
    {
        if (!wxGetKeyState(WXK_CONTROL))
            return;
    }

    if (Manager::Get()->GetDebuggerManager()->GetInterfaceFactory()->IsValueTooltipShown())
        return;

    if (!ShowValueTooltip(event.GetInt()))
        return;

    EditorBase* base = event.GetEditor();
    cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr;
    if (!ed)
        return;

    if (ed->IsContextMenuOpened())
        return;

    // get rid of other calltips (if any) [for example the code completion one, at this time we
    // want the debugger value call/tool-tip to win and be shown]
    if (ed->GetControl()->CallTipActive())
        ed->GetControl()->CallTipCancel();

    wxPoint pt;
    pt.x = event.GetX();
    pt.y = event.GetY();

    const wxString &token = GetEditorWordAtCaret(&pt);
    if (!token.empty())
    {
        pt = ed->GetControl()->ClientToScreen(pt);
        OnValueTooltip(token, wxRect(pt.x - 5, pt.y, 10, 10));
    }
}
Esempio n. 13
0
void ReopenEditor::OnEditorOpened(CodeBlocksEvent& event)
{
    if(m_pListLog->GetItemsCount() > 0)
    {
        EditorBase* eb = event.GetEditor();

        if(eb && eb->IsBuiltinEditor())
        {
            wxString fname = eb->GetFilename();
            for(size_t i = m_pListLog->GetItemsCount(); i > 0; --i)
            {
                if(fname == m_pListLog->GetFilename(i-1))
                {
                    m_pListLog->RemoveAt(i-1);
                    break;
                }
            }
        }
    }
    wxMenuBar* menuBar = Manager::Get()->GetAppFrame()->GetMenuBar();
    menuBar->Enable(idReopenEditor, (m_pListLog->GetItemsCount() > 0));
    event.Skip();
}
bool DebugInterfaceFactory::ShowValueTooltip(const cb::shared_ptr<cbWatch> &watch, const wxRect &rect)
{
    delete m_tooltip;
    m_tooltip = nullptr;

    wxPoint pt = wxGetMousePosition();
    if (!rect.Contains(pt))
        return false;
    else
    {
        m_tooltip = new ValueTooltip(watch, Manager::Get()->GetAppWindow());
#ifndef __WXMAC__
        m_tooltip->Position(pt, wxSize(0, 0));
#endif
        // hide any other tooltips
        EditorBase *base = Manager::Get()->GetEditorManager()->GetActiveEditor();
        cbEditor *ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr;
        if (ed && ed->GetControl()->CallTipActive())
            ed->GetControl()->CallTipCancel();

        m_tooltip->Show();
        return true;
    }
}
Esempio n. 15
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("'"));
    }
}
Esempio n. 16
0
void NassiPlugin::BuildModuleMenu(const ModuleType type, wxMenu* menu, 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() || !menu ) return;

    if ( type != mtEditorManager ) 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;

    wxMenu *NassiMenu = 0;

    // check if user can select to generate a diagram from selection
    if ( stc->GetLexer() == wxSCI_LEX_CPP && stc->GetSelectionEnd() - stc->GetSelectionStart() > 0 )
    {
        if (! NassiMenu ) NassiMenu = new wxMenu();
        NassiMenu->Append(idParseC, _("Create diagram"));
    }

    // check if user can insert an opened diagram
    wxArrayString names;
    for ( int i = 0 ; i < Manager::Get()->GetEditorManager()->GetEditorsCount() ; ++i )
    {
        EditorBase *ed = Manager::Get()->GetEditorManager()->GetEditor( i );
        if ( NassiEditorPanel::IsNassiEditor( ed ) )
            names.Add(ed->GetTitle( ) );
    }
    if ( stc->GetLexer() == wxSCI_LEX_CPP && names.GetCount() > 0 )
    {
        if (! NassiMenu )
        {
            NassiMenu = new wxMenu();
        }
        else
        {
            NassiMenu->AppendSeparator();
        }

        for ( int i = 0; i < static_cast<int>(names.GetCount()) && i < 10 ; ++i )
        {
            NassiMenu->Append(insertCFromDiagram[i], _("insert from ") + names[i] );
        }
    }


    if ( NassiMenu )
    {
        menu->AppendSeparator();
        menu->AppendSubMenu(NassiMenu, _("Nassi Shneiderman"));
    }

}
void SpellCheckerPlugin::OnEditorTooltip(CodeBlocksEvent& event)
{
    if (   !IsAttached() || wxGetKeyState(WXK_CONTROL)
        || !(m_sccfg->GetEnableSpellTooltips() || m_sccfg->GetEnableThesaurusTooltips()))
    {
        event.Skip();
        return;
    }
    EditorBase* base = event.GetEditor();
    cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : 0;
    if (   !ed || ed->IsContextMenuOpened()
        || wxWindow::FindFocus() != static_cast<wxWindow*>(ed->GetControl()) )
    {
        event.Skip();
        return;
    }
    cbStyledTextCtrl* stc = ed->GetControl();
    if (!stc)
        return;
    int pos = stc->PositionFromPointClose(event.GetX(), event.GetY());
    if (pos < 0 || pos >= stc->GetLength())
    {
        event.Skip();
        return;
    }

    wxString tip;
    int wordstart = pos, wordend = pos;
    while (wordstart)
    {
        if ( m_pSpellHelper->IsWhiteSpace( stc->GetCharAt(wordstart - 1) ) )
            break;
        --wordstart;
    }
    while ( wordend < stc->GetLength() )
    {
        if ( m_pSpellHelper->IsWhiteSpace( stc->GetCharAt(++wordend) ) )
            break;
    }
    int tipWidth = 0;
    if (   m_sccfg->GetEnableSpellTooltips()
        && m_pSpellChecker->IsInitialized()
        && stc->IndicatorValueAt(m_pOnlineChecker->GetIndicator(), pos))
    {
        // indicator is on -> check if we can find a suggestion
        wxString misspelledWord = stc->GetTextRange(wordstart, wordend);
        m_suggestions = m_pSpellChecker->GetSuggestions(misspelledWord);
        if (!m_suggestions.IsEmpty())
        {
            // allow maximum 12 entries in 3 rows
            int lineWidth = 0;
            for (size_t i = 0; i < 12 && i < m_suggestions.size(); ++i)
            {
                tip << m_suggestions[i];
                lineWidth += m_suggestions[i].Length();
                if (i % 4 == 3)
                {
                    tip << wxT(",\n");
                    if (lineWidth > tipWidth)
                        tipWidth = lineWidth;
                    lineWidth = 0;
                }
                else
                {
                    tip << wxT(", ");
                    lineWidth += 2;
                }
            }
            tip.RemoveLast(2);
            lineWidth -= 2;
            if (lineWidth > tipWidth) // in case the last line was not full, and thereby not checked
                tipWidth = lineWidth;
        }
    }
    else if (   m_sccfg->GetEnableThesaurusTooltips()
             && m_pThesaurus->IsOk()
             && m_pSpellHelper->HasStyleToBeChecked(ed->GetColourSet()->GetLanguageName(ed->GetLanguage()), event.GetInt()))
    {
        wxString word = stc->GetTextRange(wordstart, wordend);
        synonyms syn = m_pThesaurus->GetSynonyms(word);
        if (!syn.size()) // if not found, try lower case
            syn = m_pThesaurus->GetSynonyms(word.Lower());
        if (syn.size())
        {
            wxArrayString usedSyns; // avoid duplicate synonyms
            // allow maximum 12 entries in 4 rows
            synonyms::iterator it = syn.begin();
            for (size_t i = 0; i < 4 && it != syn.end(); ++i, ++it)
            {
                wxString tipLine(it->first + wxT(": "));
                std::vector< wxString > syns = syn[it->first];
                size_t j = 0;
                for (size_t k = 0; k < 3 && j < syns.size(); ++j, ++k)
                {
                    if (usedSyns.Index(syns[j]) == wxNOT_FOUND)
                    {
                        tipLine << syns[j] << wxT(", ");
                        usedSyns.Add(syns[j]);
                    }
                    else
                        --k; // synonym already listed, look for another word
                }
                tipLine.RemoveLast(2);
                if (tipLine.Length() > static_cast<size_t>(tipWidth))
                    tipWidth = tipLine.Length();
                tip << tipLine << wxT("\n");
            }
            tip.RemoveLast();
        }
    }

    if (tip.IsEmpty())
    {
        event.Skip();
        return;
    }

    if (stc->CallTipActive())
        stc->CallTipCancel();
    // calculation from CC
    const int lnStart = stc->PositionFromLine(stc->LineFromPosition(pos));
                  // pos - lnStart   == distance from start of line
                  //  + tipWidth + 1 == projected virtual position of tip end (with a 1 character buffer) from start of line
                  //  - (width_of_editor_in_pixels / width_of_character) == distance tip extends past window edge
                  //       horizontal scrolling is accounted for by PointFromPosition().x
    const int offset = tipWidth + pos + 1 - lnStart -
                       (stc->GetSize().x - stc->PointFromPosition(lnStart).x) /
                       stc->TextWidth(wxSCI_STYLE_LINENUMBER, _T("W"));
    if (offset > 0)
        pos -= offset;
    if (pos < lnStart) // do not go to previous line if tip is wider than editor
        pos = lnStart;

    stc->CallTipShow(pos, tip);
    event.SetExtraLong(1); // notify CC not to cancel this tooltip
    event.Skip();
}
Esempio n. 18
0
// cbEVT_EDITOR_TOOLTIP
void CCManager::OnEditorTooltip(CodeBlocksEvent& event)
{
    event.Skip();

    if (wxGetKeyState(WXK_CONTROL))
        return;

    EditorBase* base = event.GetEditor();
    cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr;
    if (!ed || ed->IsContextMenuOpened())
        return;

    cbStyledTextCtrl* stc = ed->GetControl();
    cbCodeCompletionPlugin* ccPlugin = GetProviderFor(ed);
    int pos = stc->PositionFromPointClose(event.GetX(), event.GetY());
    if (!ccPlugin || pos < 0 || pos >= stc->GetLength())
    {
        if (stc->CallTipActive() && event.GetExtraLong() == 0 && m_CallTipActive == wxSCI_INVALID_POSITION)
            static_cast<wxScintilla*>(stc)->CallTipCancel();
        return;
    }

    int hlStart, hlEnd, argsPos;
    hlStart = hlEnd = argsPos = wxSCI_INVALID_POSITION;
    bool allowCallTip = true;
    const std::vector<cbCodeCompletionPlugin::CCToken>& tokens = ccPlugin->GetTokenAt(pos, ed, allowCallTip);
    std::set<wxString> uniqueTips;
    for (size_t i = 0; i < tokens.size(); ++i)
        uniqueTips.insert(tokens[i].displayName);
    wxStringVec tips(uniqueTips.begin(), uniqueTips.end());

    const int style = event.GetInt();
    if (!tips.empty())
    {
        const int tknStart = stc->WordStartPosition(pos, true);
        const int tknEnd   = stc->WordEndPosition(pos,   true);
        if (tknEnd - tknStart > 2)
        {
            for (size_t i = 0; i < tips[0].Length(); ++i)
            {
                size_t hlLoc = tips[0].find(stc->GetTextRange(tknStart, tknEnd), i);
                if (hlLoc == wxString::npos)
                    break;
                hlStart = hlLoc;
                hlEnd = hlStart + tknEnd - tknStart;
                if (   (hlStart > 0 && (tips[0][hlStart - 1] == wxT('_') || wxIsalpha(tips[0][hlStart - 1])))
                    || (hlEnd < static_cast<int>(tips[0].Length()) - 1 && (tips[0][hlEnd] == wxT('_') || wxIsalpha(tips[0][hlEnd]))) )
                {
                    i = hlEnd;
                    hlStart = hlEnd = wxSCI_INVALID_POSITION;
                }
                else
                    break;
            }
        }
    }
    else if (  allowCallTip
             && !(   stc->IsString(style)
                  || stc->IsComment(style)
                  || stc->IsCharacter(style)
                  || stc->IsPreprocessor(style) ) )
    {
        const int line = stc->LineFromPosition(pos);
        if (pos + 4 > stc->PositionFromLine(line) + (int)ed->GetLineIndentString(line).Length())
        {
            const CallTipVec& cTips = ccPlugin->GetCallTips(pos, style, ed, argsPos);
            for (size_t i = 0; i < cTips.size(); ++i)
                tips.push_back(cTips[i].tip);
            if (!tips.empty())
            {
                hlStart = cTips[0].hlStart;
                hlEnd   = cTips[0].hlEnd;
            }
        }
    }
    if (tips.empty())
    {
        if (stc->CallTipActive() && event.GetExtraLong() == 0 && m_CallTipActive == wxSCI_INVALID_POSITION)
            static_cast<wxScintilla*>(stc)->CallTipCancel();
    }
    else
    {
        DoShowTips(tips, stc, pos, argsPos, hlStart, hlEnd);
        event.SetExtraLong(1);
    }
    m_CallTipActive = wxSCI_INVALID_POSITION;
}