Fl_Native_File_Chooser: Both File and Directory

95 views
Skip to first unread message

crocher...@gmail.com

unread,
Aug 22, 2014, 7:50:17 PM8/22/14
to fltkg...@googlegroups.com
Hi everyone,

     I'm using the Fl_Native_File_Chooser to let the user pick a file to open, that's working well. I now would like the user to be able to either open a file (of given types, that I select with the filter method, no problem) or a directory. So far the type() method allow to choose one or the other but not both. Is there a particular reason for that (quickly looking at it I don't see an evident problem about it: you can navigate with double-clicks and click open when it's the directory you want to open or open when a file is selected) ? Does anyone has already faced that problem or tried to implement a version of the Fl_Native_File_Chooser with manage the BOTH (file or directory) option ?

Thanks

Vincent

PS: So far my program have two menu items "Open a file" and "Open a folder" that tweak the Fl_Native_Chooser type and it's working well. I just want to know if I could have a nicer option and keep only one Menu item.

Greg Ercolano

unread,
Aug 22, 2014, 10:07:21 PM8/22/14
to fltkg...@googlegroups.com
On 08/22/14 16:50, crocher...@gmail.com wrote:
> I now would like the user to be able to either open a file or a directory.
> [within the same dialog].
>
> PS: So far my program have two menu items "Open a file" and "Open a folder"
> that tweak the Fl_Native_Chooser type and it's working well. I just want to know
> if I could have a nicer option and keep only one Menu item.

I don't think the FNFC (Fl_Native_File_Chooser) supports this presently.

However, it does look like e.g. the Windows platform can support this:
http://www.codeproject.com/Articles/44914/Select-file-or-folder-from-the-same-dialog

..so feel free to hack FNFC to support this, and if you have success,
send us a patch.

Not sure if the file dialogs on the other platforms support this
(e.g. OSX, Gnome, etc), as historically the platforms seem to have
managed these dialogs separately.


crocher...@gmail.com

unread,
Aug 22, 2014, 10:30:39 PM8/22/14
to fltkg...@googlegroups.com, erco_...@seriss.com
Thanks Greg. I will see if I can hack that (but I have no OSX to test w/ only Windows and GNOME). I will let you know if I'm successful w/ it.

Vincent

MacArthur, Ian (Selex ES, UK)

unread,
Aug 25, 2014, 5:07:59 AM8/25/14
to fltkg...@googlegroups.com
> Thanks Greg. I will see if I can hack that
> (but I have no OSX to test w/ only Windows
> and GNOME). I will let you know if I'm
> successful w/ it.



This is an interesting idea, but I do not think it would be a good idea to build into the fltk library as a default; I am not sure we can make it work consistently in a cross-platform fashion... However, it would be fine in platform specific user code of course.





Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

Vincent C

unread,
Aug 25, 2014, 5:54:25 AM8/25/14
to fltkg...@googlegroups.com
Actually after a first try, implementation on the FLTK chooser was simple and is working well (as a new type of Fl_File_Chooser). But as you say, the plateform specific version is clearly more tricky. For Windows the trick given here: http://www.codeproject.com/Articles/44914/Select-file-or-folder-from-the-same-dialog is ok, but really not elegant. I will look a bit more to see if I can improve that but anyway as you I clearly doubt that it could be consistent across plateform.

Vincent



--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/YhdpxJeTwbc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Ercolano

unread,
Aug 25, 2014, 12:50:18 PM8/25/14
to fltkg...@googlegroups.com
On 08/25/14 02:07, MacArthur, Ian (Selex ES, UK) wrote:
>> Thanks Greg. I will see if I can hack that
>> (but I have no OSX to test w/ only Windows
>> and GNOME). I will let you know if I'm
>> successful w/ it.
>
> This is an interesting idea, but I do not think it would be a good idea to
> build into the fltk library as a default; I am not sure we can make it work
> consistently in a cross-platform fashion... However, it would be fine in
> platform specific user code of course.

Not as a default, but as an option flag to the widget.
i.e. 'FILES_AND_DIRS' that would be a hint to the internals
to try to diddle the native widget into allowing both,
and would be ignored on platforms that don't support it.

The default for such a flag would be off.


crocher...@gmail.com

unread,
Sep 21, 2014, 12:34:59 AM9/21/14
to fltkg...@googlegroups.com, erco_...@seriss.com
To follow up on this idea of having the possibility to select either a file or a directory in the file chooser, here is a first patch to make it work... but only on the FLTK chooser. I was unable to make that working for Windows even with Greg's link (and I haven't look at Mac). So, as suggested, I made it as an OPTION of the Fl_Native_Chooser (OR_DIRECTORY) which is available for the types: Fl_Native_File_Chooser::BROWSE_FILE and Fl_Native_File_Chooser::BROWSE_MULTI_FILE. For the latest it's then possible to select multiple files, multiple directories or combination of both. The option has no effect on the Windows and Mac native choosers so far. 
Treating it as an option (as opposed as a new type) implied to now pass this option to the Fl_File_Chooser.

And sorry, I'm not sure if it's the right place and the right format for the patch...

diff fltk-1.3.2_orig/FL/Fl_File_Chooser.H fltk-1.3.2/FL/Fl_File_Chooser.H
25d24
< #include <stdio.h>
43c42,43
<   enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };
---
>   enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };
>   enum { OR_DIRECTORY = 8 };
51a52
>   int options_;
158a160,161
>   void options(int);
>   int options() const;
diff fltk-1.3.2_orig/FL/Fl_Native_File_Chooser.H fltk-1.3.2/FL/Fl_Native_File_Chooser.H
32d31
< #include <stdio.h>
119c118,119
<     PREVIEW        = 0x0004         ///< enable preview mode
---
>     PREVIEW        = 0x0004,               ///< enable preview mode
>     OR_DIRECTORY   = 0x0008           ///< enable to select either a file(s) or a directory(ies), for BROWSE_FILE and BROWSE_MULTI_FILE types (only supported with the FLTK chooser)
241a242
>   int options_fl_file(int);
diff fltk-1.3.2_orig/src/Fl_File_Chooser2.cxx fltk-1.3.2/src/Fl_File_Chooser2.cxx
353d352
< #include <stdio.h>
746c745
<     if ((type_ & MULTI) && !(type_ & DIRECTORY)) {
---
>     if ((type_ & MULTI) && !(type_ & DIRECTORY) && !(options_ & OR_DIRECTORY)) {
785c784
<     if (!_fl_filename_isdir_quick(pathname) || (type_ & DIRECTORY))
---
>     if ( !_fl_filename_isdir_quick(pathname) || (type_ & DIRECTORY) || ( (!(type_ & CREATE) && !(type_ & DIRECTORY)) && (options_ & OR_DIRECTORY)) )
diff fltk-1.3.2_orig/src/Fl_File_Chooser.cxx fltk-1.3.2/src/Fl_File_Chooser.cxx
23a24
>
70a72
>
422a425,432
> }
>
> void Fl_File_Chooser::options(int val) {
>   options_ = val;
> }
>
> int Fl_File_Chooser::options() const {
>   return(options_);
diff fltk-1.3.2_orig/src/Fl_Native_File_Chooser_FLTK.cxx fltk-1.3.2/src/Fl_Native_File_Chooser_FLTK.cxx
26a27,28
> #define FLTK_OR_DIRECTORY      Fl_File_Chooser::OR_DIRECTORY
>
99a102
>
114a118,126
>
> // PRIVATE: translate Native options to Fl_File_Chooser options
> int Fl_Native_File_Chooser::options_fl_file(int val) {
>   if(val & OR_DIRECTORY)
>       return(FLTK_OR_DIRECTORY);
>   else
>       return 0;
> }
>
129a142
>   _file_chooser->options(options_fl_file(val));



Vincent

Greg Ercolano

unread,
Sep 21, 2014, 1:15:58 PM9/21/14
to fltkg...@googlegroups.com
On 09/20/14 21:34, crocher...@gmail.com wrote:
> To follow up on this idea of having the possibility to select either a file or a directory in the file chooser, here is a first patch to make it work... but only on the FLTK chooser. I was unable to make that working for Windows even with Greg's link (and I haven't look at Mac). So, as suggested, I made it as an OPTION of the Fl_Native_Chooser (OR_DIRECTORY) which is available for the types: Fl_Native_File_Chooser::BROWSE_FILE and Fl_Native_File_Chooser::BROWSE_MULTI_FILE. For the latest it's then possible to select multiple files, multiple directories or combination of both. The option has no effect on the Windows and Mac native choosers so far.
> Treating it as an option (as opposed as a new type) implied to now pass this option to the Fl_File_Chooser.
>
> And sorry, I'm not sure if it's the right place and the right format for the patch...
>
> |
> diff fltk-1.3.2_orig/FL/Fl_File_Chooser.H fltk-1.3.2/FL/Fl_File_Chooser.H
> 25d24

It's fine to ask here.. what is best:

FLTK CORE DISCUSSIONS

To /discuss/ patches to fltk, it's probably best to post them on fltk.coredev,
as that group is for discussing core development of the fltk library.

If you have a patch that you think is really ready for FLTK, and probably
won't need much discussion, then go straight for making an RFE
(Request For Enhancement) using the STR bug report page here:
http://www.fltk.org/str.php
..so that patches won't get lost in the noise of the forum.
(Just click on 'Submit Bug or Feature Request', and in the form
change the "Priority" to "Request for enhancement".)

PATCH FORMAT

When creating patches using diff(1), it's best to use 'diff -Naur', e.g.

diff -Naur FL/Fl_File_Chooser.H.orig FL/Fl_File_Chooser.H

..where the first file is the original, and the second is your mods.
This way + indicates added lines, and - indicates removed lines.

You can just redirect the output of that diff -Naur command to a
foo.patch file, and attach to either a forum post or the RFE forms.
By including it as an attachment, it ensures your mail program won't
word wrap the contents.

Or, if you checked out FLTK code from svn, you can just make your mods
directly to the fltk code, and then send us the output of 'svn diff', e.g.

svn diff FL/Fl_File_Chooser.H

..which provides a patch in 'diff -Naur' format for the file you modified
against the original checked out code. You can then redirect that output
to a file (e.g. foo.patch) and attach.

The 'diff -Naur' format is compatible with patch(1), so that the patch
can be applied to even evolving code. (The default behavior of diff(1)
doesn't use the easier to read +/- format, and isn't good for patch(1))

MacArthur, Ian (Selex ES, UK)

unread,
Oct 1, 2014, 5:44:51 AM10/1/14
to fltkg...@googlegroups.com

> To follow up on this idea of having the possibility
> to select either a file or a directory in the file
> chooser, here is a first patch to make it work...

To be honest, I don't think we can make this fly across platforms, so it is unlikely to get into the core.

It does seem like the sort of thing that might be handy as an add-on widget though.

Note that the FNFC was originally an add-on widget too, so that's a good example to follow!



> And sorry, I'm not sure if it's the right
> place and the right format for the patch...

Patches are usually in "unified diff" format, so this is the "wrong" format, though I think recent versions of patch are smart enough to cope?

As to location, posting it against an STR would likely be a better option - see the STR pages on the website for details.

crocher...@gmail.com

unread,
Oct 3, 2014, 2:14:08 AM10/3/14
to fltkg...@googlegroups.com, ian.ma...@selex-es.com
Actually I didn't repost anything here but I did submit it as an str with the right diff format here: http://www.fltk.org/str.php?L3136+P0+S-2+C0+I0+E0+Qkennyyy .

Vincent
Reply all
Reply to author
Forward
0 new messages