@ -2,10 +2,14 @@
This module contains miscellaneous helper functions for FileManager
] ]
local BD = require ( " ui/bidi " )
local ConfirmBox = require ( " ui/widget/confirmbox " )
local Device = require ( " device " )
local DocSettings = require ( " docsettings " )
local UIManager = require ( " ui/uimanager " )
local util = require ( " ffi/util " )
local _ = require ( " gettext " )
local T = util.template
local filemanagerutil = { }
@ -59,7 +63,7 @@ function filemanagerutil.resetDocumentSettings(file)
end
end
doc_settings : makeTrue ( " docsettings_reset_done " ) -- for readertypeset block_rendering_mode
doc_settings : close ( )
doc_settings : flush ( )
end
end
@ -127,11 +131,49 @@ function filemanagerutil.genStatusButton(to_status, current_status, file, caller
end
-- Generate all book status file dialog buttons in a row
function filemanagerutil . getStatusButtonsRow ( current_status , file , caller_callback )
function filemanagerutil . getStatusButtonsRow ( file , caller_callback )
local function genStatusButton ( to_status , current_status )
local status_text = {
reading = _ ( " Reading " ) ,
abandoned = _ ( " On hold " ) ,
complete = _ ( " Finished " ) ,
}
return {
text = status_text [ to_status ] ,
id = to_status , -- used by covermenu
enabled = current_status ~= to_status ,
callback = function ( )
filemanagerutil.setStatus ( file , to_status )
caller_callback ( )
end ,
}
end
local status = filemanagerutil.getStatus ( file )
return {
filemanagerutil.genStatusButton ( " reading " , current_status , file , caller_callback ) ,
filemanagerutil.genStatusButton ( " abandoned " , current_status , file , caller_callback ) ,
filemanagerutil.genStatusButton ( " complete " , current_status , file , caller_callback ) ,
genStatusButton ( " reading " , status , file , caller_callback ) ,
genStatusButton ( " abandoned " , status , file , caller_callback ) ,
genStatusButton ( " complete " , status , file , caller_callback ) ,
}
end
-- Generate a "Reset settings" file dialog button
function filemanagerutil . genResetSettingsButton ( file , currently_opened_file , caller_callback )
return {
text = _ ( " Reset " ) ,
id = " reset " , -- used by covermenu
enabled = file ~= currently_opened_file and DocSettings : hasSidecarFile ( util.realpath ( file ) ) ,
callback = function ( )
UIManager : show ( ConfirmBox : new {
text = T ( _ ( " Reset this document? \n \n %1 \n \n All document progress, settings, bookmarks, highlights, and notes will be permanently lost. " ) ,
BD.filepath ( file ) ) ,
ok_text = _ ( " Reset " ) ,
ok_callback = function ( )
filemanagerutil.purgeSettings ( file )
require ( " readhistory " ) : fileSettingsPurged ( file )
caller_callback ( )
end ,
} )
end ,
}
end