From 2c80ff7d7bab9e08892e8e7aaae68552e229ffd3 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sat, 25 Feb 2017 19:22:04 +0100 Subject: [PATCH] FileManagerHistory: remove harmful deletion code and turn it into a feature Fixes the problem introduced in 51327911f2fbea00258717d7b284e061ad31832e and turns it into a feature that should fix #2477 --- frontend/apps/filemanager/filemanagerhistory.lua | 11 +++++++++++ frontend/readhistory.lua | 13 ++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontend/apps/filemanager/filemanagerhistory.lua b/frontend/apps/filemanager/filemanagerhistory.lua index 612cc44c7..eba8869a0 100644 --- a/frontend/apps/filemanager/filemanagerhistory.lua +++ b/frontend/apps/filemanager/filemanagerhistory.lua @@ -128,6 +128,17 @@ function FileManagerHistory:onMenuHold(item) end, }, }, + {}, + { + { + text = _("Clear history of deleted files"), + callback = function() + require("readhistory"):clearMissing() + self._manager:updateItemTable() + UIManager:close(self.histfile_dialog) + end, + }, + }, }, } UIManager:show(self.histfile_dialog) diff --git a/frontend/readhistory.lua b/frontend/readhistory.lua index baba54bd4..2d75ef379 100644 --- a/frontend/readhistory.lua +++ b/frontend/readhistory.lua @@ -47,11 +47,6 @@ function ReadHistory:_indexing(start) end function ReadHistory:_sort() - for i = #self.hist, 1, -1 do - if self.hist[i].file == nil or lfs.attributes(self.hist[i].file, "mode") ~= "file" then - table.remove(self.hist, i) - end - end table.sort(self.hist, fileFirstOrdering) -- TODO(zijiehe): Use binary insert instead of a loop to deduplicate. for i = #self.hist, 2, -1 do @@ -122,6 +117,14 @@ function ReadHistory:_init() self:_reduce() end +function ReadHistory:clearMissing() + for i = #self.hist, 1, -1 do + if self.hist[i].file == nil or lfs.attributes(self.hist[i].file, "mode") ~= "file" then + table.remove(self.hist, i) + end + end +end + function ReadHistory:removeItem(item) table.remove(self.hist, item.index) os.remove(DocSettings:getHistoryPath(item.file))