FileDialog.st
branchjv
changeset 15566 184cea584be5
parent 13289 cc75e3cd0362
parent 15451 62459e7da660
child 15726 42395c00ce64
--- a/FileDialog.st	Sun Jan 12 23:30:25 2014 +0000
+++ b/FileDialog.st	Wed Apr 01 10:38:01 2015 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2002 by eXept Software AG
               All Rights Reserved
@@ -11,6 +13,8 @@
 "
 "{ Package: 'stx:libtool' }"
 
+"{ NameSpace: Smalltalk }"
+
 SimpleDialog subclass:#FileDialog
 	instanceVariableNames:'aspects treeBrowser directory pattern filterHolder initialText
 		multipleSelect doubleClickAction cancelLabelHolder okLabelHolder
@@ -59,10 +63,18 @@
 
 examples
 "
+  usually direct access to FileDialog is not recommended;
+  please use the Dialog interface, which is able to dispatch to
+  alternative file choosers if the settings say so 
+  (native dialogs, for example):
                                                                 [exBegin]
-    FileDialog open
+    |fileOrNil|
+
+    fileOrNil := Dialog requestFileName:'Choose a File'.
+    Transcript showCR:fileOrNil
                                                                 [exEnd]
 
+  simple examples:
                                                                 [exBegin]
     FileDialog 
         requestFileName:'enter a fileName:'
@@ -73,6 +85,7 @@
         fromDirectory:'/etc'
         whenBoxCreatedEvaluate:nil.
                                                                 [exEnd]
+
                                                                 [exBegin]
     |fd|
 
@@ -81,9 +94,18 @@
     fd open
                                                                 [exEnd]
 
+                                                                [exBegin]
+    |fd|
+
+    fd := FileDialog new.
+    fd multipleSelect:true.
+    fd browseMenuItemVisible:false.
+    fd open
+                                                                [exEnd]
+
     Adding custom components:
                                                                 [exBegin]
-    DialogBox aboutToOpenBoxNotificationSignal handle:[:ex |
+    Dialog modifyingBoxWith:[:dialog |
         | fmtBox |
 
         fmtBox := ComboListView new.
@@ -91,8 +113,7 @@
                         'Microsoft Excel (.xls)'
                         'Microsoft Excel XML (.xlsx)') .
         fmtBox model:'Select...' asValue.
-        ex application addComponent: fmtBox.
-        ex proceed.
+        dialog application addComponent: fmtBox.
     ] do:[
         Dialog requestFileName: 'Save file as...'
     ]
@@ -763,207 +784,210 @@
     <resource: #canvas>
 
     ^ 
-     #(FullSpec
-        name: windowSpec
-        window: 
-       (WindowSpec
-          label: 'FileDialog'
-          name: 'FileDialog'
-          min: (Point 10 10)
-          bounds: (Rectangle 0 0 400 400)
-          menu: mainMenu
-          performer: treeBrowser
-        )
-        component: 
-       (SpecCollection
-          collection: (
-           (VerticalPanelViewSpec
-              name: 'FilePanel'
-              layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
-              horizontalLayout: fit
-              verticalLayout: bottomFit
-              horizontalSpace: 0
-              verticalSpace: 3
-              elementsChangeSize: true
-              component: 
-             (SpecCollection
-                collection: (
-                 (ViewSpec
-                    name: 'FilePart'
-                    component: 
-                   (SpecCollection
-                      collection: (
-                       (MenuPanelSpec
-                          name: 'ToolBar1'
-                          layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 40 0)
-                          tabable: true
-                          menu: toolBarMenu
-                          textDefault: true
-                        )
-                       (VariableHorizontalPanelSpec
-                          name: 'DeviceAndFilterPanel'
-                          layout: (LayoutFrame 0 0 40 0 0 1 70 0)
-                          level: 1
-                          showHandle: true
-                          component: 
-                         (SpecCollection
-                            collection: (
-                             (ViewSpec
-                                name: 'Box1'
-                                component: 
-                               (SpecCollection
-                                  collection: (
-                                   (ComboListSpec
-                                      name: 'ComboList1'
-                                      layout: (LayoutFrame 1 0 1 0.0 -1 1 -1 1)
-                                      visibilityChannel: driveSelectorVisible
-                                      model: selectedDeviceDrive
-                                      comboList: listOfDeviceDrives
-                                      useIndex: false
-                                      hidePullDownMenuButton: false
-                                    )
+    #(FullSpec
+       name: windowSpec
+       window: 
+      (WindowSpec
+         label: 'FileDialog'
+         name: 'FileDialog'
+         min: (Point 10 10)
+         bounds: (Rectangle 0 0 400 400)
+         menu: mainMenu
+         performer: treeBrowser
+       )
+       component: 
+      (SpecCollection
+         collection: (
+          (VerticalPanelViewSpec
+             name: 'FilePanel'
+             layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
+             horizontalLayout: fit
+             verticalLayout: bottomFit
+             horizontalSpace: 0
+             verticalSpace: 3
+             elementsChangeSize: true
+             component: 
+            (SpecCollection
+               collection: (
+                (ViewSpec
+                   name: 'FilePart'
+                   component: 
+                  (SpecCollection
+                     collection: (
+                      (MenuPanelSpec
+                         name: 'ToolBar1'
+                         layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 40 0)
+                         tabable: true
+                         menu: toolBarMenu
+                         textDefault: true
+                       )
+                      (VariableHorizontalPanelSpec
+                         name: 'DeviceAndFilterPanel'
+                         layout: (LayoutFrame 0 0 40 0 0 1 70 0)
+                         level: 1
+                         showHandle: true
+                         component: 
+                        (SpecCollection
+                           collection: (
+                            (ViewSpec
+                               name: 'Box1'
+                               component: 
+                              (SpecCollection
+                                 collection: (
+                                  (ComboListSpec
+                                     name: 'ComboList1'
+                                     layout: (LayoutFrame 1 0 1 0.0 -1 1 -1 1)
+                                     visibilityChannel: driveSelectorVisible
+                                     model: selectedDeviceDrive
+                                     comboList: listOfDeviceDrives
+                                     useIndex: false
+                                     hidePullDownMenuButton: false
                                    )
-                                 
-                                )
-                              )
-                             (ViewSpec
-                                name: 'Box2'
-                                component: 
-                               (SpecCollection
-                                  collection: (
-                                   (LabelSpec
-                                      label: 'Filter:'
-                                      name: 'FilterLabel'
-                                      layout: (LayoutFrame 1 0 2 0 59 0 -2 1)
-                                      translateLabel: true
-                                      adjust: right
-                                    )
-                                   (InputFieldSpec
-                                      name: 'FilterEntryField'
-                                      layout: (LayoutFrame 60 0 -27 1 -2 1 -2 1)
-                                      model: filterHolder
-                                      immediateAccept: true
-                                      acceptOnReturn: true
-                                      acceptOnTab: true
-                                      acceptOnLostFocus: true
-                                      acceptOnPointerLeave: false
-                                      postBuildCallback: postBuildFilterField:
-                                    )
+                                  )
+                                
+                               )
+                             )
+                            (ViewSpec
+                               name: 'Box2'
+                               component: 
+                              (SpecCollection
+                                 collection: (
+                                  (LabelSpec
+                                     label: 'Filter:'
+                                     name: 'FilterLabel'
+                                     layout: (LayoutFrame 1 0 2 0 59 0 -2 1)
+                                     translateLabel: true
+                                     adjust: right
                                    )
-                                 
-                                )
-                              )
+                                  (InputFieldSpec
+                                     name: 'FilterEntryField'
+                                     layout: (LayoutFrame 60 0 -27 1 -2 1 -2 1)
+                                     model: filterHolder
+                                     immediateAccept: true
+                                     acceptOnReturn: true
+                                     acceptOnTab: true
+                                     acceptOnLostFocus: true
+                                     acceptOnPointerLeave: false
+                                     postBuildCallback: postBuildFilterField:
+                                   )
+                                  )
+                                
+                               )
                              )
+                            )
+                          
+                         )
+                         handles: (Any 0.29729729729729998 1.0)
+                       )
+                      (SubCanvasSpec
+                         name: 'DirectoryTreeBrowser'
+                         layout: (LayoutFrame 0 0.0 70 0 0 1.0 -30 1)
+                         tabable: true
+                         hasHorizontalScrollBar: false
+                         hasVerticalScrollBar: false
+                         majorKey: DirectoryTreeBrowser
+                         subAspectHolders: 
+                        (Array
                            
-                          )
-                          handles: (Any 0.2972972972973 1.0)
-                        )
-                       (SubCanvasSpec
-                          name: 'DirectoryTreeBrowser'
-                          layout: (LayoutFrame 0 0.0 70 0 0 1.0 -30 1)
-                          tabable: true
-                          hasHorizontalScrollBar: false
-                          hasVerticalScrollBar: false
-                          majorKey: DirectoryTreeBrowser
-                          subAspectHolders: 
-                         (Array
-                            
-                           (SubChannelInfoSpec
-                              subAspect: filterModel
-                              aspect: filterHolder
-                            ) 
-                           (SubChannelInfoSpec
-                              subAspect: rootHolder
-                              aspect: rootDirectoryHolder
-                            )
-                            
-                           (SubChannelInfoSpec
-                              subAspect: showHiddenFiles
-                              aspect: showHiddenFiles
-                            )
-                          )
-                          createNewApplication: true
-                          createNewBuilder: true
-                          postBuildCallback: postBuildTreeBrowser:
-                        )
-                       (LabelSpec
-                          label: 'Filename:'
-                          name: 'FilenameLabel'
-                          layout: (LayoutFrame 3 0 -25 1 90 0 -1 1)
-                          translateLabel: true
-                          labelChannel: filenameLabelHolder
-                          adjust: left
-                        )
-                       (FilenameInputFieldSpec
-                          name: 'FilenameEntryField'
-                          layout: (LayoutFrame 90 0 -25 1 -2 1 -1 1)
-                          tabable: true
-                          model: filenameHolder
-                          immediateAccept: false
-                          acceptOnPointerLeave: false
-                          hasKeyboardFocusInitially: true
-                          postBuildCallback: postBuildFileNameField:
-                        )
+                          (SubChannelInfoSpec
+                             subAspect: filterModel
+                             aspect: filterHolder
+                           ) 
+                          (SubChannelInfoSpec
+                             subAspect: rootHolder
+                             aspect: rootDirectoryHolder
+                           )
+                           
+                          (SubChannelInfoSpec
+                             subAspect: showHiddenFiles
+                             aspect: showHiddenFiles
+                           )
+                         )
+                         createNewApplication: true
+                         createNewBuilder: true
+                         postBuildCallback: postBuildTreeBrowser:
                        )
-                     
-                    )
-                    extent: (Point 400 370)
-                  )
+                      (LabelSpec
+                         label: 'Filename:'
+                         name: 'FilenameLabel'
+                         layout: (LayoutFrame 3 0 -25 1 90 0 -1 1)
+                         translateLabel: true
+                         labelChannel: filenameLabelHolder
+                         adjust: left
+                       )
+                      (FilenameInputFieldSpec
+                         name: 'FilenameEntryField'
+                         layout: (LayoutFrame 90 0 -25 1 -2 1 -1 1)
+                         tabable: true
+                         model: filenameHolder
+                         immediateAccept: false
+                         acceptOnPointerLeave: true
+                         hasKeyboardFocusInitially: true
+                         postBuildCallback: postBuildFileNameField:
+                       )
+                      )
+                    
+                   )
+                   extent: (Point 400 370)
                  )
-               
-              )
-              postBuildCallback: postBuildVerticalPanelView:
-            )
-           (HorizontalPanelViewSpec
-              name: 'ButtonPanel'
-              layout: (LayoutFrame 0 0.0 -30 1 0 1 0 1)
-              visibilityChannel: buttonPanelVisibleHolder
-              horizontalLayout: fitSpace
-              verticalLayout: center
-              horizontalSpace: 3
-              verticalSpace: 3
-              reverseOrderIfOKAtLeft: true
-              component: 
-             (SpecCollection
-                collection: (
-                 (ActionButtonSpec
-                    label: 'Cancel'
-                    name: 'cancelButton'
-                    translateLabel: true
-                    labelChannel: cancelLabelHolder
-                    tabable: true
-                    model: doCancel
-                    extent: (Point 129 25)
-                  )
-                 (ActionButtonSpec
-                    label: 'Append'
-                    name: 'appendButton'
-                    visibilityChannel: appendButtonVisibleHolder
-                    translateLabel: true
-                    labelChannel: appendLabelHolder
-                    tabable: true
-                    model: appendPressed
-                    extent: (Point 129 25)
-                  )
-                 (ActionButtonSpec
-                    label: 'OK'
-                    name: 'okButton'
-                    translateLabel: true
-                    labelChannel: okLabelHolder
-                    tabable: true
-                    model: okPressed
-                    isDefault: true
-                    extent: (Point 130 25)
-                  )
+                )
+              
+             )
+             postBuildCallback: postBuildVerticalPanelView:
+           )
+          (HorizontalPanelViewSpec
+             name: 'ButtonPanel'
+             layout: (LayoutFrame 0 0.0 -30 1 0 1 0 1)
+             visibilityChannel: buttonPanelVisibleHolder
+             horizontalLayout: fitSpace
+             verticalLayout: center
+             horizontalSpace: 3
+             verticalSpace: 3
+             reverseOrderIfOKAtLeft: true
+             component: 
+            (SpecCollection
+               collection: (
+                (ActionButtonSpec
+                   label: 'Cancel'
+                   name: 'cancelButton'
+                   translateLabel: true
+                   labelChannel: cancelLabelHolder
+                   tabable: true
+                   model: doCancel
+                   extent: (Point 128 28)
+                   usePreferredHeight: true
                  )
-               
-              )
-              keepSpaceForOSXResizeHandleH: true
-            )
+                (ActionButtonSpec
+                   label: 'Append'
+                   name: 'appendButton'
+                   visibilityChannel: appendButtonVisibleHolder
+                   translateLabel: true
+                   labelChannel: appendLabelHolder
+                   tabable: true
+                   model: appendPressed
+                   extent: (Point 128 28)
+                   usePreferredHeight: true
+                 )
+                (ActionButtonSpec
+                   label: 'OK'
+                   name: 'okButton'
+                   translateLabel: true
+                   labelChannel: okLabelHolder
+                   tabable: true
+                   model: okPressed
+                   isDefault: true
+                   extent: (Point 128 28)
+                   usePreferredHeight: true
+                 )
+                )
+              
+             )
+             keepSpaceForOSXResizeHandleH: true
            )
-         
-        )
-      )
+          )
+        
+       )
+     )
 ! !
 
 !FileDialog class methodsFor:'menu specs'!
@@ -1174,7 +1198,7 @@
             itemValue: doBrowseDirectory
             translateLabel: true
             isButton: true
-            isVisible: browseVisibleHolder
+            isVisible: browsemenuItemVisibleHolder
             labelImage: (ResourceRetriever ToolbarIconLibrary startFileBrowserIcon)
           )
          )
@@ -1381,6 +1405,9 @@
 !FileDialog methodsFor:'aspects'!
 
 appendButtonVisibleHolder
+    "if set, an additional 'append' button is shown
+     (to let user append to a file, instead of overwriting the file)"
+
     appendButtonVisibleHolder isNil ifTrue:[
         appendButtonVisibleHolder := false asValue.
     ].
@@ -1405,13 +1432,28 @@
     ^ nil
 !
 
-browseVisibleHolder
+browseMenuItemVisible:aBoolean
+    "controls if an 'open filebrowser' menu item is to be shown in the toolbar"
+
+    self browseMenuItemVisibleHolder value:aBoolean
+!
+
+browseMenuItemVisibleHolder
+    "controls if an 'open filebrowser' menu item is to be shown in the toolbar"
+
     browseVisibleHolder isNil ifTrue:[
         browseVisibleHolder := true "false" asValue.
     ].
     ^ browseVisibleHolder.
 !
 
+browseVisibleHolder
+    "controls if an 'open filebrowser' menu item is to be shown in the toolbar"
+
+    <resource: #obsolete>
+    ^ self browseMenuItemVisibleHolder.
+!
+
 buttonPanelVisibleHolder
     buttonPanelVisibleHolder isNil ifTrue:[
         buttonPanelVisibleHolder := true asValue.
@@ -1911,6 +1953,8 @@
 "/        ].
     ].
 
+    treeBrowser currentFileNameHolder value:(Array with:self startFilename).
+
     "Created: / 03-06-2013 / 18:19:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
@@ -2075,11 +2119,11 @@
 !FileDialog class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileDialog.st,v 1.130 2013-07-24 21:01:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileDialog.st,v 1.134 2015-02-27 15:30:48 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/FileDialog.st,v 1.130 2013-07-24 21:01:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileDialog.st,v 1.134 2015-02-27 15:30:48 cg Exp $'
 !
 
 version_HG
@@ -2088,6 +2132,6 @@
 !
 
 version_SVN
-    ^ '$Id: FileDialog.st,v 1.130 2013-07-24 21:01:27 cg Exp $'
+    ^ '$Id: FileDialog.st,v 1.134 2015-02-27 15:30:48 cg Exp $'
 ! !