diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 31ad62999..545fd7216 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -2,6 +2,7 @@ local BD = require("ui/bidi") local Blitbuffer = require("ffi/blitbuffer") local ButtonDialog = require("ui/widget/buttondialog") local ButtonDialogTitle = require("ui/widget/buttondialogtitle") +local CenterContainer = require("ui/widget/container/centercontainer") local CheckButton = require("ui/widget/checkbutton") local ConfirmBox = require("ui/widget/confirmbox") local Device = require("device") @@ -21,6 +22,7 @@ local InfoMessage = require("ui/widget/infomessage") local InputContainer = require("ui/widget/container/inputcontainer") local InputDialog = require("ui/widget/inputdialog") local LanguageSupport = require("languagesupport") +local Menu = require("ui/widget/menu") local MultiConfirmBox = require("ui/widget/multiconfirmbox") local PluginLoader = require("pluginloader") local ReadCollection = require("readcollection") @@ -514,11 +516,11 @@ function FileManager:tapPlus() buttons = { { { - text = _("Select all files in folder"), + text = _("Show selected files list"), + enabled = actions_enabled, callback = function() UIManager:close(self.file_dialog) - self.file_chooser:selectAllFilesInFolder() - self:onRefresh() + self:showSelectedFilesList() end, }, { @@ -543,11 +545,10 @@ function FileManager:tapPlus() }, { { - text = _("Deselect all"), - enabled = actions_enabled, + text = _("Select all files in folder"), callback = function() UIManager:close(self.file_dialog) - self.selected_files = {} + self.file_chooser:selectAllFilesInFolder() self:onRefresh() end, }, @@ -573,10 +574,12 @@ function FileManager:tapPlus() }, { { - text = _("Exit select mode"), + text = _("Deselect all"), + enabled = actions_enabled, callback = function() UIManager:close(self.file_dialog) - self:onToggleSelectMode() + self.selected_files = {} + self:onRefresh() end, }, { @@ -594,7 +597,23 @@ function FileManager:tapPlus() self:onToggleSelectMode() end, }) - end + end, + }, + }, + { + { + text = _("Exit select mode"), + callback = function() + UIManager:close(self.file_dialog) + self:onToggleSelectMode() + end, + }, + { + text = _("Export highlights"), + enabled = (actions_enabled and self.exporter) and true or false, + callback = function() + self.exporter:exportFilesNotes(self.selected_files) + end, }, }, {}, -- separator @@ -1244,4 +1263,39 @@ function FileManager:onShowFolderMenu() UIManager:show(button_dialog) end +function FileManager:showSelectedFilesList() + local selected_files = {} + for file in pairs(self.selected_files) do + table.insert(selected_files, { text = file }) + end + local function sorting(a, b) + local a_path, a_name = util.splitFilePathName(a.text) + local b_path, b_name = util.splitFilePathName(b.text) + if a_path == b_path then + return BaseUtil.strcoll(a_name, b_name) + end + return BaseUtil.strcoll(a_path, b_path) + end + table.sort(selected_files, sorting) + + local menu_container = CenterContainer:new{ + dimen = Screen:getSize(), + } + local menu = Menu:new{ + is_borderless = true, + is_popout = false, + show_parent = menu_container, + onMenuSelect = function(_, item) + UIManager:close(menu_container) + self.file_chooser:changeToPath(util.splitFilePathName(item.text), item.text) + end, + close_callback = function() + UIManager:close(menu_container) + end, + } + table.insert(menu_container, menu) + menu:switchItemTable(T(_("Selected files (%1)"), #selected_files), selected_files) + UIManager:show(menu_container) +end + return FileManager diff --git a/plugins/exporter.koplugin/clip.lua b/plugins/exporter.koplugin/clip.lua index 788ae5c2d..c02cfaa83 100644 --- a/plugins/exporter.koplugin/clip.lua +++ b/plugins/exporter.koplugin/clip.lua @@ -328,6 +328,16 @@ function MyClipping:parseHistory() return clippings end +function MyClipping:parseFiles(files) + local clippings = {} + for file in pairs(files) do + if DocSettings:hasSidecarFile(file) then + self:getClippingsFromBook(clippings, file) + end + end + return clippings +end + function MyClipping:getProps(file) local document = DocumentRegistry:openDocument(file) local book_props = nil diff --git a/plugins/exporter.koplugin/main.lua b/plugins/exporter.koplugin/main.lua index 3e3ccedf3..e234d6602 100644 --- a/plugins/exporter.koplugin/main.lua +++ b/plugins/exporter.koplugin/main.lua @@ -150,11 +150,14 @@ function Exporter:getDocumentClippings() return self.parser:parseCurrentDoc(self.view) or {} end +--- Parse and export highlights from the currently opened document. function Exporter:exportCurrentNotes() local clippings = self:getDocumentClippings() self:exportClippings(clippings) end +--- Parse and export highlights from all the documents in History +-- and from the Kindle "My Clippings.txt". function Exporter:exportAllNotes() local clippings = {} clippings = updateHistoryClippings(clippings, self.parser:parseHistory()) @@ -170,6 +173,19 @@ function Exporter:exportAllNotes() self:exportClippings(clippings) end +--- Parse and export highlights from selected documents. +-- @tparam table files list of files as a table of {[file_path] = true} +function Exporter:exportFilesNotes(files) + local clippings = self.parser:parseFiles(files) + for title, booknotes in pairs(clippings) do + -- chapter number is zero + if #booknotes == 0 then + clippings[title] = nil + end + end + self:exportClippings(clippings) +end + function Exporter:exportClippings(clippings) if type(clippings) ~= "table" then return end local exportables = {}