mirror of
https://github.com/kepler155c/opus
synced 2025-04-27 13:13:14 +00:00
file associations
This commit is contained in:
parent
44d2d13e40
commit
89e47f8b93
@ -1,5 +1,3 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
@ -13,13 +11,14 @@ local shell = _ENV.shell
|
|||||||
|
|
||||||
UI:configure('Files', ...)
|
UI:configure('Files', ...)
|
||||||
|
|
||||||
local config = {
|
local config = Config.load('Files', {
|
||||||
showHidden = false,
|
showHidden = false,
|
||||||
showDirSizes = false,
|
showDirSizes = false,
|
||||||
|
})
|
||||||
|
config.associations = config.associations or {
|
||||||
|
nft = 'pain',
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.load('Files', config)
|
|
||||||
|
|
||||||
local copied = { }
|
local copied = { }
|
||||||
local marked = { }
|
local marked = { }
|
||||||
local directories = { }
|
local directories = { }
|
||||||
@ -61,6 +60,11 @@ local Browser = UI.Page {
|
|||||||
{ text = 'Hidden ^h', event = 'toggle_hidden' },
|
{ text = 'Hidden ^h', event = 'toggle_hidden' },
|
||||||
{ text = 'Dir Size ^s', event = 'toggle_dirSize' },
|
{ text = 'Dir Size ^s', event = 'toggle_dirSize' },
|
||||||
} },
|
} },
|
||||||
|
{ text = '\206',
|
||||||
|
x = -3,
|
||||||
|
dropdown = {
|
||||||
|
{ text = 'Associations', event = 'associate' },
|
||||||
|
} },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
@ -78,6 +82,56 @@ local Browser = UI.Page {
|
|||||||
{ key = 'totalSize', width = 6 },
|
{ key = 'totalSize', width = 6 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
associations = UI.SlideOut {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
menuBar = UI.MenuBar {
|
||||||
|
buttons = {
|
||||||
|
{ text = 'Save', event = 'save' },
|
||||||
|
{ text = 'Cancel', event = 'cancel' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
x = 2, ex = -6, y = 3, ey = -5,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Name', key = 'name' },
|
||||||
|
{ heading = 'Value', key = 'value' },
|
||||||
|
},
|
||||||
|
sortColumn = 'name',
|
||||||
|
accelerators = {
|
||||||
|
delete = 'remove_entry',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
remove = UI.Button {
|
||||||
|
x = -4, y = 6,
|
||||||
|
text = '-', event = 'remove_entry', help = 'Remove',
|
||||||
|
},
|
||||||
|
form = UI.Form {
|
||||||
|
x = 3, y = -3, ey = -2,
|
||||||
|
margin = 1,
|
||||||
|
manualControls = true,
|
||||||
|
[1] = UI.TextEntry {
|
||||||
|
width = 20,
|
||||||
|
formLabel = 'Name', formKey = 'name',
|
||||||
|
shadowText = 'extension',
|
||||||
|
required = true,
|
||||||
|
limit = 64,
|
||||||
|
},
|
||||||
|
[2] = UI.TextEntry {
|
||||||
|
width = 20,
|
||||||
|
formLabel = 'Name', formKey = 'value',
|
||||||
|
shadowText = 'program',
|
||||||
|
required = true,
|
||||||
|
limit = 64,
|
||||||
|
},
|
||||||
|
add = UI.Button {
|
||||||
|
x = -11, y = 1,
|
||||||
|
text = 'Add', event = 'add_association',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
statusBar = UI.StatusBar {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
},
|
||||||
|
},
|
||||||
accelerators = {
|
accelerators = {
|
||||||
q = 'quit',
|
q = 'quit',
|
||||||
e = 'edit',
|
e = 'edit',
|
||||||
@ -294,6 +348,9 @@ function Browser:eventHandler(event)
|
|||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
self:setStatus('Refreshed')
|
self:setStatus('Refreshed')
|
||||||
|
|
||||||
|
elseif event.type == 'associate' then
|
||||||
|
self.associations:show()
|
||||||
|
|
||||||
elseif event.type == 'toggle_hidden' then
|
elseif event.type == 'toggle_hidden' then
|
||||||
config.showHidden = not config.showHidden
|
config.showHidden = not config.showHidden
|
||||||
Config.update('Files', config)
|
Config.update('Files', config)
|
||||||
@ -336,7 +393,12 @@ function Browser:eventHandler(event)
|
|||||||
if file.isDir then
|
if file.isDir then
|
||||||
self:setDir(file.fullName)
|
self:setDir(file.fullName)
|
||||||
else
|
else
|
||||||
self:run(file.name)
|
local ext = file.name:match('%.(%w+)$')
|
||||||
|
if ext and config.associations[ext] then
|
||||||
|
self:run(config.associations[ext], '/' .. file.fullName)
|
||||||
|
else
|
||||||
|
self:run(file.name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -405,6 +467,58 @@ function Browser:eventHandler(event)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[ Associations slide out ]] --
|
||||||
|
function Browser.associations:show()
|
||||||
|
self.grid.values = { }
|
||||||
|
for k, v in pairs(config.associations) do
|
||||||
|
table.insert(self.grid.values, {
|
||||||
|
name = k,
|
||||||
|
value = v,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
self.grid:update()
|
||||||
|
UI.SlideOut.show(self)
|
||||||
|
self:setFocus(self.form[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
function Browser.associations:eventHandler(event)
|
||||||
|
if event.type == 'remove_entry' then
|
||||||
|
local row = self.grid:getSelected()
|
||||||
|
if row then
|
||||||
|
Util.removeByValue(self.grid.values, row)
|
||||||
|
self.grid:update()
|
||||||
|
self.grid:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'add_association' then
|
||||||
|
if self.form:save() then
|
||||||
|
local entry = Util.find(self.grid.values, 'name', self.form[1].value) or { }
|
||||||
|
entry.name = self.form[1].value
|
||||||
|
entry.value = self.form[2].value
|
||||||
|
table.insert(self.grid.values, entry)
|
||||||
|
self.form[1]:reset()
|
||||||
|
self.form[2]:reset()
|
||||||
|
self.grid:update()
|
||||||
|
self.grid:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'cancel' then
|
||||||
|
self:hide()
|
||||||
|
|
||||||
|
elseif event.type == 'save' then
|
||||||
|
config.associations = { }
|
||||||
|
for _, v in pairs(self.grid.values) do
|
||||||
|
config.associations[v.name] = v.value
|
||||||
|
end
|
||||||
|
Config.update('Files', config)
|
||||||
|
self:hide()
|
||||||
|
|
||||||
|
else
|
||||||
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
--[[-- Startup logic --]]--
|
--[[-- Startup logic --]]--
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
|
|
||||||
|
1
sys/apps/pain.lua
Normal file
1
sys/apps/pain.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
require('util').runUrl(_ENV, 'http://pastebin.com/raw/wJQ7jav0', ...)
|
@ -90,7 +90,7 @@
|
|||||||
icon = "\030 \031f\0307\031f\159\030 \159\030 \
|
icon = "\030 \031f\0307\031f\159\030 \159\030 \
|
||||||
\030 \031f\0308\031f\135\0307\0318\144\140\030f\0317\159\143\031c\139\0302\135\030f\0312\157\
|
\030 \031f\0308\031f\135\0307\0318\144\140\030f\0317\159\143\031c\139\0302\135\030f\0312\157\
|
||||||
\030 \031f\030f\0318\143\133\0312\136\0302\031f\159\159\143\131\030f\0312\132",
|
\030 \031f\030f\0318\143\133\0312\136\0302\031f\159\159\143\131\030f\0312\132",
|
||||||
run = "http://pastebin.com/raw/wJQ7jav0",
|
run = "pain",
|
||||||
},
|
},
|
||||||
[ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = {
|
[ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = {
|
||||||
title = "Breakout",
|
title = "Breakout",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user