mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
History: update on renaming/moving a folder (#10999)
This commit is contained in:
@@ -28,6 +28,7 @@ local ReadCollection = require("readcollection")
|
||||
local ReaderDeviceStatus = require("apps/reader/modules/readerdevicestatus")
|
||||
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
|
||||
local ReaderWikipedia = require("apps/reader/modules/readerwikipedia")
|
||||
local ReadHistory = require("readhistory")
|
||||
local Screenshoter = require("ui/widget/screenshoter")
|
||||
local TitleBar = require("ui/widget/titlebar")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
@@ -893,7 +894,9 @@ function FileManager:pasteHere(file)
|
||||
if self:moveFile(orig_file, dest_path) then
|
||||
if is_file then
|
||||
DocSettings:updateLocation(orig_file, dest_file)
|
||||
require("readhistory"):updateItemByPath(orig_file, dest_file) -- (will update "lastfile" if needed)
|
||||
ReadHistory:updateItemByPath(orig_file, dest_file) -- (will update "lastfile" if needed)
|
||||
else
|
||||
ReadHistory:updateItemsByPath(orig_file, dest_file)
|
||||
end
|
||||
ReadCollection:updateItemByPath(orig_file, dest_file)
|
||||
return true
|
||||
@@ -1016,7 +1019,7 @@ function FileManager:deleteFile(file, is_file)
|
||||
if ok and not err then
|
||||
if is_file then
|
||||
DocSettings:updateLocation(file)
|
||||
require("readhistory"):fileDeleted(file)
|
||||
ReadHistory:fileDeleted(file)
|
||||
end
|
||||
ReadCollection:removeItemByPath(file, not is_file)
|
||||
return true
|
||||
@@ -1065,7 +1068,9 @@ function FileManager:renameFile(file, basename, is_file)
|
||||
if self:moveFile(file, dest) then
|
||||
if is_file then
|
||||
DocSettings:updateLocation(file, dest)
|
||||
require("readhistory"):updateItemByPath(file, dest) -- (will update "lastfile" if needed)
|
||||
ReadHistory:updateItemByPath(file, dest) -- (will update "lastfile" if needed)
|
||||
else
|
||||
ReadHistory:updateItemsByPath(file, dest)
|
||||
end
|
||||
ReadCollection:updateItemByPath(file, dest)
|
||||
self:onRefresh()
|
||||
|
||||
@@ -189,6 +189,7 @@ function ReadHistory:getFileByDirectory(directory, recursive)
|
||||
end
|
||||
end
|
||||
|
||||
--- Updates the history list after renaming/moving a file.
|
||||
function ReadHistory:updateItemByPath(old_path, new_path)
|
||||
local index = self:getIndexByFile(old_path)
|
||||
if index then
|
||||
@@ -199,6 +200,22 @@ function ReadHistory:updateItemByPath(old_path, new_path)
|
||||
end
|
||||
end
|
||||
|
||||
--- Updates the history list after renaming/moving a folder.
|
||||
function ReadHistory:updateItemsByPath(old_path, new_path)
|
||||
old_path = "^"..old_path
|
||||
local history_updated
|
||||
for i, v in ipairs(self.hist) do
|
||||
local file, count = v.file:gsub(old_path, new_path)
|
||||
if count == 1 then
|
||||
self.hist[i].file = file
|
||||
history_updated = true
|
||||
end
|
||||
end
|
||||
if history_updated then
|
||||
self:_flush()
|
||||
end
|
||||
end
|
||||
|
||||
--- Updates the history list after deleting a file.
|
||||
function ReadHistory:fileDeleted(path)
|
||||
local index = self:getIndexByFile(path)
|
||||
|
||||
Reference in New Issue
Block a user