Attachment 'wpfDialogBox.v1.0.txt'

Download

   1 :Namespace wpfDialogBox
   2 
   3 ⍝ Namespace to show Dialog and Message Boxes
   4 ⍝ Check The Comments of Each Methods For More Information.
   5 
   6     (⎕IO ⎕ML ⎕WX)←1 3 3
   7 
   8     ∇ path←DialogFolder;DR;FBD;⎕USING
   9       :Access Public Shared
  10       ⍝ Selects a Directory with FolderBrowserDialog.
  11      
  12       :Trap 0
  13           ⎕USING←',System.Windows.Forms.dll'
  14           FBD←⎕NEW System.Windows.Forms.FolderBrowserDialog
  15           DR←System.Windows.Forms.DialogResult
  16      
  17           ⍝ Shows the Dialog as Modal and Owned by the Current APL Process
  18           :If DR.OK=FBD.ShowDialog ⍬
  19               path←FBD.SelectedPath
  20           :Else
  21               path←''
  22           :End
  23      
  24           FBD.Dispose  ⍝ With ShowDialog the form is not dispose automatically.
  25      
  26       :Else
  27           ⍝ Unexpected Error
  28           ⎕←GetLastError
  29           path←''
  30       :EndTrap
  31 
  32 
  33     ∇ file_name←DialogOpenFile;DR;OFD;⎕USING
  34       :Access Public Shared
  35      ⍝ Selects a File to Open With OpenFileDialog.
  36      
  37       :Trap 0
  38           ⎕USING←',System.Windows.Forms.dll'
  39           OFD←⎕NEW System.Windows.Forms.OpenFileDialog
  40           DR←System.Windows.Forms.DialogResult
  41      
  42           OFD.Title←'Select a File'
  43           OFD.CheckFileExists←0
  44           OFD.InitialDirectory←'::{20D04FE0-3AEA-1069-A2D8-08002B30309D}' ⍝ My Computer
  45           ⍝ OFD.InitialDirectory←'::{450D8FBA-AD25-11D0-98A8-0800361B1103}' ⍝ My Documents
  46           ⍝ OFD.InitialDirectory←'::{208D2C60-3AEA-1069-A2D7-08002B30309D}' ⍝ My Network Places
  47      
  48           ⍝ Shows the Dialog as Modal and Owned by the Current APL Process
  49           :If DR.OK=OFD.ShowDialog ⍬
  50               file_name←OFD.FileName
  51           :Else
  52               file_name←''
  53           :End
  54      
  55           OFD.Dispose  ⍝ With ShowDialog the form is not dispose automatically.
  56      
  57       :Else
  58           ⍝ Unexpected Error
  59           ⎕←GetLastError
  60           file_name←''
  61       :EndTrap
  62 
  63 
  64     ∇ file_name←DialogSaveFile;DR;SFD;⎕USING
  65       :Access Public Shared
  66      ⍝ Selects a File to Save With SaveFileDialog.
  67      
  68       :Trap 0
  69           ⎕USING←',System.Windows.Forms.dll'
  70           SFD←⎕NEW System.Windows.Forms.SaveFileDialog
  71           DR←System.Windows.Forms.DialogResult
  72      
  73           SFD.Title←'Save As'
  74           SFD.OverwritePrompt←1
  75           SFD.InitialDirectory←'::{20D04FE0-3AEA-1069-A2D8-08002B30309D}' ⍝ My Computer
  76           ⍝ OFD.InitialDirectory←'::{450D8FBA-AD25-11D0-98A8-0800361B1103}' ⍝ My Documents
  77           ⍝ OFD.InitialDirectory←'::{208D2C60-3AEA-1069-A2D7-08002B30309D}' ⍝ My Network Places
  78      
  79           ⍝ Shows the Dialog as Modal and Owned by the Current APL Process
  80           :If DR.OK=SFD.ShowDialog ⍬
  81               file_name←SFD.FileName
  82           :Else
  83               file_name←''
  84           :End
  85      
  86           SFD.Dispose  ⍝ With ShowDialog the form is not dispose automatically.
  87      
  88       :Else
  89           ⍝ Unexpected Error
  90           ⎕←GetLastError
  91           file_name←''
  92       :EndTrap
  93 
  94 
  95     ∇ r←{ownerwindow}ShowError(message caption button);⎕USING
  96       :Access Public Shared
  97     ⍝ Show an Error Message.
  98     ⍝ By default, the message box appears in front of the window that is currently active.
  99     ⍝ If {ownerwindow} is supplied it will displays the message box in front of the specified window
 100 
 101     ⍝ message = Error Message to Display (insert a ⎕UCS 13 in text to force a new line)
 102     ⍝ caption = Title Bar Caption (ex. 'ProgramName Error')
 103     ⍝ button  = Button Value (ex. 'OK', 'OKCancel' 'YesNo' 'YesNoCancel')
 104     ⍝ ownerwindow = WPF window [optional]
 105 
 106     ⍝ r = Button Clicked. OK=1, Cancel=2, Yes=6, No=7, Program Error=0
 107      
 108       ⎕USING←'System.Windows,WPF/PresentationFramework.dll'
 109      
 110       :Trap 0
 111           :If 0≠⎕NC'ownerwindow'
 112           :AndIf 'Window'≡ownerwindow.GetType.Name
 113               r←MessageBox.Show ownerwindow message caption(⍎'MessageBoxButton.',button)(MessageBoxImage.Error)
 114           :Else
 115               r←MessageBox.Show message caption(⍎'MessageBoxButton.',button)(MessageBoxImage.Error)
 116           :End
 117      
 118           r←r.value__ ⍝ To obtain a numeric value, otherwise it will be litteral
 119       :Else
 120         ⍝ Unexpected Error
 121           ⎕←GetLastError
 122           r←0
 123       :EndTrap
 124 
 125 
 126     ∇ r←{ownerwindow}ShowInfo(message caption button);⎕USING
 127       :Access Public Shared
 128     ⍝ Show an Information Message.
 129     ⍝ By default, the message box appears in front of the window that is currently active.
 130     ⍝ If {ownerwindow} is supplied it will displays the message box in front of the specified window
 131 
 132     ⍝ message = Information Message to Display (insert a ⎕UCS 13 in text to force a new line)
 133     ⍝ caption = Title Bar Caption (ex. 'ProgramName Info')
 134     ⍝ button  = Button Value (ex. 'OK', 'OKCancel' 'YesNo' 'YesNoCancel')
 135     ⍝ ownerwindow = WPF window [optional]
 136 
 137     ⍝ r = Button Clicked. OK=1, Cancel=2, Yes=6, No=7, Program Error=0
 138      
 139       ⎕USING←'System.Windows,WPF/PresentationFramework.dll'
 140      
 141       :Trap 0
 142           :If 0≠⎕NC'ownerwindow'
 143           :AndIf 'Window'≡ownerwindow.GetType.Name
 144               r←MessageBox.Show ownerwindow message caption(⍎'MessageBoxButton.',button)(MessageBoxImage.Information)
 145           :Else
 146               r←MessageBox.Show message caption(⍎'MessageBoxButton.',button)(MessageBoxImage.Information)
 147           :End
 148      
 149           r←r.value__ ⍝ To obtain a numeric value, otherwise it will be litteral
 150       :Else
 151         ⍝ Unexpected Error
 152           ⎕←GetLastError
 153           r←0
 154       :EndTrap
 155 
 156 
 157     ∇ r←{ownerwindow}ShowWarning(message caption button);⎕USING
 158       :Access Public Shared
 159     ⍝ Show an Information Message.
 160     ⍝ By default, the message box appears in front of the window that is currently active.
 161     ⍝ If {ownerwindow} is supplied it will displays the message box in front of the specified window
 162 
 163     ⍝ message = Information Message to Display (insert a ⎕UCS 13 in text to force a new line)
 164     ⍝ caption = Title Bar Caption (ex. 'ProgramName Warning')
 165     ⍝ button  = Button Value (ex. 'OK', 'OKCancel' 'YesNo' 'YesNoCancel')
 166     ⍝ ownerwindow = WPF window [optional]
 167 
 168     ⍝ r = Button Clicked. OK=1, Cancel=2, Yes=6, No=7, Program Error=0
 169      
 170       ⎕USING←'System.Windows,WPF/PresentationFramework.dll'
 171      
 172       :Trap 0
 173           :If 0≠⎕NC'ownerwindow'
 174           :AndIf 'Window'≡ownerwindow.GetType.Name
 175               r←MessageBox.Show ownerwindow message caption(⍎'MessageBoxButton.',button)(MessageBoxImage.Warning)
 176           :Else
 177               r←MessageBox.Show message caption(⍎'MessageBoxButton.',button)(MessageBoxImage.Warning)
 178           :End
 179      
 180           r←r.value__ ⍝ To obtain a numeric value, otherwise it will be litteral
 181       :Else
 182         ⍝ Unexpected Error
 183           ⎕←GetLastError
 184           r←0
 185       :EndTrap
 186 
 187 
 188     ∇ r←GetLastError
 189       ⍝ Returns the Last Error
 190      
 191       :If 90=⎕EN
 192           r←'EXCEPTION: ',⎕EXCEPTION.Message
 193       :Else
 194           r←(1⊃⎕DM),': ',{(~(∧\' '=⍵)∨(⌽∧\⌽' '=⍵))/⍵}(2⊃⎕DM)
 195       :EndIf
 196 
 197 
 198 :EndNamespace

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2015-02-23 01:39:07, 13.6 KB) [[attachment:DialogFolder.png]]
  • [get | view] (2015-02-23 01:39:24, 49.7 KB) [[attachment:DialogOpenFile.png]]
  • [get | view] (2015-02-23 01:39:43, 47.9 KB) [[attachment:DialogSaveFile.png]]
  • [get | view] (2015-02-23 01:40:01, 6.2 KB) [[attachment:ShowError.png]]
  • [get | view] (2015-02-23 01:40:24, 6.2 KB) [[attachment:ShowInfo.png]]
  • [get | view] (2015-02-23 01:41:06, 5.6 KB) [[attachment:ShowWarning.png]]
  • [get | view] (2015-02-23 01:37:21, 7.4 KB) [[attachment:wpfDialogBox.v1.0.txt]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.