Hi Stan,

Not sure I have anything useful to offer at all.
But that has never stopped me in the past, so here goes anyway...

On 10 Oct 2009, at 18:57, [email protected] wrote:

> Now, when "View" is clicked, and the list of files comes into
> view, I'd like to be able to deactivate the ones that don't
> exist (or cannot be opened).  I thought I might do that by checking
> the file status in the callback for the top level menu item, but
> it seems that the callback is invoked not when the item is clicked,
> but when the sub menu is "closed," either by selecting from it
> or by clicking the top level item again.  That's too late :)

Yup. Tricky...
I thought you could hook the CB when the menu was shown, but I just  
tried and it looks very much as of you are right...

OK, here's a nasty idea: make your own menu subclass, and (somehow I  
haven't thought through yet) hook the draw method that exposes the  
menu to trigger your file checks?

> I guess I'm looking for the moral equivalent of when() for
> menu items.   Any ideas on how I might go about this would be
> appreciated.

My best guess (so far) as above...

> Using fltk 1.1.8 on XP at the moment.

Hey! You are exactly the sort of guy we want/need to be trying out  
the 1.1.10 rc...

> The
> following bare bones example is illustrative, I hope.

Yup.


> char const* const filename = "strategy.log";

const correctness does my head in. I think I'd write that as "const  
char* const" to stop the two consts cuddling up like that - but maybe  
that means something different?


> void
> Window::view_cb()
> {
>     int fd = open(filename, O_RDONLY);
>     if(fd >= 0) {
>         filename_->activate();
>         close(fd);
>     }
>     else {
>         filename_->deactivate();
>     }
> }

I think I'd be tempted to use "access" or maybe even "stat" here, for  
fear that (on some platform) attempting to open a non-existent file  
would create it...?

My other idea was to only populate the menu with the names of the  
files found in each subdir (rather than starting with a list then  
marking each entry active/inactive) but I guess that suffers from the  
same problem about how to trigger that action... Also, I guess you  
are doing something like a "Recent Files" list and you want to mark  
which ones are still present...?

Cheers,
-- 
Ian





_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to