DialogBox.st
changeset 5619 1279213ad6a0
parent 5615 881147bd562b
child 5627 af8a8b824a40
--- a/DialogBox.st	Thu Mar 31 17:47:31 2016 +0200
+++ b/DialogBox.st	Fri Apr 01 13:12:31 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1994 by Claus Gittinger
 	      All Rights Reserved
@@ -2462,7 +2464,67 @@
      The matchPattern is set to pattern initially.
      Return the string, or nil if cancel was pressed."
 
-    |box defaultDir defaultNm dir enteredName|
+    ^ self
+        requestFileName:titleString 
+        default:defaultName 
+        ok:okText abort:abortText 
+        pattern:pattern 
+        orFilters:nil 
+            "argument #filtersOrNil is window specific,
+             it is an array of arrays with filter (*.zip) and its description (ZIP compressed archive file)
+             to support a call with just #filtersOrNil and no #patternOrNil the pattern will be extracted from the #filtersOrNil for linux"
+
+        fromDirectory:aDirectoryPathOrNil 
+        forSave:forSave 
+        whenBoxCreatedEvaluate:boxCreatedCallback
+!
+
+requestFileName:titleString default:defaultName ok:okText abort:abortText pattern:pattern fromDirectory:aDirectoryPathOrNil whenBoxCreatedEvaluate:boxCreatedCallback
+    "launch a Dialog, which allows user to enter a filename.
+     The files presented initially are those in aDirectoryPathOrNil, or the
+     last fileBox directory (default: current directory) (if a nil path is given).
+     The box will show okText in its okButton, abortText in the abortButton.
+     The matchPattern is set to pattern initially.
+     Return the string, or nil if cancel was pressed."
+
+    ^ self
+        requestFileName:titleString 
+        default:defaultName 
+        ok:okText 
+        abort:abortText 
+        pattern:pattern 
+        fromDirectory:aDirectoryPathOrNil 
+        forSave:false 
+        whenBoxCreatedEvaluate:boxCreatedCallback
+
+    "
+     Dialog 
+        requestFileName:'enter a fileName:'
+        default:''
+        ok:'yeah' 
+        abort:'oh, no' 
+        pattern:'rc*'
+        fromDirectory:'/etc'  
+    "
+
+    "Modified: / 24-08-2010 / 17:28:57 / sr"
+    "Modified: / 27-10-2010 / 11:21:44 / cg"
+!
+
+requestFileName:titleString default:defaultName ok:okText abort:abortText pattern:patternOrNil orFilters:filtersOrNil fromDirectory:aDirectoryPathOrNil forSave:forSave whenBoxCreatedEvaluate:boxCreatedCallback
+    "launch a Dialog, which allows user to enter a filename.
+     The files presented initially are those in aDirectoryPathOrNil, or the
+     last fileBox directory (default: current directory) (if a nil path is given).
+     The box will show okText in its okButton, abortText in the abortButton.
+     The matchPattern is set to pattern initially.
+     Return the string, or nil if cancel was pressed."
+
+    "argument #filtersOrNil is window specific,
+     it is an array of arrays with filter (*.zip) and its description (ZIP compressed archive file)
+     to support a call with just #filtersOrNil and no #patternOrNil the pattern will be extracted from the #filtersOrNil for linux"
+
+    |box defaultDir defaultNm dir enteredName
+     pattern|
 
     Screen current nativeFileDialogs ifTrue:[
         OperatingSystem isMSWINDOWSlike ifTrue:[
@@ -2473,11 +2535,20 @@
                     title:titleString 
                     inDirectory:aDirectoryPathOrNil
                     initialAnswer:defaultName
-                    filter:pattern
+                    pattern:patternOrNil
+                    orFilters:filtersOrNil
                     extension:nil
             ].
         ].
     ].
+
+    patternOrNil isNil ifTrue:[
+        "extract the pattern from #filtersOrNil"
+        pattern := self patternForFilters:filtersOrNil.
+    ] ifFalse:[
+        pattern := patternOrNil.
+    ].
+
     UserPreferences current useNewFileDialog ifTrue:[
         FileDialog notNil ifTrue:[
             ^ FileDialog 
@@ -2545,38 +2616,6 @@
     "Created: / 27-10-2010 / 11:21:05 / cg"
 !
 
-requestFileName:titleString default:defaultName ok:okText abort:abortText pattern:pattern fromDirectory:aDirectoryPathOrNil whenBoxCreatedEvaluate:boxCreatedCallback
-    "launch a Dialog, which allows user to enter a filename.
-     The files presented initially are those in aDirectoryPathOrNil, or the
-     last fileBox directory (default: current directory) (if a nil path is given).
-     The box will show okText in its okButton, abortText in the abortButton.
-     The matchPattern is set to pattern initially.
-     Return the string, or nil if cancel was pressed."
-
-    ^ self
-        requestFileName:titleString 
-        default:defaultName 
-        ok:okText 
-        abort:abortText 
-        pattern:pattern 
-        fromDirectory:aDirectoryPathOrNil 
-        forSave:false 
-        whenBoxCreatedEvaluate:boxCreatedCallback
-
-    "
-     Dialog 
-        requestFileName:'enter a fileName:'
-        default:''
-        ok:'yeah' 
-        abort:'oh, no' 
-        pattern:'rc*'
-        fromDirectory:'/etc'  
-    "
-
-    "Modified: / 24-08-2010 / 17:28:57 / sr"
-    "Modified: / 27-10-2010 / 11:21:44 / cg"
-!
-
 requestFileName:titleString default:defaultName ok:okText abort:abortText version:versionSymbol ifFail:failBlock pattern:pattern fromDirectory:aDirectoryPath whenBoxCreatedEvaluate:boxCreatedCallback asLoadDialog:aBoolean
     "launch a Dialog, which allows user to enter a filename.
      The files presented initially are those in aDirectoryPathOrNil, or the
@@ -2856,7 +2895,7 @@
                     title:titleString 
                     inDirectory:aDirectoryPath
                     initialAnswer:defaultName
-                    filter:pattern
+                    pattern:pattern
                     extension:nil
             ]
         ].
@@ -3428,7 +3467,7 @@
                         title:title 
                         inDirectory:directoryOrNil
                         initialAnswer:default
-                        filter:nil
+                        pattern:nil
                         extension:nil
                 ]
             ].
@@ -6260,6 +6299,22 @@
     "
 
     "Modified: / 16.6.1998 / 12:36:15 / cg"
+!
+
+patternForFilters:filtersOrNil
+    "argument #filtersOrNil is window specific,
+     it is an array of arrays with filter (*.zip) and its description (ZIP compressed archive file)
+     to support a call with just #filtersOrNil and no #patternOrNil the pattern will be extracted from the #filtersOrNil for linux
+
+     which is done here"
+
+    filtersOrNil isEmptyOrNil ifTrue:[
+        ^ nil
+    ].
+
+    ^ (filtersOrNil 
+        collect:[:each | each last])
+            asStringWith:'; '      
 ! !
 
 !DialogBox class methodsFor:'smalltalk dialogs'!