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
New menu option and filemanager filter to hide finished books #7158 #10895
New menu option and filemanager filter to hide finished books #7158 #10895
Conversation
@@ -128,6 +128,7 @@ function FileManager:setupLayout() | |||
right_icon_hold_callback = false, -- propagate long-press to dispatcher | |||
} | |||
|
|||
local show_finished = G_reader_settings:hasNot("show_finished") or G_reader_settings:isTrue("show_finished") |
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.
Redundant, hasNot
will never be true if isTrue
is, so this can be reduced to simply isTrue
.
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.
Wait. Brainfart ;p. Kinda forgot that this needs to be enabled by default ;).
nilOrTrue
is what you want ;).
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.
I wanted that setting to be true by default, which isTrue()
does not grant. I couldn't find a way to declare a default settings value. My experience is that a plain isTrue()
will return false if the value is not set (nil), while hasNot()
returns true.
If hasNot() or isTrue()
isn't suitable there, what is the idiomatic way with koreader to check for nil or true?
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.
Don't we have a helper function called nilOrTrue()? :-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.
Yep, see my followup above ;). (GH's weird update notifications strike again, I guess ;)).
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.
The second comment didn't show up in my browser yesterday, so sorry my reply was useless. Thanks for the advice.
Filter (1) When moving sdr folder to a new location
I think finished books should not be excluded here, so it is okay. (2) In file search
Dunno if you want to exclude finished book from the search results. In any case the check for absent
|
2e8d418
to
994a4df
Compare
@hius07 I should have mentioned that I have no experience with Lua expect for a quick try a few years ago. So a thorough code review is very useful! I felt uneasy with the untyped language. I'm not even confident in the tools I used, since my Lua LSP failed to list one of the references to |
You can use grep ;-) cd koreader/frontend $ grep -ilr "FileChooser:show_file" ./* 2>/dev/null $ grep -ilr "nilOrTrue" ./* 2>/dev/null Or some more tips here: #10708 |
I'd already read #10708 and thought that the tools were better than plain text search. I'll use "rg", e.g. |
for _, pattern in ipairs(self.exclude_files) do | ||
if filename:match(pattern) then return false end | ||
end | ||
return self.show_unsupported or self.file_filter == nil or self.file_filter(filename) | ||
if not self.show_unsupported and self.file_filter ~= nil and not self.file_filter(filename) then return false end | ||
if not self.show_finished and fullpath ~= nil and filemanagerutil.getStatus(fullpath) == "complete" then return false end |
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.
I think local FileChooser = Menu:extend{
might be missing:
show_hidden = false, -- set to true to show folders/files starting with "."
+ show_finished = true, -- show all books
In case it's used from something else than FileManager.
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, and more over.
If we start with, say, Last book, and call PathChooser, it doesn't follow our view settings, because they are read in FM:
local show_unsupported = G_reader_settings:isTrue("show_unsupported") |
I think all these 3 view flags must be initiated from G_reader_settings directly in
local FileChooser = Menu:extend{
.
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.
If in :extend, it's set at startup time and won't be reflected if we change the setting until a restart.
Rather in FileChooser:init()
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.
won't be reflected if we change the setting
We change self
when changing a setting
koreader/frontend/ui/widget/filechooser.lua
Lines 458 to 459 in 0ac258f
function FileChooser:toggleUnsupportedFiles() | |
self.show_unsupported = not self.show_unsupported |
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, but this will apply to the current self
, not to future FileChooser instances.
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.
Anyway, I was going to rewrite these three togglings a bit.
I think no need to have their parts in both FM and FileChooser, they can be combined in one place.
koreader/frontend/apps/filemanager/filemanager.lua
Lines 788 to 791 in 0ac258f
function FileManager:toggleUnsupportedFiles() | |
self.file_chooser:toggleUnsupportedFiles() | |
G_reader_settings:saveSetting("show_unsupported", self.file_chooser.show_unsupported) | |
end |
koreader/frontend/ui/widget/filechooser.lua
Lines 458 to 461 in 0ac258f
function FileChooser:toggleUnsupportedFiles() | |
self.show_unsupported = not self.show_unsupported | |
self:refreshPath() | |
end |
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.
not to future FileChooser instances.
True, we have
self.show_hidden = G_reader_settings:isTrue("show_hidden") |
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.
And we do not need this in FM, because the setting can be changed within FM only.
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.
Or not, changing the setting doesn't change the base class. I'll think of it.
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.
You could change the setting in the class:
function FileChooser:toggleUnsupportedFiles()
- self.show_unsupported = not self.show_unsupported
+ FileChooser.show_unsupported = not FileChooser.show_unsupported
CircleCI produces the error downloading zlib-1.2.13.tar.xz. |
…r#7158 The default behavior is to display the finished books (no change on upgrade). For consistency with the two similar options, it represented by a checkbox "Show hidden books" that is checked by default. The implementation is straightforward, meaning that, when the option is unchecked, each file will require a call to `filemanagerutil.getStatus` that checks its status. For clarity, the code uses the "finished books" expression because the condition is relevant to the *book* metadata, while the other settings are about *file* attributes.
Done ;). |
69b1e5b
to
b9765be
Compare
Fixes issue #7158
The default behavior is to display the finished books (no change on upgrade). For consistency with the two similar options, it represented by a checkbox "Show hidden books" that is checked by default.
The implementation is straightforward, meaning that, when the option is unchecked, each file will require a call to
filemanagerutil.getStatus
that checks its status.For clarity, the code uses the "finished books" expression because the condition is relevant to the book metadata, while the other settings are about file attributes.
This change is