I just enable the debug log in codecompletion.cpp
#define CC_CODECOMPLETION_DEBUG_OUTPUT 1
I see that the CC toolbar get refreshed many times if I click in the same function body.
E.g.
wxString func()
{
wxString rv;
rv += wxT('a'); //*** first step: click here
rv += wxT('b');
rv += wxT('c'); //*** second step: click here
return rv;
}
Here, the click is all in the same function body, but I see that the function:
void CodeCompletion::ParseFunctionsAndFillToolbar()
called multiply times.
Is that necessary? We don't need to refresh the toolbar if we click in the same function body.
void CodeCompletion::EditorEventHook(cbEditor* editor, wxScintillaEvent& event)
{
.....
.....
if (control->GetCurrentLine() != m_CurrentLine)
{
if (m_NeedReparse)
{
TRACE(_T("EditorEventHook: Starting m_TimerRealtimeParsing."));
m_TimerRealtimeParsing.Start(REALTIME_PARSING_DELAY, wxTIMER_ONE_SHOT);
m_CurrentLength = control->GetLength();
m_NeedReparse = false;
}
if (event.GetEventType() == wxEVT_SCI_UPDATEUI)
{
m_ToolbarNeedRefresh = true;
TRACE(_T("EditorEventHook: Starting m_TimerToolbar."));
if (m_TimerEditorActivated.IsRunning())
m_TimerToolbar.Start(EDITOR_ACTIVATED_DELAY + 1, wxTIMER_ONE_SHOT);
else
m_TimerToolbar.Start(TOOLBAR_REFRESH_DELAY, wxTIMER_ONE_SHOT);
}
}
// allow others to handle this event
event.Skip();
}
Look, this value is force to be true m_ToolbarNeedRefresh = true;
, even we have later set it to false.
void CodeCompletion::ParseFunctionsAndFillToolbar()
{
.....
.....
// Does the toolbar need a refresh?
if (m_ToolbarNeedRefresh || m_LastFile != filename)
{
// Update the last editor and changed flag...
if (m_ToolbarNeedRefresh)
m_ToolbarNeedRefresh = false;
if (m_LastFile != filename)
{
TRACE(_T("ParseFunctionsAndFillToolbar() : Update last file is %s"), filename.wx_str());
m_LastFile = filename;
}
// ...and refresh the toolbars.
m_Function->Clear();
if (m_Scope)
{
m_Scope->Freeze();
m_Scope->Clear();
// add to the choice controls
for (unsigned int idxSc = 0; idxSc < m_ScopeMarks.size(); ++idxSc)
{
int idxFn = m_ScopeMarks[idxSc];
const FunctionScope& fs = m_FunctionsScope[idxFn];
m_Scope->Append(fs.Scope);
}
m_Scope->Thaw();
}
else
{
m_Function->Freeze();
for (unsigned int idxFn = 0; idxFn < m_FunctionsScope.size(); ++idxFn)
{
const FunctionScope& fs = m_FunctionsScope[idxFn];
m_Function->Append(fs.Scope + fs.Name);
}
m_Function->Thaw();
}
}
// Find the current function and update
FindFunctionAndUpdate(ed->GetControl()->GetCurrentLine());
// Control the toolbar state
EnableToolbarTools(fileParseFinished);
}
Look:
if (m_ToolbarNeedRefresh)
m_ToolbarNeedRefresh = false;
Here m_ToolbarNeedRefresh = false;
in this function, but as I can see, this member variable is always be set in the editor hook handler (CodeCompletion::EditorEventHook).
I've just had slowness, probably caused by the toolbar in one of the larger files of C::B, probably codecompletion.cpp.
No external files has have been modified, but every move of the cursor caused a slowdown and a flicker of the toolbar.
OK, you confirm the bug, thanks.
As I said before, the reason is: the toolbar's contents(wxChoice's contents) were always calculated and refreshed in the editor hook function, after
if (event.GetEventType() == wxEVT_SCI_UPDATEUI)