Hi, I found an issue( In fact, I have reported in http://forums.codeblocks.org/index.php/topic,9873.msg69760.html#msg69760, but nobody give any response :(. This is really an annoying issue!)
When I double click on a tree item in the CodeCompletion's classbrowser, then the tree control will get refreshed, meanwhile the scroll bar will go down to the bottom of the window.
(http://sites.google.com/site/studycodeblocks/imagescb/cbreflash.png)
I found this behavior comes from these code:
void ClassBrowser::OnTreeItemDoubleClick(wxTreeEvent& event)
{
wxTreeCtrl* tree = (wxTreeCtrl*)event.GetEventObject();
wxTreeItemId id = event.GetItem();
CBTreeData* ctd = (CBTreeData*)tree->GetItemData(id);
if (ctd && ctd->m_pToken)
{
if (wxGetKeyState(WXK_CONTROL) && wxGetKeyState(WXK_SHIFT))
{
CCDebugInfo info(tree, m_pParser, ctd->m_pToken);
info.ShowModal();
return;
}
cbProject* prj = Manager::Get()->GetProjectManager()->GetActiveProject();
if (prj)
{
bool toImp = false;
switch (ctd->m_pToken->m_TokenKind)
{
case tkConstructor:
case tkDestructor:
case tkFunction:
if (ctd->m_pToken->m_ImplLine != 0 && !ctd->m_pToken->GetImplFilename().IsEmpty())
toImp = true;
break;
default:
break;
}
wxString base = prj->GetBasePath();
wxFileName fname;
if (toImp)
fname.Assign(ctd->m_pToken->GetImplFilename());
else
fname.Assign(ctd->m_pToken->GetFilename());
NormalizePath(fname, base);
cbEditor* ed = Manager::Get()->GetEditorManager()->Open(fname.GetFullPath());
if (ed)
{
int line;
if (toImp)
line = ctd->m_pToken->m_ImplLine - 1;
else
line = ctd->m_pToken->m_Line - 1;
ed->GotoLine(line);
// // try to move the caret on the exact token
// int lineOffset = ed->GetControl()->GetCurLine().Find(ctd->m_pToken->m_Name);
// if (lineOffset != wxNOT_FOUND)
// {
// int pos = ed->GetControl()->PositionFromLine(line) + lineOffset;
// ed->GetControl()->GotoPos(pos);
// // select the token
// int posend = ed->GetControl()->WordEndPosition(pos, true);
// ed->GetControl()->SetSelection(pos, posend);
// }
wxFocusEvent ev(wxEVT_SET_FOCUS);
ev.SetWindow(this);
#if wxCHECK_VERSION(2, 9, 0)
ed->GetControl()->GetEventHandler()->AddPendingEvent(ev);
#else
ed->GetControl()->AddPendingEvent(ev);
#endif
}
}
}
}
Since after running this function, the whole panel will get refreshed, then UpdateView() will be called.
In UpdateView(), precisely in the function void ClassBrowser::BuildTree(), the "treeMembers" TreeCtrl will be rebuild from a ClassBrowserBuilderThread.
Then after the tree was reconstructed, the Scroll bar will slip down to the bottom of that window.
So, my suggestion is:
If I can forbid a refresh event after doubleclick, the "treemembers" TreeCtrl would keep its position.
Or, we can supply a separate handler, because currently, both treeAll and treemembers share this handler.
EVT_TREE_ITEM_ACTIVATED(XRCID("treeMembers"), ClassBrowser::OnTreeItemDoubleClick)
EVT_TREE_ITEM_ACTIVATED(XRCID("treeAll"), ClassBrowser::OnTreeItemDoubleClick)
Any comments?
Thanks.