mirror of
https://github.com/kepler155c/opus
synced 2024-11-15 21:24:49 +00:00
7224d441ca
* canvas overhaul * minor tweaks * list mode for overview * bugfixes + tweaks for editor 2.0 * minor tweaks * more editor work * refactor + new transitions * use layout() where appropriate and cleanup * mouse triple click + textEntry scroll ind * cleanup * cleanup + theme editor * color rework + cleanup * changes for deprecated ui methods * can now use named colors
78 lines
1.7 KiB
Lua
78 lines
1.7 KiB
Lua
local Array = require('opus.array')
|
|
local Config = require('opus.config')
|
|
local UI = require('opus.ui')
|
|
|
|
local tab = UI.Tab {
|
|
tabTitle = 'Preferred',
|
|
description = 'Select preferred applications',
|
|
apps = UI.ScrollingGrid {
|
|
x = 2, y = 2,
|
|
ex = 12, ey = -3,
|
|
columns = {
|
|
{ key = 'name' },
|
|
},
|
|
sortColumn = 'name',
|
|
disableHeader = true,
|
|
},
|
|
choices = UI.Grid {
|
|
x = 14, y = 2,
|
|
ex = -2, ey = -3,
|
|
disableHeader = true,
|
|
columns = {
|
|
{ key = 'file' },
|
|
},
|
|
getRowTextColor = function(self, row)
|
|
if row == self.values[1] then
|
|
return 'yellow'
|
|
end
|
|
return UI.Grid.getRowTextColor(self, row)
|
|
end,
|
|
},
|
|
statusBar = UI.StatusBar {
|
|
values = 'Double-click to set as preferred'
|
|
},
|
|
}
|
|
|
|
function tab:updateChoices()
|
|
local app = self.apps:getSelected().name
|
|
local choices = { }
|
|
for _, v in pairs(self.config[app]) do
|
|
table.insert(choices, { file = v })
|
|
end
|
|
self.choices:setValues(choices)
|
|
self.choices:draw()
|
|
end
|
|
|
|
function tab:enable()
|
|
self.config = Config.load('alternate')
|
|
|
|
local apps = { }
|
|
for k, _ in pairs(self.config) do
|
|
table.insert(apps, { name = k })
|
|
end
|
|
self.apps:setValues(apps)
|
|
|
|
self:updateChoices()
|
|
|
|
UI.Tab.enable(self)
|
|
end
|
|
|
|
function tab:eventHandler(event)
|
|
if event.type == 'grid_focus_row' and event.element == self.apps then
|
|
self:updateChoices()
|
|
|
|
elseif event.type == 'grid_select' and event.element == self.choices then
|
|
local app = self.apps:getSelected().name
|
|
Array.removeByValue(self.config[app], event.selected.file)
|
|
table.insert(self.config[app], 1, event.selected.file)
|
|
self:updateChoices()
|
|
Config.update('alternate', self.config)
|
|
|
|
else
|
|
return UI.Tab.eventHandler(self, event)
|
|
end
|
|
return true
|
|
end
|
|
|
|
return tab
|