Recent

Author Topic: Additional Filedialog options for opening .app bundles and title caption  (Read 188 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 762
  • Tweaking4All.com
    • Tweaking4All
Wanting to go into .app bundles with File Dialogs (OpenFile, SaveFile, SelectDirectory), I modified the Dialogs a little bit and I'm sure others might have a use for this as well.
As an example: The "Configure External Tools" in the IDE will not allow you to select an executable that resides in an .APP bundle (needed to pass parameters).
Additionally wanted to add a title to the file dialogs, so there is that as well.

Would love to submit this, just not sure how to do it, and I'm sure someone more experienced may want to take a look at it first.
These changes add two options to OptionsEx for OpenFileDialog, SaveFileDialog and SelectDirectoryDialog dialogs.

1) ofMacOSAllowBrowseAppBundle

Allows the user to browse into App bundles as if they were directories.

2) ofMacOSUseAlternativeTitle

Displays a title (using the Title property of the file dialog), since setTitle() doesn't do anything as of macOS 10.15.
Since titles seem not often used in newer macOS versions, I figured this should be an option instead of a default.
Maybe I'm wrong 😉

Changes
 
In /lcl/dialogs.pp, around line 219 Added : ofMacOSAllowBrowseAppBundle and ofMacOSUseAlternativeTitle.
There are already quite a few OS specific options (XP and Vista), so why not add two for macOS.

Code: Pascal  [Select][+][-]
  1.   TOpenOptionEx = (
  2.     ofHidePinnedPlaces,         // Windows Vista+: Hide items shown by default in the view's navigation pane.
  3.     ofStrictFileTypes,          // Windows Vista+: In the Save dialog, only allow the user to choose a file that has one of the file name extensions specified through Filter property.
  4.     ofPickFolders,              // Windows Vista+: Turns the dialog into a TSelectDirectoryDialog.
  5.     ofOkButtonNeedsInteraction, // Windows Vista+: The OK button will be disabled until the user navigates the view or edits the filename (if applicable).
  6.     ofForceFileSystem,          // Windows Vista+: Ensures that returned items are file system items.
  7.     ofAllNonStorageItems,       // Windows Vista+: Enables the user to choose any item in the Shell namespace, not just those with SFGAO_STREAM or SFAGO_FILESYSTEM attributes. Flag cannot be combined with ofForceFileSystem.
  8.     ofUseXPStyleAsFallBack,     // Windows Vista+: Use XP-style dialog if creating Vista-style dialog fails (e.g. when running under Windows Recovery).
  9.     ofMacOSAllowBrowseAppBundle,// macOS: All browsing .App bundles
  10.     ofMacOSUseAlternativeTitle  // macOS: Display a title in the dialog window
  11.     // Intentionally not supported: ofDefaultNoMiniMode, ofHideMruPlaces: these values are not supported as of Windows 7.
  12.   );
 
 
And in /lcl/interfaces/cocoa/cocoawsdialogs.pas added around 480 (TCocoaWSFileDialog.ShowModal)

 
Code: Pascal  [Select][+][-]
  1.       openDlg.setTreatsFilePackagesAsDirectories(ofMacOSAllowBrowseAppBundle in TSelectDirectoryDialog(FileDialog).OptionsEx);
  2.       openDlg.setAccessoryView(nil);
  3.  
  4.       if ofMacOSUseAlternativeTitle in TSelectDirectoryDialog(FileDialog).OptionsEx then
  5.       begin
  6.         openDlg.setMessage(NSSTR(FileDialog.Title));       // works macOS 10.15+
  7.         openDlg.setTitleVisibility(0);
  8.       end;


 
Code: Pascal  [Select][+][-]
  1.       openDlg.setTreatsFilePackagesAsDirectories(ofMacOSAllowBrowseAppBundle in TOpenDialog(FileDialog).OptionsEx);
  2.       openDlg.setAccessoryView(nil);
  3.  
  4.       if ofMacOSUseAlternativeTitle in TOpenDialog(FileDialog).OptionsEx then
  5.       begin
  6.         openDlg.setMessage(NSSTR(FileDialog.Title));       // works macOS 10.15+
  7.         openDlg.setTitleVisibility(0);
  8.       end;


 
Code: Pascal  [Select][+][-]
  1.     saveDlg.setTreatsFilePackagesAsDirectories(ofMacOSAllowBrowseAppBundle in TSaveDialog(FileDialog).OptionsEx);
  2.  
  3.     if ofMacOSUseAlternativeTitle in TSaveDialog(FileDialog).OptionsEx then
  4.     begin
  5.       openDlg.setMessage(NSSTR(FileDialog.Title));       // works macOS 10.15+
  6.       openDlg.setTitleVisibility(0);
  7.     end;                                                    
                                                                     


It was quite a pain to figure out how to even make a patch file (added "how to make a patch for uncommitted changes" to the Wiki page), and I'm not even sure I did this the right way.
So any input/assistance would be greatly appreciated.

Attached the patch file I created based on Lazarus 4.99 (rev main_4_99-2821-gcab4db5c42) FPC 3.3.1 x86_64-darwin-cocoa.
The Laz hash of the trunk version I'm running should be "cab4db5c42" according to FPCUpDeluxe (had trouble building a more recent Lazarus trunk version).

Also attached a screenshot with and without a title caption in the file dialog.

Please let me know what you guys think 😊


Bart

  • Hero Member
  • *****
  • Posts: 5674
    • Bart en Mariska's Webstek
Re: Additional Filedialog options for opening .app bundles and title caption
« Reply #1 on: January 13, 2026, 06:41:19 pm »
Please file a feature request in the bugtracker.
Attach a diff containing the changes.

I would ask to remove the "Mac" from the start of the properties.
The comments that this is Mac only should suffice.

I'll ask Rich to look at the implementation then (I have no Mac).

Bart

Hansaplast

  • Hero Member
  • *****
  • Posts: 762
  • Tweaking4All.com
    • Tweaking4All
Re: Additional Filedialog options for opening .app bundles and title caption
« Reply #2 on: January 13, 2026, 07:39:28 pm »
Thanks Bart! 😊

Posted it in Bugtracker: [urlhttps://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/42001]issues 42001[/url].

As for leaving MacOS out of it, I can image it to be confusing for non-Mac users.
But you're right, if the comment already clarify this (had not even noticed them haha).
I'll leave that choice up to you guys (happy to do the change of course).

 

TinyPortal © 2005-2018