From e97770d8ae90c1fe7fe362993d48d1d8a624ac4b Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 20 Oct 2012 13:53:57 +0100 Subject: [PATCH] Alt-R to switch between STANDARD and KOPTReader Currently it closes the file and drops you back to the filemanager, so you have to re-open it manually. --- extentions.lua | 18 +++++++++++------- reader.lua | 3 +++ unireader.lua | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/extentions.lua b/extentions.lua index 2d9a3525b..84c0afd71 100644 --- a/extentions.lua +++ b/extentions.lua @@ -1,7 +1,6 @@ -- List of acceptable extensions ext = { - koptRead = ";djvu;pdf;", djvuRead = ";djvu;", pdfRead = ";pdf;xps;cbz;", creRead = ";epub;txt;rtf;htm;html;mobi;prc;azw;fb2;chm;pdb;doc;tcr;zip;", @@ -10,17 +9,22 @@ ext = { } -function ext:getReader(ftype) +function ext:getReader(ftype, oldreader) local s = ";" if ftype == "" then return nil - -- for testing use koptreader for djvu/pdf files by default - elseif string.find(self.koptRead,s..ftype..s) then - return KOPTReader elseif string.find(self.pdfRead,s..ftype..s) then - return PDFReader + if oldreader and oldreader.use_koptreader == true then + return KOPTReader + else + return PDFReader + end elseif string.find(self.djvuRead,s..ftype..s) then - return DJVUReader + if oldreader and oldreader.use_koptreader then + return KOPTReader + else + return DJVUReader + end elseif string.find(self.picRead,s..ftype..s) then return PICViewer elseif FileChooser.filemanager_expert_mode > FileChooser.BEGINNERS_MODE diff --git a/reader.lua b/reader.lua index 3fcc1af0e..dd901ff25 100755 --- a/reader.lua +++ b/reader.lua @@ -46,6 +46,9 @@ function openFile(filename) if reader then InfoMessage:inform("Opening document... ", nil, 0, MSG_AUX) reader:preLoadSettings(filename) + -- re-establish the reader due to use_koptreader setting + reader = ext:getReader(file_type, reader) + reader:preLoadSettings(filename) local ok, err = reader:open(filename) if ok then reader:loadSettings(filename) diff --git a/unireader.lua b/unireader.lua index c8adca218..87579f7a0 100644 --- a/unireader.lua +++ b/unireader.lua @@ -68,6 +68,7 @@ UniReader = { show_overlap = 0, show_overlap_enable, show_links_enable, + use_koptreader, -- the document: doc = nil, @@ -949,6 +950,12 @@ end function UniReader:preLoadSettings(filename) self.settings = DocSettings:open(filename) self.cache_document_size = self.settings:readSetting("cache_document_size") or self.cache_document_size + + local tmp = self.settings:readSetting("use_koptreader") + if tmp ~= nil then + self.use_koptreader = tmp + print("set use_koptreader=", self.use_koptreader) + end end -- all defaults which can be overriden by reader objects @@ -956,6 +963,7 @@ end function UniReader:setDefaults() self.show_overlap_enable = true self.show_links_enable = true + self.use_koptreader = false end -- This is a low-level method that can be shared with all readers. @@ -2621,6 +2629,21 @@ function UniReader:addAllCommands() self:redrawCurrentPage() end) + self.commands:add(KEY_R, MOD_ALT, "R", + "toggle between standard and koptreader", + function(unireader) + unireader.use_koptreader = not unireader.use_koptreader + if unireader.use_koptreader then + InfoMessage:inform("Switching to KOPTReader", 1000, 1, MSG_AUX) + else + InfoMessage:inform("Switching to STANDARD Reader", 1000, 1, MSG_AUX) + end + self.settings:saveSetting("use_koptreader", unireader.use_koptreader) + self.doc:close() + self.doc = nil + return "break" + end) + self.commands:add(KEY_R, MOD_SHIFT, "R", "set full screen refresh count", function(unireader)