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 think the problem here was the case, that the file was modified from externally. Then, you don't know where you are, the content could have been change completely. Thus, the toolbar better does a refresh.
Quote from: MortenMacFly on December 21, 2012, 08:46:13 AM
...I think the problem here was the case, that the file was modified from externally. Then, you don't know where you are, the content could have been change completely. Thus, the toolbar better does a refresh.
I don't think this is related to my original question.
Currently, I think if I can detect the click (caret position) remains in the same function body, we don't need to update the toolbar. If you see your screen carefully, you will see it refresh everytime when you click the caret(event in the same function body).
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.
Quote from: oBFusCATed on February 04, 2013, 11:55:34 AM
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)
Look at the refresh logic in the most recent patch in my queue; some of it probably would be applicable here as well.
Quote from: Alpha on February 04, 2013, 04:09:53 PM
Look at the refresh logic in the most recent patch in my queue; some of it probably would be applicable here as well.
CCsemant4.patch? (see attachment if other forum user want to test)
CC's toolbar have mainly two functions:
1, if the user select a function (wxChoice), then the caret will jump to the selected function in the editor.
2, if the user move the caret in the editor, the toolbar(wxChoice) should be updated to indicate which function was the caret located in.
I think the above "2" currently cause the lag, and should be optimized, I mean, if the user move the caret in the same function scope. (a function body usually contains a starting brace line and the closing brace line), we don't need to update the wxChoice.