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 2 commits
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")
@@ -23,6 +24,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local PluginLoader = require("pluginloader")
local ReadCollection = require("readcollection")
local ReaderDeviceStatus = require("apps/reader/modules/readerdevicestatus")
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
local ReaderGesture = require("apps/reader/modules/readergesture")
@@ -288,25 +290,27 @@ 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 or #(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 ReadCollection:checkItemExist(file, "favorites") then
return _("Remove from favorites")
else
return _("Add to favorites")
end
end,
enabled = DocumentRegistry:getProviders(file) ~= nil,
callback = function()
if ReadCollection:checkItemExist(file, "favorites") then
ReadCollection:removeItem(file, "favorites")
else
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,10 +720,11 @@ 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.
local dest_file = string.format("%s/%s", dest, util.basename(orig))
require("readhistory"):updateItemByPath(orig, dest_file)
--update last open file
ReadCollection:updateItemByPath(orig, dest_file)
-- Update last open file.
if G_reader_settings:readSetting("lastfile") == orig then
G_reader_settings:saveSetting("lastfile", dest_file)
end
@@ -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,7 @@ function FileManager:deleteFile(file)
end
doc_settings:purge()
end
ReadCollection:removeItemByPath(file, is_dir)
UIManager:show(InfoMessage:new{
text = util.template(_("Deleted %1"), file),
timeout = 2,
@@ -804,6 +832,7 @@ 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
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 ReadCollection = require("readcollection")
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)
menu_items.collections = {
text = self.coll_menu_title,
callback = function()
self:onShowColl("favorites")
end,
}
end

function FileManagerCollection:updateItemTable()
-- Try to stay on 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,
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
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()
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.