Fire Fl_File_Browser callback on Enter press

13 views
Skip to first unread message

monocasual laboratories

unread,
Jun 23, 2016, 11:14:34 AM6/23/16
to fltk.general
Hi all,

I was playing with the great Erco's examples on FL_File_Browser usage. What I'm trying to do is to set up a very bare-bone file browser that reacts (i.e. fires its callback) when the user presses Enter key on a selected item OR double clicks on an item.
This is the code so far:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_File_Browser.H>
#include <FL/fl_ask.H>


void callback(Fl_Widget *w, void *data) {
  Fl_File_Browser *fbrow = (Fl_File_Browser*) w;
  int index = fbrow->value();
  if (index > 0) {  
    printf("Selected: %d (%s)\n", index, fbrow->text(index));  // show item's text
  }
}

int main(int argc, char **argv) {
Fl_Window win(300, 200, "Fl_File_Browser with Callback");
Fl_File_Browser fbrow(10, 10, 280, 180);
fbrow.load(".");
fbrow.type(FL_HOLD_BROWSER);
fbrow.callback(callback);
fbrow.when(FL_WHEN_ENTER_KEY);
win.end();
win.show(argc,argv);
return(Fl::run());
}


That code creates a browser that fires the callback on each item change - namely when I move the selection with the arrow keys and, mostly, does nothing when I press Enter.

I guess the causes are to be found in the browser type (FL_HOLD_BROWSER), but FL_MULTI_BROWSER wouldn't fit my needs. Any ideas? 

Thanks in advance

Albrecht Schlosser

unread,
Jun 23, 2016, 6:01:26 PM6/23/16
to fltkg...@googlegroups.com
On 23.06.2016 17:14 monocasual laboratories wrote:

> I was playing with the great Erco's examples on FL_File_Browser usage
> <http://seriss.com/people/erco/fltk/#Fl_File_Browser>. What I'm trying
> to do is to set up a very bare-bone file browser that reacts (i.e. fires
> its callback) when the user presses Enter key on a selected item OR
> double clicks on an item.
> This is the code so far:
...
> That code creates a browser that fires the callback on each item change
> - namely when I move the selection with the arrow keys and, mostly, does
> nothing when I press Enter.
>
> I guess the causes are to be found in the browser type
> (FL_HOLD_BROWSER), but FL_MULTI_BROWSER wouldn't fit my needs. Any ideas?

Hmm, according to your description the given class is close to what you
want to achieve but doesn't react on certain key presses (the Enter key)
as you like. That sounds very much like an occasion to subclass
Fl_File_Browser and write your own handle() method. Did you consider this?

It's hard to tell what your coding and particularly FLTK skills are, so
please ask more (specific) questions if you need other type of help.

Message has been deleted

monocasual laboratories

unread,
Jun 24, 2016, 6:23:23 AM6/24/16
to fltk.general, Albrech...@online.de
Hi Albrecht, I think subclassing FL_File_Browser and create a custom handle() method is the way to go. Thanks for your help! 
Reply all
Reply to author
Forward
0 new messages