New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File browser, Collection: improve group actions #11178
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot, just had a quick glance, trusting you.
Thanks for the needed revamping of readcollection :)
function FileManager:pasteFileFromClipboard(file) | ||
local orig_file = BaseUtil.realpath(self.clipboard) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just asking: can we get here with not a filepath in the clipboard (eg. selected text from a book)? And what would happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filemanager self.clipboard
is not a system clipboard, currently there is no way to fill it with anything other than a filepath.
local text1, text2 | ||
if self.cutfile then | ||
text1 = "1 file was not moved" | ||
text2 = "%1 files were not moved" | ||
else | ||
text1 = "1 file was not copied" | ||
text2 = "%1 files were not copied" | ||
end | ||
UIManager:show(InfoMessage:new{ | ||
text = T(N_(text1, text2, skipped_nb), skipped_nb), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Frenzie : will this be properly picked up by the translatable strings extraction stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't, it's just a relatively dumb text match.
frontend/readcollection.lua
Outdated
if v.file == item then | ||
table.remove(coll, k) | ||
break | ||
function ReadCollection:isAdded(file, collection_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminds me of #11108 (comment) :)
:hasFile()
?
frontend/readcollection.lua
Outdated
end | ||
|
||
function ReadCollection:updateItemsByPath(path, new_path) | ||
path = "^" .. path .. "/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Reminds me of another recent comment :)
Possible risk if using :gsub() and path contains some pattern, might be safer to use string comparison like util.stringStartsWith() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I remember #11090 (comment) about string.match
.
But here we need to do actual gsub
, to replace old path with the new one.
One more place is
koreader/frontend/readhistory.lua
Lines 194 to 198 in dce12de
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But here we need to do actual gsub, to replace old path with the new one
But can this :gsub fail if paths happen to have crap characters interpreted as pattern ? (If yes, we may need to try to escape these chars.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting conundrum.
Escaping ought to be relatively simple (e.g., string:gsub("%W", "%%%1")
, but I imagine you'll need to unescape it after that, and it might get trickier there ;p.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe string:gsub("%%(%W)", "%1")
ought to do the trick to handle unescaping...
frontend/readhistory.lua
Outdated
if v.file:sub(1, l) == old_path then | ||
self.hist[i].file = new_path .. v.file:sub(l + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local l = #old_path
The choice of l
as the variable name makes this hard to read :) may be call it len
?
@@ -19,7 +20,7 @@ local ReadHistory = { | |||
|
|||
local function getMandatory(date_time) | |||
return G_reader_settings:isTrue("history_datetime_short") | |||
and datetime.secondsToDate(date_time):sub(3) or datetime.secondsToDateTime(date_time) | |||
and os.date(C_("Date string", "%y-%m-%d"), date_time) or datetime.secondsToDateTime(date_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that one; I would perhaps have extended datetime.secondsToDate
to provide the century-less format directly via an extra argument instead of hard-coding it here?
updateItemByPath has recently been replaced with updateItem in both readhistory and readcollection. Fixes: aabd6d7 ("File browser, Collection: improve group actions (koreader#11178)")
updateItemByPath has recently been replaced with updateItem in both readhistory and readcollection. Fixes: aabd6d7 ("File browser, Collection: improve group actions (koreader#11178)") Fixes: koreader#11320
In file group actions (copy, move, delete files or folders) we maintain History and Collection.
With these changes flushing History and Collection is done not for every file but at the end of the action.
ReadCollection (rewritten) now does not ask the storage on each favorites status request.
(Opens the door for long awaiting favorites marker)
Currently one collection only is supported (Favorites) but the infrastructure is done ready for other collections, UI changes only needed.
This change is