mirror of
https://github.com/kepler155c/opus
synced 2025-11-06 02:23:01 +00:00
global clipboard plus directory sizes in Files
This commit is contained in:
@@ -2,6 +2,7 @@ require = requireInjector(getfenv(1))
|
||||
local Util = require('util')
|
||||
local Event = require('event')
|
||||
local UI = require('ui')
|
||||
local Config = require('config')
|
||||
|
||||
local cleanEnv = Util.shallowCopy(getfenv(1))
|
||||
cleanEnv.require = nil
|
||||
@@ -9,10 +10,16 @@ cleanEnv.require = nil
|
||||
multishell.setTitle(multishell.getCurrent(), 'Files')
|
||||
UI:configure('Files', ...)
|
||||
|
||||
local config = {
|
||||
showHidden = false,
|
||||
showDirSizes = false,
|
||||
}
|
||||
|
||||
Config.load('Files', config)
|
||||
|
||||
local copied = { }
|
||||
local marked = { }
|
||||
local directories = { }
|
||||
local hidden = true
|
||||
local cutMode = false
|
||||
|
||||
function formatSize(size)
|
||||
@@ -60,6 +67,7 @@ local Browser = UI.Page {
|
||||
buttons = {
|
||||
{ text = 'Refresh r', event = 'refresh' },
|
||||
{ text = 'Hidden ^h', event = 'toggle_hidden' },
|
||||
{ text = 'Dir Size ^s', event = 'toggle_dirSize' },
|
||||
UI.Text { },
|
||||
}
|
||||
},
|
||||
@@ -200,12 +208,18 @@ function Browser:updateDirectory(dir)
|
||||
dir.totalSize = dir.totalSize + file.size
|
||||
file.fsize = formatSize(file.size)
|
||||
else
|
||||
if config.showDirSizes then
|
||||
file.size = fs.getSize(file.fullName, true)
|
||||
|
||||
dir.totalSize = dir.totalSize + file.size
|
||||
file.fsize = formatSize(file.size)
|
||||
end
|
||||
file.flags = 'D'
|
||||
end
|
||||
if file.isReadOnly then
|
||||
file.flags = file.flags .. 'R'
|
||||
end
|
||||
if not hidden or file.name:sub(1, 1) ~= '.' then
|
||||
if config.showHidden or file.name:sub(1, 1) ~= '.' then
|
||||
dir.files[file.fullName] = file
|
||||
end
|
||||
end
|
||||
@@ -277,15 +291,27 @@ function Browser:eventHandler(event)
|
||||
self:setStatus('Refreshed')
|
||||
|
||||
elseif event.type == 'toggle_hidden' then
|
||||
hidden = not hidden
|
||||
config.showHidden = not config.showHidden
|
||||
Config.update('Files', config)
|
||||
|
||||
self:updateDirectory(self.dir)
|
||||
self.grid:draw()
|
||||
if hidden then
|
||||
if not config.showHidden then
|
||||
self:setStatus('Hiding hidden')
|
||||
else
|
||||
self:setStatus('Displaying hidden')
|
||||
end
|
||||
|
||||
elseif event.type == 'toggle_dirSize' then
|
||||
config.showDirSizes = not config.showDirSizes
|
||||
Config.update('Files', config)
|
||||
|
||||
self:updateDirectory(self.dir)
|
||||
self.grid:draw()
|
||||
if config.showDirSizes then
|
||||
self:setStatus('Displaying dir sizes')
|
||||
end
|
||||
|
||||
elseif event.type == 'mark' and file then
|
||||
file.marked = not file.marked
|
||||
if file.marked then
|
||||
|
||||
@@ -258,6 +258,10 @@ function page.grid:eventHandler(event)
|
||||
elseif event.type == 'grid_select' then
|
||||
page:setPrompt(commandAppend(), true)
|
||||
page:executeStatement(commandAppend())
|
||||
elseif event.type == 'copy' then
|
||||
if entry then
|
||||
clipboard.setData(entry.rawValue)
|
||||
end
|
||||
else
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
|
||||
@@ -29,15 +29,36 @@ local fileInfo
|
||||
local dirty = { y = 1, ey = h }
|
||||
local mark = { anchor, active, continue }
|
||||
local keyboard
|
||||
local clipboard = { size, internal }
|
||||
local searchPattern
|
||||
local undo = { chain = { }, pointer = 0 }
|
||||
local complete = { }
|
||||
|
||||
if _G.__CLIPBOARD then
|
||||
clipboard = _G.__CLIPBOARD
|
||||
else
|
||||
_G.__CLIPBOARD = clipboard
|
||||
if not clipboard then
|
||||
_G.clipboard = { internal, data }
|
||||
clipboard.shim = true
|
||||
|
||||
function clipboard.setData(data)
|
||||
clipboard.data = data
|
||||
if data then
|
||||
clipboard.useInternal(true)
|
||||
end
|
||||
end
|
||||
|
||||
function clipboard.getText()
|
||||
if clipboard.data then
|
||||
return Util.tostring(clipboard.data)
|
||||
end
|
||||
end
|
||||
|
||||
function clipboard.isInternal()
|
||||
return clipboard.internal
|
||||
end
|
||||
|
||||
function clipboard.useInternal(mode)
|
||||
if mode ~= clipboard.mode then
|
||||
clipboard.internal = mode
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local color = {
|
||||
@@ -363,7 +384,7 @@ local function redraw()
|
||||
|
||||
if not (w < 32 and #sStatus > 0) then
|
||||
local clipboardIndicator = 'S'
|
||||
if clipboard.internal then
|
||||
if clipboard.isInternal() then
|
||||
clipboardIndicator = 'I'
|
||||
end
|
||||
|
||||
@@ -1016,8 +1037,10 @@ local __actions = {
|
||||
end,
|
||||
|
||||
toggle_clipboard = function()
|
||||
clipboard.internal = not clipboard.internal
|
||||
if clipboard.internal then
|
||||
if clipboard.shim then
|
||||
clipboard.setInternal(not clipboard.internal)
|
||||
end
|
||||
if clipboard.isInternal() then
|
||||
setStatus('Using internal clipboard')
|
||||
else
|
||||
setStatus('Using system clipboard')
|
||||
@@ -1025,10 +1048,11 @@ local __actions = {
|
||||
end,
|
||||
|
||||
copy_marked = function()
|
||||
clipboard.lines, clipboard.size =
|
||||
local text, size =
|
||||
actions.copyText(mark.x, mark.y, mark.ex, mark.ey)
|
||||
setStatus('%d chars copied', clipboard.size)
|
||||
clipboard.internal = true
|
||||
clipboard.setData(text)
|
||||
setStatus('%d chars copied', size)
|
||||
clipboard.useInternal(true)
|
||||
end,
|
||||
|
||||
cut = function()
|
||||
@@ -1049,16 +1073,14 @@ local __actions = {
|
||||
if mark.active then
|
||||
actions.delete()
|
||||
end
|
||||
if clipboard.internal then
|
||||
if clipboard.lines then
|
||||
actions.insertText(x, y, clipboard.lines)
|
||||
setStatus('%d chars added', clipboard.size)
|
||||
else
|
||||
setStatus('Internal clipboard empty')
|
||||
end
|
||||
else
|
||||
if clipboard.isInternal() then
|
||||
text = clipboard.getText()
|
||||
end
|
||||
if text then
|
||||
actions.insertText(x, y, text)
|
||||
setStatus('%d chars added', #text)
|
||||
else
|
||||
setStatus('Clipboard empty')
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user