wxDirTraverser Issues

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Stewie
Earned a small fee
Earned a small fee
Posts: 21
Joined: Wed Sep 02, 2009 7:04 pm
Location: Western Canada

wxDirTraverser Issues

Post by Stewie » Sat Oct 10, 2009 8:48 pm

I currently have a wxDirTraverser that searches a client's specified folder for a list of matching files for his use. However, if the client should realize that he has typed in the wrong criterion, and is searching, say, the entire C: drive, I would like for him to be able to stop searching.

So, using Yield() and setting up a Stop button, I set a class variable called "m_TerminateSearch" to true. If the Traverser detects that this is true, it returns wxDIR_STOP using this code:

Code: Select all

if (wxGetApp().m_TerminateSearch) {
	wxGetApp().Yield();
	return wxDIR_STOP;
}
However, when I hit the Stop button (or set m_TerminateSearch to true in any way), the application freezes for a short while as if it's traversing the rest of the directory anyway. (A quick test confirms that indeed, it does go through the rest of the files anyway.)

How can I force the Traverser to actually STOP searching?

van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user » Mon Oct 12, 2009 9:19 am

Code: Select all

if (wxGetApp().m_TerminateSearch) {
        wxGetApp().Yield();
        return wxDIR_STOP;
}
For what purpose you use Yield( ) here? Maybe this line not need?

Stewie
Earned a small fee
Earned a small fee
Posts: 21
Joined: Wed Sep 02, 2009 7:04 pm
Location: Western Canada

Post by Stewie » Tue Oct 13, 2009 2:19 am

I've tried without as well. I just used that to make sure the program didn't turn to a white screen upon termination. Neither way prevented the freeze-up.

User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 429
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Post by xaviou » Tue Oct 13, 2009 9:03 am

Hi
In your code, the Yield() is called only if wxGetApp().m_TerminateSearch is set to true.

But I think the button event that allow you to stop the search can't be treated, because the app is running, and the search in a too big job.

Try to put the Yield before, and it sould work better :

Code: Select all

wxGetApp().Yield();
if (wxGetApp().m_TerminateSearch) return wxDIR_STOP;
Of course, this will slow you app, so you can do somethind to call this 1 time evvery 10 files founded, for example.

Regards

Xav'
My wxWidgets stuff web page : [email protected]'s wxStuff

Stewie
Earned a small fee
Earned a small fee
Posts: 21
Joined: Wed Sep 02, 2009 7:04 pm
Location: Western Canada

Post by Stewie » Wed Oct 14, 2009 9:46 pm

No luck; putting it before (or after and outside of the statement) had no effect. I also tried removing it entirely, which had no effect either.

Post Reply