Skip to content
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

Merged
merged 18 commits into from Dec 10, 2023
Merged

Conversation

hius07
Copy link
Member

@hius07 hius07 commented Nov 29, 2023

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 Reviewable

Copy link
Contributor

@poire-z poire-z left a 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 :)

Comment on lines +834 to 835
function FileManager:pasteFileFromClipboard(file)
local orig_file = BaseUtil.realpath(self.clipboard)
Copy link
Contributor

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?

Copy link
Member Author

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.

Comment on lines 957 to 966
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),
Copy link
Contributor

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?

Copy link
Member

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.

if v.file == item then
table.remove(coll, k)
break
function ReadCollection:isAdded(file, collection_name)
Copy link
Contributor

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() ?

end

function ReadCollection:updateItemsByPath(path, new_path)
path = "^" .. path .. "/"
Copy link
Contributor

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() ?

Copy link
Member Author

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

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)

Copy link
Contributor

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.)

Copy link
Member

@NiLuJe NiLuJe Dec 3, 2023

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.

Copy link
Member

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...

@Frenzie Frenzie added this to the 2023.12 milestone Nov 29, 2023
Comment on lines 215 to 216
if v.file:sub(1, l) == old_path then
self.hist[i].file = new_path .. v.file:sub(l + 1)
Copy link
Contributor

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 ?

@hius07 hius07 merged commit aabd6d7 into koreader:master Dec 10, 2023
3 checks passed
@hius07 hius07 deleted the coll-group branch December 10, 2023 06:05
@@ -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)
Copy link
Member

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?

liskin added a commit to liskin/koreader that referenced this pull request Jan 5, 2024
updateItemByPath has recently been replaced with updateItem in both
readhistory and readcollection.

Fixes: aabd6d7 ("File browser, Collection: improve group actions (koreader#11178)")
liskin added a commit to liskin/koreader that referenced this pull request Jan 5, 2024
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
Frenzie pushed a commit that referenced this pull request Jan 5, 2024
updateItemByPath has recently been replaced with updateItem in both
readhistory and readcollection.

Fixes: aabd6d7 ("File browser, Collection: improve group actions (#11178)")
Fixes: #11320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants