2012-02-06 02:44:47 +01:00
|
|
|
ModuleManager = {}
|
|
|
|
|
|
|
|
local moduleManagerWindow
|
|
|
|
local moduleManagerButton
|
|
|
|
local moduleList
|
|
|
|
|
|
|
|
function ModuleManager.init()
|
2012-06-26 00:13:30 +02:00
|
|
|
moduleManagerWindow = g_ui.displayUI('modulemanager.otui')
|
2012-02-06 02:44:47 +01:00
|
|
|
moduleManagerWindow:hide()
|
|
|
|
moduleList = moduleManagerWindow:getChildById('moduleList')
|
|
|
|
connect(moduleList, { onChildFocusChange = function(self, focusedChild)
|
|
|
|
if focusedChild == nil then return end
|
|
|
|
ModuleManager.updateModuleInfo(focusedChild:getText())
|
|
|
|
end })
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.bindKeyPress('Up', function() moduleList:focusPreviousChild(KeyboardFocusReason) end, moduleManagerWindow)
|
|
|
|
g_keyboard.bindKeyPress('Down', function() moduleList:focusNextChild(KeyboardFocusReason) end, moduleManagerWindow)
|
2012-02-06 13:53:28 +01:00
|
|
|
|
2012-04-26 21:54:16 +02:00
|
|
|
moduleManagerButton = TopMenu.addLeftButton('moduleManagerButton', tr('Module Manager'), 'modulemanager.png', ModuleManager.toggle)
|
2012-02-06 02:44:47 +01:00
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
-- refresh modules only after all modules are loaded
|
2012-02-06 02:44:47 +01:00
|
|
|
addEvent(ModuleManager.listModules)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.terminate()
|
|
|
|
moduleManagerWindow:destroy()
|
|
|
|
moduleManagerWindow = nil
|
|
|
|
moduleManagerButton:destroy()
|
|
|
|
moduleManagerButton = nil
|
|
|
|
moduleList = nil
|
2012-02-07 01:41:53 +01:00
|
|
|
ModuleManager = nil
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.hide()
|
|
|
|
moduleManagerWindow:hide()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.show()
|
|
|
|
moduleManagerWindow:show()
|
|
|
|
moduleManagerWindow:raise()
|
2012-02-20 03:27:08 +01:00
|
|
|
moduleManagerWindow:focus()
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.toggle()
|
|
|
|
if moduleManagerWindow:isVisible() then
|
|
|
|
ModuleManager.hide()
|
|
|
|
else
|
|
|
|
ModuleManager.show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.refreshModules()
|
|
|
|
g_modules.discoverModules()
|
|
|
|
ModuleManager.listModules()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.listModules()
|
2012-02-06 20:19:47 +01:00
|
|
|
if not moduleManagerWindow then return end
|
|
|
|
|
2012-02-06 02:44:47 +01:00
|
|
|
moduleList:destroyChildren()
|
|
|
|
|
|
|
|
local modules = g_modules.getModules()
|
|
|
|
for i,module in ipairs(modules) do
|
2012-06-26 00:13:30 +02:00
|
|
|
local label = g_ui.createWidget('ModuleListLabel', moduleList)
|
2012-02-06 02:44:47 +01:00
|
|
|
label:setText(module:getName())
|
2012-02-06 20:19:47 +01:00
|
|
|
label:setOn(module:isLoaded())
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
moduleList:focusChild(moduleList:getFirstChild(), ActiveFocusReason)
|
|
|
|
end
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
function ModuleManager.refreshLoadedModules()
|
|
|
|
if not moduleManagerWindow then return end
|
|
|
|
|
|
|
|
for i,child in ipairs(moduleList:getChildren()) do
|
|
|
|
local module = g_modules.getModule(child:getText())
|
|
|
|
child:setOn(module:isLoaded())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-06 02:44:47 +01:00
|
|
|
function ModuleManager.updateModuleInfo(moduleName)
|
2012-02-06 20:19:47 +01:00
|
|
|
if not moduleManagerWindow then return end
|
|
|
|
|
2012-02-06 02:44:47 +01:00
|
|
|
local name = ''
|
|
|
|
local description = ''
|
|
|
|
local autoLoad = ''
|
|
|
|
local author = ''
|
|
|
|
local website = ''
|
|
|
|
local version = ''
|
2012-02-06 20:19:47 +01:00
|
|
|
local loaded = false
|
|
|
|
local canReload = false
|
2012-02-06 02:44:47 +01:00
|
|
|
local canUnload = false
|
|
|
|
|
|
|
|
local module = g_modules.getModule(moduleName)
|
|
|
|
if module then
|
|
|
|
name = module:getName()
|
|
|
|
description = module:getDescription()
|
|
|
|
author = module:getAuthor()
|
|
|
|
website = module:getWebsite()
|
|
|
|
version = module:getVersion()
|
2012-02-06 20:19:47 +01:00
|
|
|
loaded = module:isLoaded()
|
2012-02-20 03:27:08 +01:00
|
|
|
canReload = module:canReload()
|
2012-02-06 20:19:47 +01:00
|
|
|
canUnload = module:canUnload()
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name)
|
|
|
|
moduleManagerWindow:recursiveGetChildById('moduleDescription'):setText(description)
|
|
|
|
moduleManagerWindow:recursiveGetChildById('moduleAuthor'):setText(author)
|
|
|
|
moduleManagerWindow:recursiveGetChildById('moduleWebsite'):setText(website)
|
|
|
|
moduleManagerWindow:recursiveGetChildById('moduleVersion'):setText(version)
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
local reloadButton = moduleManagerWindow:recursiveGetChildById('moduleReloadButton')
|
|
|
|
reloadButton:setEnabled(canReload)
|
|
|
|
if loaded then reloadButton:setText('Reload')
|
|
|
|
else reloadButton:setText('Load') end
|
|
|
|
|
|
|
|
local unloadButton = moduleManagerWindow:recursiveGetChildById('moduleUnloadButton')
|
|
|
|
unloadButton:setEnabled(canUnload)
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
function ModuleManager.reloadCurrentModule()
|
2012-02-06 02:44:47 +01:00
|
|
|
local focusedChild = moduleList:getFocusedChild()
|
|
|
|
if focusedChild then
|
|
|
|
local module = g_modules.getModule(focusedChild:getText())
|
|
|
|
if module then
|
2012-02-06 20:19:47 +01:00
|
|
|
module:reload()
|
2012-02-20 03:27:08 +01:00
|
|
|
if ModuleManager == nil then return end
|
2012-02-06 02:44:47 +01:00
|
|
|
ModuleManager.updateModuleInfo(module:getName())
|
2012-02-06 20:19:47 +01:00
|
|
|
ModuleManager.refreshLoadedModules()
|
|
|
|
ModuleManager.show()
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ModuleManager.unloadCurrentModule()
|
|
|
|
local focusedChild = moduleList:getFocusedChild()
|
|
|
|
if focusedChild then
|
|
|
|
local module = g_modules.getModule(focusedChild:getText())
|
|
|
|
if module then
|
|
|
|
module:unload()
|
2012-02-20 03:27:08 +01:00
|
|
|
if ModuleManager == nil then return end
|
2012-02-06 02:44:47 +01:00
|
|
|
ModuleManager.updateModuleInfo(module:getName())
|
2012-02-06 20:19:47 +01:00
|
|
|
ModuleManager.refreshLoadedModules()
|
2012-02-06 02:44:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
function ModuleManager.reloadAllModules()
|
2012-07-19 20:54:24 +02:00
|
|
|
g_modules.reloadModules()
|
2012-02-06 20:19:47 +01:00
|
|
|
ModuleManager.refreshLoadedModules()
|
|
|
|
ModuleManager.show()
|
|
|
|
end
|
|
|
|
|