Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: ollydbg on December 21, 2012, 07:04:28 am

Title: Time to refresh the CC Toolbar
Post by: ollydbg on December 21, 2012, 07:04:28 am
I just enable the debug log in codecompletion.cpp

Code
#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.
Code
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:
Code
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.
Title: Re: Time to refresh the CC Toolbar
Post by: ollydbg on December 21, 2012, 07:10:45 am
Code
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
Code
m_ToolbarNeedRefresh = true;
, even we have later set it to false.
Code
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:
Code
        if (m_ToolbarNeedRefresh)
            m_ToolbarNeedRefresh = false;
Here
Code
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).
Title: Re: Time to refresh the CC Toolbar
Post by: 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.
Title: Re: Time to refresh the CC Toolbar
Post by: ollydbg on December 21, 2012, 09:06:56 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).
Title: Re: Time to refresh the CC Toolbar
Post by: 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.
Title: Re: Time to refresh the CC Toolbar
Post by: ollydbg on February 04, 2013, 02:49:46 pm
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
Code
if (event.GetEventType() == wxEVT_SCI_UPDATEUI)
Title: Re: Time to refresh the CC Toolbar
Post by: 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.
Title: Re: Time to refresh the CC Toolbar
Post by: ollydbg on February 04, 2013, 04:29:28 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.