#FEATURE by sr
authorsr
Thu, 25 Oct 2018 10:58:37 +0200
changeset 8551 778f2fbb3b69
parent 8550 fb57a584f13f
child 8552 720ee7137040
#FEATURE by sr class: WinWorkstation added: #nativeFileDialogWithTitle:defaultFilename:owningTopView:filter:filterIndex:trueForSave:trueForMultiSelect:trueForPromptOverwrite: removed: #nativeFileDialogWithTitle:defaultFilename:owningTopView:filter:filterIndex:trueForSave:trueForPromptOverwrite: changed: #primGetNativeFileDialogResultByDataAddress:
WinWorkstation.st
--- a/WinWorkstation.st	Thu Oct 25 02:46:48 2018 +0200
+++ b/WinWorkstation.st	Thu Oct 25 10:58:37 2018 +0200
@@ -16590,6 +16590,7 @@
     filter:filterStringOrArrayOfPairs
     filterIndex:filterIndexArg
     trueForSave:trueForSave
+    trueForMultiSelect:trueForMultiSelect         
     trueForPromptOverwrite:trueForPromptOverwrite    
 
     "opens a native windows file dialog,
@@ -16650,7 +16651,7 @@
             filterString:filterString
             filterIndex:filterIndexArg ? 1
             trueForSave:trueForSave
-            trueForMultiSelect:false "/ not yet implemented            
+            trueForMultiSelect:trueForMultiSelect ? false          
             trueForPromptOverwrite:trueForPromptOverwrite ? true.    
 
         dataAddress := dataAddressAndThreadAddress first.
@@ -16703,7 +16704,9 @@
                 'All', null, '*.*', null,
                 null
             filterIndex:3
-            doSave:false.
+            trueForSave:false
+            trueForMultiSelect:nil         
+            trueForPromptOverwrite:nil
 
     ########### example2 without owning view and termination ##########
 
@@ -16721,8 +16724,10 @@
                         'expecco Testsuite', null, '*.ets', null,
                         'expecco Logfile', null, '*.elf', null,
                         null
-                    filterIndex:2
-                    doSave:false.
+                    filterIndex:2           
+                    trueForSave:false
+                    trueForMultiSelect:nil         
+                    trueForPromptOverwrite:nil      
             ] fork.
 
         Delay waitForSeconds:5.
@@ -16744,8 +16749,10 @@
                         #('expecco Testsuite' '*.ets')
                         #('expecco Logfile' '*.elf')
                     )
-            filterIndex:2
-            doSave:false.
+            filterIndex:2      
+            trueForSave:false
+            trueForMultiSelect:nil         
+            trueForPromptOverwrite:nil.   
 
     ########### example4 with owning view (makes the launcher modal) and termination ##########
 
@@ -16765,7 +16772,9 @@
                         #('expecco Logfile' '*.elf')
                     )
                     filterIndex:2
-                    doSave:false.
+                    trueForSave:false
+                    trueForMultiSelect:nil         
+                    trueForPromptOverwrite:nil.       
             ] fork.
 
         Delay waitForSeconds:5.
@@ -16773,7 +16782,7 @@
         p terminate.
     "
 
-    "Created: / 24-10-2018 / 13:15:17 / sr"
+    "Created: / 25-10-2018 / 10:54:52 / sr"
 !
 
 primCloseNativeFileDialogByDataAddress:dataAddress
@@ -16810,7 +16819,7 @@
      returns an empty string if the file dialog was canceled
      returns the full path to the user selected file"
 
-    |targetFileOrNil multiSelectValues|
+    |targetFileOrNil multiSelectValues needsSlash|
 
 %{  /* STACK: 100000 */
     if (__isExternalAddress(dataAddress)) {
@@ -16821,39 +16830,19 @@
 
             if ((!pFdd->trueForSave) && pFdd->trueForMultiSelect) {
                 wchar_t buffer[1000 * MAX_PATH]; // big buffer to support multiselect
-                int pos = wcslen(pFdd->filename);
-                BYTE *b = &pFdd->filename[pos + 1];
-
-                ZeroMemory(buffer, sizeof(buffer));
-                if ((*b + *(b + 1)) != 0) {
-                    multiSelectValues = __MKU16STRING(&pFdd->filename[pos + 1]);
-                }
-
-                multiSelectValues = __MKU16STRING(buffer);
-
-#if 0
-
-                do {
-                    printf("pos: %d\n", pos);
-                    *b = &pFdd->filename[pos];
-
-                    pos++;
-                } while((*b + *(b + 1)) != 0);
-
-                wprintf(L"bytes next char '%d'\n", *b + *(b + 1));
-                if (*b + *(b + 1))
-
-
-
-                wprintf(L"pos '%d'\n", pos);
-                wchar_t buff[5];
-                wcsncpy(buff, &pFdd->filename[pos], 1);
-                wprintf(L"char '%ls'\n", buff);
-                BYTE *b;
-                b = &pFdd->filename[pos];
-                wprintf(L"char byte1 '%d'\n", *b);
-                wprintf(L"char byte2 '%d'\n", *(b + 1));
-#endif
+                ZeroMemory(buffer, sizeof(buffer));    
+
+                int len = wcslen(pFdd->filename);
+                int pos = len + 1;
+
+                while ((len = wcslen(&pFdd->filename[pos])) > 0) {
+                    wcscat(buffer, &pFdd->filename[pos]);
+                    wcscat(buffer, L"|");
+                    pos = pos + len + 1;      
+                    wprintf(L"char '%ls'\n", buffer);
+                }
+
+                multiSelectValues = __MKU16STRING(buffer);     
             }
 
             free(pFdd);
@@ -16861,17 +16850,28 @@
     }
 %}.
 
-    ^ targetFileOrNil
-"/    targetFileOrNil isNil ifTrue:[
-"/        ^ nil
-"/    ].
-"/
-"/    ^ Array
-"/        with:targetFileOrNil
-"/        with:multiSelectValues
-
-    "Created: / 22-10-2018 / 13:52:47 / sr"
-    "Modified: / 23-10-2018 / 14:41:06 / sr"
+    targetFileOrNil isNil ifTrue:[
+        ^ nil
+    ].
+    targetFileOrNil isEmpty ifTrue:[
+        ^ ''
+    ].
+    multiSelectValues isEmptyOrNil ifTrue:[
+        ^ targetFileOrNil
+    ].
+
+    needsSlash := targetFileOrNil last ~= $\.
+
+    ^ (multiSelectValues 
+        subStrings:$|)
+            reject:[:each | each isEmptyOrNil]
+            thenCollect:[:each | 
+                needsSlash ifTrue:[
+                    targetFileOrNil, '\', each
+                ] ifFalse:[
+                    targetFileOrNil, each
+                ].
+            ]
 !
 
 primNativeFileDialogWithTitle:dialogTitle