FLTK logo

STR #3406

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | SVN ⇄ GIT ]

STR #3406

Application:FLTK Library
Status:1 - Closed w/Resolution
Priority:3 - Moderate, e.g. unable to compile the software
Scope:2 - Specific to an operating system
Subsystem:MacOS
Summary:Fl_Native_File_Chooser on Mac: not showing pre-selected file
Version:1.4-current
Created By:greg.ercolano
Assigned To:manolo
Fix Version:1.4-current (SVN: v12561)
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:


Name/Time/Date Filename/Size  
 
#1 greg.ercolano
17:41 Sep 25, 2017
fnfc-preselected-file_v1.patch
2k
 
     

Trouble Report Comments:


Name/Time/Date Text  
 
#1 greg.ercolano
15:08 Sep 25, 2017
I noticed examples/nativefilechooser-simple isn't showing the preselected
file in the chooser when it opens.

I can *force* it to work if I hack the src/Fl_Native_File_Chooser_MAC.mm code to do this:

     [(NSSavePanel*)_panel setDirectoryURL:[NSURL URLWithString:@"/var/tmp/foo.txt"]];

..just before the call to runModal.

Not sure how to exactly determine what the code is doing right now,
as I have trouble reading objc code.
 
 
#2 greg.ercolano
17:41 Sep 25, 2017
Attaching a patch that seems to work on the 10.10.5 Mac.

This ensures the file is selected in the browser when it opens for the
following cases:

    1) If preset_file() is set to the absolute path of the existing file
    2) If directory() and preset_file() together form the absolute path of the existing file

Without the patch, the chooser doesn't open with the file preselected.

If the file specified doesn't exist (e.g. dir exists, but file does not),
the patch takes the precaution of falling back to the old behavior that sets
the dir and file separately, ensuring that at least the dir is displayed.
(Without this check, the chooser shows the Documents directory instead)

Note: I'm not an objc programmer, so I'd appreciate peer review. Please
check for proper memory management, and new code in context of existing;
perhaps this code can be simplified.

I used examples/nativefilechooser-simple.cxx, and ran these test cases:

   1) I only set G_chooser->preset_file("/var/tmp/foo.cxx");
      and left G_chooser->directory() unset:
      ..if foo.cxx exists, the chooser shows /var/tmp with foo.cxx selected.
      ..if foo.cxx DOESN'T exist, the chooser opens /var/tmp with nothing selected.

   2) If I only set G_chooser->directory("/var/tmp");
      and left G_chooser->preset_file() unset: the chooser opens /var/tmp.

   3) If I set both of these this way:
      G_chooser->preset_file("foo.cxx");   // just filename
      G_chooser->directory("/var/tmp");    // just dir
      ..then:
      ..if foo.cxx exists, the chooser shows /var/tmp with foo.cxx selected.
      ..if foo.cxx DOESN'T exist, the chooser opens /var/tmp with nothing selected.

   4) If I set both of these this way:
      G_chooser->preset_file("/var/tmp/foo.cxx");  // full path
      G_chooser->directory("/var/tmp");            // directory as well
      ..then:
      ..if foo.cxx exists, the chooser shows /var/tmp with foo.cxx selected.
      ..if foo.cxx DOESN'T exist, the chooser opens /var/tmp with nothing selected.

This is the behavior I'd expect for the above variations of FNFC, which the patch
seems to do.

I'm *Not* sure about other test cases, like how this works with multiselect,
which I don't *think* we support for pre selection.
 
 
#3 manolo
13:44 Nov 13, 2017
Fixed in Subversion repository.

Thanks for the patch which is correct.
I have committed a slightly simplified version of it.
 
 
#4 greg.ercolano
14:08 Nov 13, 2017
Great -- thanks!

I guess I should get a book on Obj-C -- any recommendations?
I try to keep article #1347 handy, but that's not enough ;)
http://www.fltk.org/articles.php?L1347
 
     

Return to Bugs & Features ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.