[ReaderDictionary] Enable dictionary prioritisation via new menu - #13768
Conversation
| end | ||
|
|
||
| -- Before starting the search, remove any dictionaries that are disabled for *this* book. | ||
| if dict_names and self.book_disabled_dicts then |
There was a problem hiding this comment.
and self.book_disabled_dicts > 1 ? as you make it a dict and not a nil in onReadSettings (or make it a nil there, I may prefer that if there's no reason to keep a {]).
There was a problem hiding this comment.
changing to only readSetting("...") in ReadSettings then
| local buttons = {} | ||
| local disabled_buttons = {} -- store disabled dict buttons separately | ||
|
|
||
| local function makeButtonEntry(dict, is_disabled) |
There was a problem hiding this comment.
May read better with a is_enabled where it is called?
|
Mentionning that (not sure I would enjoy the adding kludge, but...) since you were recently into footer presets, you could in the same way make dictioneries presets, just swapping the managed list of enabled dicts? Would solve more issues and would be less cumbersome to have to do the re-org on each new book of some kind. |
|
It should have a one-tap option to clear the entire prioritization. How about adding a Reset button on the bottom of the info-text (on long-press)? |
There was a problem hiding this comment.
since you were recently into footer presets
you too? i can't deal with this one-hit-wonder nonsense anymore... listen i hear you, i am happy to look into it, but i would add them on-top as opposed to instead-of, (i still want to assing priority on NT, and this is the only sane way of doing it) because...
would be less cumbersome to have to do the re-org on each new book of some kind
that is kind of the point for me, some dicts are better aimed towards american spelling and others towards UK spelling, i actually want to be able to have that level of nuisance nuance.
Oh, right, so this PR is obviously fine.
Well, then no real need :) Take some vacations ! |
I am not entirely sure how to interpret this, it feels like you're telling me off, are you? I will have a nap though |
|
What's common preset functionality precisely? |
|
the menu creation stuff (about 100 lines)... and the function for dispatcher. Everything else is custom (i.e save, load and build) |
|
And preset means more than just the dictionary? |
|
No, just a list of enabled dictionaries at time of creation. We don't store anything else, an anything added after (new dicts) is treated as if it had disabled originally. There's even a fancy check for deleted ones. Makes sense for presets like: english, french, spanish, etc Edit: if you tell me where to place the file, i can push it and then we can see it |
|
That sounds like |
|
This feature is quite nice! |
|
@Frenzie there is a draft open now, status bar presets would use |
You put it in frontend/ui/elements/presets_menu.lua in #13774. I would even name it just "presets.lua", who know what other common non-menu-related generic stuff you may end up putting into it. |
|
Got it, now if someone could review this, it'd be great as this will conflict with #13774 so would be nice to get it out of the way soon-ish. |
| if is_docless then -- remove the "Set dictionary priority for this book" entry | ||
| table.remove(menu_items.dictionary_settings.sub_item_table, 2) | ||
| end |
There was a problem hiding this comment.
Don't we usually do this the other way around?
There was a problem hiding this comment.
Would you prefer it the other way around? I just didn't want to break the order.
Edit: we rarely (a few cases still though) do it this way.
There was a problem hiding this comment.
Well, generally speaking yes. Creating a whole table, then removing and garbage collecting it seems pretty silly at best.
There was a problem hiding this comment.
I'll change it, but wouldn't the collector still run anyway?
There was a problem hiding this comment.
I'm not entirely sure what you're asking. It won't or rather can't run for something you didn't create in the first place. ;-)
There was a problem hiding this comment.
I was only suggesting that (in the words of Taylor Swift), "collector gonna collect" regardless... it won't just be coming for these 8 bytes, it will come for all bytes equally ;)
in Pratchett-ian words: LORD, WHAT CAN THE HARVEST HOPE FOR, IF NOT FOR THE CARE OF THE REAPER MAN?
0c383b7 to
a1283ed
Compare
a1283ed to
ce7eebb
Compare
| else | ||
| self.disable_fuzzy_search = G_reader_settings:isTrue("disable_fuzzy_search") | ||
| end | ||
| -- Add thw disabled-dictionaries list for this book |
| self.disable_fuzzy_search = G_reader_settings:isTrue("disable_fuzzy_search") | ||
| end | ||
| -- Add the disabled-dictionaries list for this book | ||
| self.disabled_dicts_per_book = config:readSetting("disabled_dicts_per_book") or {} |
There was a problem hiding this comment.
The name of this variable and setting sounds strange to me: it's about the current book, but it's named "per_book" and is read from the current book settings: it should just not have any reference to "book" (we don't name our setting margin_for_book, style_tweaks_per_book).
In case you really want this, doesn't "xyz_for_book" sounds better for the current book than "xyz_per_book" ?
(And the comment says enough if one is in doubt - but why the word "add" ?.)
There was a problem hiding this comment.
Because i have been doing this late at night, and should probably proof read it when 100% alert ;), i’ll change it
There was a problem hiding this comment.
I get the same feeling with _by_book ...
It's saved in the book metadata.epub.lua - so there's no need to have _by/for/per_book in here.
I understand that may be (?) in the code, because there are global settings (?) and local book settings that it may be helping to carry the fact in the variable name - but is it really?
There was a problem hiding this comment.
This is about the code, someone reading this in 2 years time needs to know, this disabled is different from the global one. You could not even remember what you wrote in a comment yesterday ;), do you really expect to remember which is the global later on?
There was a problem hiding this comment.
Hm? Globals are G. The distinction normally only matters when initializing (1. use document settings 2. use global 3. use defaults)
There was a problem hiding this comment.
document_disabled_dicts?
There was a problem hiding this comment.
Sounds better.
But just disabled_dicts or dicts_disabled in metadata.epub.lua sounds even better :)
But you could name the variable doc_dicts_disabled or doc_disabled_dicts if you think it helps readability.
| text = _("Set dictionary priority for this book"), | ||
| help_text = _("This feature enables you to specify dictionary priorities on a per-book basis. Results from higher-priority dictionaries will be displayed first when looking up words. Only dictionaries that are currently active can be selected and prioritized."), | ||
| enabled_func = function() | ||
| -- we allow to use preferred dictionaries even if no dictionaries are enabled globally (see self:updateSdcvDictNamesOptions) |
There was a problem hiding this comment.
Strange what this comment says ? If no dict are enabled, why would some of none be used ?!
There was a problem hiding this comment.
just playing by your rules here, you tell me why that is a thing… ;)
koreader/frontend/apps/reader/modules/readerdictionary.lua
Lines 199 to 201 in 68a9a8d
There was a problem hiding this comment.
Oh, didn't remember that.
Does it still make sense ? (Feels like it allowed some workaround for what your PR is doing as its main feature ?) Fine either way.
There was a problem hiding this comment.
I don't think it does but, I will let you come to that conclusion and change the world later on. ;)
6c564b9 to
89ce3e8
Compare
| if self.ui.doc_settings then | ||
| self.ui.doc_settings:saveSetting("preferred_dictionaries", self.preferred_dictionaries) | ||
| self.ui.doc_settings:saveSetting("preferred_dictionaries", next(self.preferred_dictionaries) and self.preferred_dictionaries or nil) | ||
| self.ui.doc_settings:saveSetting("doc_disabled_dicts", next(self.doc_disabled_dicts) and self.doc_disabled_dicts or nil) |
There was a problem hiding this comment.
Again, in metadata.epub.lua, all the settings are related to this document.
All of them could be prefixed with doc_ - but none is ! (except doc_pages and doc_path).
So, please save it just as disabled_dicts - and you can still have it as self.doc_disabled_dicts in this module if you really want it for reading clarity.
There was a problem hiding this comment.
oh my bad, I see what you mean now... sorry!
39e0957 to
0ff617f
Compare
|
anything else here?, I would really like to rebase presets with this on. Also, I think I have been acting in good faith so, I am not entirely sure how to react to certain actions (pun intended) that are occurring at the moment. |
|
@Commodore64user I didn't merge it this morning because your reply made me think there was still an ongoing discussion and I didn't notice the approval right above it. In this specific context "ping" or "bump" is fine. |
what's new
This pull request enhances the
ReaderDictionarymodule by introducing functionality to manage dictionary preferences on a per-book basis. It allows users to prioritise dictionaries and disable specific dictionaries for individual books.showPreferredDictsDialogmethod: This dialog allows users to prioritise active dictionaries and toggle their enabled/disabled state for the current book. Disabled dictionaries are visually marked and placed at the bottom of the list.addToMainMenumethod: Introduced a new menu item, "Set dictionary priority for this book," which opens the dictionary preferences dialog. This menu item is conditionally displayed based on the document state and the number of active dictionaries.stardictLookupmethod to exclude dictionaries disabled for the current book before performing a lookup.onReadSettingsandonSaveSettingsmethods to load and save the list of disabled dictionaries for each book.ButtonDialogdependency to support the new preferences dialog.screenshots
Expand to see some footage
related issues
This change is