View Issue Details

IDProjectCategoryView StatusLast Update
0031492LazarusLCLpublic2017-05-02 09:47
ReporterThomas Frey Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformintelOSMacOS Sierra 
Product Version1.7 (SVN) 
Summary0031492: Save Dialog returns wrong filename in Carbon
DescriptionIf the Save Dialog is populated with a new filename that doesn't exist in that folder yet (not tested if non-existance is a requirement) and the user just accepts the name or only changes the name, the filenameresult is "<originalFilenam>/<acceptedFilenam>"

if the dialog was opened with filename "/whateverexistingpath/plan1.ext"
filename is "plan1.ext/plan1.ext" when it returns.

Changing the folder fixes it, even if switching back to the original folder.
TagsNo tags attached.
Fixed in Revisionr54780
LazTarget-
WidgetsetCarbon
Attached Files

Relationships

related to 0030533 resolvedJuha Manninen TOpenDialog odd behavior under El Capitan 

Activities

CudaText man

2017-04-30 14:47

reporter  

savedl.diff (1,407 bytes)   
Index: lcl/interfaces/carbon/carbonwsdialogs.pp
===================================================================
--- lcl/interfaces/carbon/carbonwsdialogs.pp	(revision 54779)
+++ lcl/interfaces/carbon/carbonwsdialogs.pp	(working copy)
@@ -322,7 +322,7 @@
   I: Integer;
   ParsedFilter: TParseStringList;
   M: TMaskList;
-  filterext: String;
+  filterext, InitDir: String;
   supportPackages: Boolean; //todo: select packages by name
 begin
   {$IFDEF VerboseWSClass}
@@ -331,6 +331,11 @@
 
   FileDialog := ACommonDialog as TFileDialog;
 
+  // two sources of init dir
+  InitDir := FileDialog.InitialDir;
+  if InitDir = '' then
+    InitDir := ExtractFileDir(FileDialog.FileName);
+
   // Initialize record to default values
   if OSError(NavGetDefaultDialogCreationOptions(CreationOptions{%H-}),
     Self, SShowModal, 'NavGetDefaultDialogCreationOptions') then Exit;
@@ -420,7 +425,7 @@
       if NavDialogGetUserAction(DialogRef) <> kNavUserActionCancel then // User OK?
       begin
         if FileDialog.FCompStyle=csSaveFileDialog then
-          FileDialog.FileName := FileDialog.FileName + PathDelim +
+          FileDialog.FileName := InitDir + PathDelim +
             CFStringToStr(NavDialogGetSaveFileName(DialogRef));
             {Note: Not at all clear from Apple docs that NavReplyRecord.Selection
               returns only path to file's folder with Save dialog. Also, what they
savedl.diff (1,407 bytes)   

CudaText man

2017-04-30 14:48

reporter   ~0100005

Seen bug in another way:
made fix, diff.
Pls confirm someone. I see it ok now

CudaText man

2017-04-30 15:40

reporter  

savedl_cocoa.diff (1,903 bytes)   
Index: lcl/interfaces/cocoa/cocoawsdialogs.pp
===================================================================
--- lcl/interfaces/cocoa/cocoawsdialogs.pp	(revision 54779)
+++ lcl/interfaces/cocoa/cocoawsdialogs.pp	(working copy)
@@ -119,7 +119,7 @@
   nsfilter: NSMutableArray;
   Filters: TStringList;
   ParsedFilter: TParseStringList;
-  filterext: string;
+  InitName, InitDir, filterext: string;
   Masks: TParseStringList;
   Extensions: TParseStringList;
   extension: string;
@@ -137,6 +137,12 @@
 
   Filters := TStringList.Create;
 
+  // two sources for init dir
+  InitName := ExtractFileName(FileDialog.FileName);
+  InitDir := FileDialog.InitialDir;
+  if InitDir = '' then
+    InitDir := ExtractFileDir(FileDialog.FileName);
+
   // Cocoa doesn't supports a filter list selector like we know from windows. So we add all the masks into one filter list.
 
   ParsedFilter := TParseStringList.Create(FileDialog.Filter, '|');
@@ -205,7 +211,7 @@
       openDlg.setAllowedFileTypes(nsfilter);
     end;
     openDlg.setTitle(NSStringUtf8(FileDialog.Title));
-    openDlg.setDirectoryURL(NSURL.fileURLWithPath(NSStringUtf8(FileDialog.InitialDir)));
+    openDlg.setDirectoryURL(NSURL.fileURLWithPath(NSStringUtf8(InitDir)));
 
     if openDlg.runModal = NSOKButton then
     begin
@@ -223,9 +229,8 @@
     saveDlg.setCanCreateDirectories(True);
     saveDlg.setTitle(NSStringUtf8(FileDialog.Title));
     saveDlg.setAllowedFileTypes(nsfilter);
-    saveDlg.setDirectoryURL(NSURL.fileURLWithPath(
-      NSStringUtf8(FileDialog.InitialDir)));
-    saveDlg.setNameFieldStringValue(NSStringUtf8(extractfilename(FileDialog.FileName)));
+    saveDlg.setDirectoryURL(NSURL.fileURLWithPath(NSStringUtf8(InitDir)));
+    saveDlg.setNameFieldStringValue(NSStringUtf8(InitName));
     if saveDlg.runModal = NSOKButton then
     begin
       FileDialog.FileName := NSStringToString(saveDlg.URL.path);
savedl_cocoa.diff (1,903 bytes)   

CudaText man

2017-04-30 15:43

reporter   ~0100010

Second diff
Cocoa. Does almost same: fixes: dir in FileName not considered
Pls apply too

Juha Manninen

2017-04-30 15:50

developer   ~0100011

Applied both patches in one go. Thanks.

C Western

2017-05-01 23:19

reporter   ~0100052

The carbon patch does not work for me if the initial directory is blank - see alternative patch in 30533. I have not tried Cocoa.

CudaText man

2017-05-02 08:14

reporter  

save-fix.diff (1,050 bytes)   
Index: lcl/interfaces/carbon/carbonwsdialogs.pp
===================================================================
--- lcl/interfaces/carbon/carbonwsdialogs.pp	(revision 54782)
+++ lcl/interfaces/carbon/carbonwsdialogs.pp	(working copy)
@@ -332,7 +332,7 @@
   FileDialog := ACommonDialog as TFileDialog;
 
   // two sources of init dir
-  InitDir := FileDialog.InitialDir;
+  InitDir := ExcludeTrailingPathDelimiter(FileDialog.InitialDir);
   if InitDir = '' then
     InitDir := ExtractFileDir(FileDialog.FileName);
 
@@ -425,7 +425,7 @@
       if NavDialogGetUserAction(DialogRef) <> kNavUserActionCancel then // User OK?
       begin
         if FileDialog.FCompStyle=csSaveFileDialog then
-          FileDialog.FileName := InitDir + PathDelim +
+          FileDialog.FileName := FileDialog.FileName + PathDelim +
             CFStringToStr(NavDialogGetSaveFileName(DialogRef));
             {Note: Not at all clear from Apple docs that NavReplyRecord.Selection
               returns only path to file's folder with Save dialog. Also, what they
save-fix.diff (1,050 bytes)   

CudaText man

2017-05-02 08:15

reporter   ~0100054

Last edited: 2017-05-02 08:17

View 2 revisions

That patch broken saving of proj in ide. Ops :\. Must apply save-fix.diff

(maybe source issue again exists, but save-fix fixes IDE)

C Western

2017-05-02 09:42

reporter   ~0100055

Please try the patch proposed in 30533 instead - I believe it is more general

Issue History

Date Modified Username Field Change
2017-03-06 20:53 Thomas Frey New Issue
2017-04-30 14:47 CudaText man File Added: savedl.diff
2017-04-30 14:48 CudaText man Note Added: 0100005
2017-04-30 15:40 CudaText man File Added: savedl_cocoa.diff
2017-04-30 15:41 Juha Manninen Assigned To => Juha Manninen
2017-04-30 15:41 Juha Manninen Status new => assigned
2017-04-30 15:43 CudaText man Note Added: 0100010
2017-04-30 15:50 Juha Manninen Fixed in Revision => r54780
2017-04-30 15:50 Juha Manninen LazTarget => -
2017-04-30 15:50 Juha Manninen Note Added: 0100011
2017-04-30 15:50 Juha Manninen Status assigned => resolved
2017-04-30 15:50 Juha Manninen Resolution open => fixed
2017-05-01 23:19 C Western Note Added: 0100052
2017-05-02 08:14 CudaText man File Added: save-fix.diff
2017-05-02 08:15 CudaText man Note Added: 0100054
2017-05-02 08:17 CudaText man Note Edited: 0100054 View Revisions
2017-05-02 09:42 C Western Note Added: 0100055
2017-05-02 09:47 Juha Manninen Relationship added related to 0030533