mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Exporter: export to book folder, register to Dispatcher (#12569)
This commit is contained in:
@@ -27,6 +27,7 @@ The parser looks to bookmarks._.text field for edited notes. bookmarks._.notes i
|
||||
|
||||
local DataStorage = require("datastorage")
|
||||
local Device = require("device")
|
||||
local Dispatcher = require("dispatcher")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local MyClipping = require("clip")
|
||||
local NetworkMgr = require("ui/network/manager")
|
||||
@@ -115,13 +116,19 @@ local Exporter = WidgetContainer:extend{
|
||||
|
||||
function Exporter:init()
|
||||
migrateSettings()
|
||||
self.parser = MyClipping:new {
|
||||
history_dir = DataStorage:getDataDir() .. "/history",
|
||||
}
|
||||
for k, _ in pairs(self.targets) do
|
||||
self.targets[k].path = self.path
|
||||
self.parser = MyClipping:new{}
|
||||
for _, v in pairs(self.targets) do
|
||||
v.path = self.path
|
||||
end
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
self:onDispatcherRegisterActions()
|
||||
end
|
||||
|
||||
function Exporter:onDispatcherRegisterActions()
|
||||
Dispatcher:registerAction("export_current_notes",
|
||||
{category="none", event="ExportCurrentNotes", title=_("Export all notes in current book"), reader=true,})
|
||||
Dispatcher:registerAction("export_all_notes",
|
||||
{category="none", event="ExportAllNotes", title=_("Export all notes in all books in history"), reader=true, filemanager=true})
|
||||
end
|
||||
|
||||
function Exporter:isReady()
|
||||
@@ -134,7 +141,7 @@ function Exporter:isReady()
|
||||
end
|
||||
|
||||
function Exporter:isDocReady()
|
||||
return self.ui and self.ui.document and self.view or false
|
||||
return self.ui.document and true or false
|
||||
end
|
||||
|
||||
function Exporter:isReadyToExport()
|
||||
@@ -156,7 +163,8 @@ function Exporter:getDocumentClippings()
|
||||
end
|
||||
|
||||
--- Parse and export highlights from the currently opened document.
|
||||
function Exporter:exportCurrentNotes()
|
||||
function Exporter:onExportCurrentNotes()
|
||||
if not self:isReadyToExport() then return end
|
||||
self.ui.annotation:updatePageNumbers(true)
|
||||
local clippings = self:getDocumentClippings()
|
||||
self:exportClippings(clippings)
|
||||
@@ -164,7 +172,8 @@ end
|
||||
|
||||
--- Parse and export highlights from all the documents in History
|
||||
-- and from the Kindle "My Clippings.txt".
|
||||
function Exporter:exportAllNotes()
|
||||
function Exporter:onExportAllNotes()
|
||||
if not self:isReady() then return end
|
||||
local clippings = {}
|
||||
clippings = updateHistoryClippings(clippings, self.parser:parseHistory())
|
||||
if Device:isKindle() then
|
||||
@@ -224,7 +233,7 @@ function Exporter:exportClippings(clippings)
|
||||
})
|
||||
end)
|
||||
|
||||
UIManager:show(InfoMessage:new {
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Exporting may take several seconds…"),
|
||||
timeout = 1,
|
||||
})
|
||||
@@ -284,12 +293,12 @@ function Exporter:addToMainMenu(menu_items)
|
||||
text = _("Export highlights"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Export all notes in this book"),
|
||||
text = _("Export all notes in curent book"),
|
||||
enabled_func = function()
|
||||
return self:isReadyToExport()
|
||||
end,
|
||||
callback = function()
|
||||
self:exportCurrentNotes()
|
||||
self:onExportCurrentNotes()
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -298,7 +307,7 @@ function Exporter:addToMainMenu(menu_items)
|
||||
return self:isReady()
|
||||
end,
|
||||
callback = function()
|
||||
self:exportAllNotes()
|
||||
self:onExportAllNotes()
|
||||
end,
|
||||
separator = #share_submenu == 0,
|
||||
},
|
||||
@@ -309,6 +318,7 @@ function Exporter:addToMainMenu(menu_items)
|
||||
{
|
||||
text = _("Choose highlight styles"),
|
||||
sub_item_table = styles_submenu,
|
||||
separator = true,
|
||||
},
|
||||
{
|
||||
text = _("Choose export folder"),
|
||||
@@ -317,6 +327,15 @@ function Exporter:addToMainMenu(menu_items)
|
||||
self:chooseFolder()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Use book folder for single export"),
|
||||
checked_func = function()
|
||||
return settings.clipping_dir_book
|
||||
end,
|
||||
callback = function()
|
||||
settings.clipping_dir_book = not settings.clipping_dir_book or nil
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
if #share_submenu > 0 then
|
||||
@@ -342,9 +361,6 @@ function Exporter:chooseFolder()
|
||||
local default_path = DataStorage:getFullDataDir() .. "/clipboard"
|
||||
local caller_callback = function(path)
|
||||
settings.clipping_dir = path
|
||||
for _, target in pairs(self.targets) do
|
||||
target.clipping_dir = path
|
||||
end
|
||||
end
|
||||
filemanagerutil.showChooseDialog(title_header, caller_callback, current_path, default_path)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user