Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/CopyFile Test
This example is the version from Wed, 20th Aug 2019.
Project "CopyFile Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
// maybe register plugin here
#If Not TargetMacOS Then
MsgBox "This is for MacOS only!"
#EndIf
MainWindow.show
End EventHandler
EventHandler Function UnhandledException(error As RuntimeException) As Boolean
Dim stack() As String = error.Stack
MsgBox Join(stack, EndOfLine)
Break
End EventHandler
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control MyThread Inherits Thread
ControlInstance MyThread Inherits Thread
EventHandler Sub Run()
me.Sleep 10 // let window show
Dim m As New MyCopyFile
m.list = List
m.YieldTicks = 3 // 20 times per second, we yield to other threads
Dim flags As Integer = m.kFlagsAll
flags = BitwiseOr(flags, m.kFlagsRecursive)
result = m.CopyFile(source, dest, flags)
xojo.Core.Timer.CallLater 0, WeakAddressOf threadFinished
End EventHandler
End Control
EventHandler Sub Open()
source = SpecialFolder.Desktop.Child("test")
dest = SpecialFolder.Desktop.Child("dest")
If Not source.Exists Then
// please put a test folder on desktop
Break
End If
MyThread.run
End EventHandler
Sub threadFinished()
// show msgbox on main thread
If result = 0 Then
MsgBox "Copy successful."
Else
MsgBox "Failed to copy."+EndOfLine+EndOfLine+CopyFileMBS.ErrorMessage(result)
End If
End Sub
Property Dest As FolderItem
Property Source As FolderItem
Property result As Integer
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyCopyFile Inherits CopyFileMBS
EventHandler Function Progress(What as Integer, Stage as Integer, Source as String, Dest as String) As Integer
Dim WhatString As String
Select Case what
Case kWhatCopyData
WhatString = "Copy Data"
Case kWhatCopyXAttr
WhatString = "Copy XAttr"
Case kWhatRecurseDir
WhatString = "Recurse Dir"
Case kWhatRecurseDirCleanup
WhatString = "Recurse Dir Cleanup"
Case kWhatRecurseError
WhatString = "Recurse Error"
Case kWhatRecurseFile
WhatString = "Recurse File"
Else
Break
End Select
Dim StageString As String
Select Case Stage
Case kStageError
StageString = "Error"
Case kStageFinish
StageString = "Finish"
Case kStageProgress
StageString = "Progress"
Case kStageStart
StageString = "Start"
Else
Break
End Select
Dim values() As String
values.Append WhatString
values.Append StageString
values.Append source
values.Append dest
values.Append Str(Me.BytesCopied)
// don't use WeakAddressOf here as it may cause NilObjectException later
xojo.core.Timer.CallLater 0, AddressOf AddToLogList, values
End EventHandler
Sub AddToLogList(values as auto)
// add to list on main thread
Dim v() As String = values
list.AddRow v
End Sub
Property list As listbox
End Class
End Project
The items on this page are in the following plugins: MBS MacOSX Plugin.