Author Topic: Close file tab on middle-click  (Read 7104 times)

Offline DaKaLKa

  • Single posting newcomer
  • *
  • Posts: 8
Close file tab on middle-click
« on: October 12, 2005, 10:14:15 pm »
I started to look on the C::B-Code and want to add a feature.
I just want to add that middle-click on files-tabs close the file, so i made a

Code
m_pNotebook->Connect(wxEVT_MIDDLE_UP, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &EditorManager::OnMouseMiddleNotebook);

in the editormanager.cpp and add the OnMouseMiddleNotebook in EditorManager.
Everything was ok, but then i tried to implement the function, with this code
Code
void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
index = GetNotebook()->HitTest(event.GetPosition());
   if(index != wxNOT_FOUND){
      QueryClose(GetEditor(index));
   }
}
But when i run c::b and click on the file-tab, c::b crash.

I tried some modified code, but it seems, that "HitTest" crash.
I'm using wxWidget 2.6.2, MinGW (ported with c::b) and WinXP.
I'm just started using wxWidgets, is something wrong in my code?

Hope this is the right board to post such a message
See codeblocks.txt for stack dump.

Thx, DaKaLKa



[attachment deleted by admin]

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Close file tab on middle-click
« Reply #1 on: October 12, 2005, 10:46:17 pm »
The function looks ok, even though it boldly assumes that all pointers returned are valid.
However, if you can see a file tab, then you can assume that there is a notebook, fair enough.

Have you tried writing index to the debug console?
Maybe HitTest returns garbage (off by one, possibly? Try opening 3 documents, and click on the middle one - if the wrong document closes, you know). If index is garbage, then GetEditor() returns a null pointer.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline DaKaLKa

  • Single posting newcomer
  • *
  • Posts: 8
Re: Close file tab on middle-click
« Reply #2 on: October 13, 2005, 11:34:37 am »
I've changed my code to
Code
void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
    wxPoint pt = event.GetPosition();
    Manager::Get()->GetMessageManager()->DebugLog("X : %d Y : %d \n", pt.x,pt.y);
    Manager::Get()->GetMessageManager()->DebugLog("Start HitTest!",index);
    int pageNr = m_pNotebook->HitTest (pt);
    Manager::Get()->GetMessageManager()->DebugLog("HitTest completed!",index);
return;
But it seems, that there is a problem with HitTest, C::B crash just after "Start HitTest!" is printed in debug-log.
Very strange.
Has anybody an idea?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close file tab on middle-click
« Reply #3 on: October 13, 2005, 12:01:05 pm »
Try this:

Code
void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
    wxPoint pt = event.GetPosition();
    Manager::Get()->GetMessageManager()->DebugLog("X : %d Y : %d \n", pt.x,pt.y);
    Manager::Get()->GetMessageManager()->DebugLog("Start HitTest!");
    int pageNr = m_pNotebook->HitTest (pt);
    Manager::Get()->GetMessageManager()->DebugLog("HitTest completed: %d",pageNr);
event.Skip();
Be patient!
This bug will be fixed soon...

Offline DaKaLKa

  • Single posting newcomer
  • *
  • Posts: 8
Re: Close file tab on middle-click
« Reply #4 on: October 13, 2005, 03:23:51 pm »
Thanks, I've tried "event.Skip()", but it still crash  :cry:
I even tried m_pNotebook->HitTest(wxPoint(0,0)), but it still crashed when calling HitTest.
Has somebody the same behaviour?
Thx,

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Close file tab on middle-click
« Reply #5 on: October 13, 2005, 03:29:18 pm »
event.Skip() wasn't the only change. I hope you noticed it...
Be patient!
This bug will be fixed soon...

Offline DaKaLKa

  • Single posting newcomer
  • *
  • Posts: 8
Re: Close file tab on middle-click
« Reply #6 on: October 13, 2005, 05:34:47 pm »
Ahh, i didn't notice them, but i just copy-and-paste your code so i also copied all your changes.
BTW, i played a little bit with the wxWidgets-Samples which also use wxNotebook, but every time i try to rum "HitTest", the sample crashes also.
After that I've build wxWidgets as debug-build and link the samples against it, but still the same problem and the stack-dump go deeply into the wxWidgets source-code.
So I think this is a wxWidget Bug, (or feature  :D) Maybe I find something about it in the wxWidgets forums.

Thx for your effort.

Offline Florianx

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Close file tab on middle-click
« Reply #7 on: October 13, 2005, 05:37:59 pm »
I can't help you with your problem, but the future, you wan't to add, is included in my little plugin:
http://forums.codeblocks.org/index.php?topic=1005
Perphaps you find the solution for your problem in my code, or simply use my plugin :D

Offline DaKaLKa

  • Single posting newcomer
  • *
  • Posts: 8
Re: Close file tab on middle-click
« Reply #8 on: October 13, 2005, 06:27:27 pm »
Just found your plugin some minutes ago and try to compile and use it - sounds good.  :D