Author Topic: how to forbid a refresh when a tree item get double clicked  (Read 20771 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
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.



I found this behavior comes from these code:

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.

Code
	EVT_TREE_ITEM_ACTIVATED(XRCID("treeMembers"), ClassBrowser::OnTreeItemDoubleClick) 


EVT_TREE_ITEM_ACTIVATED(XRCID("treeAll"), ClassBrowser::OnTreeItemDoubleClick)        

Any comments?

Thanks.

« Last Edit: June 14, 2009, 06:55:53 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: how to forbid a refresh when a tree item get double clicked
« Reply #1 on: June 14, 2009, 08:46:03 pm »
Or, we can supply a separate handler, because currently, both treeAll and treemembers share this handler.
Any comments?
This sounds most convenient to me. :-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: how to forbid a refresh when a tree item get double clicked
« Reply #2 on: June 14, 2009, 09:01:45 pm »
This does only happen, if the view is "Current files's symbols".

And what's more, if I see it right, it does not happen in new CC, what's currently in testing phase.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #3 on: June 15, 2009, 04:11:49 am »
thanks for alll the replies!

This does only happen, if the view is "Current files's symbols".

Yes, seems it only affects the "current files's symbols"
Quote
And what's more, if I see it right, it does not happen in new CC, what's currently in testing phase.

I have just download and build the AUI_branch(windows MinGW), but I found this issue still happens there. :(





If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: how to forbid a refresh when a tree item get double clicked
« Reply #4 on: June 15, 2009, 06:42:36 am »
I have just download and build the AUI_branch(windows MinGW), but I found this issue still happens there. :(

That's because the new CC-code is not (yet) in any branch.

By the way, the issue only appears (at least for me), if the double-clicked token is in another file (normally the header or source file with the same basename).

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #5 on: June 20, 2009, 03:27:39 pm »
@Jens:

Where can I find the new CC code (patch)? I would like to test them :D

BTW:
Why the scrollingdialog patch were still not applied in trunk? I think it is quite useful? Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: how to forbid a refresh when a tree item get double clicked
« Reply #6 on: June 22, 2009, 06:57:37 am »
Where can I find the new CC code (patch)? I would like to test them :D
I'll put it into SVN once the wxAUI merge is done.
I believe meanwhile I am the only one maintaining all the mods for CC.

Why the scrollingdialog patch were still not applied in trunk? I think it is quite useful? Thanks.
...which one? If you mean the huge one of Jens he explained in the thread why this most likely won't e applied. (Although I don't recall myself now...) :lol:
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #7 on: June 22, 2009, 08:15:01 am »
Where can I find the new CC code (patch)? I would like to test them :D
I'll put it into SVN once the wxAUI merge is done.
I believe meanwhile I am the only one maintaining all the mods for CC.
I'm ready for testing :D, once it is in SVN.

Quote
...which one? If you mean the huge one of Jens he explained in the thread why this most likely won't e applied.
The one in this post:
http://forums.codeblocks.org/index.php/topic,10594.msg72683.html#msg72683

And the thread:
http://forums.codeblocks.org/index.php/topic,10124.0.html
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #9 on: July 07, 2009, 02:26:29 pm »
Where can I find the new CC code (patch)? I would like to test them :D
I'll put it into SVN once the wxAUI merge is done.
I believe meanwhile I am the only one maintaining all the mods for CC.

Why the scrollingdialog patch were still not applied in trunk? I think it is quite useful? Thanks.
...which one? If you mean the huge one of Jens he explained in the thread why this most likely won't e applied. (Although I don't recall myself now...) :lol:

I'm grad to see that the wxAUI branch is merged to trunk!

So, I'm grad that the new CC code will be added and tested!

Thanks to all the devs!!!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: how to forbid a refresh when a tree item get double clicked
« Reply #10 on: July 07, 2009, 04:18:16 pm »
So, I'm grad that the new CC code will be added and tested!
This is already done in a new branch called "codecompletion_refactoring" -> feel free to try...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #11 on: July 08, 2009, 08:01:30 am »
So, I'm grad that the new CC code will be added and tested!
This is already done in a new branch called "codecompletion_refactoring" -> feel free to try...
@Macfly
Thanks
I checked out the new CC branch, but failed on compiling.
see the log in this post:
http://forums.codeblocks.org/index.php/topic,10813.0.html
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #12 on: July 08, 2009, 11:53:23 am »
Let's continue my original topic.(I test in new CC branch)

It seems first time, I double click on the entry will still cause a scroll down move(as I stated in my original post).

After that, double click on the entry will keep the tree position. quite strange. :D

Edit:
I find more detailed information:

When I double click on an tree entry, if it will switch the "tab"( for example, from XXX.h to XXX.cpp) , then the tree will get refreshed, but that was by design. :D
« Last Edit: July 08, 2009, 12:17:24 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: how to forbid a refresh when a tree item get double clicked
« Reply #13 on: December 23, 2009, 01:31:25 pm »
This is a reminder, this problem is fixed in the rev 5945.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.