Skip to content

Simplified NSOpenPanel and NSSavePanel Delphi bridge using MacApi default units #DelphiCocoaFlavored

Notifications You must be signed in to change notification settings

LilyStilson/Macapi.Dialogs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

Macapi.Dialogs

Simplified NSOpenPanel and NSSavePanel Delphi bridge using MacApi default units #DelphiCocoaFlavored

Lily Stilson // 2019 - 2020


Usage

This unit is meant to be working with RAD Studio 10.3.2. Other remain untested, but probably will work too.

InvokeNSOpenPanel

Simplified NSOpenPanel creation.

function InvokeNSOpenPanel (const Title: String; const InitialDir: String; 
                            const Flags: String; const AllowedFileTypes: TArray<String>; 
                            var ADir: String): Boolean
  • Title - NSOpenPanel Title
  • InitialDir - Initial NSOpenPanel directory
  • Flags - A string set of flags separated with space, that will enable or disable certain NSOpenPanel features
    • multiple - Enable multiple file selection
    • others - Enable file types other than AllowedFileTypes ones
    • create - Allow NSOpenPanel to create folders
    • hidden - Enable hidden directories
  • AllowedFileTypes - An array of allowed file types for NSOpenPanel
  • ADir - Returnable value of path to opened file / files

InvokeNSSavePanel

Simplified NSSavePanel creation.

function InvokeNSSavePanel (const Title: String; const InitialDir: String; 
                            const Flags: String; const FileTypesDescription: TArray<String>;
                            const AllowedFileTypes: TArray<String>; var ADir: String): Boolean
  • Title - NSSavePanel Title
  • InitialDir - Initial NSSavePanel directory
  • Flags - A string set of flags separated with space, that will enable or disable certain NSSavePanel features
    • others - Enable file types other than AllowedFileTypes ones
    • create - Allow NSSavePanel to create folders
    • hidden - Enable hidden directories
  • FileTypesDescription - An array of names of allowed file types for NSSavePanel
  • AllowedFileTypes - An array of allowed file types for NSSavePanel
  • ADir - Returnable value of path to saved file

InvokeNSOpenDirPanel

Simplified NSOpenPanel creation in Directory selection mode.

function InvokeNSOpenDirPanel(const Title: String; const InitialDir: String; 
                              const Flags: String; var ADir: String): Boolean
  • Title - NSOpenPanel Title
  • InitialDir - Initial NSOpenPanel directory
  • Flags - A string set of flags separated with space, that will enable or disable certain NSOpenPanel features
    • multiple - Enable multiple file selection
    • create - Allow NSOpenPanel to create folders
    • hidden - Enable hidden directories
  • ADir - Returnable value of path to selected directory / directories

Examples

// NSOpenPanel // Form contains TButton and TEdit.
procedure TNSDialogsTestForm.NSOpenPanelButtonClick (Sender: TObject);
var
  ADir: String;
begin
  if InvokeNSOpenPanel ('Select Photoshop project', '/Applications/', 'multiple others create', ['psd', 'psb'], ADir) then
    NSOpenPanelPath.Text := ADir
  else
    NSOpenPanelPath.Text := '';
end;
// NSSavePanel // Form contains TButton and TEdit
procedure TNSDialogsTestForm.NSSavePanelButtonClick (Sender: TObject);
var
  ADir: String;
begin
  if InvokeNSSavePanel ('Save database', '', 'others create hidden', ['Database Files', 'Plain Text Files'], ['db', 'txt'], Adir) then
    NSSavePanelPath.Text := ADir
  else
    NSSavePanelPath.Text := '';
begin
end;
// NSOpenPanel in Directory selection mode // Form contains TButton and TEdit
procedure TNSDialogsTestForm.NSOpenDirPanelButtonClick (Sender: TObject);
var
  ADir: String;
begin
  if InvokeNSOpenDirPanel ('Select project directory', '', 'hidden', ADir) then
    NSOpenDirPanelPath.Text := ADir
  else
    NSOpenDirPanelPath.Text := '';
end;

About

Simplified NSOpenPanel and NSSavePanel Delphi bridge using MacApi default units #DelphiCocoaFlavored

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages