SUB FileListDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
IF Event% = EVENT_INITIALIZATION THEN
ShowFileListDialog.DirectoryListBox.SetStyle STYLE_INVISIBLE 'hide directory list box (for tracking files - user doesn't need to see this)
ShowFileListDialog.SelectedDirectoryListBox.SetStyle STYLE_INVISIBLE 'hide selected directory list box (for tracking files - user doesn't need to see this)
ShowFileListDialog.FilesCountText.SetStyle STYLE_RIGHT_JUSTIFY 'right justify text displaying file count
ShowFileListDialog.SelectedFilesCountText.SetStyle STYLE_RIGHT_JUSTIFY 'right justify text displaying selected files count
'disable NEXT button until file(s) have been selected
IF ShowFileListDialog.SelectedFileListBox.GetItemCount() = 0 THEN
ShowFileListDialog.NextButton.Enable FALSE
ELSE
ShowFileListDialog.NextButton.Enable TRUE
ENDIF
'IF files have already been selected, display same list
IF SelectedFilesCount > 0 THEN
ShowFileListDialog.FileListBox.SetArray AvailableFiles$ 'display available files list in Available Files listbox
ShowFileListDialog.DirectoryListBox.SetArray AvailableDirs$ 'display available dirs list in Avaialable Dirs listbox
ShowFileListDialog.SelectedFileListBox.SetArray SelectedFiles$ 'display selected files list in Selected Files listbox
ShowFileListDialog.SelectedDirectoryListBox.SetArray SelectedDirs$ 'display selected dirs list in Selected Dirs listbox
'get and display list of files (with extension FileExt$) starting in Source directory
ELSE
GetFileList SourceDir$, FileExt$ 'get file list
ShowFileListDialog.FileListBox.SetSelect 1 'give focus to first element in file list box
ShowFileListDialog.StatusText.SetText ShowFileListDialog.DirectoryListBox.GetItem(1) 'set status text to first item in file list
ShowFileListDialog.FilesCountText.SetText ShowFileListDialog.FileListBox.GetItemCount() 'set file count to number of available files
ShowFileListDialog.SelectedFilesCountText.SetText ShowFileListDialog.SelectedFileListBox.GetItemCount() 'set selected files count to number of selected files
REDIM AvailableFiles$(AvailableFilesCount) 'redimension array to accomodate all available files
REDIM AvailableDirs$(AvailableFilesCount) 'redimension array to accomodate all available directories
FOR i% = 1 TO AvailableFilesCount% 'FOR all items in avialable files list
AvailableFiles$(i%) = ShowFileListDialog.FileListBox.GetItem(i%) 'add item to file list
AvailableDirs$(i%) = ShowFileListDialog.DirectoryListBox.GetItem(i%) 'add item to directory list
NEXT i%
ShowFileListDialog.closedialog DIALOG_RETURN_NEXT
CASE ShowFileListDialog.BackButton.GetID()
ShowFileListDialog.closedialog DIALOG_RETURN_BACK
CASE ShowFileListDialog.SelectButton.GetID()
indx% = ShowFileListDialog.FileListBox.GetSelect() 'get index of current selection
IF indx%=0 THEN 'no files selected, display appropriate message
IF ShowFileListDialog.FileListBox.GetItemCount() = 0 THEN
MESSAGE "There are no files available for selection."
ELSE
MESSAGE "Please select a file from the available files list."
ENDIF
ELSE 'valid selection, add current selection to selected files list
ShowFileListDialog.SelectedFileListBox.AddItem ShowFileListDialog.FileListBox.GetItem(indx%) 'add current selection to selected files list
ShowFileListDialog.FileListBox.RemoveItem indx% 'remove current selection from available files list
ShowFileListDialog.SelectedDirectoryListBox.AddItem ShowFileListDialog.DirectoryListBox.GetItem(indx%) 'add current selection to selected directory list
ShowFileListDialog.DirectoryListBox.RemoveItem indx% 'remove current selection from available directory list
IF indx% > ShowFileListDialog.FileListBox.GetItemCount() THEN 'IF current selection is not the last
ShowFileListDialog.FileListBox.SetSelect indx%-1 'set focus to previous item
ELSE
ShowFileListDialog.FileListBox.SetSelect indx% 'ELSE set focus to current selection
indx% = ShowFileListDialog.SelectedFileListBox.GetSelect() 'get index of current selection
IF indx%=0 THEN 'no files selected, display appropriate message
IF ShowFileListDialog.SelectedFileListBox.GetItemCount() = 0 THEN
MESSAGE "There are no files available for deselection"
ELSE
MESSAGE "Please select a file from the selected files list."
ENDIF
ELSE 'valid selection, remove current selection from selected files list
ShowFileListDialog.FileListBox.AddItem ShowFileListDialog.SelectedFileListBox.GetItem(indx%) 'add current selection to available files list
ShowFileListDialog.SelectedFileListBox.RemoveItem indx% 'remove current selection from selected files list
ShowFileListDialog.DirectoryListBox.AddItem ShowFileListDialog.SelectedDirectoryListBox.GetItem(indx%) 'add current selection to available directory list
ShowFileListDialog.SelectedDirectoryListBox.RemoveItem indx% 'remove current selection from selected directory list
IF indx% > ShowFileListDialog.SelectedFileListBox.GetItemCount() THEN 'IF current selection is not the last
ShowFileListDialog.SelectedFileListBox.SetSelect indx%-1 'set focus to previous item
ELSE
ShowFileListDialog.SelectedFileListBox.SetSelect indx% 'ELSE set focus to current selection
'This section finds files of the type specified by FileExt in the directory specified by SourceDir
File$ = FINDFIRSTFOLDER(SourceDir$ & FileExt$, FILEATTR_READ_ONLY OR FILEATTR_HIDDEN OR FILEATTR_SYSTEM OR FILEATTR_ARCHIVE OR FILEATTR_NORMAL_FILE OR FILEATTR_TEMPORARY OR FILEATTR_COMPRESSED)
DO WHILE File$ <> ""
ShowFileListDialog.FileListBox.AddItem File$ 'add file name to File drop-down list
ShowFileListDialog.DirectoryListBox.AddItem SourceDir$ 'add file dir to Directory drop-down list
File$ = FINDNEXTFOLDER()
LOOP
'This section finds directories starting in the directory specified by SourceDir
File$ = FINDFIRSTFOLDER(SourceDir$ & "*.*", FILEATTR_FOLDER OR FILEATTR_READ_ONLY OR FILEATTR_HIDDEN OR FILEATTR_SYSTEM OR FILEATTR_ARCHIVE OR FILEATTR_NORMAL_FILE OR FILEATTR_TEMPORARY OR FILEATTR_COMPRESSED)
DO WHILE File$ <> ""
IF File$ <> "." AND File$ <> ".." AND File$ <> SourceDir$ THEN
GetFileList SourceDir$ & File$ & "\", FileExt$
' This next loop resets the FINDNEXTFOLDER function to the same place as it was before
' we recursed into ourselves.
SearchFile$ = FINDFIRSTFOLDER(SourceDir$ & "*.*", FILEATTR_FOLDER OR FILEATTR_READ_ONLY OR FILEATTR_HIDDEN OR FILEATTR_SYSTEM OR FILEATTR_ARCHIVE OR FILEATTR_NORMAL_FILE OR FILEATTR_TEMPORARY OR FILEATTR_COMPRESSED)