cocoa: UI optimization for the file selection dialog. Do not use path_shouldEnableURL if not filters are used by the openDialog. todo: The same approach could be used if the only filter is any file

git-svn-id: trunk@64419 -
This commit is contained in:
dmitry 2021-01-24 21:14:52 +00:00
parent 31e6d57c33
commit 7ab17842cd

View File

@ -164,15 +164,20 @@ type
FileDialog: TFileDialog; FileDialog: TFileDialog;
OpenDialog: TOpenDialog; OpenDialog: TOpenDialog;
selUrl: NSURL; selUrl: NSURL;
filter: NSOpenSavePanelDelegateProtocol;
procedure dealloc; override; procedure dealloc; override;
function panel_shouldEnableURL(sender: id; url: NSURL): LCLObjCBoolean;
procedure panel_didChangeToDirectoryURL(sender: id; url: NSURL); procedure panel_didChangeToDirectoryURL(sender: id; url: NSURL);
function panel_userEnteredFilename_confirmed(sender: id; filename: NSString; okFlag: LCLObjCBoolean): NSString; function panel_userEnteredFilename_confirmed(sender: id; filename: NSString; okFlag: LCLObjCBoolean): NSString;
procedure panel_willExpand(sender: id; expanding: LCLObjCBoolean); procedure panel_willExpand(sender: id; expanding: LCLObjCBoolean);
procedure panelSelectionDidChange(sender: id); procedure panelSelectionDidChange(sender: id);
end; end;
// Having path_shouldEnableURL is causing a slowness on a file selection
// Just having the method declared already introduces a lag in the file selection
TOpenSaveDelegateWithFilter = objcclass(TOpenSaveDelegate, NSOpenSavePanelDelegateProtocol)
filter: NSOpenSavePanelDelegateProtocol;
function panel_shouldEnableURL(sender: id; url: NSURL): LCLObjCBoolean;
end;
{ TOpenSaveDelegate } { TOpenSaveDelegate }
procedure TOpenSaveDelegate.dealloc; procedure TOpenSaveDelegate.dealloc;
@ -181,7 +186,7 @@ begin
inherited dealloc; inherited dealloc;
end; end;
function TOpenSaveDelegate.panel_shouldEnableURL(sender: id; url: NSURL function TOpenSaveDelegateWithFilter.panel_shouldEnableURL(sender: id; url: NSURL
): LCLObjCBoolean; ): LCLObjCBoolean;
begin begin
if Assigned(filter) then if Assigned(filter) then
@ -431,12 +436,17 @@ begin
saveDlg.retain; // this is for OSX 10.6 (and we don't use ARC either) saveDlg.retain; // this is for OSX 10.6 (and we don't use ARC either)
callback:=TOpenSaveDelegate.alloc; if not Assigned(lFilter) then
callback:=TOpenSaveDelegate.alloc
else begin
callback:=TOpenSaveDelegateWithFilter.alloc;
TOpenSaveDelegateWithFilter(callback).filter := lFilter;
end;
callback := callback.init;
callback.autorelease; callback.autorelease;
callback.FileDialog := FileDialog; callback.FileDialog := FileDialog;
if FileDialog is TOpenDialog then if FileDialog is TOpenDialog then
callback.OpenDialog := TOpenDialog(FileDialog); callback.OpenDialog := TOpenDialog(FileDialog);
callback.filter := lFilter;
saveDlg.setDelegate(callback); saveDlg.setDelegate(callback);
saveDlg.setTitle(NSStringUtf8(FileDialog.Title)); saveDlg.setTitle(NSStringUtf8(FileDialog.Title));
saveDlg.setDirectoryURL(NSURL.fileURLWithPath(NSStringUtf8(InitDir))); saveDlg.setDirectoryURL(NSURL.fileURLWithPath(NSStringUtf8(InitDir)));