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

Add book to favorites #5527

Merged
merged 7 commits into from Nov 5, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -9,6 +9,7 @@ local DocumentRegistry = require("document/documentregistry")
local Event = require("ui/event")
local FileChooser = require("ui/widget/filechooser")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local FileManagerCollection = require("apps/filemanager/filemanagercollection")
local FileManagerConverter = require("apps/filemanager/filemanagerconverter")
local FileManagerFileSearcher = require("apps/filemanager/filemanagerfilesearcher")
local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
@@ -288,25 +289,28 @@ function FileManager:init()
},
-- a little hack to get visual functionality grouping
{},
{
}
if lfs.attributes(file, "mode") == "file" then
table.insert(buttons, {
{
text = _("Open with…"),
enabled = lfs.attributes(file, "mode") == "file" and (DocumentRegistry:getProviders(file) == nil
or #(DocumentRegistry:getProviders(file)) > 1),
enabled = DocumentRegistry:getProviders(file) ~= nil

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member

What's the relation between this change and #5497? At a glance it looks like an accidental reversal?

This comment has been minimized.

Copy link
@robert00s

robert00s Oct 24, 2019

Author Contributor

Yes, you're right. This was taken from commit before #5497.

and #(DocumentRegistry:getProviders(file)) > 1,
callback = function()
UIManager:close(self.file_dialog)
self:showSetProviderButtons(file, FileManager.instance, ReaderUI)
end,
},
{
text = _("Convert"),
enabled = lfs.attributes(file, "mode") == "file"
and FileManagerConverter:isSupported(file),
enabled = FileManagerConverter:isSupported(file),
callback = function()
UIManager:close(self.file_dialog)
FileManagerConverter:showConvertButtons(file, self)
end,
},
})
table.insert(buttons, {
{
text = _("Book information"),
enabled = FileManagerBookInfo:isSupported(file),
@@ -315,8 +319,26 @@ function FileManager:init()
UIManager:close(self.file_dialog)
end,
},
},
}
{
text_func = function()
if require("readcollection"):checkItemExist(file, "favorites") then
return _("Remove from favorites")
else
return _("Add to favorites")
end
end,
enabled = DocumentRegistry:getProviders(file) ~= nil,
callback = function()
if require("readcollection"):checkItemExist(file, "favorites") then

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member

While the results of require are cached, it should still be preferable to do local ReadCollection = require(…). (And it should be fine at the top of the file I figure?)

require("readcollection"):removeItem(file, "favorites")
else
require("readcollection"):addItem(file, "favorites")
end
UIManager:close(self.file_dialog)
end,
},
})
end
if lfs.attributes(file, "mode") == "directory" then
local realpath = util.realpath(file)
table.insert(buttons, {
@@ -361,6 +383,9 @@ function FileManager:init()
table.insert(self, FileManagerHistory:new{
ui = self,
})
table.insert(self, FileManagerCollection:new{
ui = self,
})
table.insert(self, FileManagerFileSearcher:new{ ui = self })
table.insert(self, FileManagerShortcuts:new{ ui = self })
table.insert(self, ReaderDictionary:new{ ui = self })
@@ -695,9 +720,10 @@ function FileManager:pasteHere(file)
self:moveFile(DocSettings:getSidecarDir(orig), dest) -- dest is always a directory
end
if self:moveFile(orig, dest) then
--update history
--update history and collections

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member

If we're updating comments, they like to be proper sentences. ;-)

Suggested change
--update history and collections
-- Update history and collections.
local dest_file = string.format("%s/%s", dest, util.basename(orig))
require("readhistory"):updateItemByPath(orig, dest_file)
require("readcollection"):updateItemByPath(orig, dest_file)
--update last open file
if G_reader_settings:readSetting("lastfile") == orig then
G_reader_settings:saveSetting("lastfile", dest_file)
@@ -764,7 +790,7 @@ function FileManager:createFolder(curr_folder, new_folder)
end

function FileManager:deleteFile(file)
local ok, err
local ok, err, is_dir
local file_abs_path = util.realpath(file)
if file_abs_path == nil then
UIManager:show(InfoMessage:new{
@@ -778,6 +804,7 @@ function FileManager:deleteFile(file)
ok, err = os.remove(file_abs_path)
else
ok, err = util.purgeDir(file_abs_path)
is_dir = true
end
if ok and not err then
if is_doc then
@@ -789,6 +816,8 @@ function FileManager:deleteFile(file)
end
doc_settings:purge()
end
--remove from collections

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member

Seems slightly redundant with the code.

Suggested change
--remove from collections
require("readcollection"):removeItemByPath(file, is_dir)
UIManager:show(InfoMessage:new{
text = util.template(_("Deleted %1"), file),
timeout = 2,
@@ -804,6 +833,8 @@ function FileManager:renameFile(file)
if util.basename(file) ~= self.rename_dialog:getInputText() then
local dest = util.joinPath(util.dirname(file), self.rename_dialog:getInputText())
if self:moveFile(file, dest) then
-- update collections

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member
Suggested change
-- update collections
require("readcollection"):updateItemByPath(file, dest)
if lfs.attributes(dest, "mode") == "file" then
local doc = require("docsettings")
local move_history = true;
@@ -0,0 +1,124 @@
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InputContainer = require("ui/widget/container/inputcontainer")
local Menu = require("ui/widget/menu")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local _ = require("gettext")

local FileManagerCollection = InputContainer:extend{
coll_menu_title = _("Favorites"),
}

function FileManagerCollection:init()
self.ui.menu:registerToMainMenu(self)
end

function FileManagerCollection:addToMainMenu(menu_items)
-- insert table to main tab of filemanager menu

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member

Well, technically just wherever MenuSorter is told to put it by the user. ;-)

But this is the same as every addToMainMenu function; I don't think a comment adds much?

Suggested change
-- insert table to main tab of filemanager menu
menu_items.collections = {
text = self.coll_menu_title,
callback = function()
self:onShowColl("favorites")
end,
}
end

function FileManagerCollection:updateItemTable()
-- try to stay on current page

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member
Suggested change
-- try to stay on current page
-- Try to stay on current page.

This comment has been minimized.

Copy link
@Frenzie

Frenzie Oct 24, 2019

Member

Actually that should be the current page.

local select_number = nil
if self.coll_menu.page and self.coll_menu.perpage then
select_number = (self.coll_menu.page - 1) * self.coll_menu.perpage + 1
end
self.coll_menu:switchItemTable(self.coll_menu_title,
require("readcollection"):prepareList(self.coll_menu.collection), select_number)
end

function FileManagerCollection:onMenuHold(item)
local collfile_dialog = nil
local buttons = {
{
{
text = _("Sort"),
callback = function()
UIManager:close(collfile_dialog)
local item_table = {}
for i=1, #self._manager.coll_menu.item_table do
table.insert(item_table, {text = self._manager.coll_menu.item_table[i].text, label = self._manager.coll_menu.item_table[i].file})
end
local SortWidget = require("ui/widget/sortwidget")
local sort_item
sort_item = SortWidget:new{
title = _("Sort favorites book"),

This comment has been minimized.

Copy link
@poire-z

poire-z Oct 31, 2019

Contributor

Sort favorite books or just Sort favorites

item_table = item_table,
callback = function()
local new_order_table = {}
for i=1, #sort_item.item_table do
table.insert(new_order_table, {
file = sort_item.item_table[i].label,
order = i
})
end
require("readcollection"):writeCollection(new_order_table, self._manager.coll_menu.collection)
self._manager:updateItemTable()
end
}
UIManager:show(sort_item)

end,
},
{
text = _("Remove from collection"),
callback = function()
require("readcollection"):removeItem(item.file, self._manager.coll_menu.collection)
self._manager:updateItemTable()
UIManager:close(collfile_dialog)
end,
},
},
{
{
text = _("Book information"),
enabled = FileManagerBookInfo:isSupported(item.file),
callback = function()
FileManagerBookInfo:show(item.file)
Comment on lines +81 to +84

This comment has been minimized.

Copy link
@poire-z

poire-z Oct 31, 2019

Contributor

Later, you might want to tweak the onHold dialog when the user uses a CoverBrowser mode, like we did for History in:

-- Similar to onFileHold setup just above, but for History,
-- which is plugged in main.lua _FileManagerHistory_updateItemTable()
function CoverMenu:onHistoryMenuHold(item)

so we have the other buttons like View book description, View full size cover...

UIManager:close(collfile_dialog)
end,
},
},
}
collfile_dialog = ButtonDialogTitle:new{
title = item.text:match("([^/]+)$"),
title_align = "center",
buttons = buttons,
}
UIManager:show(collfile_dialog)
return true
end

function FileManagerCollection:onShowColl(collection)
self.coll_menu = Menu:new{
ui = self.ui,
width = Screen:getWidth(),
height = Screen:getHeight(),
covers_fullscreen = true, -- hint for UIManager:_repaint()
is_borderless = true,
is_popout = false,
onMenuHold = self.onMenuHold,
_manager = self,
collection = collection,
}
self:updateItemTable()
self.coll_menu.close_callback = function()
-- Close it at next tick so it stays displayed
-- while a book is opening (avoids a transient
-- display of the underlying File Browser)
UIManager:nextTick(function()
UIManager:close(self.coll_menu)
end)
end
UIManager:show(self.coll_menu)
return true
end

return FileManagerCollection
@@ -11,6 +11,7 @@ local DocSettings = require("docsettings")
local DocumentRegistry = require("document/documentregistry")
local Event = require("ui/event")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local FileManagerCollection = require("apps/filemanager/filemanagercollection")
local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
local FileManagerFileSearcher = require("apps/filemanager/filemanagerfilesearcher")
local FileManagerShortcuts = require("apps/filemanager/filemanagershortcuts")
@@ -351,6 +352,11 @@ function ReaderUI:init()
dialog = self.dialog,
ui = self,
})
-- collections/favorites view
self:registerModule("collections", FileManagerCollection:new{
dialog = self.dialog,
ui = self,
})
-- book info
self:registerModule("bookinfo", FileManagerBookInfo:new{
dialog = self.dialog,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.