Enhancements to DiskCopy. #8
@@ -1,4 +1,5 @@
|
|||||||
local Ansi = require('ansi')
|
local Ansi = require('ansi')
|
||||||
|
local Config = require('config')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@@ -28,7 +29,12 @@ local directions = {
|
|||||||
[ COPY_LEFT ] = { text = '-->>' },
|
[ COPY_LEFT ] = { text = '-->>' },
|
||||||
[ COPY_RIGHT ] = { text = '<<--' },
|
[ COPY_RIGHT ] = { text = '<<--' },
|
||||||
}
|
}
|
||||||
local copyDir = COPY_LEFT
|
|
||||||
|
local config = Config.load('DiskCopy', {
|
||||||
|
eject = true,
|
||||||
|
automatic = false,
|
||||||
|
copyDir = COPY_LEFT
|
||||||
|
})
|
||||||
|
|
||||||
local page = UI.Page {
|
local page = UI.Page {
|
||||||
linfo = UI.Window {
|
linfo = UI.Window {
|
||||||
@@ -45,13 +51,20 @@ local page = UI.Page {
|
|||||||
x = 2, ex = -2, y = -4,
|
x = 2, ex = -2, y = -4,
|
||||||
backgroundColor = colors.black,
|
backgroundColor = colors.black,
|
||||||
},
|
},
|
||||||
cloneText = UI.Text {
|
ejectText = UI.Text {
|
||||||
x = 2, y = -2,
|
x = 2, y = -2,
|
||||||
value = 'Clone'
|
value = 'Eject'
|
||||||
},
|
},
|
||||||
clone = UI.Checkbox {
|
eject = UI.Checkbox {
|
||||||
x = 8, y = -2,
|
x = 8, y = -2,
|
||||||
},
|
},
|
||||||
|
automaticText = UI.Text {
|
||||||
|
x = 12, y = -2,
|
||||||
|
value = 'Copy automatically'
|
||||||
|
},
|
||||||
|
automatic = UI.Checkbox {
|
||||||
|
x = 31, y = -2,
|
||||||
|
},
|
||||||
copyButton = UI.Button {
|
copyButton = UI.Button {
|
||||||
x = -7, y = -2,
|
x = -7, y = -2,
|
||||||
text = 'Copy',
|
text = 'Copy',
|
||||||
@@ -67,7 +80,13 @@ local page = UI.Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function page:enable()
|
function page:enable()
|
||||||
Util.merge(self.dir, directions[copyDir])
|
Util.merge(self.dir, directions[config.copyDir])
|
||||||
|
|
||||||
|
self.eject.value = config.eject
|
||||||
|
self.automatic.value = config.automatic
|
||||||
|
|
||||||
|
self.dir.x = math.floor((self.width / 2) - 3) + 1
|
||||||
|
|
||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -119,7 +138,10 @@ function page:scan()
|
|||||||
self.progress:clear()
|
self.progress:clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:copy(sdrive, tdrive)
|
function page:copy()
|
||||||
|
local sdrive = config.copyDir == COPY_LEFT and drives.left or drives.right
|
||||||
|
local tdrive = config.copyDir == COPY_LEFT and drives.right or drives.left
|
||||||
|
|
||||||
local throttle = Util.throttle()
|
local throttle = Util.throttle()
|
||||||
local sourceFiles, targetFiles = { }, { }
|
local sourceFiles, targetFiles = { }, { }
|
||||||
|
|
||||||
@@ -187,28 +209,48 @@ function page:copy(sdrive, tdrive)
|
|||||||
self.progress:clear()
|
self.progress:clear()
|
||||||
|
|
||||||
self:scan()
|
self:scan()
|
||||||
|
|
||||||
|
if config.eject then
|
||||||
|
tdrive.ejectDisk()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'change_dir' then
|
if event.type == 'change_dir' then
|
||||||
copyDir = (copyDir) % 2 + 1
|
config.copyDir = (config.copyDir) % 2 + 1
|
||||||
Util.merge(self.dir, directions[copyDir])
|
Util.merge(self.dir, directions[config.copyDir])
|
||||||
|
Config.update('DiskCopy', config)
|
||||||
self.dir:draw()
|
self.dir:draw()
|
||||||
|
|
||||||
elseif event.type == 'copy' then
|
elseif event.type == 'copy' then
|
||||||
if copyDir == COPY_LEFT then
|
self:copy()
|
||||||
self:copy(drives.left, drives.right)
|
|
||||||
else
|
elseif event.type == 'checkbox_change' then
|
||||||
self:copy(drives.right, drives.left)
|
if event.element == self.eject then
|
||||||
|
config.eject = not not event.checked
|
||||||
|
elseif event.element == self.automatic then
|
||||||
|
config.automatic = not not event.checked
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Config.update('DiskCopy', config)
|
||||||
|
event.element:draw()
|
||||||
|
|
||||||
else
|
else
|
||||||
return UI.Page.eventHandler(self, event)
|
return UI.Page.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
Event.on({ 'disk', 'disk_eject' }, function()
|
Event.on("disk", function()
|
||||||
|
page:scan()
|
||||||
|
page:sync()
|
||||||
|
|
||||||
|
if config.automatic and not page.copyButton.inactive then
|
||||||
|
page:copy()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Event.on("disk_eject", function()
|
||||||
page:scan()
|
page:scan()
|
||||||
page:sync()
|
page:sync()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user