@ -480,6 +480,21 @@ function ReaderUI:showFileManager(file)
end
end
end
end
function ReaderUI : onShowingReader ( )
-- Allows us to optimize out a few useless refreshes in various CloseWidgets handlers...
self.tearing_down = true
self.dithered = nil
self : onClose ( )
end
-- Same as above, except we don't close it yet. Useful for plugins that need to close custom Menus before calling showReader.
function ReaderUI : onSetupShowReader ( )
self.tearing_down = true
self.dithered = nil
end
--- @note: Will sanely close existing FileManager/ReaderUI instance for you!
function ReaderUI : showReader ( file , provider )
function ReaderUI : showReader ( file , provider )
logger.dbg ( " show reader ui " )
logger.dbg ( " show reader ui " )
@ -497,6 +512,10 @@ function ReaderUI:showReader(file, provider)
self : showFileManager ( file )
self : showFileManager ( file )
return
return
end
end
-- We can now signal the existing ReaderUI/FileManager instances that it's time to go bye-bye...
UIManager : broadcastEvent ( Event : new ( " ShowingReader " ) )
-- prevent crash due to incompatible bookmarks
-- prevent crash due to incompatible bookmarks
--- @todo Split bookmarks from metadata and do per-engine in conversion.
--- @todo Split bookmarks from metadata and do per-engine in conversion.
provider = provider or DocumentRegistry : getProvider ( file )
provider = provider or DocumentRegistry : getProvider ( file )
@ -550,7 +569,7 @@ end
local _running_instance = nil
local _running_instance = nil
function ReaderUI : doShowReader ( file , provider )
function ReaderUI : doShowReader ( file , provider )
logger.info ( " opening file " , file )
logger.info ( " opening file " , file )
-- k eep only one instance running
-- K eep only one instance running
if _running_instance then
if _running_instance then
_running_instance : onClose ( )
_running_instance : onClose ( )
end
end
@ -591,12 +610,17 @@ function ReaderUI:doShowReader(file, provider)
end
end
Device : notifyBookState ( title , document )
Device : notifyBookState ( title , document )
UIManager : show ( reader )
-- This is mostly for the few callers that bypass the coroutine shenanigans and call doShowReader directly,
_running_instance = reader
-- instead of showReader...
-- Otherwise, showReader will have taken care of that *before* instantiating a new RD,
-- in order to ensure a sane ordering of plugins teardown -> instantiation.
local FileManager = require ( " apps/filemanager/filemanager " )
local FileManager = require ( " apps/filemanager/filemanager " )
if FileManager.instance then
if FileManager.instance then
FileManager.instance : onClose ( )
FileManager.instance : onClose ( )
end
end
UIManager : show ( reader )
_running_instance = reader
end
end
function ReaderUI : _getRunningInstance ( )
function ReaderUI : _getRunningInstance ( )
@ -756,6 +780,11 @@ end
function ReaderUI : reloadDocument ( after_close_callback )
function ReaderUI : reloadDocument ( after_close_callback )
local file = self.document . file
local file = self.document . file
local provider = getmetatable ( self.document ) . __index
local provider = getmetatable ( self.document ) . __index
-- Mimic onShowingReader's refresh optimizations
self.tearing_down = true
self.dithered = nil
self : handleEvent ( Event : new ( " CloseReaderMenu " ) )
self : handleEvent ( Event : new ( " CloseReaderMenu " ) )
self : handleEvent ( Event : new ( " CloseConfigMenu " ) )
self : handleEvent ( Event : new ( " CloseConfigMenu " ) )
self.highlight : onClose ( ) -- close highlight dialog if any
self.highlight : onClose ( ) -- close highlight dialog if any
@ -764,15 +793,22 @@ function ReaderUI:reloadDocument(after_close_callback)
-- allow caller to do stuff between close an re-open
-- allow caller to do stuff between close an re-open
after_close_callback ( file , provider )
after_close_callback ( file , provider )
end
end
self : showReader ( file , provider )
self : showReader ( file , provider )
end
end
function ReaderUI : switchDocument ( new_file )
function ReaderUI : switchDocument ( new_file )
if not new_file then return end
if not new_file then return end
-- Mimic onShowingReader's refresh optimizations
self.tearing_down = true
self.dithered = nil
self : handleEvent ( Event : new ( " CloseReaderMenu " ) )
self : handleEvent ( Event : new ( " CloseReaderMenu " ) )
self : handleEvent ( Event : new ( " CloseConfigMenu " ) )
self : handleEvent ( Event : new ( " CloseConfigMenu " ) )
self.highlight : onClose ( ) -- close highlight dialog if any
self.highlight : onClose ( ) -- close highlight dialog if any
self : onClose ( false )
self : onClose ( false )
self : showReader ( new_file )
self : showReader ( new_file )
end
end