feat: trash support for linux and mac (#165)
* wip: skeleton code for trash adapter * refactor: split trash implementation for mac and linux * fix: ensure we create the .Trash/$uid dir * feat: code complete linux trash implementation * doc: write up trash features * feat: code complete mac trash implementation * cleanup: remove previous, terrible, undocumented trash feature * fix: always disabled trash * feat: show original path of trashed files * doc: add a note about calling actions directly * fix: bugs in trash implementation * fix: schedule_wrap in mac trash * doc: fix typo and line wrapping * fix: parsing of arguments to :Oil command * doc: small documentation tweaks * doc: fix awkward wording in the toggle_trash action * fix: warning on Windows when delete_to_trash = true * feat: :Oil --trash can open specific trash directories * fix: show all trash files in device root * fix: trash mtime should be sortable * fix: shorten_path handles optional trailing slash * refactor: overhaul the UI * fix: keep trash original path vtext from stacking * refactor: replace disable_changes with an error filter * fix: shorten path names in home directory relative to root * doc: small README format changes * cleanup: remove unnecessary preserve_undo logic * test: add a functional test for the freedesktop trash adapter * test: more functional tests for trash * fix: schedule a callback to avoid main loop error * refactor: clean up mutator logic * doc: some comments and type annotations
This commit is contained in:
parent
d8f0d91b10
commit
6175bd6462
27 changed files with 1580 additions and 229 deletions
|
|
@ -4,10 +4,12 @@ local M = {}
|
|||
|
||||
local FIELD_ID = constants.FIELD_ID
|
||||
local FIELD_NAME = constants.FIELD_NAME
|
||||
local FIELD_META = constants.FIELD_META
|
||||
|
||||
local next_id = 1
|
||||
|
||||
-- Map<url, Map<entry name, oil.InternalEntry>>
|
||||
---@type table<string, table<string, oil.InternalEntry>>
|
||||
local url_directory = {}
|
||||
|
||||
---@type table<integer, oil.InternalEntry>
|
||||
|
|
@ -118,6 +120,15 @@ M.get_entry_by_id = function(id)
|
|||
return entries_by_id[id]
|
||||
end
|
||||
|
||||
---@param url string
|
||||
---@return nil|oil.InternalEntry
|
||||
M.get_entry_by_url = function(url)
|
||||
local scheme, path = util.parse_url(url)
|
||||
local parent_url = scheme .. vim.fn.fnamemodify(path, ":h")
|
||||
local basename = vim.fn.fnamemodify(path, ":t")
|
||||
return M.list_url(parent_url)[basename]
|
||||
end
|
||||
|
||||
---@param id integer
|
||||
---@return string
|
||||
M.get_parent_url = function(id)
|
||||
|
|
@ -129,18 +140,12 @@ M.get_parent_url = function(id)
|
|||
end
|
||||
|
||||
---@param url string
|
||||
---@return oil.InternalEntry[]
|
||||
---@return table<string, oil.InternalEntry>
|
||||
M.list_url = function(url)
|
||||
url = util.addslash(url)
|
||||
return url_directory[url] or {}
|
||||
end
|
||||
|
||||
M.get_entry_by_url = function(url)
|
||||
local parent, name = url:match("^(.+)/([^/]+)$")
|
||||
local cache = url_directory[parent]
|
||||
return cache and cache[name]
|
||||
end
|
||||
|
||||
---@param action oil.Action
|
||||
M.perform_action = function(action)
|
||||
if action.type == "create" then
|
||||
|
|
@ -172,6 +177,8 @@ M.perform_action = function(action)
|
|||
dest_parent = {}
|
||||
url_directory[dest_parent_url] = dest_parent
|
||||
end
|
||||
-- We have to clear the metadata because it can be inaccurate after the move
|
||||
entry[FIELD_META] = nil
|
||||
dest_parent[dest_name] = entry
|
||||
parent_url_by_id[entry[FIELD_ID]] = dest_parent_url
|
||||
entry[FIELD_NAME] = dest_name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue