on baCopyXFilesProgress sourceDir, destDir, fileSpec, overwrite
-- replacement for baCopyXFiles which adds a progress copy dialog with cancel button
-- reuires MUI Xtra
global gKeepCopying
set sDir = addSeperator( sourceDir )
set dDir = addSeperator( destDir )
set fileList = baFileList( sDir, fileSpec )
set fileCount = count( fileList )
if fileCount > 0 then
set fileNum = 1
set gKeepCopying = true
showCopyProgress
repeat while (fileNum <= fileCount ) and (gKeepCopying = true) )
setCopyStatus "Copying:" && getAt( fileList, fileNum ), fileNum, fileCount
baCopyFile( sDir & getAt( fileList, fileNum ), dDir & getAt( fileList, fileNum ), overwrite )
set fileNum = fileNum + 1
end repeat
closeCopyProgress
end if
end
on baXCopyProgress sourceDir, destDir, fileSpec, overwrite
-- replaces baXCopy to show a progress copy dialog with cancel button
-- requires MUI Xtra
global gKeepCopying
set sDir = addSeperator( sourceDir )
set dDir = addSeperator( destDir )
-- can take some time to prepare list of files, so show dialog first
showCopyProgress
setCopyStatus "Preparing to copy...", 1, 100
set folderList = getAllSubFolders( sDir )
addAt( folderList, 1, sDir )
set folderCount = count( folderList )
set sourceList = []
set destList = []
set folderNum = 1
set startPos = length( sDir ) + 1
repeat while folderNum <= folderCount
set fileList = baFileList( string( getAt( folderList, folderNum )), fileSpec )
set fileCount = count( fileList )
set fileNum = 1
repeat while fileNum <= fileCount
append sourceList, getAt( folderList, folderNum ) & getAt( fileList, fileNum )
append destList, dDir & chars( getAt( folderList, folderNum ), startPos, 1000 ) & getAt( fileList, fileNum )
set fileNum = fileNum + 1
end repeat
set folderNum = folderNum + 1
end repeat
set fileCount = count( sourceList )
if fileCount > 0 then
set the itemDelimiter = the last char of sDir
set fileNum = 1
set gKeepCopying = true
repeat while (fileNum <= fileCount ) and (gKeepCopying = true) )
setCopyStatus "Copying:" && the last item of getAt( sourceList, fileNum ), fileNum, fileCount
baCopyFile( getAt( sourceList, fileNum ), getAt( destList, fileNum ), overwrite )
set fileNum = fileNum + 1
end repeat
end if
closeCopyProgress
end baXCopyProgress
on setCopyStatus status, number, total,
global gMUIobject, gWindowItems, gWindowProps
set baseItemList = duplicate( getAt( gWindowItems, 2 ) )
set the value of baseItemList = string( status )
itemUpdate( gMUIobject, 2, baseItemList )
set baseItemList = duplicate( getAt( gWindowItems, 4 ) )
set the value of baseItemList = "pb" & string( 22 * number / total )
itemUpdate( gMUIobject, 4, baseItemList )
end
on getAllSubFolders startDir
-- returns a list of all the sub folders in startDir
-- returns empty list if no subfolders or startDir doesn't exist
-- reuturns full path to the folders, always ends with folder delimiter
if the platform contains "Win" then
set delimiter = "\"
else
set delimiter = ":"
end if
set result = []
if baFolderExists( startDir ) then
if the last char of startDir = delimiter then
append result, startDir
else
append result, startDir & delimiter
end if
set i = 1
repeat while i <= count( result )
getFolders( getAt( result, i ), result ) -- add list of sub folders to end of list
set i = i + 1 -- keep going till no more folders
end repeat
deleteAt result, 1 -- delete original folder from start of list
end if
return result
end
on getFolders startDir, folderList
-- adds a list of folders to list
if the platform contains "Win" then
set delimiter = "\"
else
set delimiter = ":"
end if
set temp = baFolderList( startDir )
set i = 1
repeat while i <= count( temp )
append folderList, startDir & getAt( temp, i ) & delimiter
set i = i + 1
end repeat
end
on addSeperator source
if the platform contains "Win" then
set seperator = "\"
else
set seperator = ":"
end if
if the last char of source <> seperator then
return source & seperator
else
return source
end if
end
-- Dialog box based on code from 'Lingo in a Nutshell' by Bruce Epstein
-- If you don't have a copy, get one now!
on showCopyProgress
global gMUIobject
global gWindowProps
global gWindowItems
set dialogWidth = 250
set dialogHeight = 115
-- Instantiate the Xtra
set gMUIobject = new (xtra "MUI")
-- Start with the default container window's attributes
set gWindowProps = GetWindowPropList(gMUIobject)
-- Set the title and width of the dialog
set the name of gWindowProps = "Copy progress"
set the width of gWindowProps = dialogWidth
set the Mode of gWindowProps = #pixel
set the xPosition of gWindowProps = the stageLeft + ((the stageRight - the stageLeft) - dialogWidth) / 2
set the yPosition of gWindowProps = the stageTop + ((the stageBottom - the stageTop) - dialogWidth) / 2
set the height of gWindowProps = dialogHeight
set the modal of gWindowProps = false
set the closeBox of gWindowProps = false
-- Specify callback handler that responds to user actions
set the callback of gWindowProps = "copyProgressHandler()"
-- Build a list of the contents of the window
set gWindowItems = []
-- The first widget in the dialog must be #WindowBegin
-- Start with a generic item's attributes
set widget1 = GetItemPropList(gMUIobject)
set the type of widget1 = #windowBegin
add gWindowItems, widget1
-- Add a simple text field
set widget2 = GetItemPropList(gMUIobject)
set the value of widget2 = "Copying: "
set the type of widget2 = #label
set the width of widget2 = dialogWidth - 20
set the locH of widget2 = 13
set the locV of widget2 = 12
set the height of widget2 = 20
add gWindowItems, widget2
-- Add a dismiss button
set widget3 = GetItemPropList(gMUIobject)
set the type of widget3 = #defaultPushButton
set the title of widget3 = "Cancel"
set the width of widget3 = 100
set the locH of widget3 = (dialogWidth - the width of widget3) / 2
set the height of widget3 = 24
set the locV of widget3 = dialogHeight - 34
add gWindowItems, widget3
-- add bitmap
set widget4 = GetItemPropList(gMUIobject)
set the type of widget4 = #bitmap
set the value of widget4 = "pb0"
set the width of widget4 = 224
set the locH of widget4 = (dialogWidth - the width of widget4) / 2
set the height of widget4 = 20
set the locV of widget4 = dialogHeight - 75
add gWindowItems, widget4
-- The last widget in the dialog must be #WindowEnd
set widget5 = GetItemPropList(gMUIobject)
set the type of widget5 = #windowEnd
add gWindowItems, widget5
-- Draw the dialog
--Run (gMUIobject)
WindowOperation( gMUIobject, #show )
end showCopyProgress
-- This is your callback handler (see gWindowProps above)
on copyProgressHandler event, itemNumber, itemPropList
global gMUIobject, gKeepCopying
if not objectP(gMUIobject ) then
alert "gMUIobject must be declared globally elsewhere"
exit
end if
case (event) of
#itemClicked:
-- In an emergency this will stop both
-- modal and non-modal dialogs.
set gKeepCopying = false
stop(gMUIobject, 1)
windowOperation (gMUIobject , #hide)
otherwise:
nothing
end case
end copyProgressHandler
on closeCopyProgress
global gMUIobject, gKeepCopying
set gKeepCopying = false
stop(gMUIobject, 1)
windowOperation (gMUIobject , #hide)
end closeCopyProgress
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA